From ffc1f5a061ad81fa3c1c48a638869bbecb8720c7 Mon Sep 17 00:00:00 2001 From: fkndean Date: Sun, 27 Nov 2016 12:00:37 -0500 Subject: [PATCH 1/9] Add Magic The Gathering card search --- src/NadekoBot/Modules/Searches/Searches.cs | 45 +++++++++++++++++++ .../Resources/CommandStrings.Designer.cs | 35 +++++++++++++-- src/NadekoBot/Resources/CommandStrings.resx | 9 ++++ 3 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 47429830..8e674928 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -208,6 +208,51 @@ $@"🌍 **Weather for** 【{obj["target"]}】 .ConfigureAwait(false); } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task MagicTheGathering(IUserMessage umsg, [Remainder] string name = null) + { + var channel = (ITextChannel)umsg.Channel; + var arg = name; + if (string.IsNullOrWhiteSpace(arg)) + { + await channel.SendMessageAsync("💢 `Please enter a card name to search for.`").ConfigureAwait(false); + return; + } + + await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false); + string response = ""; + using (var http = new HttpClient()) + { + http.DefaultRequestHeaders.Clear(); + response = await http.GetStringAsync($"https://api.deckbrew.com/mtg/cards?name={Uri.EscapeUriString(arg)}") + .ConfigureAwait(false); + try + { + var items = JArray.Parse(response).Shuffle().ToList(); + var images = new List(); + if (items == null) + throw new KeyNotFoundException("Cannot find a card by that name"); + + using (var sr = await http.GetStreamAsync(items[0]["editions"][0]["image_url"].ToString())) + { + var imgStream = new MemoryStream(); + await sr.CopyToAsync(imgStream); + imgStream.Position = 0; + images.Add(new Image(imgStream)); + } + var ms = new MemoryStream(); + images.Merge().SaveAsJpeg(ms); + ms.Position = 0; + await channel.SendFileAsync(ms, arg + ".jpg", null).ConfigureAwait(false); + } + catch + { + await channel.SendMessageAsync($"💢 Error could not find the card {arg}").ConfigureAwait(false); + } + } + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Hearthstone(IUserMessage umsg, [Remainder] string name = null) diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 5d6bdf64..f534b0c8 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -906,7 +906,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Toggles automatic deletion of bye messages.. + /// Looks up a localized string similar to Sets the time it takes (in seconds) for bye messages to be auto-deleted. Set 0 to disable automatic deletion.. /// public static string byedel_desc { get { @@ -915,7 +915,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to `{0}byedel`. + /// Looks up a localized string similar to `{0}byedel 0` or `{0}byedel 30`. /// public static string byedel_usage { get { @@ -2688,7 +2688,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Toggles automatic deletion of greet messages.. + /// Looks up a localized string similar to Sets the time it takes (in seconds) for greet messages to be auto-deleted. Set 0 to disable automatic deletion.. /// public static string greetdel_desc { get { @@ -2697,7 +2697,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to `{0}greetdel`. + /// Looks up a localized string similar to `{0}greetdel 0` or `{0}greetdel 30`. /// public static string greetdel_usage { get { @@ -3974,6 +3974,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to magicthegathering mtg. + /// + public static string magicthegathering_cmd { + get { + return ResourceManager.GetString("magicthegathering_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Searches for a Magic The Gathering card.. + /// + public static string magicthegathering_desc { + get { + return ResourceManager.GetString("magicthegathering_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}magicthegathering about face` or `{0}mtg about face`. + /// + public static string magicthegathering_usage { + get { + return ResourceManager.GetString("magicthegathering_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to manga mang mq. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 76c0a001..010bc1aa 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2700,4 +2700,13 @@ `{0}yandere tag1+tag2` + + magicthegathering mtg + + + Searches for a Magic The Gathering card. + + + `{0}magicthegathering about face` or `{0}mtg about face` + \ No newline at end of file From a32fd3a2cb5bbbbb270090db75fa75ec51fc92b5 Mon Sep 17 00:00:00 2001 From: fkndean Date: Sun, 27 Nov 2016 12:12:40 -0500 Subject: [PATCH 2/9] Add card description in output message. --- src/NadekoBot/Modules/Searches/Searches.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 8e674928..9d9f19a7 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -241,10 +241,17 @@ $@"🌍 **Weather for** 【{obj["target"]}】 imgStream.Position = 0; images.Add(new Image(imgStream)); } + var msg = $@"```css +[☕ Magic The Gathering]: {items[0]["name"].ToString()} +[Store URL]: {await _google.ShortenUrl(items[0]["store_url"].ToString())} +[Cost]: {items[0]["cost"].ToString()} +[Description]: {items[0]["text"].ToString()} +```"; var ms = new MemoryStream(); images.Merge().SaveAsJpeg(ms); ms.Position = 0; await channel.SendFileAsync(ms, arg + ".jpg", null).ConfigureAwait(false); + await channel.SendMessageAsync(msg).ConfigureAwait(false); } catch { From d363af4dfe3f34029a61fc3f50e54ee1e22f253d Mon Sep 17 00:00:00 2001 From: fkndean Date: Sun, 27 Nov 2016 12:16:22 -0500 Subject: [PATCH 3/9] remove message output - kwoth request --- src/NadekoBot/Modules/Searches/Searches.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 9d9f19a7..8e674928 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -241,17 +241,10 @@ $@"🌍 **Weather for** 【{obj["target"]}】 imgStream.Position = 0; images.Add(new Image(imgStream)); } - var msg = $@"```css -[☕ Magic The Gathering]: {items[0]["name"].ToString()} -[Store URL]: {await _google.ShortenUrl(items[0]["store_url"].ToString())} -[Cost]: {items[0]["cost"].ToString()} -[Description]: {items[0]["text"].ToString()} -```"; var ms = new MemoryStream(); images.Merge().SaveAsJpeg(ms); ms.Position = 0; await channel.SendFileAsync(ms, arg + ".jpg", null).ConfigureAwait(false); - await channel.SendMessageAsync(msg).ConfigureAwait(false); } catch { From 2e7ff45bd5bede7b1958d610c05c81003cb74031 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 27 Nov 2016 21:53:58 +0100 Subject: [PATCH 4/9] removed expired token --- src/NadekoBot/credentials.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/credentials.json b/src/NadekoBot/credentials.json index 30f8f88f..31a9414f 100644 --- a/src/NadekoBot/credentials.json +++ b/src/NadekoBot/credentials.json @@ -1,7 +1,7 @@ { "ClientId": 123123123, "BotId": null, - "Token": "MTE5Nzc3MDIxMzE5NTc3NjEw.CxK2Og.N4u_RpZws88zmXWF16mQaQUSphI", + "Token": "", "OwnerIds": [ 0 ], From 1e2d5ee6b70b8a3a5447d512f629150a26256796 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 28 Nov 2016 01:11:19 +0100 Subject: [PATCH 5/9] Fixed greetdmmsg --- .../Modules/Administration/Commands/ServerGreetCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs index 32550225..a2a7cf16 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs @@ -274,7 +274,7 @@ namespace NadekoBot.Modules.Administration return; } - var sendGreetEnabled = ServerGreetCommands.SetGreetMessage(channel.Guild.Id, ref text); + var sendGreetEnabled = ServerGreetCommands.SetGreetDmMessage(channel.Guild.Id, ref text); await channel.SendMessageAsync("🆗 New DM greet message **set**.").ConfigureAwait(false); if (!sendGreetEnabled) From 7ad43e8345413f3241e6f6736861b986aa200d18 Mon Sep 17 00:00:00 2001 From: fkndean Date: Sun, 27 Nov 2016 20:17:46 -0500 Subject: [PATCH 6/9] Just append card url instead of downloading. --- src/NadekoBot/Modules/Searches/Searches.cs | 35 +++++----------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 8e674928..14bcc5bf 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -194,20 +194,6 @@ $@"🌍 **Weather for** 【{obj["target"]}】 await msg.Channel.SendMessageAsync(await NadekoBot.Google.ShortenUrl(arg).ConfigureAwait(false)); } - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - public async Task Google(IUserMessage umsg, [Remainder] string terms = null) - { - var channel = (ITextChannel)umsg.Channel; - - - terms = terms?.Trim(); - if (string.IsNullOrWhiteSpace(terms)) - return; - await channel.SendMessageAsync($"https://google.com/search?q={ WebUtility.UrlEncode(terms).Replace(' ', '+') }") - .ConfigureAwait(false); - } - [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task MagicTheGathering(IUserMessage umsg, [Remainder] string name = null) @@ -230,21 +216,16 @@ $@"🌍 **Weather for** 【{obj["target"]}】 try { var items = JArray.Parse(response).Shuffle().ToList(); - var images = new List(); if (items == null) throw new KeyNotFoundException("Cannot find a card by that name"); - - using (var sr = await http.GetStreamAsync(items[0]["editions"][0]["image_url"].ToString())) - { - var imgStream = new MemoryStream(); - await sr.CopyToAsync(imgStream); - imgStream.Position = 0; - images.Add(new Image(imgStream)); - } - var ms = new MemoryStream(); - images.Merge().SaveAsJpeg(ms); - ms.Position = 0; - await channel.SendFileAsync(ms, arg + ".jpg", null).ConfigureAwait(false); + var msg = $@"```css +[☕ Magic The Gathering]: {items[0]["name"].ToString()} +[Store URL]: {await _google.ShortenUrl(items[0]["store_url"].ToString())} +[Cost]: {items[0]["cost"].ToString()} +[Description]: {items[0]["text"].ToString()} +``` +{items[0]["editions"][0]["image_url"].ToString()}"; + await channel.SendMessageAsync(msg).ConfigureAwait(false); } catch { From c50e192dbe33be016d528a2c3b33f6ea1bbf41c8 Mon Sep 17 00:00:00 2001 From: fkndean Date: Sun, 27 Nov 2016 20:19:12 -0500 Subject: [PATCH 7/9] whoops accidentally removed Google. --- src/NadekoBot/Modules/Searches/Searches.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 14bcc5bf..82bf2ece 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -194,6 +194,20 @@ $@"🌍 **Weather for** 【{obj["target"]}】 await msg.Channel.SendMessageAsync(await NadekoBot.Google.ShortenUrl(arg).ConfigureAwait(false)); } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task Google(IUserMessage umsg, [Remainder] string terms = null) + { + var channel = (ITextChannel)umsg.Channel; + + + terms = terms?.Trim(); + if (string.IsNullOrWhiteSpace(terms)) + return; + await channel.SendMessageAsync($"https://google.com/search?q={ WebUtility.UrlEncode(terms).Replace(' ', '+') }") + .ConfigureAwait(false); + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task MagicTheGathering(IUserMessage umsg, [Remainder] string name = null) From f1318a31ffe1ef738daf2fbfb3c5f13da89424a6 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 28 Nov 2016 11:39:23 +0100 Subject: [PATCH 8/9] Updated discord.net --- discord.net | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord.net b/discord.net index 9766a978..95a4f7a7 160000 --- a/discord.net +++ b/discord.net @@ -1 +1 @@ -Subproject commit 9766a978b61294fda58964fc271d9c80c3c36e0b +Subproject commit 95a4f7a73e2b66bef3a841ac6b415f7269839f42 From 9d4061265d32ce9627c68eb6b136365e7933e1c7 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 28 Nov 2016 20:47:10 +0100 Subject: [PATCH 9/9] Fix to .grdel and .byedel --- .../Modules/Administration/Commands/ServerGreetCommands.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs index a2a7cf16..38e207c4 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs @@ -55,7 +55,7 @@ namespace NadekoBot.Modules.Administration { var t = Task.Run(async () => { - await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes + await Task.Delay(conf.AutoDeleteByeMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes try { await toDelete.DeleteAsync().ConfigureAwait(false); } catch { } }); } @@ -90,7 +90,7 @@ namespace NadekoBot.Modules.Administration try { var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false); - if (conf.AutoDeleteByeMessagesTimer > 0) + if (conf.AutoDeleteGreetMessagesTimer > 0) { var t = Task.Run(async () => {