Add Yande.re search
This commit is contained in:
parent
09d90e4a03
commit
769d034eab
@ -386,6 +386,20 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
||||
await channel.SendMessageAsync($"https://images.google.com/searchbyimage?image_url={imageLink}").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Yandere(IUserMessage umsg, [Remainder] string tag = null)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
tag = tag?.Trim() ?? "";
|
||||
var link = await GetYandereImageLink(tag).ConfigureAwait(false);
|
||||
if (link == null)
|
||||
await channel.SendMessageAsync("`No results.`");
|
||||
else
|
||||
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Safebooru(IUserMessage umsg, [Remainder] string tag = null)
|
||||
@ -478,6 +492,22 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
||||
await channel.SendMessageAsync(await _google.ShortenUrl(usr.AvatarUrl).ConfigureAwait(false)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static async Task<string> GetYandereImageLink(string tag)
|
||||
{
|
||||
var rng = new NadekoRandom();
|
||||
var url =
|
||||
$"https://yande.re/post.xml?limit=100&tags={tag.Replace(" ", "_")}";
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
var webpage = await http.GetStringAsync(url).ConfigureAwait(false);
|
||||
var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
|
||||
if (matches.Count == 0)
|
||||
return null;
|
||||
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 NadekoRandom();
|
||||
|
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -7753,5 +7753,32 @@ namespace NadekoBot.Resources {
|
||||
return ResourceManager.GetString("youtube_usage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to yandere.
|
||||
/// </summary>
|
||||
public static string yandere_cmd {
|
||||
get {
|
||||
return ResourceManager.GetString("yandere_cmd", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Shows a random image from yandere with a given tag. Tag is optional but preferred. (multiple tags are appended with +).
|
||||
/// </summary>
|
||||
public static string yandere_desc {
|
||||
get {
|
||||
return ResourceManager.GetString("yandere_desc", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to `{0}yandere tag1+tag2`.
|
||||
/// </summary>
|
||||
public static string yandere_usage {
|
||||
get {
|
||||
return ResourceManager.GetString("yandere_usage", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2682,4 +2682,13 @@
|
||||
<data name="bfu_usage" xml:space="preserve">
|
||||
<value>`{0}bfu platform game user`</value>
|
||||
</data>
|
||||
<data name="yandere_cmd" xml:space="preserve">
|
||||
<value>yandere</value>
|
||||
</data>
|
||||
<data name="yandere_desc" xml:space="preserve">
|
||||
<value>Shows a random image from yandere with a given tag. Tag is optional but preferred. (multiple tags are appended with +)</value>
|
||||
</data>
|
||||
<data name="yandere_usage" xml:space="preserve">
|
||||
<value>`{0}yandere tag1+tag2`</value>
|
||||
</data>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user