Merge pull request #193 from GoBJIuH/fixpr
Fixed gelbooru, added safebooru and rule34xxx
This commit is contained in:
commit
5471012504
@ -196,22 +196,46 @@ namespace NadekoBot.Classes {
|
|||||||
$"{matches[rng.Next(0, matches.Count)].Groups["id"].Value}";
|
$"{matches[rng.Next(0, matches.Count)].Groups["id"].Value}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string> GetGelbooruImageLink(string tag) {
|
public static async Task<string> GetGelbooruImageLink(string tag)
|
||||||
|
{
|
||||||
|
var url =
|
||||||
|
$"http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
||||||
|
var webpage = await GetResponseStringAsync(url);
|
||||||
|
var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
|
||||||
|
if (matches.Count == 0)
|
||||||
|
throw new FileNotFoundException();
|
||||||
|
var rng = new Random();
|
||||||
|
var match = matches[rng.Next(0, matches.Count)];
|
||||||
|
return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<string> GetSafebooruImageLink(string tag)
|
||||||
|
{
|
||||||
var rng = new Random();
|
var rng = new Random();
|
||||||
var url =
|
var url =
|
||||||
$"http://gelbooru.com/index.php?page=post&s=list&pid={rng.Next(0, 10) * 42}&tags={tag.Replace(" ", "_")}";
|
$"http://safebooru.org/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
||||||
var webpage = await GetResponseStringAsync(url); // first extract the post id and go to that posts page
|
var webpage = await GetResponseStringAsync(url);
|
||||||
//src="htp://gelbooru.com/thumbnails/1b/5e/thumbnail_1b5e1dae36237ef0cd030575b93b5bd2.jpg?3064956"
|
var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
|
||||||
var matches = Regex.Matches(webpage, @"src=\""http:\/\/gelbooru\.com\/thumbnails\/" +
|
|
||||||
@"(?<folder>.*\/.*?)\/thumbnail_(?<id>.*?)\""");
|
|
||||||
if (matches.Count == 0)
|
if (matches.Count == 0)
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
var match = matches[rng.Next(0, matches.Count)];
|
var match = matches[rng.Next(0, matches.Count)];
|
||||||
//http://simg4.gelbooru.com//images/58/20/58209047098e86c2f96c323fb85b8691.jpg?3076643
|
return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
||||||
return $"http://simg4.gelbooru.com//images/" +
|
|
||||||
$"{match.Groups["folder"]}/{match.Groups["id"]}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<string> GetRule34ImageLink(string tag)
|
||||||
|
{
|
||||||
|
var rng = new Random();
|
||||||
|
var url =
|
||||||
|
$"http://rule34.xxx/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
||||||
|
var webpage = await GetResponseStringAsync(url);
|
||||||
|
var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
|
||||||
|
if (matches.Count == 0)
|
||||||
|
throw new FileNotFoundException();
|
||||||
|
var match = matches[rng.Next(0, matches.Count)];
|
||||||
|
return "http:" + matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static async Task<string> GetE621ImageLink(string tags) {
|
internal static async Task<string> GetE621ImageLink(string tags) {
|
||||||
var rng = new Random();
|
var rng = new Random();
|
||||||
var url = $"https://e621.net/post/index/{rng.Next(0, 5)}/{Uri.EscapeUriString(tags)}";
|
var url = $"https://e621.net/post/index/{rng.Next(0, 5)}/{Uri.EscapeUriString(tags)}";
|
||||||
|
@ -38,6 +38,20 @@ namespace NadekoBot.Modules {
|
|||||||
var tag = e.GetArg("tag")?.Trim() ?? "";
|
var tag = e.GetArg("tag")?.Trim() ?? "";
|
||||||
await e.Channel.SendMessage(await SearchHelper.GetGelbooruImageLink(tag));
|
await e.Channel.SendMessage(await SearchHelper.GetGelbooruImageLink(tag));
|
||||||
});
|
});
|
||||||
|
cgb.CreateCommand(Prefix + "safebooru")
|
||||||
|
.Description("Shows a random image from safebooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)\n**Usage**: ~gelbooru yuri+kissing")
|
||||||
|
.Parameter("tag", ParameterType.Unparsed)
|
||||||
|
.Do(async e => {
|
||||||
|
var tag = e.GetArg("tag")?.Trim() ?? "";
|
||||||
|
await e.Channel.SendMessage(await SearchHelper.GetSafebooruImageLink(tag));
|
||||||
|
});
|
||||||
|
cgb.CreateCommand(Prefix + "rule34")
|
||||||
|
.Description("Shows a random image from rule34.xx with a given tag. Tag is optional but preffered. (multiple tags are appended with +)\n**Usage**: ~gelbooru yuri+kissing")
|
||||||
|
.Parameter("tag", ParameterType.Unparsed)
|
||||||
|
.Do(async e => {
|
||||||
|
var tag = e.GetArg("tag")?.Trim() ?? "";
|
||||||
|
await e.Channel.SendMessage(await SearchHelper.GetRule34ImageLink(tag));
|
||||||
|
});
|
||||||
cgb.CreateCommand(Prefix + "e621")
|
cgb.CreateCommand(Prefix + "e621")
|
||||||
.Description("Shows a random hentai image from e621.net with a given tag. Tag is optional but preffered. Use spaces for multiple tags.\n**Usage**: ~e621 yuri+kissing")
|
.Description("Shows a random hentai image from e621.net with a given tag. Tag is optional but preffered. Use spaces for multiple tags.\n**Usage**: ~e621 yuri+kissing")
|
||||||
.Parameter("tag", ParameterType.Unparsed)
|
.Parameter("tag", ParameterType.Unparsed)
|
||||||
|
Loading…
Reference in New Issue
Block a user