Removed redundant JSON object in configuration
This commit is contained in:
parent
6860bf98de
commit
bdc0d223cd
2 changed files with 17 additions and 29 deletions
|
@ -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<string, Command>(StringComparer.OrdinalIgnoreCase);
|
||||
var commandconf = config["Commands"];
|
||||
if (commandconf != null)
|
||||
foreach (var def in inconf.Children<JProperty>())
|
||||
{
|
||||
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<JProperty>())
|
||||
{
|
||||
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<string, Command>(commands);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue