Added option for automatic deletion of successfullcommands (.delmsgoncmd)

This commit is contained in:
Master Kwoth 2016-06-26 22:06:48 +02:00
parent 2b7e81e68f
commit 9bcce1f2d8
2 changed files with 43 additions and 0 deletions

View File

@ -108,6 +108,18 @@ namespace NadekoBot.Classes
[JsonIgnore]
private ObservableCollection<StreamNotificationConfig> observingStreams;
[JsonIgnore]
private bool autoDeleteMessagesOnCommand = false;
public bool AutoDeleteMessagesOnCommand {
get { return autoDeleteMessagesOnCommand; }
set {
autoDeleteMessagesOnCommand = value;
if (!SpecificConfigurations.Instantiated) return;
OnPropertyChanged();
}
}
public ObservableCollection<StreamNotificationConfig> ObservingStreams {
get { return observingStreams; }
set {

View File

@ -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<CommandService>().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())