diff --git a/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs b/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs index c9de745e..ec99afa5 100644 --- a/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs +++ b/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs @@ -74,7 +74,7 @@ namespace NadekoBot.Modules.Administration.Commands var name = e.GetArg("name"); if (!NadekoBot.Config.CustomReactions.ContainsKey(name)) { - await e.Channel.SendMessage("Could not find given key"); + await e.Channel.SendMessage("Could not find given commandname"); return; } string message = ""; diff --git a/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/NadekoBot/Modules/CustomReactions/CustomReactions.cs index cf677b6b..ef95c9d0 100644 --- a/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -5,6 +5,7 @@ using Discord.Modules; using Discord.Commands; using NadekoBot.Modules.Permissions.Classes; using NadekoBot.Extensions; +using System.Text.RegularExpressions; namespace NadekoBot.Modules.CustomReactions { @@ -20,19 +21,16 @@ namespace NadekoBot.Modules.CustomReactions cgb.AddCheck(PermissionChecker.Instance); Random range = new Random(); - Dictionary> MyFuncs = new Dictionary> + Dictionary> commandFuncs = new Dictionary> { {"%rng%", (e) => range.Next().ToString()}, {"%mention%", (e) => NadekoBot.BotMention }, {"%user%", e => e.User.Mention }, - {"%target%", e => - { - var arg = e.GetArg("args"); - return string.IsNullOrWhiteSpace(arg) ? "" : arg; - } } - + {"%target%", e => e.GetArg("args")?.Trim() ?? "" }, }; + + foreach (var command in NadekoBot.Config.CustomReactions) { var commandName = command.Key.Replace("%mention%", NadekoBot.BotMention); @@ -43,7 +41,7 @@ namespace NadekoBot.Modules.CustomReactions c.Do(async e => { string str = command.Value[range.Next(0, command.Value.Count())]; - MyFuncs.Keys.ForEach(k => str = str.Replace(k, MyFuncs[k](e))); + commandFuncs.Keys.ForEach(k => str = str.Replace(k, commandFuncs[k](e))); await e.Channel.SendMessage(str).ConfigureAwait(false); }); }