diff --git a/Module/ModCommands/ConfigItem.cs b/Module/ModCommands/ConfigItem.cs index 87c59c2..0f7c8e5 100644 --- a/Module/ModCommands/ConfigItem.cs +++ b/Module/ModCommands/ConfigItem.cs @@ -22,29 +22,19 @@ namespace Noikoio.RegexBot.Module.ModCommands { throw new RuleImportException("Configuration for this section is invalid."); } - var config = (JObject)inconf; // Command instance creation var commands = new Dictionary(StringComparer.OrdinalIgnoreCase); - var commandconf = config["Commands"]; - if (commandconf != null) + foreach (var def in inconf.Children()) { - if (commandconf.Type != JTokenType.Object) - { - throw new RuleImportException("CommandDefs is not properly defined."); - } + string label = def.Name; + var cmd = Command.CreateInstance(instance, def); + if (commands.ContainsKey(cmd.Trigger)) + throw new RuleImportException( + $"{label}: 'command' value must not be equal to that of another definition. " + + $"Given value is being used for \"{commands[cmd.Trigger].Label}\"."); - foreach (var def in commandconf.Children()) - { - string label = def.Name; - var cmd = Command.CreateInstance(instance, def); - if (commands.ContainsKey(cmd.Trigger)) - throw new RuleImportException( - $"{label}: 'command' value must not be equal to that of another definition. " + - $"Given value is being used for \"{commands[cmd.Trigger].Label}\"."); - - commands.Add(cmd.Trigger, cmd); - } + commands.Add(cmd.Trigger, cmd); } _cmdInstances = new ReadOnlyDictionary(commands); } diff --git a/docs/modcommands.md b/docs/modcommands.md index bfbc307..685099a 100644 --- a/docs/modcommands.md +++ b/docs/modcommands.md @@ -5,22 +5,20 @@ ModCommands is the name of the component that provides the ability for one to cr Sample within a [server definition](serverdef.html): ``` "ModCommands": { - "Commands": { - "Kick": { // a plain and simple kick command - "type": "kick", - "command": "!!kick" - }, - "Party Ban": { // self-explanatory - "type": "ban", - "command": "!!party", - "successmsg": "Yay! $target got banned!\nhttps://i.imgur.com/i4CIBtT.jpg" - } + "Kick": { // a plain and simple kick command + "type": "kick", + "command": "!!kick" + }, + "Party Ban": { // self-explanatory + "type": "ban", + "command": "!!party", + "successmsg": "Yay! $target got banned!\nhttps://i.imgur.com/i4CIBtT.jpg" } } ``` ### Definition structure -Commands are defined within a JSON object named `Commands` within another object named `ModCommands`. They are defined by means of name/value pairs, with the name serving as its label. +Commands are defined within a `ModCommands` object, itself within a [server definition](serverdef.html). They are defined by means of name/value pairs, with the name serving as its label. The following values are **required** in a definition: * type (*string*) - Specifies the type of behavior that the command should take.