From ed59d11d715688537c45d634cf2132591352755a Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 29 Jun 2016 21:02:43 +0200 Subject: [PATCH] added ~memegen and ~memelist commands --- .../Searches/Commands/MemegenCommands.cs | 46 +++++++++++++++++++ NadekoBot/Modules/Searches/SearchesModule.cs | 1 + NadekoBot/NadekoBot.csproj | 2 +- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 NadekoBot/Modules/Searches/Commands/MemegenCommands.cs diff --git a/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs b/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs new file mode 100644 index 00000000..ebbdbf34 --- /dev/null +++ b/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs @@ -0,0 +1,46 @@ +using Discord.Commands; +using NadekoBot.Classes; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace NadekoBot.Modules.Searches.Commands +{ + class MemegenCommands : DiscordCommand + { + public MemegenCommands(DiscordModule module) : base(module) + { + } + + internal override void Init(CommandGroupBuilder cgb) + { + cgb.CreateCommand(Prefix + "memelist") + .Description("Pulls a list of memes you can use with `~memegen` from http://memegen.link/templates/") + .Do(async e => + { + int i = 0; + await e.Channel.SendMessage("`List Of Commands:`\n```xl\n" + + string.Join("\n", JsonConvert.DeserializeObject>(await SearchHelper.GetResponseStringAsync("http://memegen.link/templates/")) + .Select(kvp => Path.GetFileName(kvp.Value)) + .GroupBy(item => (i++) / 4) + .Select(ig => string.Join("", ig.Select(el => $"{el,-17}")))) + + $"\n```").ConfigureAwait(false); + }); + + cgb.CreateCommand(Prefix + "memegen") + .Description("Generates a meme from memelist with top and bottom text. | `~memegen biw \"gets iced coffee\" \"in the winter\"`") + .Parameter("meme", ParameterType.Required) + .Parameter("toptext", ParameterType.Required) + .Parameter("bottext", ParameterType.Required) + .Do(async e => + { + var meme = e.GetArg("meme"); + var top = Uri.EscapeDataString(e.GetArg("toptext").Replace(' ', '-')); + var bot = Uri.EscapeDataString(e.GetArg("bottext").Replace(' ', '-')); + await e.Channel.SendMessage($"http://memegen.link/{meme}/{top}/{bot}.jpg"); + }); + } + } +} diff --git a/NadekoBot/Modules/Searches/SearchesModule.cs b/NadekoBot/Modules/Searches/SearchesModule.cs index e8d57934..11333f09 100644 --- a/NadekoBot/Modules/Searches/SearchesModule.cs +++ b/NadekoBot/Modules/Searches/SearchesModule.cs @@ -31,6 +31,7 @@ namespace NadekoBot.Modules.Searches commands.Add(new CalcCommand(this)); commands.Add(new OsuCommands(this)); commands.Add(new PokemonSearchCommands(this)); + commands.Add(new MemegenCommands(this)); rng = new Random(); } diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 3d57402e..a47af49b 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -149,6 +149,7 @@ + @@ -210,7 +211,6 @@ -