From 1ff54fee2e78a942823537d6063939f9a8114d78 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 30 Mar 2016 12:46:02 +0200 Subject: [PATCH] $take and $award bot owner commands added. ref #163 --- NadekoBot/Modules/Gambling/GamblingModule.cs | 46 ++++++++++++++++ NadekoBot/Modules/Games.cs | 55 ++++++++++++-------- 2 files changed, 79 insertions(+), 22 deletions(-) diff --git a/NadekoBot/Modules/Gambling/GamblingModule.cs b/NadekoBot/Modules/Gambling/GamblingModule.cs index ee1661d3..911fd367 100644 --- a/NadekoBot/Modules/Gambling/GamblingModule.cs +++ b/NadekoBot/Modules/Gambling/GamblingModule.cs @@ -33,9 +33,11 @@ namespace NadekoBot.Modules.Gambling .Description("Prints a name and ID of a random user from the online list from the (optional) role.") .Parameter("role", ParameterType.Optional) .Do(RaffleFunc()); + cgb.CreateCommand(Prefix + "$$") .Description(string.Format("Check how much {0}s you have.", NadekoBot.Config.CurrencyName)) .Do(NadekoFlowerCheckFunc()); + cgb.CreateCommand(Prefix + "give") .Description(string.Format("Give someone a certain amount of {0}s", NadekoBot.Config.CurrencyName)) .Parameter("amount", ParameterType.Required) @@ -67,6 +69,50 @@ namespace NadekoBot.Modules.Gambling await e.Channel.SendMessage($"{e.User.Mention} successfully sent {amount} {NadekoBot.Config.CurrencyName}s to {mentionedUser.Mention}!"); }); + + cgb.CreateCommand(Prefix + "award") + .Description("Gives someone a certain amount of flowers. **Owner only!**") + .AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly()) + .Parameter("amount", ParameterType.Required) + .Parameter("receiver", ParameterType.Unparsed) + .Do(async e => + { + var amountStr = e.GetArg("amount")?.Trim(); + long amount; + if (!long.TryParse(amountStr, out amount) || amount < 0) + return; + + var mentionedUser = e.Message.MentionedUsers.FirstOrDefault(u => + u.Id != NadekoBot.Client.CurrentUser.Id); + if (mentionedUser == null) + return; + + await FlowersHandler.AddFlowersAsync(mentionedUser, $"Awarded by bot owner. ({e.User.Name}/{e.User.Id})", (int)amount); + + await e.Channel.SendMessage($"{e.User.Mention} successfully awarded {amount} {NadekoBot.Config.CurrencyName}s to {mentionedUser.Mention}!"); + }); + + cgb.CreateCommand(Prefix + "take") + .Description("Takes a certain amount of flowers from someone. **Owner only!**") + .AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly()) + .Parameter("amount", ParameterType.Required) + .Parameter("rektperson", ParameterType.Unparsed) + .Do(async e => + { + var amountStr = e.GetArg("amount")?.Trim(); + long amount; + if (!long.TryParse(amountStr, out amount) || amount < 0) + return; + + var mentionedUser = e.Message.MentionedUsers.FirstOrDefault(u => + u.Id != NadekoBot.Client.CurrentUser.Id); + if (mentionedUser == null) + return; + + await FlowersHandler.RemoveFlowersAsync(mentionedUser, $"Taken by bot owner.({e.User.Name}/{e.User.Id})", (int)amount); + + await e.Channel.SendMessage($"{e.User.Mention} successfully took {amount} {NadekoBot.Config.CurrencyName}s from {mentionedUser.Mention}!"); + }); }); } diff --git a/NadekoBot/Modules/Games.cs b/NadekoBot/Modules/Games.cs index 9321859a..508a0603 100644 --- a/NadekoBot/Modules/Games.cs +++ b/NadekoBot/Modules/Games.cs @@ -1,28 +1,31 @@ -using System; -using System.Linq; +using Discord.Commands; using Discord.Modules; using NadekoBot.Commands; -using Newtonsoft.Json.Linq; -using System.IO; -using Discord.Commands; using NadekoBot.Extensions; +using System; +using System.Linq; -namespace NadekoBot.Modules { - internal class Games : DiscordModule { +namespace NadekoBot.Modules +{ + internal class Games : DiscordModule + { private readonly Random rng = new Random(); - public Games() { + public Games() + { commands.Add(new Trivia(this)); commands.Add(new SpeedTyping(this)); commands.Add(new PollCommand(this)); //commands.Add(new BetrayGame(this)); - + } public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Games; - public override void Install(ModuleManager manager) { - manager.CreateCommands("", cgb => { + public override void Install(ModuleManager manager) + { + manager.CreateCommands("", cgb => + { cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); @@ -30,8 +33,9 @@ namespace NadekoBot.Modules { cgb.CreateCommand(Prefix + "choose") .Description("Chooses a thing from a list of things\n**Usage**: >choose Get up;Sleep;Sleep more") - .Parameter("list", Discord.Commands.ParameterType.Unparsed) - .Do(async e => { + .Parameter("list", ParameterType.Unparsed) + .Do(async e => + { var arg = e.GetArg("list"); if (string.IsNullOrWhiteSpace(arg)) return; @@ -43,24 +47,29 @@ namespace NadekoBot.Modules { cgb.CreateCommand(Prefix + "8ball") .Description("Ask the 8ball a yes/no question.") - .Parameter("question", Discord.Commands.ParameterType.Unparsed) - .Do(async e => { + .Parameter("question", ParameterType.Unparsed) + .Do(async e => + { var question = e.GetArg("question"); if (string.IsNullOrWhiteSpace(question)) return; - try { + try + { await e.Channel.SendMessage( $":question: **Question**: `{question}` \n🎱 **8Ball Answers**: `{NadekoBot.Config._8BallResponses[rng.Next(0, NadekoBot.Config._8BallResponses.Length)]}`"); - } catch { } + } + catch { } }); cgb.CreateCommand(Prefix + "rps") - .Description("Play a game of rocket paperclip scissors with nadkeo.\n**Usage**: >rps scissors") + .Description("Play a game of rocket paperclip scissors with Nadeko.\n**Usage**: >rps scissors") .Parameter("input", ParameterType.Required) - .Do(async e => { + .Do(async e => + { var input = e.GetArg("input").Trim(); int pick; - switch (input) { + switch (input) + { case "r": case "rock": case "rocket": @@ -96,7 +105,8 @@ namespace NadekoBot.Modules { .Description("Prints a customizable Linux interjection") .Parameter("gnu", ParameterType.Required) .Parameter("linux", ParameterType.Required) - .Do(async e => { + .Do(async e => + { var guhnoo = e.Args[0]; var loonix = e.Args[1]; @@ -112,7 +122,8 @@ There really is a {loonix}, and these people are using it, but it is just a part }); } - private string GetRPSPick(int i) { + private string GetRPSPick(int i) + { if (i == 0) return "rocket"; else if (i == 1)