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.");
|
throw new RuleImportException("Configuration for this section is invalid.");
|
||||||
}
|
}
|
||||||
var config = (JObject)inconf;
|
|
||||||
|
|
||||||
// Command instance creation
|
// Command instance creation
|
||||||
var commands = new Dictionary<string, Command>(StringComparer.OrdinalIgnoreCase);
|
var commands = new Dictionary<string, Command>(StringComparer.OrdinalIgnoreCase);
|
||||||
var commandconf = config["Commands"];
|
foreach (var def in inconf.Children<JProperty>())
|
||||||
if (commandconf != null)
|
|
||||||
{
|
{
|
||||||
if (commandconf.Type != JTokenType.Object)
|
string label = def.Name;
|
||||||
{
|
var cmd = Command.CreateInstance(instance, def);
|
||||||
throw new RuleImportException("CommandDefs is not properly defined.");
|
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>())
|
commands.Add(cmd.Trigger, cmd);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_cmdInstances = new ReadOnlyDictionary<string, Command>(commands);
|
_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):
|
Sample within a [server definition](serverdef.html):
|
||||||
```
|
```
|
||||||
"ModCommands": {
|
"ModCommands": {
|
||||||
"Commands": {
|
"Kick": { // a plain and simple kick command
|
||||||
"Kick": { // a plain and simple kick command
|
"type": "kick",
|
||||||
"type": "kick",
|
"command": "!!kick"
|
||||||
"command": "!!kick"
|
},
|
||||||
},
|
"Party Ban": { // self-explanatory
|
||||||
"Party Ban": { // self-explanatory
|
"type": "ban",
|
||||||
"type": "ban",
|
"command": "!!party",
|
||||||
"command": "!!party",
|
"successmsg": "Yay! $target got banned!\nhttps://i.imgur.com/i4CIBtT.jpg"
|
||||||
"successmsg": "Yay! $target got banned!\nhttps://i.imgur.com/i4CIBtT.jpg"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Definition structure
|
### 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:
|
The following values are **required** in a definition:
|
||||||
* type (*string*) - Specifies the type of behavior that the command should take.
|
* type (*string*) - Specifies the type of behavior that the command should take.
|
||||||
|
|
Loading…
Reference in a new issue