diff --git a/src/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs b/src/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs index 5f7b0064..dcf4d0f5 100644 --- a/src/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs @@ -6,12 +6,28 @@ using System.Linq; using System.Threading.Tasks; using NadekoBot.Attributes; using System.Net.Http; +using System.Text; using NadekoBot.Extensions; namespace NadekoBot.Modules.Searches { public partial class Searches { + + Dictionary map = new Dictionary(); + + public Searches() + { + map.Add('?', "~q"); + map.Add('%', "~p"); + map.Add('#', "~h"); + map.Add('/', "~s"); + map.Add(' ', "-"); + map.Add('-', "--"); + map.Add('_', "__"); + map.Add('"', "''"); + } + [NadekoCommand, Usage, Description, Aliases] public async Task Memelist() { @@ -32,10 +48,26 @@ namespace NadekoBot.Modules.Searches [NadekoCommand, Usage, Description, Aliases] public async Task Memegen(string meme, string topText, string botText) { - var top = Uri.EscapeDataString(topText.Replace(' ', '-')); - var bot = Uri.EscapeDataString(botText.Replace(' ', '-')); + var top = Replace(topText); + var bot = Replace(botText); await Context.Channel.SendMessageAsync($"http://memegen.link/{meme}/{top}/{bot}.jpg") .ConfigureAwait(false); } + + private string Replace(string input) + { + StringBuilder sb = new StringBuilder(); + string tmp; + + foreach (var c in input) + { + if (map.TryGetValue(c, out tmp)) + sb.Append(tmp); + else + sb.Append(c); + } + + return sb.ToString(); + } } }