Searches.cs prettified with embeds ✨
This commit is contained in:
parent
b3635ae577
commit
b907f1bf2f
@ -1,4 +1,6 @@
|
|||||||
using Newtonsoft.Json;
|
using Discord;
|
||||||
|
using Discord.API;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -32,6 +34,17 @@ namespace NadekoBot.Modules.Searches.Commands.OMDB
|
|||||||
public string Plot { get; set; }
|
public string Plot { get; set; }
|
||||||
public string Poster { get; set; }
|
public string Poster { get; set; }
|
||||||
|
|
||||||
|
public Embed GetEmbed() =>
|
||||||
|
new EmbedBuilder().WithColor(NadekoBot.OkColor)
|
||||||
|
.WithTitle(Title)
|
||||||
|
.WithUrl($"http://www.imdb.com/title/{ImdbId}/")
|
||||||
|
.WithDescription(Plot)
|
||||||
|
.AddField(efb => efb.WithName("Rating").WithValue(ImdbRating).WithIsInline(true))
|
||||||
|
.AddField(efb => efb.WithName("Genre").WithValue(Genre).WithIsInline(true))
|
||||||
|
.AddField(efb => efb.WithName("Year").WithValue(Year).WithIsInline(true))
|
||||||
|
.WithImage(eib => eib.WithUrl(Poster))
|
||||||
|
.Build();
|
||||||
|
|
||||||
public override string ToString() =>
|
public override string ToString() =>
|
||||||
$@"`Title:` {Title}
|
$@"`Title:` {Title}
|
||||||
`Year:` {Year}
|
`Year:` {Year}
|
||||||
|
@ -59,10 +59,13 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var result = (await NadekoBot.Google.GetVideosByKeywordsAsync(query, 1)).FirstOrDefault();
|
var result = (await NadekoBot.Google.GetVideosByKeywordsAsync(query, 1)).FirstOrDefault();
|
||||||
if (string.IsNullOrWhiteSpace(result))
|
if (string.IsNullOrWhiteSpace(result))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("No results found for that query.");
|
await channel.SendErrorAsync("No results found for that query.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await channel.SendMessageAsync(result).ConfigureAwait(false);
|
await channel.SendMessageAsync(result).ConfigureAwait(false);
|
||||||
|
|
||||||
|
//await channel.EmbedAsync(new Discord.API.Embed() { Video = new Discord.API.EmbedVideo() { Url = result.Replace("watch?v=", "embed/") }, Color = NadekoBot.OkColor }).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -77,10 +80,10 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var movie = await OmdbProvider.FindMovie(query);
|
var movie = await OmdbProvider.FindMovie(query);
|
||||||
if (movie == null)
|
if (movie == null)
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("Failed to find that movie.").ConfigureAwait(false);
|
await channel.SendErrorAsync("Failed to find that movie.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync(movie.ToString()).ConfigureAwait(false);
|
await channel.EmbedAsync(movie.GetEmbed()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -90,9 +93,8 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
using (var http = new HttpClient())
|
using (var http = new HttpClient())
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync(JObject.Parse(
|
var res = JObject.Parse(await http.GetStringAsync("http://www.random.cat/meow").ConfigureAwait(false));
|
||||||
await http.GetStringAsync("http://www.random.cat/meow").ConfigureAwait(false))["file"].ToString())
|
await channel.SendMessageAsync(res["file"].ToString()).ConfigureAwait(false);
|
||||||
.ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +105,8 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
using (var http = new HttpClient())
|
using (var http = new HttpClient())
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("http://random.dog/" + await http.GetStringAsync("http://random.dog/woof").ConfigureAwait(false)).ConfigureAwait(false);
|
await channel.SendMessageAsync("http://random.dog/" + await http.GetStringAsync("http://random.dog/woof")
|
||||||
|
.ConfigureAwait(false)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,11 +131,12 @@ namespace NadekoBot.Modules.Searches
|
|||||||
{
|
{
|
||||||
if (exception.Message.Contains("403 (Forbidden)"))
|
if (exception.Message.Contains("403 (Forbidden)"))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("Daily limit reached!");
|
await channel.SendErrorAsync("Daily limit reached!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("Something went wrong.");
|
await channel.SendErrorAsync("Something went wrong.");
|
||||||
|
_log.Error(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,11 +164,12 @@ namespace NadekoBot.Modules.Searches
|
|||||||
{
|
{
|
||||||
if (exception.Message.Contains("403 (Forbidden)"))
|
if (exception.Message.Contains("403 (Forbidden)"))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("Daily limit reached!");
|
await channel.SendErrorAsync("Daily limit reached!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("Something went wrong.");
|
await channel.SendErrorAsync("Something went wrong.");
|
||||||
|
_log.Error(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,7 +184,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
if (string.IsNullOrWhiteSpace(ffs))
|
if (string.IsNullOrWhiteSpace(ffs))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await channel.SendMessageAsync(await NadekoBot.Google.ShortenUrl($"<http://lmgtfy.com/?q={ Uri.EscapeUriString(ffs) }>"))
|
await channel.SendConfirmAsync(await NadekoBot.Google.ShortenUrl($"<http://lmgtfy.com/?q={ Uri.EscapeUriString(ffs) }>"))
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +195,19 @@ namespace NadekoBot.Modules.Searches
|
|||||||
if (string.IsNullOrWhiteSpace(arg))
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await msg.Channel.SendMessageAsync(await NadekoBot.Google.ShortenUrl(arg).ConfigureAwait(false));
|
var shortened = await NadekoBot.Google.ShortenUrl(arg).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (shortened == arg)
|
||||||
|
{
|
||||||
|
await msg.Channel.SendErrorAsync("Failed to shorten that url.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await msg.Channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
|
||||||
|
.AddField(efb => efb.WithName("Original Url")
|
||||||
|
.WithValue($"<{arg}>"))
|
||||||
|
.AddField(efb => efb.WithName("Short Url")
|
||||||
|
.WithValue($"<{shortened}>"))
|
||||||
|
.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -199,11 +216,11 @@ namespace NadekoBot.Modules.Searches
|
|||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
|
|
||||||
terms = terms?.Trim();
|
terms = terms?.Trim();
|
||||||
if (string.IsNullOrWhiteSpace(terms))
|
if (string.IsNullOrWhiteSpace(terms))
|
||||||
return;
|
return;
|
||||||
await channel.SendMessageAsync($"https://google.com/search?q={ WebUtility.UrlEncode(terms).Replace(' ', '+') }")
|
|
||||||
|
await channel.SendConfirmAsync($"https://google.com/search?q={ WebUtility.UrlEncode(terms).Replace(' ', '+') }")
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +232,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var arg = name;
|
var arg = name;
|
||||||
if (string.IsNullOrWhiteSpace(arg))
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 `Please enter a card name to search for.`").ConfigureAwait(false);
|
await channel.SendErrorAsync("Please enter a card name to search for.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,18 +248,26 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var items = JArray.Parse(response).Shuffle().ToList();
|
var items = JArray.Parse(response).Shuffle().ToList();
|
||||||
if (items == null)
|
if (items == null)
|
||||||
throw new KeyNotFoundException("Cannot find a card by that name");
|
throw new KeyNotFoundException("Cannot find a card by that name");
|
||||||
var msg = $@"```css
|
var item = items[0];
|
||||||
[☕ Magic The Gathering]: {items[0]["name"].ToString()}
|
var storeUrl = await NadekoBot.Google.ShortenUrl(item["store_url"].ToString());
|
||||||
[Store URL]: {await NadekoBot.Google.ShortenUrl(items[0]["store_url"].ToString())}
|
var cost = item["cost"].ToString();
|
||||||
[Cost]: {items[0]["cost"].ToString()}
|
var desc = item["text"].ToString();
|
||||||
[Description]: {items[0]["text"].ToString()}
|
var types = String.Join(",\n", item["types"].ToObject<string[]>());
|
||||||
```
|
var img = item["editions"][0]["image_url"].ToString();
|
||||||
{items[0]["editions"][0]["image_url"].ToString()}";
|
var embed = new EmbedBuilder().WithColor(NadekoBot.OkColor)
|
||||||
await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
.WithTitle(item["name"].ToString())
|
||||||
|
.WithDescription(desc)
|
||||||
|
.WithImage(eib => eib.WithUrl(img))
|
||||||
|
.AddField(efb => efb.WithName("Store Url").WithValue(storeUrl).WithIsInline(true))
|
||||||
|
.AddField(efb => efb.WithName("Cost").WithValue(cost).WithIsInline(true))
|
||||||
|
.AddField(efb => efb.WithName("Types").WithValue(types).WithIsInline(true));
|
||||||
|
//.AddField(efb => efb.WithName("Store Url").WithValue(await NadekoBot.Google.ShortenUrl(items[0]["store_url"].ToString())).WithIsInline(true));
|
||||||
|
|
||||||
|
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync($"💢 Error could not find the card {arg}").ConfigureAwait(false);
|
await channel.SendErrorAsync($"Error could not find the card '{arg}'.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,13 +280,13 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var arg = name;
|
var arg = name;
|
||||||
if (string.IsNullOrWhiteSpace(arg))
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 `Please enter a card name to search for.`").ConfigureAwait(false);
|
await channel.SendErrorAsync("Please enter a card name to search for.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.MashapeKey))
|
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.MashapeKey))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 `Bot owner didn't specify MashapeApiKey. You can't use this functionality.`").ConfigureAwait(false);
|
await channel.SendErrorAsync ("Bot owner didn't specify MashapeApiKey. You can't use this functionality.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +326,8 @@ namespace NadekoBot.Modules.Searches
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync($"💢 Error {ex.Message}").ConfigureAwait(false);
|
await channel.SendErrorAsync($"Error occured.").ConfigureAwait(false);
|
||||||
|
_log.Error(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,14 +340,14 @@ namespace NadekoBot.Modules.Searches
|
|||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.MashapeKey))
|
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.MashapeKey))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 `Bot owner didn't specify MashapeApiKey. You can't use this functionality.`").ConfigureAwait(false);
|
await channel.SendErrorAsync("Bot owner didn't specify MashapeApiKey. You can't use this functionality.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var arg = query;
|
var arg = query;
|
||||||
if (string.IsNullOrWhiteSpace(arg))
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 `Please enter a sentence.`").ConfigureAwait(false);
|
await channel.SendErrorAsync("Please enter a sentence.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||||
@ -334,18 +360,15 @@ namespace NadekoBot.Modules.Searches
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var embed = new EmbedBuilder()
|
var embed = new EmbedBuilder()
|
||||||
.WithTitle("Young Padawan")
|
|
||||||
.WithUrl("http://www.yodaspeak.co.uk/")
|
.WithUrl("http://www.yodaspeak.co.uk/")
|
||||||
.WithAuthor(au => au.WithName("Yoda").WithIconUrl("http://www.yodaspeak.co.uk/yoda-small1.gif"))
|
.WithAuthor(au => au.WithName("Yoda").WithIconUrl("http://www.yodaspeak.co.uk/yoda-small1.gif"))
|
||||||
.WithDescription("Seek advice, you must!")
|
.WithDescription(res)
|
||||||
.WithThumbnail(th => th.WithUrl("http://i.imgur.com/62Uh4u6.jpg"))
|
|
||||||
.AddField(fb => fb.WithName($"🌍 **{umsg.Author.Username}**").WithValue($"{res.ToString()}").WithIsInline(false))
|
|
||||||
.WithColor(NadekoBot.OkColor);
|
.WithColor(NadekoBot.OkColor);
|
||||||
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
|
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 Failed to yodify your sentence.").ConfigureAwait(false);
|
await channel.SendErrorAsync("Failed to yodify your sentence.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,14 +381,14 @@ namespace NadekoBot.Modules.Searches
|
|||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.MashapeKey))
|
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.MashapeKey))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 `Bot owner didn't specify MashapeApiKey. You can't use this functionality.`").ConfigureAwait(false);
|
await channel.SendErrorAsync("Bot owner didn't specify MashapeApiKey. You can't use this functionality.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var arg = query;
|
var arg = query;
|
||||||
if (string.IsNullOrWhiteSpace(arg))
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 `Please enter a search term.`").ConfigureAwait(false);
|
await channel.SendErrorAsync("Please enter a search term.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||||
@ -377,15 +400,19 @@ namespace NadekoBot.Modules.Searches
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var items = JObject.Parse(res);
|
var items = JObject.Parse(res);
|
||||||
var sb = new StringBuilder();
|
var item = items["list"][0];
|
||||||
sb.AppendLine($"`Term:` {items["list"][0]["word"].ToString()}");
|
var word = item["word"].ToString();
|
||||||
sb.AppendLine($"`Definition:` {items["list"][0]["definition"].ToString()}");
|
var def = item["definition"].ToString();
|
||||||
sb.Append($"`Link:` <{await NadekoBot.Google.ShortenUrl(items["list"][0]["permalink"].ToString()).ConfigureAwait(false)}>");
|
var link = item["permalink"].ToString();
|
||||||
await channel.SendMessageAsync(sb.ToString());
|
var embed = new EmbedBuilder().WithColor(NadekoBot.OkColor)
|
||||||
|
.WithUrl(link)
|
||||||
|
.WithAuthor(eab => eab.WithIconUrl("http://i.imgur.com/nwERwQE.jpg").WithName(word))
|
||||||
|
.WithDescription(def);
|
||||||
|
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 Failed finding a definition for that term.").ConfigureAwait(false);
|
await channel.SendErrorAsync("Failed finding a definition for that term.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -399,12 +426,12 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var arg = query;
|
var arg = query;
|
||||||
if (string.IsNullOrWhiteSpace(arg))
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 `Please enter a search term.`").ConfigureAwait(false);
|
await channel.SendErrorAsync("Please enter a search term.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.MashapeKey))
|
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.MashapeKey))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 `Bot owner didn't specify MashapeApiKey. You can't use this functionality.`").ConfigureAwait(false);
|
await channel.SendErrorAsync("Bot owner didn't specify MashapeApiKey. You can't use this functionality.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,14 +447,20 @@ namespace NadekoBot.Modules.Searches
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var items = JObject.Parse(res);
|
var items = JObject.Parse(res);
|
||||||
var str = $@"`Hashtag:` {items["defs"]["def"]["hashtag"].ToString()}
|
var item = items["defs"]["def"];
|
||||||
`Definition:` {items["defs"]["def"]["text"].ToString()}
|
var hashtag = item["hashtag"].ToString();
|
||||||
`Link:` <{await NadekoBot.Google.ShortenUrl(items["defs"]["def"]["uri"].ToString()).ConfigureAwait(false)}>";
|
var link = item["uri"].ToString();
|
||||||
await channel.SendMessageAsync(str);
|
var desc = item["text"].ToString();
|
||||||
|
await channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
|
||||||
|
.WithAuthor(eab => eab.WithUrl(link)
|
||||||
|
.WithIconUrl("http://res.cloudinary.com/urbandictionary/image/upload/a_exif,c_fit,h_200,w_200/v1394975045/b8oszuu3tbq7ebyo7vo1.jpg")
|
||||||
|
.WithName(query))
|
||||||
|
.WithDescription(desc)
|
||||||
|
.Build());
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 Failed finding a definition for that tag.").ConfigureAwait(false);
|
await channel.SendErrorAsync("Failed finding a definition for that tag.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,7 +474,9 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var response = await http.GetStringAsync("http://catfacts-api.appspot.com/api/facts").ConfigureAwait(false);
|
var response = await http.GetStringAsync("http://catfacts-api.appspot.com/api/facts").ConfigureAwait(false);
|
||||||
if (response == null)
|
if (response == null)
|
||||||
return;
|
return;
|
||||||
await channel.SendMessageAsync($"🐈 `{JObject.Parse(response)["facts"][0].ToString()}`").ConfigureAwait(false);
|
|
||||||
|
var fact = JObject.Parse(response)["facts"][0].ToString();
|
||||||
|
await channel.SendConfirmAsync("🐈fact", fact).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,7 +488,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
|
|
||||||
if (usr == null)
|
if (usr == null)
|
||||||
usr = umsg.Author;
|
usr = umsg.Author;
|
||||||
await channel.SendMessageAsync($"https://images.google.com/searchbyimage?image_url={usr.AvatarUrl}").ConfigureAwait(false);
|
await channel.SendConfirmAsync($"https://images.google.com/searchbyimage?image_url={usr.AvatarUrl}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -465,7 +500,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(imageLink))
|
if (string.IsNullOrWhiteSpace(imageLink))
|
||||||
return;
|
return;
|
||||||
await channel.SendMessageAsync($"https://images.google.com/searchbyimage?image_url={imageLink}").ConfigureAwait(false);
|
await channel.SendConfirmAsync($"https://images.google.com/searchbyimage?image_url={imageLink}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -477,7 +512,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
tag = tag?.Trim() ?? "";
|
tag = tag?.Trim() ?? "";
|
||||||
var link = await GetSafebooruImageLink(tag).ConfigureAwait(false);
|
var link = await GetSafebooruImageLink(tag).ConfigureAwait(false);
|
||||||
if (link == null)
|
if (link == null)
|
||||||
await channel.SendMessageAsync("`No results.`");
|
await channel.SendErrorAsync("No results.");
|
||||||
else
|
else
|
||||||
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
await channel.SendMessageAsync(link).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@ -496,7 +531,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var result = await http.GetStringAsync("https://en.wikipedia.org//w/api.php?action=query&format=json&prop=info&redirects=1&formatversion=2&inprop=url&titles=" + Uri.EscapeDataString(query));
|
var result = await http.GetStringAsync("https://en.wikipedia.org//w/api.php?action=query&format=json&prop=info&redirects=1&formatversion=2&inprop=url&titles=" + Uri.EscapeDataString(query));
|
||||||
var data = JsonConvert.DeserializeObject<WikipediaApiModel>(result);
|
var data = JsonConvert.DeserializeObject<WikipediaApiModel>(result);
|
||||||
if (data.Query.Pages[0].Missing)
|
if (data.Query.Pages[0].Missing)
|
||||||
await channel.SendMessageAsync("`That page could not be found.`");
|
await channel.SendErrorAsync("That page could not be found.");
|
||||||
else
|
else
|
||||||
await channel.SendMessageAsync(data.Query.Pages[0].FullUrl);
|
await channel.SendMessageAsync(data.Query.Pages[0].FullUrl);
|
||||||
}
|
}
|
||||||
@ -536,12 +571,12 @@ namespace NadekoBot.Modules.Searches
|
|||||||
str += new NadekoRandom().Next();
|
str += new NadekoRandom().Next();
|
||||||
foreach (var usr in allUsrsArray)
|
foreach (var usr in allUsrsArray)
|
||||||
{
|
{
|
||||||
await (await (usr as IGuildUser).CreateDMChannelAsync()).SendMessageAsync(str).ConfigureAwait(false);
|
await (await (usr as IGuildUser).CreateDMChannelAsync()).SendConfirmAsync(str).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex);
|
_log.Error(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,7 +589,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
var usr = umsg.MentionedUsers.FirstOrDefault();
|
var usr = umsg.MentionedUsers.FirstOrDefault();
|
||||||
if (usr == null)
|
if (usr == null)
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("Invalid user specified.").ConfigureAwait(false);
|
await channel.SendErrorAsync("Invalid user specified.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync(await NadekoBot.Google.ShortenUrl(usr.AvatarUrl).ConfigureAwait(false)).ConfigureAwait(false);
|
await channel.SendMessageAsync(await NadekoBot.Google.ShortenUrl(usr.AvatarUrl).ConfigureAwait(false)).ConfigureAwait(false);
|
||||||
@ -576,23 +611,23 @@ namespace NadekoBot.Modules.Searches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum BfGame
|
||||||
|
{
|
||||||
|
Bf3, Bf4
|
||||||
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task BFO(IUserMessage umsg, [Remainder] string game = null)
|
public async Task BFO(IUserMessage umsg, [Remainder] BfGame game)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
if (string.IsNullOrWhiteSpace(game))
|
|
||||||
{
|
|
||||||
await channel.SendMessageAsync("💢 Please enter a game `(bf3, bf4)`").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||||
using (var http = new HttpClient())
|
using (var http = new HttpClient())
|
||||||
{
|
{
|
||||||
http.DefaultRequestHeaders.Clear();
|
http.DefaultRequestHeaders.Clear();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (game.Equals("bf3", StringComparison.OrdinalIgnoreCase))
|
if (game == BfGame.Bf3)
|
||||||
{
|
{
|
||||||
var res = await http.GetStringAsync($"http://api.bf3stats.com/global/onlinestats/").ConfigureAwait(false);
|
var res = await http.GetStringAsync($"http://api.bf3stats.com/global/onlinestats/").ConfigureAwait(false);
|
||||||
var items = JObject.Parse(res);
|
var items = JObject.Parse(res);
|
||||||
@ -610,7 +645,7 @@ PC: ✔[{pc.ToString()}]
|
|||||||
```";
|
```";
|
||||||
await channel.SendMessageAsync(response);
|
await channel.SendMessageAsync(response);
|
||||||
}
|
}
|
||||||
else if (game.Equals("bf4", StringComparison.OrdinalIgnoreCase))
|
else if (game == BfGame.Bf4)
|
||||||
{
|
{
|
||||||
var res = await http.GetStringAsync($"http://api.bf4stats.com/api/onlinePlayers?output=json").ConfigureAwait(false);
|
var res = await http.GetStringAsync($"http://api.bf4stats.com/api/onlinePlayers?output=json").ConfigureAwait(false);
|
||||||
var items = JObject.Parse(res);
|
var items = JObject.Parse(res);
|
||||||
@ -625,29 +660,31 @@ PC: ✔[{pc.ToString()}]
|
|||||||
sb.AppendLine("```css");
|
sb.AppendLine("```css");
|
||||||
sb.AppendLine($"[☕ BF4 Status: {status}]");
|
sb.AppendLine($"[☕ BF4 Status: {status}]");
|
||||||
|
|
||||||
foreach (var i in items) {
|
foreach (var i in items)
|
||||||
|
{
|
||||||
var plat = items[i.Key];
|
var plat = items[i.Key];
|
||||||
sb.AppendLine($"{plat["label"]}: ✔[{plat["count"]}] / ↑[{plat["peak24"]}]");
|
sb.AppendLine($"{plat["label"]}: ✔[{plat["count"]}] / ↑[{plat["peak24"]}]");
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append("```");
|
sb.Append("```");
|
||||||
await channel.SendMessageAsync(sb.ToString());
|
await channel.SendConfirmAsync(sb.ToString());
|
||||||
}
|
}
|
||||||
} catch
|
}
|
||||||
|
catch
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync($"💢 BF3/BF4 API is most likely not working at the moment or could not find {game}.").ConfigureAwait(false);
|
await channel.SendErrorAsync($"BF3/BF4 API is most likely not working at the moment or could not find {game}.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task BFU(IUserMessage umsg, string platform, string game, [Remainder] string query = null)
|
public async Task BFU(IUserMessage umsg, string platform, BfGame game, [Remainder] string query = null)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
if (string.IsNullOrWhiteSpace(platform) || string.IsNullOrWhiteSpace(game) || string.IsNullOrWhiteSpace(query))
|
if (string.IsNullOrWhiteSpace(platform) || string.IsNullOrWhiteSpace(query))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 Please enter a platform `(pc, xbox, ps3, xone, ps4)`, game `(bf3, bf4)`, followed by a search query.").ConfigureAwait(false);
|
await channel.SendErrorAsync("Please enter a platform `(pc, xbox, ps3, xone, ps4)`, game `(bf3, bf4)`, followed by a search query.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||||
@ -656,7 +693,7 @@ PC: ✔[{pc.ToString()}]
|
|||||||
http.DefaultRequestHeaders.Clear();
|
http.DefaultRequestHeaders.Clear();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (game.Equals("bf3", StringComparison.OrdinalIgnoreCase))
|
if (game == BfGame.Bf3)
|
||||||
{
|
{
|
||||||
var res = await http.GetStringAsync($"http://api.bf3stats.com/{Uri.EscapeUriString(platform)}/playerlist/players={Uri.EscapeUriString(query)}?output=json").ConfigureAwait(false);
|
var res = await http.GetStringAsync($"http://api.bf3stats.com/{Uri.EscapeUriString(platform)}/playerlist/players={Uri.EscapeUriString(query)}?output=json").ConfigureAwait(false);
|
||||||
var items = JObject.Parse(res);
|
var items = JObject.Parse(res);
|
||||||
@ -688,7 +725,7 @@ Accuracy: %[{playerGlobal_Accuracy.ToString()}]
|
|||||||
ELO: [{playerGlobal_ELO.ToString()}]
|
ELO: [{playerGlobal_ELO.ToString()}]
|
||||||
```";
|
```";
|
||||||
await channel.SendMessageAsync(response);
|
await channel.SendMessageAsync(response);
|
||||||
} else if (game.Equals("bf4", StringComparison.OrdinalIgnoreCase))
|
} else if (game == BfGame.Bf4)
|
||||||
{
|
{
|
||||||
var res = await http.GetStringAsync($"http://api.bf4stats.com/api/playerInfo?plat={Uri.EscapeUriString(platform)}&name={Uri.EscapeUriString(query)}&output=json").ConfigureAwait(false);
|
var res = await http.GetStringAsync($"http://api.bf4stats.com/api/playerInfo?plat={Uri.EscapeUriString(platform)}&name={Uri.EscapeUriString(query)}&output=json").ConfigureAwait(false);
|
||||||
var items = JObject.Parse(res);
|
var items = JObject.Parse(res);
|
||||||
@ -725,7 +762,7 @@ ELO: [{playerELO.ToString()}]
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync($"💢 BF3/BF4 API is most likely not working at the moment or could not find {query}.").ConfigureAwait(false);
|
await channel.SendErrorAsync($"BF3/BF4 API is most likely not working at the moment or could not find {query}.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -737,7 +774,7 @@ ELO: [{playerELO.ToString()}]
|
|||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
if (string.IsNullOrWhiteSpace(target) || string.IsNullOrWhiteSpace(query))
|
if (string.IsNullOrWhiteSpace(target) || string.IsNullOrWhiteSpace(query))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 Please enter a target wikia, followed by search query.").ConfigureAwait(false);
|
await channel.SendErrorAsync("Please enter a target wikia, followed by search query.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||||
@ -756,7 +793,7 @@ ELO: [{playerELO.ToString()}]
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync($"💢 Failed finding `{query}`.").ConfigureAwait(false);
|
await channel.SendErrorAsync($"Failed finding `{query}`.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -769,7 +806,7 @@ ELO: [{playerELO.ToString()}]
|
|||||||
var arg = query;
|
var arg = query;
|
||||||
if (string.IsNullOrWhiteSpace(arg))
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 Please enter a `ip:port`.").ConfigureAwait(false);
|
await channel.SendErrorAsync("💢 Please enter a `ip:port`.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||||
@ -793,7 +830,7 @@ ELO: [{playerELO.ToString()}]
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync($"💢 Failed finding `{arg}`.").ConfigureAwait(false);
|
await channel.SendErrorAsync($"Failed finding `{arg}`.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -806,7 +843,7 @@ ELO: [{playerELO.ToString()}]
|
|||||||
var arg = query;
|
var arg = query;
|
||||||
if (string.IsNullOrWhiteSpace(arg))
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("💢 Please enter a `ip:port`.").ConfigureAwait(false);
|
await channel.SendErrorAsync("Please enter `ip:port`.").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||||
@ -833,7 +870,7 @@ ELO: [{playerELO.ToString()}]
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync($"💢 Failed finding server `{arg}`.").ConfigureAwait(false);
|
await channel.SendErrorAsync($"Failed finding server `{arg}`.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -841,7 +878,7 @@ ELO: [{playerELO.ToString()}]
|
|||||||
public static async Task<bool> ValidateQuery(ITextChannel ch, string query)
|
public static async Task<bool> ValidateQuery(ITextChannel ch, string query)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(query.Trim())) return true;
|
if (!string.IsNullOrEmpty(query.Trim())) return true;
|
||||||
await ch.SendMessageAsync("Please specify search parameters.").ConfigureAwait(false);
|
await ch.SendErrorAsync("Please specify search parameters.").ConfigureAwait(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user