From 0a7d077e0214fe4173af4cd5a7ea5b6f89b44911 Mon Sep 17 00:00:00 2001 From: Nitix Date: Thu, 23 Feb 2017 04:37:24 +0100 Subject: [PATCH] Fix specials characters for memegen --- .../Searches/Commands/MemegenCommands.cs | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) 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(); + } } }