This commit is contained in:
Kwoth 2017-02-23 14:35:26 +01:00
commit d0fa050c30

View File

@ -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<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]
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();
}
}
}