From a09be962002ffaca4180f5076460abc37967142f Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 16 Sep 2021 22:51:58 +0200 Subject: [PATCH] Added DmHelpTextKeywords to data/bot.yml - Bot now sends dm help text ONLY if the message contains one of the keywords specified - If no keywords are specified, bot will reply to every DM (like before) - Fixed several commands which used error color for success confirmation messages --- CHANGELOG.md | 7 +++++-- src/NadekoBot/Common/Configs/BotConfig.cs | 16 ++++++++++++++-- .../Modules/Administration/SelfCommands.cs | 12 ++++++------ .../Modules/Help/Services/HelpService.cs | 5 +++++ .../Modules/Xp/Services/XpConfigService.cs | 2 +- .../Services/Settings/BotConfigService.cs | 16 ++++++---------- src/NadekoBot/data/bot.yml | 11 ++++++++++- 7 files changed, 47 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da43ea310..2aef80b9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,16 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog. ### Added - Fully translated to Brazilian Portuguese 🎉 - Added `%server.boosters%` and `%server.boost_level%` placeholders +- Added `DmHelpTextKeywords` to `data/bot.yml` + - Bot now sends dm help text ONLY if the message contains one of the keywords specified + - If no keywords are specified, bot will reply to every DM (like before) ### Fixed - Possible fix for `.repeat` bug - Slight adjustment for repeater logic - Timer should no longer increase on some repeaters - - Repeaters should no longer have periods when they're missing from the list - + - Repeaters should no longer have periods when they're missing from the list +- Fixed several commands which used error color for success confirmation messages ## [3.0.3] - 15.09.2021 diff --git a/src/NadekoBot/Common/Configs/BotConfig.cs b/src/NadekoBot/Common/Configs/BotConfig.cs index c62658cb9..4a94bee3d 100644 --- a/src/NadekoBot/Common/Configs/BotConfig.cs +++ b/src/NadekoBot/Common/Configs/BotConfig.cs @@ -12,7 +12,7 @@ namespace NadekoBot.Common.Configs public sealed partial class BotConfig : ICloneable { [Comment(@"DO NOT CHANGE")] - public int Version { get; set; } + public int Version { get; set; } = 2; [Comment(@"Most commands, when executed, have a small colored line next to the response. The color depends whether the command @@ -48,6 +48,11 @@ they will receive this message. Leave empty for no response. The string which wi Supports embeds. How it looks: https://puu.sh/B0BLV.png")] [YamlMember(ScalarStyle = ScalarStyle.Literal)] public string DmHelpText { get; set; } + + [Comment(@"Only users who send a DM to the bot containing one of the specified words will get a DmHelpText response. +Case insensitive. +Leave empty to reply with DmHelpText to every DM.")] + public List DmHelpTextKeywords { get; set; } [Comment(@"This is the response for the .h command")] [YamlMember(ScalarStyle = ScalarStyle.Literal)] @@ -89,7 +94,6 @@ See RotatingStatuses submodule in Administration.")] public BotConfig() { - Version = 1; var color = new ColorConfig(); Color = color; DefaultLocale = new CultureInfo("en-US"); @@ -127,6 +131,14 @@ See RotatingStatuses submodule in Administration.")] Prefix = "."; RotateStatuses = false; GroupGreets = false; + DmHelpTextKeywords = new List() + { + "help", + "commands", + "cmds", + "module", + "can you do" + }; } } diff --git a/src/NadekoBot/Modules/Administration/SelfCommands.cs b/src/NadekoBot/Modules/Administration/SelfCommands.cs index c225eddd7..c9e4be88b 100644 --- a/src/NadekoBot/Modules/Administration/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfCommands.cs @@ -88,7 +88,7 @@ namespace NadekoBot.Modules.Administration }; _service.AddNewAutoCommand(cmd); - await ReplyErrorLocalizedAsync(strs.autocmd_add(Format.Code(Format.Sanitize(cmdText)), cmd.Interval)); + await ReplyConfirmLocalizedAsync(strs.autocmd_add(Format.Code(Format.Sanitize(cmdText)), cmd.Interval)); } [NadekoCommand, Aliases] @@ -226,7 +226,7 @@ namespace NadekoBot.Modules.Administration if (enabled) await ReplyConfirmLocalizedAsync(strs.fwdm_start).ConfigureAwait(false); else - await ReplyConfirmLocalizedAsync(strs.fwdm_stop).ConfigureAwait(false); + await ReplyPendingLocalizedAsync(strs.fwdm_stop).ConfigureAwait(false); } [NadekoCommand, Aliases] @@ -238,7 +238,7 @@ namespace NadekoBot.Modules.Administration if (enabled) await ReplyConfirmLocalizedAsync(strs.fwall_start).ConfigureAwait(false); else - await ReplyConfirmLocalizedAsync(strs.fwall_stop).ConfigureAwait(false); + await ReplyPendingLocalizedAsync(strs.fwall_stop).ConfigureAwait(false); } @@ -376,7 +376,7 @@ namespace NadekoBot.Modules.Administration var curUser = await ctx.Guild.GetCurrentUserAsync().ConfigureAwait(false); await curUser.ModifyAsync(u => u.Nickname = newNick).ConfigureAwait(false); - await ReplyErrorLocalizedAsync(strs.bot_nick(Format.Bold(newNick) ?? "-")); + await ReplyConfirmLocalizedAsync(strs.bot_nick(Format.Bold(newNick) ?? "-")); } [NadekoCommand, Aliases] @@ -395,7 +395,7 @@ namespace NadekoBot.Modules.Administration await gu.ModifyAsync(u => u.Nickname = newNick).ConfigureAwait(false); - await ReplyErrorLocalizedAsync(strs.user_nick(Format.Bold(gu.ToString()), Format.Bold(newNick) ?? "-")); + await ReplyConfirmLocalizedAsync(strs.user_nick(Format.Bold(gu.ToString()), Format.Bold(newNick) ?? "-")); } [NadekoCommand, Aliases] @@ -496,7 +496,7 @@ namespace NadekoBot.Modules.Administration public async Task ImagesReload() { await _service.ReloadImagesAsync(); - await ReplyErrorLocalizedAsync(strs.images_loading); + await ReplyConfirmLocalizedAsync(strs.images_loading); } [NadekoCommand, Aliases] diff --git a/src/NadekoBot/Modules/Help/Services/HelpService.cs b/src/NadekoBot/Modules/Help/Services/HelpService.cs index 25a9b51f3..d21e34f50 100644 --- a/src/NadekoBot/Modules/Help/Services/HelpService.cs +++ b/src/NadekoBot/Modules/Help/Services/HelpService.cs @@ -44,6 +44,11 @@ namespace NadekoBot.Modules.Help.Services { if (string.IsNullOrWhiteSpace(settings.DmHelpText) || settings.DmHelpText == "-") return Task.CompletedTask; + + // only send dm help text if it contains one of the keywords, if they're specified + // if they're not, then reply to every DM + if (settings.DmHelpTextKeywords.Any() && !settings.DmHelpTextKeywords.Any(k => msg.Content.Contains(k))) + return Task.CompletedTask; var rep = new ReplacementBuilder() .WithOverride("%prefix%", () => _bss.Data.Prefix) diff --git a/src/NadekoBot/Modules/Xp/Services/XpConfigService.cs b/src/NadekoBot/Modules/Xp/Services/XpConfigService.cs index 8c8123bb7..d27531cef 100644 --- a/src/NadekoBot/Modules/Xp/Services/XpConfigService.cs +++ b/src/NadekoBot/Modules/Xp/Services/XpConfigService.cs @@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Xp.Services private void Migrate() { - if (_data.Version <= 1) + if (_data.Version < 2) { ModifyConfig(c => { diff --git a/src/NadekoBot/Services/Settings/BotConfigService.cs b/src/NadekoBot/Services/Settings/BotConfigService.cs index f30107da2..b163c6f95 100644 --- a/src/NadekoBot/Services/Settings/BotConfigService.cs +++ b/src/NadekoBot/Services/Settings/BotConfigService.cs @@ -28,19 +28,15 @@ namespace NadekoBot.Services AddParsedProp("locale", bs => bs.DefaultLocale, ConfigParsers.Culture, ConfigPrinters.Culture); AddParsedProp("prefix", bs => bs.Prefix, ConfigParsers.String, ConfigPrinters.ToString); - UpdateColors(); + Migrate(); } - private void UpdateColors() + private void Migrate() { - var ok = _data.Color.Ok; - var error = _data.Color.Error; - var pend = _data.Color.Pending; - } - - protected override void OnStateUpdate() - { - UpdateColors(); + if (_data.Version < 2) + { + ModifyConfig(c => c.Version = 2); + } } } } \ No newline at end of file diff --git a/src/NadekoBot/data/bot.yml b/src/NadekoBot/data/bot.yml index 320b767c5..9eaf1a89e 100644 --- a/src/NadekoBot/data/bot.yml +++ b/src/NadekoBot/data/bot.yml @@ -1,5 +1,5 @@ # DO NOT CHANGE -version: 1 +version: 2 # 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) @@ -28,6 +28,15 @@ forwardToAllOwners: false # Supports embeds. How it looks: https://puu.sh/B0BLV.png dmHelpText: |- {"description": "Type `%prefix%h` for help."} +# Only users who send a DM to the bot containing one of the specified words will get a DmHelpText response. +# Case insensitive. +# Leave empty to reply with DmHelpText to every DM. +dmHelpTextKeywords: + - help + - commands + - cmds + - module + - can you do # This is the response for the .h command helpText: |- {