diff --git a/NadekoBot/Classes/Leet.cs b/NadekoBot/Classes/Leet.cs new file mode 100644 index 00000000..ec85b3a7 --- /dev/null +++ b/NadekoBot/Classes/Leet.cs @@ -0,0 +1,279 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +//taken from +//http://www.codeproject.com/Tips/207582/L-t-Tr-nsl-t-r-Leet-Translator (thanks) +// because i don't want to waste my time on this cancerous command +namespace NadekoBot.Classes { + public static class Leet { + /// + /// Translate text to Leet - Extension methods for string class + /// + /// Orginal text + /// Degree of translation (1 - 3) + /// Leet translated text + public static string ToLeet(this string text, int degree = 1) => + Translate(text, degree); + + /// + /// Translate text to Leet + /// + /// Orginal text + /// Degree of translation (1 - 3) + /// Leet translated text + public static string Translate(string text, int degree = 1) { + if (degree > 6) + degree = 6; + if (degree <= 0) + return text; + + // StringBuilder to store result. + StringBuilder sb = new StringBuilder(text.Length); + foreach (char c in text) { + #region Degree 1 + if (degree == 1) { + switch (c) { + case 'a': sb.Append("4"); break; + case 'e': sb.Append("3"); break; + case 'i': sb.Append("1"); break; + case 'o': sb.Append("0"); break; + case 'A': sb.Append("4"); break; + case 'E': sb.Append("3"); break; + case 'I': sb.Append("1"); break; + case 'O': sb.Append("0"); break; + default: sb.Append(c); break; + } + } + #endregion + #region Degree 2 + else if (degree == 2) { + switch (c) { + case 'a': sb.Append("4"); break; + case 'e': sb.Append("3"); break; + case 'i': sb.Append("1"); break; + case 'o': sb.Append("0"); break; + case 'A': sb.Append("4"); break; + case 'E': sb.Append("3"); break; + case 'I': sb.Append("1"); break; + case 'O': sb.Append("0"); break; + case 's': sb.Append("$"); break; + case 'S': sb.Append("$"); break; + case 'l': sb.Append("£"); break; + case 'L': sb.Append("£"); break; + case 'c': sb.Append("("); break; + case 'C': sb.Append("("); break; + case 'y': sb.Append("¥"); break; + case 'Y': sb.Append("¥"); break; + case 'u': sb.Append("µ"); break; + case 'U': sb.Append("µ"); break; + case 'd': sb.Append("Ð"); break; + case 'D': sb.Append("Ð"); break; + default: sb.Append(c); break; + } + } + #endregion + #region Degree 3 + else if (degree == 3) { + switch (c) { + case 'a': sb.Append("4"); break; + case 'e': sb.Append("3"); break; + case 'i': sb.Append("1"); break; + case 'o': sb.Append("0"); break; + case 'A': sb.Append("4"); break; + case 'E': sb.Append("3"); break; + case 'I': sb.Append("1"); break; + case 'O': sb.Append("0"); break; + case 'k': sb.Append("|{"); break; + case 'K': sb.Append("|{"); break; + case 's': sb.Append("$"); break; + case 'S': sb.Append("$"); break; + case 'g': sb.Append("9"); break; + case 'G': sb.Append("9"); break; + case 'l': sb.Append("£"); break; + case 'L': sb.Append("£"); break; + case 'c': sb.Append("("); break; + case 'C': sb.Append("("); break; + case 't': sb.Append("7"); break; + case 'T': sb.Append("7"); break; + case 'z': sb.Append("2"); break; + case 'Z': sb.Append("2"); break; + case 'y': sb.Append("¥"); break; + case 'Y': sb.Append("¥"); break; + case 'u': sb.Append("µ"); break; + case 'U': sb.Append("µ"); break; + case 'f': sb.Append("ƒ"); break; + case 'F': sb.Append("ƒ"); break; + case 'd': sb.Append("Ð"); break; + case 'D': sb.Append("Ð"); break; + default: sb.Append(c); break; + } + } + #endregion + #region Degree 4 + else if (degree == 4) { + switch (c) { + case 'a': sb.Append("4"); break; + case 'e': sb.Append("3"); break; + case 'i': sb.Append("1"); break; + case 'o': sb.Append("0"); break; + case 'A': sb.Append("4"); break; + case 'E': sb.Append("3"); break; + case 'I': sb.Append("1"); break; + case 'O': sb.Append("0"); break; + case 'k': sb.Append("|{"); break; + case 'K': sb.Append("|{"); break; + case 's': sb.Append("$"); break; + case 'S': sb.Append("$"); break; + case 'g': sb.Append("9"); break; + case 'G': sb.Append("9"); break; + case 'l': sb.Append("£"); break; + case 'L': sb.Append("£"); break; + case 'c': sb.Append("("); break; + case 'C': sb.Append("("); break; + case 't': sb.Append("7"); break; + case 'T': sb.Append("7"); break; + case 'z': sb.Append("2"); break; + case 'Z': sb.Append("2"); break; + case 'y': sb.Append("¥"); break; + case 'Y': sb.Append("¥"); break; + case 'u': sb.Append("µ"); break; + case 'U': sb.Append("µ"); break; + case 'f': sb.Append("ƒ"); break; + case 'F': sb.Append("ƒ"); break; + case 'd': sb.Append("Ð"); break; + case 'D': sb.Append("Ð"); break; + case 'n': sb.Append(@"|\\|"); break; + case 'N': sb.Append(@"|\\|"); break; + case 'w': sb.Append(@"\\/\\/"); break; + case 'W': sb.Append(@"\\/\\/"); break; + case 'h': sb.Append(@"|-|"); break; + case 'H': sb.Append(@"|-|"); break; + case 'v': sb.Append(@"\\/"); break; + case 'V': sb.Append(@"\\/"); break; + case 'm': sb.Append(@"|\\/|"); break; + case 'M': sb.Append(@"|\/|"); break; + default: sb.Append(c); break; + } + } + #endregion + #region Degree 5 + else if (degree == 5) { + switch (c) { + case 'a': sb.Append("4"); break; + case 'e': sb.Append("3"); break; + case 'i': sb.Append("1"); break; + case 'o': sb.Append("0"); break; + case 'A': sb.Append("4"); break; + case 'E': sb.Append("3"); break; + case 'I': sb.Append("1"); break; + case 'O': sb.Append("0"); break; + case 's': sb.Append("$"); break; + case 'S': sb.Append("$"); break; + case 'g': sb.Append("9"); break; + case 'G': sb.Append("9"); break; + case 'l': sb.Append("£"); break; + case 'L': sb.Append("£"); break; + case 'c': sb.Append("("); break; + case 'C': sb.Append("("); break; + case 't': sb.Append("7"); break; + case 'T': sb.Append("7"); break; + case 'z': sb.Append("2"); break; + case 'Z': sb.Append("2"); break; + case 'y': sb.Append("¥"); break; + case 'Y': sb.Append("¥"); break; + case 'u': sb.Append("µ"); break; + case 'U': sb.Append("µ"); break; + case 'f': sb.Append("ƒ"); break; + case 'F': sb.Append("ƒ"); break; + case 'd': sb.Append("Ð"); break; + case 'D': sb.Append("Ð"); break; + case 'n': sb.Append(@"|\\|"); break; + case 'N': sb.Append(@"|\\|"); break; + case 'w': sb.Append(@"\\/\\/"); break; + case 'W': sb.Append(@"\\/\\/"); break; + case 'h': sb.Append("|-|"); break; + case 'H': sb.Append("|-|"); break; + case 'v': sb.Append("\\/"); break; + case 'V': sb.Append(@"\\/"); break; + case 'k': sb.Append("|{"); break; + case 'K': sb.Append("|{"); break; + case 'r': sb.Append("®"); break; + case 'R': sb.Append("®"); break; + case 'm': sb.Append(@"|\\/|"); break; + case 'M': sb.Append(@"|\\/|"); break; + case 'b': sb.Append("ß"); break; + case 'B': sb.Append("ß"); break; + case 'q': sb.Append("Q"); break; + case 'Q': sb.Append("Q¸"); break; + case 'x': sb.Append(")("); break; + case 'X': sb.Append(")("); break; + default: sb.Append(c); break; + } + } + #endregion + #region Degree 6 + else if (degree == 6) { + switch (c) { + case 'a': sb.Append("4"); break; + case 'e': sb.Append("3"); break; + case 'i': sb.Append("1"); break; + case 'o': sb.Append("0"); break; + case 'A': sb.Append("4"); break; + case 'E': sb.Append("3"); break; + case 'I': sb.Append("1"); break; + case 'O': sb.Append("0"); break; + case 's': sb.Append("$"); break; + case 'S': sb.Append("$"); break; + case 'g': sb.Append("9"); break; + case 'G': sb.Append("9"); break; + case 'l': sb.Append("£"); break; + case 'L': sb.Append("£"); break; + case 'c': sb.Append("("); break; + case 'C': sb.Append("("); break; + case 't': sb.Append("7"); break; + case 'T': sb.Append("7"); break; + case 'z': sb.Append("2"); break; + case 'Z': sb.Append("2"); break; + case 'y': sb.Append("¥"); break; + case 'Y': sb.Append("¥"); break; + case 'u': sb.Append("µ"); break; + case 'U': sb.Append("µ"); break; + case 'f': sb.Append("ƒ"); break; + case 'F': sb.Append("ƒ"); break; + case 'd': sb.Append("Ð"); break; + case 'D': sb.Append("Ð"); break; + case 'n': sb.Append(@"|\\|"); break; + case 'N': sb.Append(@"|\\|"); break; + case 'w': sb.Append(@"\\/\\/"); break; + case 'W': sb.Append(@"\\/\\/"); break; + case 'h': sb.Append("|-|"); break; + case 'H': sb.Append("|-|"); break; + case 'v': sb.Append(@"\\/"); break; + case 'V': sb.Append(@"\\/"); break; + case 'k': sb.Append("|{"); break; + case 'K': sb.Append("|{"); break; + case 'r': sb.Append("®"); break; + case 'R': sb.Append("®"); break; + case 'm': sb.Append(@"|\\/|"); break; + case 'M': sb.Append(@"|\\/|"); break; + case 'b': sb.Append("ß"); break; + case 'B': sb.Append("ß"); break; + case 'j': sb.Append("_|"); break; + case 'J': sb.Append("_|"); break; + case 'P': sb.Append("|°"); break; + case 'q': sb.Append("¶"); break; + case 'Q': sb.Append("¶¸"); break; + case 'x': sb.Append(")("); break; + case 'X': sb.Append(")("); break; + default: sb.Append(c); break; + } + } + #endregion + } + return sb.ToString(); // Return result. + } + } +} diff --git a/NadekoBot/Modules/Conversations.cs b/NadekoBot/Modules/Conversations.cs index c32f4818..d49d9b78 100644 --- a/NadekoBot/Modules/Conversations.cs +++ b/NadekoBot/Modules/Conversations.cs @@ -9,6 +9,7 @@ using System.Diagnostics; using System.Drawing; using System.IO; using System.Drawing.Imaging; +using NadekoBot.Classes; using NadekoBot.Extensions; using NadekoBot.Properties; using NadekoBot.Commands; @@ -388,6 +389,21 @@ namespace NadekoBot.Modules { } await e.Channel.SendMessage(await usr.AvatarUrl.ShortenUrl()); }); + + cgb.CreateCommand("leet") + .Parameter("level", ParameterType.Required) + .Parameter("text", ParameterType.Unparsed) + .Do(async e => { + var text = e.GetArg("text")?.Trim(); + var levelStr = e.GetArg("level")?.Trim(); + int level; + if (!int.TryParse(levelStr, out level)) + return; + if (string.IsNullOrWhiteSpace(text)) + return; + await e.Channel.SendMessage(text.ToLeet(level)); + }); + }); } diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 5999d683..7493237e 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -124,6 +124,7 @@ +