Added .dmmod and .dmcmd to disable modules and commands in bot DMs
This commit is contained in:
parent
4a723b7c1c
commit
dc9ec2dafe
7 changed files with 103 additions and 10 deletions
|
@ -73,5 +73,38 @@ public partial class Permissions
|
|||
|
||||
await Response().Confirm(strs.gcmd_remove(Format.Bold(cmd.Name))).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public async Task DmModule(ModuleOrExpr module)
|
||||
{
|
||||
var moduleName = module.Name.ToLowerInvariant();
|
||||
|
||||
var added = _service.ToggleModule(moduleName, true);
|
||||
|
||||
if (added)
|
||||
{
|
||||
await Response().Confirm(strs.dmmod_add(Format.Bold(module.Name))).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await Response().Confirm(strs.dmmod_remove(Format.Bold(module.Name))).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public async Task DmCommand(CommandOrExprInfo cmd)
|
||||
{
|
||||
var commandName = cmd.Name.ToLowerInvariant();
|
||||
var added = _service.ToggleCommand(commandName, true);
|
||||
|
||||
if (added)
|
||||
{
|
||||
await Response().Confirm(strs.dmcmd_add(Format.Bold(cmd.Name))).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await Response().Confirm(strs.dmcmd_remove(Format.Bold(cmd.Name))).SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,11 +24,20 @@ public class GlobalPermissionService : IExecPreCommand, IEService
|
|||
var settings = _bss.Data;
|
||||
var commandName = command.Name.ToLowerInvariant();
|
||||
|
||||
if (commandName != "resetglobalperms"
|
||||
&& (settings.Blocked.Commands.Contains(commandName)
|
||||
|| settings.Blocked.Modules.Contains(moduleName.ToLowerInvariant())))
|
||||
if (commandName != "resetglobalperms")
|
||||
{
|
||||
if (settings.Blocked.Commands.Contains(commandName)
|
||||
|| settings.Blocked.Modules.Contains(moduleName.ToLowerInvariant()))
|
||||
return Task.FromResult(true);
|
||||
|
||||
if (ctx.Guild is null)
|
||||
{
|
||||
if (settings.DmBlocked.Commands.Contains(commandName)
|
||||
|| settings.DmBlocked.Modules.Contains(moduleName.ToLowerInvariant()))
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
|
@ -37,13 +46,30 @@ public class GlobalPermissionService : IExecPreCommand, IEService
|
|||
/// </summary>
|
||||
/// <param name="moduleName">Lowercase module name</param>
|
||||
/// <returns>Whether the module is added</returns>
|
||||
public bool ToggleModule(string moduleName)
|
||||
public bool ToggleModule(string moduleName, bool priv = false)
|
||||
{
|
||||
var added = false;
|
||||
_bss.ModifyConfig(bs =>
|
||||
{
|
||||
if (bs.Blocked.Modules.Add(moduleName))
|
||||
if (priv)
|
||||
{
|
||||
if (bs.DmBlocked.Modules.Add(moduleName))
|
||||
{
|
||||
added = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bs.DmBlocked.Modules.Remove(moduleName);
|
||||
added = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (bs.Blocked.Modules.Add(moduleName))
|
||||
{
|
||||
added = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bs.Blocked.Modules.Remove(moduleName);
|
||||
|
@ -59,13 +85,30 @@ public class GlobalPermissionService : IExecPreCommand, IEService
|
|||
/// </summary>
|
||||
/// <param name="commandName">Lowercase command name</param>
|
||||
/// <returns>Whether the command is added</returns>
|
||||
public bool ToggleCommand(string commandName)
|
||||
public bool ToggleCommand(string commandName, bool priv = false)
|
||||
{
|
||||
var added = false;
|
||||
_bss.ModifyConfig(bs =>
|
||||
{
|
||||
if (priv)
|
||||
{
|
||||
if (bs.Blocked.Commands.Add(commandName))
|
||||
{
|
||||
added = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bs.Blocked.Commands.Remove(commandName);
|
||||
added = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (bs.Blocked.Commands.Add(commandName))
|
||||
{
|
||||
added = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bs.Blocked.Commands.Remove(commandName);
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace EllieBot.Common.Configs;
|
|||
public sealed partial class BotConfig : ICloneable<BotConfig>
|
||||
{
|
||||
[Comment("""DO NOT CHANGE""")]
|
||||
public int Version { get; set; } = 8;
|
||||
public int Version { get; set; } = 9;
|
||||
|
||||
[Comment("""
|
||||
Most commands, when executed, have a small colored line
|
||||
|
@ -81,6 +81,9 @@ public sealed partial class BotConfig : ICloneable<BotConfig>
|
|||
[Comment("""List of modules and commands completely blocked on the bot""")]
|
||||
public BlockedConfig Blocked { get; set; }
|
||||
|
||||
[Comment("""List of modules and commands blocked from usage in DMs on the bot""")]
|
||||
public BlockedConfig DmBlocked { get; set; } = new();
|
||||
|
||||
[Comment("""Which string will be used to recognize the commands""")]
|
||||
public string Prefix { get; set; }
|
||||
|
||||
|
|
|
@ -70,10 +70,10 @@ public sealed class BotConfigService : ConfigServiceBase<BotConfig>
|
|||
c.IgnoreOtherBots = true;
|
||||
});
|
||||
|
||||
if(data.Version < 8)
|
||||
if(data.Version < 9)
|
||||
ModifyConfig(c =>
|
||||
{
|
||||
c.Version = 8;
|
||||
c.Version = 9;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1039,6 +1039,12 @@ gamevoicechannel:
|
|||
- gvc
|
||||
shoplistadd:
|
||||
- shoplistadd
|
||||
dmcommand:
|
||||
- dmcommand
|
||||
- dmcmd
|
||||
dmmodule:
|
||||
- dmmodule
|
||||
- dmmod
|
||||
globalcommand:
|
||||
- globalcommand
|
||||
- gcmd
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# DO NOT CHANGE
|
||||
version: 8
|
||||
version: 9
|
||||
# Most commands, when executed, have a small colored line
|
||||
# next to the response. The color depends whether the command
|
||||
# is completed, errored or in progress (pending)
|
||||
|
@ -78,6 +78,10 @@ helpText: |-
|
|||
blocked:
|
||||
commands: []
|
||||
modules: []
|
||||
# List of modules and commands blocked from usage in DMs on the bot
|
||||
dmBlocked:
|
||||
commands: []
|
||||
modules: []
|
||||
# Which string will be used to recognize the commands
|
||||
prefix: .
|
||||
# Whether the bot will rotate through all specified statuses.
|
||||
|
|
|
@ -758,6 +758,10 @@
|
|||
"gcmd_remove": "Command {0} has been enabled on all servers.",
|
||||
"gmod_add": "Module {0} has been disabled on all servers.",
|
||||
"gmod_remove": "Module {0} has been enabled on all servers.",
|
||||
"dmmod_add": "Module {0} has been disabled in bot DMs.",
|
||||
"dmmod_remove": "Module {0} has been enabled in bot DMs.",
|
||||
"dmcmd_add": "Command {0} has been disabled in bot DMs.",
|
||||
"dmcmd_remove": "Command {0} has been enabled in bot DMs.",
|
||||
"lgp_none": "No blocked commands or modules.",
|
||||
"cant_read_or_send": "You can't read from or send messages to that channel.",
|
||||
"quotes_notfound": "No quotes found matching the quote ID specified.",
|
||||
|
|
Loading…
Reference in a new issue