Browse Source

Configuration - Added channel specific configuration editing (enable/disable modules/commands)

tags/3.1.1
Teknikode 4 years ago
parent
commit
a9d0eb7527
2 changed files with 196 additions and 14 deletions
  1. 78
    0
      Modules/Configuration/Configuration.cs
  2. 118
    14
      Modules/Configuration/Module.Default.json

+ 78
- 0
Modules/Configuration/Configuration.cs View File

@@ -648,6 +648,84 @@ namespace Combot.Modules.Plugins
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notFound);
}
break;
case "Channel Configuration":
string chanType = command.Arguments["Type"];
string channel = (command.Arguments.ContainsKey("Channel")) ? command.Arguments["Channel"] : command.Location;
if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, command.Access))
{
switch (chanType.ToLower())
{
case "command":
Module cmdModule = Bot.Modules.Find(module => module.Commands.Exists(c => c.Triggers.Contains(command.Arguments["Command"]) || c.Name.ToLower() == command.Arguments["Command"].ToLower()));
if (cmdModule != null)
{
ConfigLock.EnterWriteLock();
Command cmd = cmdModule.Commands.Find(c => c.Triggers.Contains(command.Arguments["Command"]) || c.Name == command.Arguments["Command"]);
string action = command.Arguments["Action"];
string cmdMsg = string.Empty;
if (action.ToLower() == "enable")
{
cmd.ChannelBlacklist.Remove(channel);
cmdMsg = string.Format("\u0002{0}\u0002 is now \u0002Enabled\u0002 in \u0002{1}\u0002", command.Arguments["Command"], channel);
}
else
{
if (!cmd.ChannelBlacklist.Contains(channel))
{
cmd.ChannelBlacklist.Add(channel);
}
cmdMsg = string.Format("\u0002{0}\u0002 is now \u0002Disabled\u0002 in \u0002{1}\u0002", command.Arguments["Command"], channel);
}
cmdModule.SaveConfig();
ConfigLock.ExitWriteLock();

SendResponse(command.MessageType, command.Location, command.Nick.Nickname, cmdMsg);
}
else
{
string notFound = string.Format("\u0002{0}\u000F is not a valid command.", command.Arguments["Command"]);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notFound);
}
break;
case "module":
Module modConfig = Bot.Modules.Find(module => module.Name.ToLower() == command.Arguments["Module"].ToLower() || module.ClassName.ToLower() == command.Arguments["Module"].ToLower());
if (modConfig != null)
{
ConfigLock.EnterWriteLock();
string action = command.Arguments["Action"];
string modMsg = string.Empty;
if (action.ToLower() == "enable")
{
modConfig.ChannelBlacklist.Remove(channel);
modMsg = string.Format("\u0002{0}\u0002 is now \u0002Enabled\u0002 in \u0002{1}\u0002", command.Arguments["Module"], channel);
}
else
{
if (!modConfig.ChannelBlacklist.Contains(channel))
{
modConfig.ChannelBlacklist.Add(channel);
}
modMsg = string.Format("\u0002{0}\u0002 is now \u0002Disabled\u0002 in \u0002{1}\u0002", command.Arguments["Module"], channel);
}
modConfig.SaveConfig();
ConfigLock.ExitWriteLock();

SendResponse(command.MessageType, command.Location, command.Nick.Nickname, modMsg);
}
else
{
string notFound = string.Format("\u0002{0}\u000F is not a valid module.", command.Arguments["Module"]);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notFound);
}
break;
}
}
else
{
string noAccess = string.Format("You do not have access to change the configuration for \u0002{0}\u0002.", channel);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, noAccess);
}
break;
}
}
}

+ 118
- 14
Modules/Configuration/Module.Default.json View File

@@ -2,15 +2,15 @@
"Name": "Configuration",
"ClassName": "Configuration",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"ChannelBlacklist": [ ],
"NickBlacklist": [ ],
"Commands": [
{
"Name": "Command Configuration",
"Description": "Allows you access to a command's configuration.",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"ChannelBlacklist": [ ],
"NickBlacklist": [ ],
"Triggers": [
"command"
],
@@ -18,8 +18,8 @@
{
"Name": "Command",
"Description": "The command you want to interact with.",
"AllowedValues": [],
"DependentArguments": [],
"AllowedValues": [ ],
"DependentArguments": [ ],
"MessageTypes": [
0,
1,
@@ -43,7 +43,7 @@
"ShowHelp",
"SpamCheck"
],
"DependentArguments": [],
"DependentArguments": [ ],
"MessageTypes": [
0,
1,
@@ -108,7 +108,7 @@
{
"Name": "Value",
"Description": "The value for the parameter you want to modify.",
"AllowedValues": [],
"AllowedValues": [ ],
"DependentArguments": [
{
"Name": "Action",
@@ -142,8 +142,8 @@
"Name": "Module Configuration",
"Description": "Allows you access to a module's configuration.",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"ChannelBlacklist": [ ],
"NickBlacklist": [ ],
"Triggers": [
"module"
],
@@ -151,8 +151,8 @@
{
"Name": "Module",
"Description": "The module you want to interact with.",
"AllowedValues": [],
"DependentArguments": [],
"AllowedValues": [ ],
"DependentArguments": [ ],
"MessageTypes": [
0,
1,
@@ -172,7 +172,7 @@
"Commands",
"Options"
],
"DependentArguments": [],
"DependentArguments": [ ],
"MessageTypes": [
0,
1,
@@ -233,7 +233,7 @@
{
"Name": "Value",
"Description": "The value for the parameter you want to modify.",
"AllowedValues": [],
"AllowedValues": [ ],
"DependentArguments": [
{
"Name": "Action",
@@ -262,6 +262,110 @@
],
"ShowHelp": true,
"SpamCheck": true
},
{
"Name": "Channel Configuration",
"Description": "Allows you to modify channel specific configurations.",
"Enabled": true,
"ChannelBlacklist": [ ],
"NickBlacklist": [ ],
"Triggers": [
"channel"
],
"Arguments": [
{
"Name": "Channel",
"Description": "The channel the configuration is for.",
"AllowedValues": [ ],
"DependentArguments": [ ],
"MessageTypes": [
1,
2
],
"Required": true
},
{
"Name": "Type",
"Description": "The type of configuration you want to edit.",
"AllowedValues": [
"Module",
"Command"
],
"DependentArguments": [ ],
"MessageTypes": [
0,
1,
2
],
"Required": true
},
{
"Name": "Command",
"Description": "The command you want to edit.",
"AllowedValues": [ ],
"DependentArguments": [
{
"Name": "Type",
"Values": [
"Command"
]
}
],
"MessageTypes": [
0,
1,
2
],
"Required": true
},
{
"Name": "Module",
"Description": "The module you want to edit.",
"AllowedValues": [ ],
"DependentArguments": [
{
"Name": "Type",
"Values": [
"Module"
]
}
],
"MessageTypes": [
0,
1,
2
],
"Required": true
},
{
"Name": "Action",
"Description": "The action you want to perform on the config.",
"AllowedValues": [
"Enable",
"Disable"
],
"DependentArguments": [ ],
"MessageTypes": [
0,
1,
2
],
"Required": true
}
],
"AllowedMessageTypes": [
0,
1,
2
],
"AllowedAccess": [
3,
4,
5,
6
],
"ShowHelp": true,
"SpamCheck": true
}
],
"Options": []

Loading…
Cancel
Save