Moved to seperate file

This commit is contained in:
appelemac 2016-05-05 11:47:47 +02:00
parent 40390ed17c
commit 3b3ac5496f
3 changed files with 126 additions and 99 deletions

View File

@ -28,6 +28,7 @@ namespace NadekoBot.Modules.Administration
commands.Add(new SelfAssignedRolesCommand(this));
commands.Add(new Remind(this));
commands.Add(new InfoCommands(this));
commands.Add(new CustomReactionsCommands(this));
}
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration;
@ -851,103 +852,6 @@ namespace NadekoBot.Modules.Administration
await e.Channel.SendMessage(":ok:");
});
cgb.CreateCommand(Prefix + "addcustomreaction")
.Alias(Prefix + "acr")
.Description($"Add a custom reaction. **Owner Only!**\n**Usage**: {Prefix}acr \"hello\" I love saying hello to %user%")
.AddCheck(SimpleCheckers.OwnerOnly())
.Parameter("name", ParameterType.Required)
.Parameter("message", ParameterType.Unparsed)
.Do(async e =>
{
var name = e.GetArg("name");
var message = e.GetArg("message").Trim();
if (string.IsNullOrWhiteSpace(message))
{
await e.Channel.SendMessage($"Incorrect command usage. See -h {Prefix}acr for correct formatting").ConfigureAwait(false);
return;
}
try
{
NadekoBot.Config.CustomReactions[name].Add(message);
}
catch (System.Collections.Generic.KeyNotFoundException)
{
NadekoBot.Config.CustomReactions.Add(name, new System.Collections.Generic.List<string>() { message });
}
finally
{
Classes.JSONModels.ConfigHandler.SaveConfig();
}
await e.Channel.SendMessage($"Added {name} : {message}").ConfigureAwait(false);
});
cgb.CreateCommand(Prefix + "listcustomreactions")
.Alias(Prefix + "lcr")
.Description("Lists all current custom reactions. **Owner Only!**")
.AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e =>
{
string message = $"Custom reactions:";
foreach (var cr in NadekoBot.Config.CustomReactions)
{
if (message.Length > 1500)
{
await e.Channel.SendMessage(message).ConfigureAwait(false);
message = "";
}
message += $"\n**\"{Format.Escape(cr.Key)}\"**:";
int i = 1;
foreach (var reaction in cr.Value)
{
message += "\n " + i++ + "." + Format.Code(reaction);
}
}
await e.Channel.SendMessage(message);
});
cgb.CreateCommand(Prefix + "deletecustomreaction")
.Alias(Prefix + "dcr")
.Description("Deletes a custome reaction with given name (and index)")
.Parameter("name", ParameterType.Required)
.Parameter("index", ParameterType.Optional)
.Do(async e =>
{
var name = e.GetArg("name");
if (!NadekoBot.Config.CustomReactions.ContainsKey(name))
{
await e.Channel.SendMessage("Could not find given key");
return;
}
string message = "";
int index;
if (int.TryParse(e.GetArg("index") ?? "", out index))
{
try
{
NadekoBot.Config.CustomReactions[name].RemoveAt(index - 1);
if (!NadekoBot.Config.CustomReactions[name].Any())
{
NadekoBot.Config.CustomReactions.Remove(name);
}
message = $"Deleted response #{index} from {name}";
}
catch (ArgumentOutOfRangeException)
{
await e.Channel.SendMessage("Index given was out of range").ConfigureAwait(false);
return;
}
}
else
{
NadekoBot.Config.CustomReactions.Remove(name);
message = $"Deleted custom reaction \"{name}\"";
}
Classes.JSONModels.ConfigHandler.SaveConfig();
await e.Channel.SendMessage(message);
});
});
}

View File

@ -0,0 +1,123 @@
using NadekoBot.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord.Commands;
using NadekoBot.Modules.Permissions.Classes;
using Discord;
namespace NadekoBot.Modules.Administration.Commands
{
class CustomReactionsCommands : DiscordCommand
{
public CustomReactionsCommands(DiscordModule module) : base(module)
{
}
internal override void Init(CommandGroupBuilder cgb)
{
var Prefix = Module.Prefix;
cgb.CreateCommand(Prefix + "addcustomreaction")
.Alias(Prefix + "acr")
.Description($"Add a custom reaction. **Owner Only!**\n**Usage**: {Prefix}acr \"hello\" I love saying hello to %user%")
.AddCheck(SimpleCheckers.OwnerOnly())
.Parameter("name", ParameterType.Required)
.Parameter("message", ParameterType.Unparsed)
.Do(async e =>
{
var name = e.GetArg("name");
var message = e.GetArg("message").Trim();
if (string.IsNullOrWhiteSpace(message))
{
await e.Channel.SendMessage($"Incorrect command usage. See -h {Prefix}acr for correct formatting").ConfigureAwait(false);
return;
}
try
{
NadekoBot.Config.CustomReactions[name].Add(message);
}
catch (KeyNotFoundException)
{
NadekoBot.Config.CustomReactions.Add(name, new System.Collections.Generic.List<string>() { message });
}
finally
{
Classes.JSONModels.ConfigHandler.SaveConfig();
}
await e.Channel.SendMessage($"Added {name} : {message}").ConfigureAwait(false);
});
cgb.CreateCommand(Prefix + "listcustomreactions")
.Alias(Prefix + "lcr")
.Description("Lists all current custom reactions. **Owner Only!**")
.AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e =>
{
string message = $"Custom reactions:";
foreach (var cr in NadekoBot.Config.CustomReactions)
{
if (message.Length > 1500)
{
await e.Channel.SendMessage(message).ConfigureAwait(false);
message = "";
}
message += $"\n**\"{Format.Escape(cr.Key)}\"**:";
int i = 1;
foreach (var reaction in cr.Value)
{
message += "\n " + i++ + "." + Format.Code(reaction);
}
}
await e.Channel.SendMessage(message);
});
cgb.CreateCommand(Prefix + "deletecustomreaction")
.Alias(Prefix + "dcr")
.Description("Deletes a custome reaction with given name (and index)")
.Parameter("name", ParameterType.Required)
.Parameter("index", ParameterType.Optional)
.Do(async e =>
{
var name = e.GetArg("name");
if (!NadekoBot.Config.CustomReactions.ContainsKey(name))
{
await e.Channel.SendMessage("Could not find given key");
return;
}
string message = "";
int index;
if (int.TryParse(e.GetArg("index") ?? "", out index))
{
try
{
NadekoBot.Config.CustomReactions[name].RemoveAt(index - 1);
if (!NadekoBot.Config.CustomReactions[name].Any())
{
NadekoBot.Config.CustomReactions.Remove(name);
}
message = $"Deleted response #{index} from {name}";
}
catch (ArgumentOutOfRangeException)
{
await e.Channel.SendMessage("Index given was out of range").ConfigureAwait(false);
return;
}
}
else
{
NadekoBot.Config.CustomReactions.Remove(name);
message = $"Deleted custom reaction \"{name}\"";
}
Classes.JSONModels.ConfigHandler.SaveConfig();
await e.Channel.SendMessage(message);
});
}
}
}

View File

@ -120,13 +120,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Modules\Administration\Commands\CustomReactionsCommands.cs" />
<Compile Include="Modules\ClashOfClans\ClashOfClans.cs" />
<Compile Include="Classes\DBHandler.cs" />
<Compile Include="Classes\FlowersHandler.cs" />
<Compile Include="Modules\CustomReactions\CustomReactions.cs" />
<Compile Include="Modules\Programming\Commands\HaskellRepl.cs" />
<Compile Include="Modules\Programming\ProgrammingModule.cs" />
<Compile Include="Modules\Searches\Commands\IMDB\ImdbMovie.cs" />
<Compile Include="Modules\Searches\Commands\IMDB\ImdbScraper.cs" />
<Compile Include="Classes\IncidentsHandler.cs" />
@ -483,4 +483,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>