Merge pull request #1084 from Nitix/fix-meme

Fix specials characters for memegen
This commit is contained in:
Master Kwoth 2017-02-23 11:45:53 +01:00 committed by GitHub
commit c59a49aa33

View File

@ -6,12 +6,28 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using NadekoBot.Attributes; using NadekoBot.Attributes;
using System.Net.Http; using System.Net.Http;
using System.Text;
using NadekoBot.Extensions; using NadekoBot.Extensions;
namespace NadekoBot.Modules.Searches namespace NadekoBot.Modules.Searches
{ {
public partial class Searches public partial class Searches
{ {
Dictionary<char, string> map = new Dictionary<char, string>();
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] [NadekoCommand, Usage, Description, Aliases]
public async Task Memelist() public async Task Memelist()
{ {
@ -32,10 +48,26 @@ namespace NadekoBot.Modules.Searches
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
public async Task Memegen(string meme, string topText, string botText) public async Task Memegen(string meme, string topText, string botText)
{ {
var top = Uri.EscapeDataString(topText.Replace(' ', '-')); var top = Replace(topText);
var bot = Uri.EscapeDataString(botText.Replace(' ', '-')); var bot = Replace(botText);
await Context.Channel.SendMessageAsync($"http://memegen.link/{meme}/{top}/{bot}.jpg") await Context.Channel.SendMessageAsync($"http://memegen.link/{meme}/{top}/{bot}.jpg")
.ConfigureAwait(false); .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();
}
} }
} }