Update to conform to Kwoth

This commit is contained in:
appelemac 2016-05-04 23:34:24 +02:00
parent 1bd3e7481c
commit 40390ed17c

View File

@ -15,13 +15,13 @@ namespace NadekoBot.Modules.CustomReactions
public override void Install(ModuleManager manager) public override void Install(ModuleManager manager)
{ {
manager.CreateCommands("",cgb => manager.CreateCommands("", cgb =>
{ {
cgb.AddCheck(PermissionChecker.Instance); cgb.AddCheck(PermissionChecker.Instance);
Random range = new Random(); Random range = new Random();
Dictionary<string, Func<CommandEventArgs, string>> MyFuncs = new Dictionary<string, Func<CommandEventArgs, string>> Dictionary<string, Func<CommandEventArgs, string>> MyFuncs = new Dictionary<string, Func<CommandEventArgs, string>>
{ {
{"%rng%", (e) => range.Next().ToString()}, {"%rng%", (e) => range.Next().ToString()},
{"%mention%", (e) => NadekoBot.BotMention }, {"%mention%", (e) => NadekoBot.BotMention },
{"%user%", e => e.User.Mention }, {"%user%", e => e.User.Mention },
@ -31,43 +31,24 @@ namespace NadekoBot.Modules.CustomReactions
return string.IsNullOrWhiteSpace(arg) ? "" : arg; return string.IsNullOrWhiteSpace(arg) ? "" : arg;
} } } }
}; };
foreach (var command in NadekoBot.Config.CustomReactions) foreach (var command in NadekoBot.Config.CustomReactions)
{ {
var commandName = command.Key.Replace("%mention%", NadekoBot.BotMention); var commandName = command.Key.Replace("%mention%", NadekoBot.BotMention);
var c = cgb.CreateCommand(commandName); var c = cgb.CreateCommand(commandName);
c.Description($"Custom reaction.\n**Usage**:{command.Key}"); c.Description($"Custom reaction.\n**Usage**:{command.Key}");
c.Parameter("args", ParameterType.Unparsed); c.Parameter("args", ParameterType.Unparsed);
c.Do(async e => 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);
});
}
var ownerMentioned = e.Message.MentionedUsers.Where(x =>NadekoBot.IsOwner(x.Id)); });
var ownerReactions = command.Value.Where(x => x.Contains("%owner%")).ToList();
string str;
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);
});
}
});
} }
} }
} }