From 40390ed17c395c1ecbc3a6ff372b6de390408d98 Mon Sep 17 00:00:00 2001 From: appelemac Date: Wed, 4 May 2016 23:34:24 +0200 Subject: [PATCH] Update to conform to Kwoth --- .../CustomReactions/CustomReactions.cs | 61 +++++++------------ 1 file changed, 21 insertions(+), 40 deletions(-) diff --git a/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/NadekoBot/Modules/CustomReactions/CustomReactions.cs index ab794377..cf677b6b 100644 --- a/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -15,13 +15,13 @@ namespace NadekoBot.Modules.CustomReactions public override void Install(ModuleManager manager) { - manager.CreateCommands("",cgb => - { + manager.CreateCommands("", cgb => + { - cgb.AddCheck(PermissionChecker.Instance); - Random range = new Random(); - Dictionary> MyFuncs = new Dictionary> - { + cgb.AddCheck(PermissionChecker.Instance); + Random range = new Random(); + Dictionary> MyFuncs = new Dictionary> + { {"%rng%", (e) => range.Next().ToString()}, {"%mention%", (e) => NadekoBot.BotMention }, {"%user%", e => e.User.Mention }, @@ -31,43 +31,24 @@ namespace NadekoBot.Modules.CustomReactions return string.IsNullOrWhiteSpace(arg) ? "" : arg; } } - }; + }; - foreach (var command in NadekoBot.Config.CustomReactions) - { - var commandName = command.Key.Replace("%mention%", NadekoBot.BotMention); + foreach (var command in NadekoBot.Config.CustomReactions) + { + var commandName = command.Key.Replace("%mention%", NadekoBot.BotMention); - var c = cgb.CreateCommand(commandName); - c.Description($"Custom reaction.\n**Usage**:{command.Key}"); - c.Parameter("args", ParameterType.Unparsed); - c.Do(async e => - { - - var ownerMentioned = e.Message.MentionedUsers.Where(x =>NadekoBot.IsOwner(x.Id)); - var ownerReactions = command.Value.Where(x => x.Contains("%owner%")).ToList(); - string str; + var c = cgb.CreateCommand(commandName); + c.Description($"Custom reaction.\n**Usage**:{command.Key}"); + c.Parameter("args", ParameterType.Unparsed); + 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))); + await e.Channel.SendMessage(str).ConfigureAwait(false); + }); + } - if (ownerMentioned.Any() && ownerReactions.Any()) - { - str = ownerReactions[range.Next(0, ownerReactions.Count)]; - str = str.Replace("%owner%", ownerMentioned.FirstOrDefault().Mention); - } - else if (ownerReactions.Any()) - { - var others = command.Value.Except(ownerReactions).ToList(); - str = others[range.Next(0, others.Count())]; - } - else - { - str = command.Value[range.Next(0, command.Value.Count())]; - } - MyFuncs.Keys.ForEach(k => str = str.Replace(k, MyFuncs[k](e))); - - await e.Channel.SendMessage(str).ConfigureAwait(false); - }); - } - - }); + }); } } } \ No newline at end of file