From 9bcce1f2d86affc3c81e19e4162252f218aa0557 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sun, 26 Jun 2016 22:06:48 +0200 Subject: [PATCH] Added option for automatic deletion of successfullcommands (.delmsgoncmd) --- NadekoBot/Classes/ServerSpecificConfig.cs | 12 +++++++ .../Administration/AdministrationModule.cs | 31 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/NadekoBot/Classes/ServerSpecificConfig.cs b/NadekoBot/Classes/ServerSpecificConfig.cs index a8efee5d..47384bfd 100644 --- a/NadekoBot/Classes/ServerSpecificConfig.cs +++ b/NadekoBot/Classes/ServerSpecificConfig.cs @@ -108,6 +108,18 @@ namespace NadekoBot.Classes [JsonIgnore] private ObservableCollection observingStreams; + + [JsonIgnore] + private bool autoDeleteMessagesOnCommand = false; + public bool AutoDeleteMessagesOnCommand { + get { return autoDeleteMessagesOnCommand; } + set { + autoDeleteMessagesOnCommand = value; + if (!SpecificConfigurations.Instantiated) return; + OnPropertyChanged(); + } + } + public ObservableCollection ObservingStreams { get { return observingStreams; } set { diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index b8777f2f..8eaa7a41 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -29,6 +29,22 @@ namespace NadekoBot.Modules.Administration commands.Add(new CustomReactionsCommands(this)); commands.Add(new AutoAssignRole(this)); commands.Add(new SelfCommands(this)); + + NadekoBot.Client.GetService().CommandExecuted += DeleteCommandMessage; + } + + private void DeleteCommandMessage(object sender, CommandEventArgs e) + { + if (e.Server == null || e.Channel.IsPrivate) + return; + var conf = SpecificConfigurations.Default.Of(e.Server.Id); + if (!conf.AutoDeleteMessagesOnCommand) + return; + try + { + e.Message.Delete(); + } + catch { } } public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration; @@ -45,6 +61,21 @@ namespace NadekoBot.Modules.Administration commands.ForEach(cmd => cmd.Init(cgb)); + cgb.CreateCommand(Prefix + "delmsgoncmd") + .Description("Toggles the automatic deletion of user's successful command message to prevent chat flood. Server Manager Only.") + .AddCheck(SimpleCheckers.ManageServer()) + .Do(async e => + { + var conf = SpecificConfigurations.Default.Of(e.Server.Id); + conf.AutoDeleteMessagesOnCommand = !conf.AutoDeleteMessagesOnCommand; + Classes.JSONModels.ConfigHandler.SaveConfig(); + if (conf.AutoDeleteMessagesOnCommand) + await e.Channel.SendMessage("❗`Now automatically deleting successfull command invokations.`"); + else + await e.Channel.SendMessage("❗`Stopped automatic deletion of successfull command invokations.`"); + + }); + cgb.CreateCommand(Prefix + "restart") .Description("Restarts the bot. Might not work.") .AddCheck(SimpleCheckers.OwnerOnly())