Leet moved to games

This commit is contained in:
Master Kwoth 2016-04-15 00:35:19 +02:00
parent 1617994e20
commit 4950e6b92c
3 changed files with 58 additions and 38 deletions

View File

@ -1,7 +1,6 @@
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Discord.Modules; using Discord.Modules;
using NadekoBot.Classes;
using NadekoBot.Classes.Conversations.Commands; using NadekoBot.Classes.Conversations.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules.Permissions.Classes; using NadekoBot.Modules.Permissions.Classes;
@ -489,21 +488,6 @@ namespace NadekoBot.Modules.Conversations
await e.Channel.SendMessage(await usr.AvatarUrl.ShortenUrl()); 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));
});
}); });
} }

View File

@ -1,21 +1,25 @@
using System; using Discord.Commands;
using System.Collections.Generic; using NadekoBot.Classes;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
//taken from //taken from
//http://www.codeproject.com/Tips/207582/L-t-Tr-nsl-t-r-Leet-Translator (thanks) //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 // because i don't want to waste my time on this cancerous command
namespace NadekoBot.Classes { namespace NadekoBot.Modules.Games.Commands
public static class Leet { {
internal class Leet : DiscordCommand
{
public Leet(DiscordModule module) : base(module)
{
}
/// <summary> /// <summary>
/// Translate text to Leet - Extension methods for string class /// Translate text to Leet - Extension methods for string class
/// </summary> /// </summary>
/// <param name="text">Orginal text</param> /// <param name="text">Orginal text</param>
/// <param name="degree">Degree of translation (1 - 3)</param> /// <param name="degree">Degree of translation (1 - 3)</param>
/// <returns>Leet translated text</returns> /// <returns>Leet translated text</returns>
public static string ToLeet(this string text, int degree = 1) => public static string ToLeet(string text, int degree = 1) =>
Translate(text, degree); Translate(text, degree);
/// <summary> /// <summary>
@ -24,7 +28,8 @@ namespace NadekoBot.Classes {
/// <param name="text">Orginal text</param> /// <param name="text">Orginal text</param>
/// <param name="degree">Degree of translation (1 - 3)</param> /// <param name="degree">Degree of translation (1 - 3)</param>
/// <returns>Leet translated text</returns> /// <returns>Leet translated text</returns>
public static string Translate(string text, int degree = 1) { public static string Translate(string text, int degree = 1)
{
if (degree > 6) if (degree > 6)
degree = 6; degree = 6;
if (degree <= 0) if (degree <= 0)
@ -32,10 +37,13 @@ namespace NadekoBot.Classes {
// StringBuilder to store result. // StringBuilder to store result.
StringBuilder sb = new StringBuilder(text.Length); StringBuilder sb = new StringBuilder(text.Length);
foreach (char c in text) { foreach (char c in text)
{
#region Degree 1 #region Degree 1
if (degree == 1) { if (degree == 1)
switch (c) { {
switch (c)
{
case 'a': sb.Append("4"); break; case 'a': sb.Append("4"); break;
case 'e': sb.Append("3"); break; case 'e': sb.Append("3"); break;
case 'i': sb.Append("1"); break; case 'i': sb.Append("1"); break;
@ -49,8 +57,10 @@ namespace NadekoBot.Classes {
} }
#endregion #endregion
#region Degree 2 #region Degree 2
else if (degree == 2) { else if (degree == 2)
switch (c) { {
switch (c)
{
case 'a': sb.Append("4"); break; case 'a': sb.Append("4"); break;
case 'e': sb.Append("3"); break; case 'e': sb.Append("3"); break;
case 'i': sb.Append("1"); break; case 'i': sb.Append("1"); break;
@ -76,8 +86,10 @@ namespace NadekoBot.Classes {
} }
#endregion #endregion
#region Degree 3 #region Degree 3
else if (degree == 3) { else if (degree == 3)
switch (c) { {
switch (c)
{
case 'a': sb.Append("4"); break; case 'a': sb.Append("4"); break;
case 'e': sb.Append("3"); break; case 'e': sb.Append("3"); break;
case 'i': sb.Append("1"); break; case 'i': sb.Append("1"); break;
@ -113,8 +125,10 @@ namespace NadekoBot.Classes {
} }
#endregion #endregion
#region Degree 4 #region Degree 4
else if (degree == 4) { else if (degree == 4)
switch (c) { {
switch (c)
{
case 'a': sb.Append("4"); break; case 'a': sb.Append("4"); break;
case 'e': sb.Append("3"); break; case 'e': sb.Append("3"); break;
case 'i': sb.Append("1"); break; case 'i': sb.Append("1"); break;
@ -160,8 +174,10 @@ namespace NadekoBot.Classes {
} }
#endregion #endregion
#region Degree 5 #region Degree 5
else if (degree == 5) { else if (degree == 5)
switch (c) { {
switch (c)
{
case 'a': sb.Append("4"); break; case 'a': sb.Append("4"); break;
case 'e': sb.Append("3"); break; case 'e': sb.Append("3"); break;
case 'i': sb.Append("1"); break; case 'i': sb.Append("1"); break;
@ -215,8 +231,10 @@ namespace NadekoBot.Classes {
} }
#endregion #endregion
#region Degree 6 #region Degree 6
else if (degree == 6) { else if (degree == 6)
switch (c) { {
switch (c)
{
case 'a': sb.Append("4"); break; case 'a': sb.Append("4"); break;
case 'e': sb.Append("3"); break; case 'e': sb.Append("3"); break;
case 'i': sb.Append("1"); break; case 'i': sb.Append("1"); break;
@ -275,5 +293,23 @@ namespace NadekoBot.Classes {
} }
return sb.ToString(); // Return result. return sb.ToString(); // Return result.
} }
internal override void Init(CommandGroupBuilder cgb)
{
cgb.CreateCommand(Module.Prefix + "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(ToLeet(text, level));
});
}
} }
} }

View File

@ -133,7 +133,7 @@
<Compile Include="Classes\JSONModels\MangaResult.cs" /> <Compile Include="Classes\JSONModels\MangaResult.cs" />
<Compile Include="Classes\JSONModels\PokemonType.cs" /> <Compile Include="Classes\JSONModels\PokemonType.cs" />
<Compile Include="Classes\JSONModels\_JSONModels.cs" /> <Compile Include="Classes\JSONModels\_JSONModels.cs" />
<Compile Include="Classes\Leet.cs" /> <Compile Include="Modules\Games\Commands\LeetCommand.cs" />
<Compile Include="Modules\Music\Classes\MusicControls.cs" /> <Compile Include="Modules\Music\Classes\MusicControls.cs" />
<Compile Include="Modules\Music\Classes\PoopyBuffer.cs" /> <Compile Include="Modules\Music\Classes\PoopyBuffer.cs" />
<Compile Include="Modules\Music\Classes\Song.cs" /> <Compile Include="Modules\Music\Classes\Song.cs" />