internal override void Init(CommandGroupBuilder cgb) { cgb.CreateCommand(Module.Prefix + "pick") .Description("Picks a flower planted in this channel.") .Do(async e => { Message msg; await e.Message.Delete().ConfigureAwait(false); if (!plantedFlowerChannels.TryRemove(e.Channel.Id, out msg)) { return; } await msg.Delete().ConfigureAwait(false); await FlowersHandler.AddFlowersAsync(e.User, "Picked a flower.", 1, true).ConfigureAwait(false); msg = await e.Channel.SendMessage($"**{e.User.Name}** picked a {WizBot.Config.CurrencyName}!").ConfigureAwait(false); await Task.Delay(10000).ConfigureAwait(false); await msg.Delete().ConfigureAwait(false); }); cgb.CreateCommand(Module.Prefix + "plant") .Description("Spend a flower to plant it in this channel. (If bot is restarted or crashes, flower will be lost)") .Do(async e => { lock (locker) { if (plantedFlowerChannels.ContainsKey(e.Channel.Id)) { e.Channel.SendMessage($"There is already a {WizBot.Config.CurrencyName} in this channel."); return; } var removed = FlowersHandler.RemoveFlowers(e.User, "Planted a flower.", 1); if (!removed) { e.Channel.SendMessage($"You don't have any {WizBot.Config.CurrencyName}s.").Wait(); return; } var rng = new Random(); var file = Directory.GetFiles("data/currency_images").OrderBy(s => rng.Next()).FirstOrDefault(); Message msg; //todo send message after, not in lock if (file == null) { msg = e.Channel.SendMessage(WizBot.Config.CurrencySign).GetAwaiter().GetResult(); } else { msg = e.Channel.SendFile(file).GetAwaiter().GetResult(); } plantedFlowerChannels.TryAdd(e.Channel.Id, msg); } var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(WizBot.Config.CurrencyName[0]); var msg2 = await e.Channel.SendMessage($"Oh how Nice! **{e.User.Name}** planted {(vowelFirst ? "an" : "a")} {WizBot.Config.CurrencyName}. Pick it using {Module.Prefix}pick"); await Task.Delay(20000).ConfigureAwait(false); await msg2.Delete().ConfigureAwait(false); }); }
public Func <CommandEventArgs, Task> BetFlipCoinFunc() => async e => { var amountstr = e.GetArg("amount").Trim(); var guessStr = e.GetArg("guess").Trim().ToUpperInvariant(); if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS") { return; } int amount; if (!int.TryParse(amountstr, out amount) || amount < 1) { return; } var userFlowers = GamblingModule.GetUserFlowers(e.User.Id); if (userFlowers < amount) { await e.Channel.SendMessage($"{e.User.Mention} You don't have enough {WizBot.Config.CurrencyName}s. You only have {userFlowers}{WizBot.Config.CurrencySign}.").ConfigureAwait(false); return; } await FlowersHandler.RemoveFlowers(e.User, "Betflip Gamble", (int)amount, true).ConfigureAwait(false); //heads = true //tails = false var guess = guessStr == "HEADS" || guessStr == "H"; bool result = false; if (rng.Next(0, 2) == 1) { await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false); result = true; } else { await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false); } string str; if (guess == result) { str = $"{e.User.Mention}`You guessed it!` You won {amount * 2}{WizBot.Config.CurrencySign}"; await FlowersHandler.AddFlowersAsync(e.User, "Betflip Gamble", amount * 2, true).ConfigureAwait(false); } else { str = $"{e.User.Mention}`More luck next time.`"; } await e.Channel.SendMessage(str).ConfigureAwait(false); };
internal override void Init(CommandGroupBuilder cgb) { cgb.CreateCommand(Prefix + "race") .Description($"Starts a new animal race. | `{Prefix}race`") .Do(e => { var ar = new AnimalRace(e.Server.Id, e.Channel); if (ar.Fail) { return; } }); cgb.CreateCommand(Prefix + "joinrace") .Alias(Prefix + "jr") .Description($"Joins a new race. You can specify an amount of flowers for betting (optional). You will get YourBet*(participants-1) back if you win. | `{Prefix}jr` or `{Prefix}jr 5`") .Parameter("amount", ParameterType.Optional) .Do(async e => { int amount; if (!int.TryParse(e.GetArg("amount"), out amount) || amount < 0) { amount = 0; } var userFlowers = GamblingModule.GetUserFlowers(e.User.Id); if (userFlowers < amount) { await e.Channel.SendMessage($"{e.User.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You only have {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false); return; } if (amount > 0) { await FlowersHandler.RemoveFlowers(e.User, "BetRace", (int)amount, true).ConfigureAwait(false); } AnimalRace ar; if (!AnimalRaces.TryGetValue(e.Server.Id, out ar)) { await e.Channel.SendMessage("No race exists on this server"); return; } await ar.JoinRace(e.User, amount); }); }
internal override void Init(CommandGroupBuilder cgb) { cgb.CreateCommand(Prefix + "race") .Description($"Startet ein neues Tier-Rennen. | `{Prefix}race`") .Do(e => { var ar = new AnimalRace(e.Server.Id, e.Channel); if (ar.Fail) { return; } }); cgb.CreateCommand(Prefix + "joinrace") .Alias(Prefix + "jr") .Description($"Tritt einem Rennen bei. Du kannst eine Anzahl an {MidnightBot.Config.CurrencyName} zum Wetten setzen (Optional). Du bekommst deine Wette*(Teilnehmer-1) zurück, wenn du gewinnst. | `{Prefix}jr` oder `{Prefix}jr 5`") .Parameter("amount", ParameterType.Optional) .Do(async e => { int amount; if (!int.TryParse(e.GetArg("amount"), out amount) || amount < 0) { amount = 0; } var userFlowers = GamblingModule.GetUserFlowers(e.User.Id); if (userFlowers < amount) { await e.Channel.SendMessage($"{e.User.Mention} Du hast nicht genug {MidnightBot.Config.CurrencyName}. Du hast nur {userFlowers}{MidnightBot.Config.CurrencySign}.").ConfigureAwait(false); return; } if (amount > 0) { await FlowersHandler.RemoveFlowers(e.User, "BetRace", (int)amount, true).ConfigureAwait(false); } AnimalRace ar; if (!AnimalRaces.TryGetValue(e.Server.Id, out ar)) { await e.Channel.SendMessage("Es existiert kein Rennen auf diesem Server."); return; } await ar.JoinRace(e.User, amount); }); }
public override void Install(ModuleManager manager) { manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); commands.ForEach(cmd => cmd.Init(cgb)); cgb.CreateCommand(Prefix + "attack") .Description("Attacks a target with the given move") .Parameter("move", ParameterType.Required) .Parameter("target", ParameterType.Unparsed) .Do(async e => { var move = e.GetArg("move"); var targetStr = e.GetArg("target")?.Trim(); if (string.IsNullOrWhiteSpace(targetStr)) { return; } var target = e.Server.FindUsers(targetStr).FirstOrDefault(); if (target == null) { await e.Channel.SendMessage("No such person."); return; } else if (target == e.User) { await e.Channel.SendMessage("You can't attack yourself."); return; } // Checking stats first, then move //Set up the userstats PokeStats userStats; userStats = Stats.GetOrAdd(e.User.Id, new PokeStats()); //Check if able to move //User not able if HP < 0, has made more than 4 attacks if (userStats.Hp < 0) { await e.Channel.SendMessage($"{e.User.Mention} has fainted and was not able to move!"); return; } if (userStats.MovesMade >= 5) { await e.Channel.SendMessage($"{e.User.Mention} has used too many moves in a row and was not able to move!"); return; } if (userStats.LastAttacked.Contains(target.Id)) { await e.Channel.SendMessage($"{e.User.Mention} can't attack again without retaliation!"); return; } //get target stats PokeStats targetStats; targetStats = Stats.GetOrAdd(target.Id, new PokeStats()); //If target's HP is below 0, no use attacking if (targetStats.Hp <= 0) { await e.Channel.SendMessage($"{target.Mention} has already fainted!"); return; } //Check whether move can be used PokemonType userType = GetPokeType(e.User.Id); var enabledMoves = userType.Moves; if (!enabledMoves.Contains(move.ToLowerInvariant())) { await e.Channel.SendMessage($"{e.User.Mention} was not able to use **{move}**, use `{Prefix}ml` to see moves you can use"); return; } //get target type PokemonType targetType = GetPokeType(target.Id); //generate damage int damage = GetDamage(userType, targetType); //apply damage to target targetStats.Hp -= damage; var response = $"{e.User.Mention} used **{move}**{userType.Icon} on {target.Mention}{targetType.Icon} for **{damage}** damage"; //Damage type if (damage < 40) { response += "\nIt's not effective.."; } else if (damage > 60) { response += "\nIt's super effective!"; } else { response += "\nIt's somewhat effective"; } //check fainted if (targetStats.Hp <= 0) { response += $"\n**{target.Name}** has fainted!"; } else { response += $"\n**{target.Name}** has {targetStats.Hp} HP remaining"; } //update other stats userStats.LastAttacked.Add(target.Id); userStats.MovesMade++; targetStats.MovesMade = 0; if (targetStats.LastAttacked.Contains(e.User.Id)) { targetStats.LastAttacked.Remove(e.User.Id); } //update dictionary //This can stay the same right? Stats[e.User.Id] = userStats; Stats[target.Id] = targetStats; await e.Channel.SendMessage(response); }); cgb.CreateCommand(Prefix + "ml") .Alias("movelist") .Description("Lists the moves you are able to use") .Do(async e => { var userType = GetPokeType(e.User.Id); var movesList = userType.Moves; var str = $"**Moves for `{userType.Name}` type.**"; foreach (string m in movesList) { str += $"\n{userType.Icon}{m}"; } await e.Channel.SendMessage(str); }); cgb.CreateCommand(Prefix + "heal") .Description($"Heals someone. Revives those that fainted. Costs a {NadekoBot.Config.CurrencyName} \n**Usage**:{Prefix}revive @someone") .Parameter("target", ParameterType.Unparsed) .Do(async e => { var targetStr = e.GetArg("target")?.Trim(); if (string.IsNullOrWhiteSpace(targetStr)) { return; } var usr = e.Server.FindUsers(targetStr).FirstOrDefault(); if (usr == null) { await e.Channel.SendMessage("No such person."); return; } if (Stats.ContainsKey(usr.Id)) { var targetStats = Stats[usr.Id]; int HP = targetStats.Hp; if (targetStats.Hp == targetStats.MaxHp) { await e.Channel.SendMessage($"{usr.Name} already has full HP!"); return; } //Payment~ var amount = 1; var pts = Classes.DbHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0; if (pts < amount) { await e.Channel.SendMessage($"{e.User.Mention} you don't have enough {NadekoBot.Config.CurrencyName}s! \nYou still need {amount - pts} {NadekoBot.Config.CurrencySign} to be able to do this!"); return; } var target = (usr.Id == e.User.Id) ? "yourself" : usr.Name; FlowersHandler.RemoveFlowers(e.User, $"Poke-Heal {target}", amount); //healing targetStats.Hp = targetStats.MaxHp; if (HP < 0) { //Could heal only for half HP? Stats[usr.Id].Hp = (targetStats.MaxHp / 2); await e.Channel.SendMessage($"{e.User.Name} revived {usr.Name} with one {NadekoBot.Config.CurrencySign}"); return; } var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(NadekoBot.Config.CurrencyName[0]); await e.Channel.SendMessage($"{e.User.Name} healed {usr.Name} for {targetStats.MaxHp - HP} HP with {(vowelFirst ? "an" : "a")} {NadekoBot.Config.CurrencySign}"); return; } else { await e.Channel.SendMessage($"{usr.Name} already has full HP!"); } }); cgb.CreateCommand(Prefix + "type") .Description($"Get the poketype of the target.\n**Usage**: {Prefix}type @someone") .Parameter("target", ParameterType.Unparsed) .Do(async e => { var usrStr = e.GetArg("target")?.Trim(); if (string.IsNullOrWhiteSpace(usrStr)) { return; } var usr = e.Server.FindUsers(usrStr).FirstOrDefault(); if (usr == null) { await e.Channel.SendMessage("No such person."); return; } var pType = GetPokeType(usr.Id); await e.Channel.SendMessage($"Type of {usr.Name} is **{pType.Name.ToLowerInvariant()}**{pType.Icon}"); }); cgb.CreateCommand(Prefix + "settype") .Description($"Set your poketype. Costs a {NadekoBot.Config.CurrencyName}.\n**Usage**: {Prefix}settype fire") .Parameter("targetType", ParameterType.Unparsed) .Do(async e => { var targetTypeStr = e.GetArg("targetType")?.ToUpperInvariant(); if (string.IsNullOrWhiteSpace(targetTypeStr)) { return; } var targetType = stringToPokemonType(targetTypeStr); if (targetType == null) { await e.Channel.SendMessage("Invalid type specified. Type must be one of:\nNORMAL, FIRE, WATER, ELECTRIC, GRASS, ICE, FIGHTING, POISON, GROUND, FLYING, PSYCHIC, BUG, ROCK, GHOST, DRAGON, DARK, STEEL"); return; } if (targetType == GetPokeType(e.User.Id)) { await e.Channel.SendMessage($"Your type is already {targetType.Name.ToLowerInvariant()}{targetType.Icon}"); return; } //Payment~ var amount = 1; var pts = DbHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0; if (pts < amount) { await e.Channel.SendMessage($"{e.User.Mention} you don't have enough {NadekoBot.Config.CurrencyName}s! \nYou still need {amount - pts} {NadekoBot.Config.CurrencySign} to be able to do this!"); return; } FlowersHandler.RemoveFlowers(e.User, $"set usertype to {targetTypeStr}", amount); //Actually changing the type here var preTypes = DbHandler.Instance.GetAllRows <UserPokeTypes>(); Dictionary <long, int> Dict = preTypes.ToDictionary(x => x.UserId, y => y.Id.Value); if (Dict.ContainsKey((long)e.User.Id)) { //delete previous type DbHandler.Instance.Delete <UserPokeTypes>(Dict[(long)e.User.Id]); } DbHandler.Instance.InsertData(new UserPokeTypes { UserId = (long)e.User.Id, type = targetType.Name }); //Now for the response await e.Channel.SendMessage($"Set type of {e.User.Mention} to {targetTypeStr}{targetType.Icon} for a {NadekoBot.Config.CurrencySign}"); }); }); }
public Func <CommandEventArgs, Task> BetFlipCoinFunc() => async e => { var amountstr = e.GetArg("amount").Trim(); var guessStr = e.GetArg("guess").Trim().ToUpperInvariant(); if (guessStr != "K" && guessStr != "Z" && guessStr != "KOPF" && guessStr != "ZAHL") { return; } int amount; if (!int.TryParse(amountstr, out amount) || amount < 1) { return; } var userFlowers = GamblingModule.GetUserFlowers(e.User.Id); if (userFlowers < amount) { await e.Channel.SendMessage($"{e.User.Mention} Du hast nicht genug {MidnightBot.Config.CurrencyName}s. Du hast nur {userFlowers}{MidnightBot.Config.CurrencySign}.").ConfigureAwait(false); return; } await FlowersHandler.RemoveFlowers(e.User, "Betflip Gamble", (int)amount, true).ConfigureAwait(false); //kopf = true //zahl = false if (guessStr == "KOPF" || guessStr == "K") { var guess = guessStr == "KOPF" || guessStr == "K"; bool result = false; if (rng.Next(0, 3) == 1) { await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false); result = true; } else { await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false); } string str; if (guess == result) { str = $"{e.User.Mention}`Du hast richtig geraten!` Du hast {amount * 2}{MidnightBot.Config.CurrencySign} gewonnen."; await FlowersHandler.AddFlowersAsync(e.User, "Betflip Gamble", amount * 2, true).ConfigureAwait(false); } else { str = $"{e.User.Mention}`Viel Glück beim nächsten Mal.`"; } await e.Channel.SendMessage(str).ConfigureAwait(false); } else { var guess = guessStr == "ZAHL" || guessStr == "Z"; bool result = false; if (rng.Next(0, 3) == 1) { await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false); result = true; } else { await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false); } string str; if (guess == result) { str = $"{e.User.Mention}`Du hast richtig geraten!` Du hast {amount * 2}{MidnightBot.Config.CurrencySign} gewonnen."; await FlowersHandler.AddFlowersAsync(e.User, "Betflip Gamble", amount * 2, true).ConfigureAwait(false); } else { str = $"{e.User.Mention}`Viel Glück beim nächsten Mal.`"; } await e.Channel.SendMessage(str).ConfigureAwait(false); } };
public override void Install(ModuleManager manager) { manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); commands.ForEach(com => com.Init(cgb)); cgb.CreateCommand(Prefix + "raffle") .Description("Prints a name and ID of a random user from the online list from the (optional) role.") .Parameter("role", ParameterType.Optional) .Do(async e => { var arg = string.IsNullOrWhiteSpace(e.GetArg("role")) ? "@everyone" : e.GetArg("role"); var role = e.Server.FindRoles(arg).FirstOrDefault(); if (role == null) { await e.Channel.SendMessage("💢 Role not found.").ConfigureAwait(false); return; } var members = role.Members.Where(u => u.Status == UserStatus.Online); // only online var membersArray = members as User[] ?? members.ToArray(); var usr = membersArray[new Random().Next(0, membersArray.Length)]; await e.Channel.SendMessage($"**Raffled user:** {usr.Name} (id: {usr.Id})").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "$$") .Description(string.Format("Check how much {0}s a person has. (Defaults to yourself)\n**Usage**:`{1}$$` or `{1}$$ @Someone`", NadekoBot.Config.CurrencyName, Prefix)) .Parameter("all", ParameterType.Unparsed) .Do(async e => { var usr = e.Message.MentionedUsers.FirstOrDefault() ?? e.User; var pts = GetUserFlowers(usr.Id); var str = $"{usr.Name} has {pts} {NadekoBot.Config.CurrencySign}"; await e.Channel.SendMessage(str).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "give") .Description(string.Format("Give someone a certain amount of {0}s", NadekoBot.Config.CurrencyName)) .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 && u.Id != e.User.Id); if (mentionedUser == null) { return; } var userFlowers = GetUserFlowers(e.User.Id); if (userFlowers < amount) { await e.Channel.SendMessage($"{e.User.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You have only {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false); return; } FlowersHandler.RemoveFlowers(e.User, "Gift", (int)amount); await FlowersHandler.AddFlowersAsync(mentionedUser, "Gift", (int)amount).ConfigureAwait(false); await e.Channel.SendMessage($"{e.User.Mention} successfully sent {amount} {NadekoBot.Config.CurrencyName}s to {mentionedUser.Mention}!").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "award") .Description("Gives someone a certain amount of flowers. **Bot Owner Only!**\n**Usage**: `$award 100 @person`") .AddCheck(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).ConfigureAwait(false); await e.Channel.SendMessage($"{e.User.Mention} successfully awarded {amount} {NadekoBot.Config.CurrencyName}s to {mentionedUser.Mention}!").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "take") .Description("Takes a certain amount of flowers from someone. **Bot Owner Only!**") .AddCheck(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; } FlowersHandler.RemoveFlowers(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}!").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "leaderboard") .Alias(Prefix + "lb") .Do(async e => { var richestTemp = DbHandler.Instance.GetTopRichest(); var richest = richestTemp as CurrencyState[] ?? richestTemp.ToArray(); if (richest.Length == 0) { return; } await e.Channel.SendMessage( richest.Aggregate(new StringBuilder( $@"```xl ┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓ ┃ Id ┃ $$$ ┃ "), (cur, cs) => cur.AppendLine( $@"┣━━━━━━━━━━━━━━━━━━━╋━━━━━━━┫ ┃{cs.UserId,-18} ┃ {cs.Value,5} ┃") ).ToString() + "┗━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛```"); }); }); }
internal override void Init(CommandGroupBuilder cgb) { cgb.CreateCommand(Module.Prefix + "pick") .Description($"Picks a flower planted in this channel. | `{Prefix}pick`") .Do(async e => { IEnumerable <Message> msgs; await e.Message.Delete().ConfigureAwait(false); if (!plantedFlowerChannels.TryRemove(e.Channel.Id, out msgs)) { return; } foreach (var msgToDelete in msgs) { await msgToDelete.Delete().ConfigureAwait(false); } await FlowersHandler.AddFlowersAsync(e.User, "Picked a flower.", 1, true).ConfigureAwait(false); var msg = await e.Channel.SendMessage($"**{e.User.Name}** picked a {NadekoBot.Config.CurrencyName}!").ConfigureAwait(false); ThreadPool.QueueUserWorkItem(async(state) => { try { await Task.Delay(10000).ConfigureAwait(false); await msg.Delete().ConfigureAwait(false); } catch { } }); }); cgb.CreateCommand(Module.Prefix + "plant") .Description($"Spend a flower to plant it in this channel. (If bot is restarted or crashes, flower will be lost) | `{Prefix}plant`") .Do(async e => { await locker.WaitAsync().ConfigureAwait(false); try { if (plantedFlowerChannels.ContainsKey(e.Channel.Id)) { await e.Channel.SendMessage($"There is already a {NadekoBot.Config.CurrencyName} in this channel.").ConfigureAwait(false); return; } var removed = await FlowersHandler.RemoveFlowers(e.User, "Planted a flower.", 1, true).ConfigureAwait(false); if (!removed) { await e.Channel.SendMessage($"You don't have any {NadekoBot.Config.CurrencyName}s.").ConfigureAwait(false); return; } var file = GetRandomCurrencyImagePath(); Message msg; if (file == null) { msg = await e.Channel.SendMessage(NadekoBot.Config.CurrencySign).ConfigureAwait(false); } else { msg = await e.Channel.SendFile(file).ConfigureAwait(false); } var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(NadekoBot.Config.CurrencyName[0]); var msg2 = await e.Channel.SendMessage($"Oh how Nice! **{e.User.Name}** planted {(vowelFirst ? "an" : "a")} {NadekoBot.Config.CurrencyName}. Pick it using {Module.Prefix}pick").ConfigureAwait(false); plantedFlowerChannels.TryAdd(e.Channel.Id, new[] { msg, msg2 }); } finally { locker.Release(); } }); cgb.CreateCommand(Prefix + "gencurrency") .Alias(Prefix + "gc") .Description($"Toggles currency generation on this channel. Every posted message will have 2% chance to spawn a {NadekoBot.Config.CurrencyName}. Optional parameter cooldown time in minutes, 5 minutes by default. Requires Manage Messages permission. | `{Prefix}gc` or `{Prefix}gc 60`") .AddCheck(SimpleCheckers.ManageMessages()) .Parameter("cd", ParameterType.Unparsed) .Do(async e => { var cdStr = e.GetArg("cd"); int cd = 2; if (!int.TryParse(cdStr, out cd) || cd < 0) { cd = 2; } var config = SpecificConfigurations.Default.Of(e.Server.Id); int throwaway; if (config.GenerateCurrencyChannels.TryRemove(e.Channel.Id, out throwaway)) { await e.Channel.SendMessage("`Currency generation disabled on this channel.`").ConfigureAwait(false); } else { if (config.GenerateCurrencyChannels.TryAdd(e.Channel.Id, cd)) { await e.Channel.SendMessage($"`Currency generation enabled on this channel. Cooldown is {cd} minutes.`").ConfigureAwait(false); } } }); }
public override void Install(ModuleManager manager) { manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); commands.ForEach(com => com.Init(cgb)); cgb.CreateCommand(Prefix + "raffle") .Description($"Prints a name and ID of a random user from the online list from the (optional) role. | `{Prefix}raffle` or `{Prefix}raffle RoleName`") .Parameter("role", ParameterType.Optional) .Do(async e => { var arg = string.IsNullOrWhiteSpace(e.GetArg("role")) ? "@everyone" : e.GetArg("role"); var role = e.Server.FindRoles(arg).FirstOrDefault(); if (role == null) { await e.Channel.SendMessage("💢 Role not found.").ConfigureAwait(false); return; } var members = role.Members.Where(u => u.Status == UserStatus.Online); // only online var membersArray = members as User[] ?? members.ToArray(); var usr = membersArray[new Random().Next(0, membersArray.Length)]; await e.Channel.SendMessage($"**Raffled user:** {usr.Name} (id: {usr.Id})").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "$$") .Description(string.Format("Check how much {0}s a person has. (Defaults to yourself) |`{1}$$` or `{1}$$ @Someone`", WizBot.Config.CurrencyName, Prefix)) .Parameter("all", ParameterType.Unparsed) .Do(async e => { var usr = e.Message.MentionedUsers.FirstOrDefault() ?? e.User; var pts = GetUserFlowers(usr.Id); var str = $"{usr.Name} has {pts} {WizBot.Config.CurrencySign}"; await e.Channel.SendMessage(str).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "give") .Description(string.Format("Give someone a certain amount of {0}s", WizBot.Config.CurrencyName) + $"|`{Prefix}give 1 \"@SomeGuy\"`") .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 != WizBot.Client.CurrentUser.Id && u.Id != e.User.Id); if (mentionedUser == null) { return; } var userFlowers = GetUserFlowers(e.User.Id); if (userFlowers < amount) { await e.Channel.SendMessage($"{e.User.Mention} You don't have enough {WizBot.Config.CurrencyName}s. You only have {userFlowers}{WizBot.Config.CurrencySign}.").ConfigureAwait(false); return; } await FlowersHandler.RemoveFlowers(e.User, "Gift", (int)amount, true).ConfigureAwait(false); await FlowersHandler.AddFlowersAsync(mentionedUser, "Gift", (int)amount).ConfigureAwait(false); await e.Channel.SendMessage($"{e.User.Mention} successfully sent {amount} {WizBot.Config.CurrencyName}s to {mentionedUser.Mention}!").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "award") .Description($"Gives someone a certain amount of flowers. **Bot Owner Only!** | `{Prefix}award 100 @person`") .AddCheck(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 != WizBot.Client.CurrentUser.Id); if (mentionedUser == null) { return; } await FlowersHandler.AddFlowersAsync(mentionedUser, $"Awarded by bot owner. ({e.User.Name}/{e.User.Id})", (int)amount).ConfigureAwait(false); await e.Channel.SendMessage($"{e.User.Mention} successfully awarded {amount} {WizBot.Config.CurrencyName}s to {mentionedUser.Mention}!").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "take") .Description($"Takes a certain amount of flowers from someone. **Bot Owner Only!** | `{Prefix}take 1 \"@someguy\"`") .AddCheck(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 != WizBot.Client.CurrentUser.Id); if (mentionedUser == null) { return; } await FlowersHandler.RemoveFlowers(mentionedUser, $"Taken by bot owner.({e.User.Name}/{e.User.Id})", (int)amount).ConfigureAwait(false); await e.Channel.SendMessage($"{e.User.Mention} successfully took {amount} {WizBot.Config.CurrencyName}s from {mentionedUser.Mention}!").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "betroll") .Alias(Prefix + "br") .Description($"Bets a certain amount of {WizBot.Config.CurrencyName}s and rolls a dice. Rolling over 66 yields x2 flowers, over 90 - x3 and 100 x10. | `{Prefix}br 5`") .Parameter("amount", ParameterType.Required) .Do(async e => { var amountstr = e.GetArg("amount").Trim(); int amount; if (!int.TryParse(amountstr, out amount) || amount < 1) { return; } var userFlowers = GetUserFlowers(e.User.Id); if (userFlowers < amount) { await e.Channel.SendMessage($"{e.User.Mention} You don't have enough {WizBot.Config.CurrencyName}s. You only have {userFlowers}{WizBot.Config.CurrencySign}.").ConfigureAwait(false); return; } await FlowersHandler.RemoveFlowers(e.User, "Betroll Gamble", (int)amount, true).ConfigureAwait(false); var rng = new Random().Next(0, 101); var str = $"{e.User.Mention} `You rolled {rng}.` "; if (rng < 67) { str += "Better luck next time."; } else if (rng < 90) { str += $"Congratulations! You won {amount * 2}{WizBot.Config.CurrencySign} for rolling above 66"; await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 2, true).ConfigureAwait(false); } else if (rng < 100) { str += $"Congratulations! You won {amount * 3}{WizBot.Config.CurrencySign} for rolling above 90."; await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 3, true).ConfigureAwait(false); } else { str += $"👑 Congratulations! You won {amount * 10}{WizBot.Config.CurrencySign} for rolling **100**. 👑"; await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 10, true).ConfigureAwait(false); } await e.Channel.SendMessage(str).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "leaderboard") .Alias(Prefix + "lb") .Description($"Displays bot currency leaderboard | `{Prefix}lb`") .Do(async e => { var richestTemp = DbHandler.Instance.GetTopRichest(); var richest = richestTemp as CurrencyState[] ?? richestTemp.ToArray(); if (richest.Length == 0) { return; } await e.Channel.SendMessage( richest.Aggregate(new StringBuilder( $@"```xl ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓ ┃ Id ┃ $$$ ┃ "), (cur, cs) => cur.AppendLine( $@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━┫ ┃{(e.Server.Users.Where(u => u.Id == (ulong)cs.UserId).FirstOrDefault()?.Name.TrimTo(18, true) ?? cs.UserId.ToString()),-20} ┃ {cs.Value,5} ┃") ).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛```").ConfigureAwait(false); }); }); }
public override void Install(ModuleManager manager) { manager.CreateCommands("", cgb => { cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); commands.ForEach(com => com.Init(cgb)); cgb.CreateCommand(Prefix + "raffle") .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) .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 && u.Id != e.User.Id); if (mentionedUser == null) { return; } var userFlowers = GetUserFlowers(e.User.Id); if (userFlowers < amount) { await e.Channel.SendMessage($"{e.User.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You have only {userFlowers}{NadekoBot.Config.CurrencySign}."); return; } FlowersHandler.RemoveFlowers(e.User, "Gift", (int)amount); await FlowersHandler.AddFlowersAsync(mentionedUser, "Gift", (int)amount); 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; } FlowersHandler.RemoveFlowers(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}!"); }); }); }
internal override void Init(CommandGroupBuilder cgb) { cgb.CreateCommand(Module.Prefix + "pick") .Description($"Nimmt einen in diesem Channel hinterlegten {MidnightBot.Config.CurrencyName}. | `{Prefix}pick`") .Do(async e => { IEnumerable <Message> msgs; await e.Message.Delete().ConfigureAwait(false); if (!plantedFlowerChannels.TryRemove(e.Channel.Id, out msgs)) { return; } foreach (var msgToDelete in msgs) { await msgToDelete.Delete().ConfigureAwait(false); } await FlowersHandler.AddFlowersAsync(e.User, "Took a dollar.", 1, true).ConfigureAwait(false); var msg = await e.Channel.SendMessage($"**{e.User.Name}** hat den {MidnightBot.Config.CurrencyName} aufgehoben!").ConfigureAwait(false); ThreadPool.QueueUserWorkItem(async(state) => { try { await Task.Delay(10000).ConfigureAwait(false); await msg.Delete().ConfigureAwait(false); } catch { } }); }); cgb.CreateCommand(Module.Prefix + "plant") .Description($"Gib einen {MidnightBot.Config.CurrencyName} aus, um in in diesen Channel zu legen. (Wenn der Bot neustartet, oder crashed, ist der {MidnightBot.Config.CurrencyName} verloren) | `{Prefix}plant`") .Do(async e => { await locker.WaitAsync().ConfigureAwait(false); try { if (plantedFlowerChannels.ContainsKey(e.Channel.Id)) { await e.Channel.SendMessage($"Hier liegt bereits ein {MidnightBot.Config.CurrencyName} in diesem Channel.").ConfigureAwait(false); return; } var removed = await FlowersHandler.RemoveFlowers(e.User, "Planted a flower.", 1, true).ConfigureAwait(false); if (!removed) { await e.Channel.SendMessage($"Du hast keinen {MidnightBot.Config.CurrencyName}s.").ConfigureAwait(false); return; } var file = GetRandomCurrencyImagePath(); Message msg; if (file == null) { msg = await e.Channel.SendMessage(MidnightBot.Config.CurrencySign).ConfigureAwait(false); } else { msg = await e.Channel.SendFile(file).ConfigureAwait(false); } var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(MidnightBot.Config.CurrencyName[0]); var msg2 = await e.Channel.SendMessage($"Oh wie nett! **{e.User.Name}** hinterlies {(vowelFirst ? "einen" : "einen")} {MidnightBot.Config.CurrencyName}. Nimm ihn per {Module.Prefix}pick").ConfigureAwait(false); plantedFlowerChannels.TryAdd(e.Channel.Id, new[] { msg, msg2 }); } finally { locker.Release(); } }); cgb.CreateCommand(Prefix + "gencurrency") .Alias(Prefix + "gc") .Description($"Ändert Währungs Erstellung in diesem Channel. Jede geschriebene Nachricht hat eine Chance von 2%, einen {MidnightBot.Config.CurrencyName} zu spawnen. Optionaler Parameter ist die Cooldown Zeit in Minuten. 5 Minuten sind Standard. Benötigt Manage Messages Berechtigungen | `{Prefix}gc` oder `{Prefix}gc 60`") .AddCheck(SimpleCheckers.ManageMessages()) .Parameter("cd", ParameterType.Unparsed) .Do(async e => { var cdStr = e.GetArg("cd"); int cd = 2; if (!int.TryParse(cdStr, out cd) || cd < 0) { cd = 2; } var config = SpecificConfigurations.Default.Of(e.Server.Id); int throwaway; if (config.GenerateCurrencyChannels.TryRemove(e.Channel.Id, out throwaway)) { await e.Channel.SendMessage("`Währungs Erstellung deaktiviert in diesem Channel.`").ConfigureAwait(false); } else { if (config.GenerateCurrencyChannels.TryAdd(e.Channel.Id, cd)) { await e.Channel.SendMessage($"`Währungserstellung aktiviert in diesem Channel. Cooldown ist {cd} Minuten.`").ConfigureAwait(false); } } }); }
public override void Install(ModuleManager manager) { manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); commands.ForEach(com => com.Init(cgb)); cgb.CreateCommand(Prefix + "raffle") .Description($"Schreibt den Namen und die ID eines zufälligen Benutzers aus der Online Liste einer (optionalen) Rolle. | `{Prefix}raffle` oder `{Prefix}raffle RoleName`") .Parameter("role", ParameterType.Optional) .Do(async e => { var arg = string.IsNullOrWhiteSpace(e.GetArg("role")) ? "@everyone" : e.GetArg("role"); var role = e.Server.FindRoles(arg).FirstOrDefault(); if (role == null) { await e.Channel.SendMessage("💢 Rolle nicht gefunden.").ConfigureAwait(false); return; } var members = role.Members.Where(u => u.Status == UserStatus.Online); // only online var membersArray = members as User[] ?? members.ToArray(); var usr = membersArray[new Random().Next(0, membersArray.Length)]; await e.Channel.SendMessage($"**Gezogener Benutzer:** {usr.Name} (Id: {usr.Id})").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "$$") .Description(string.Format("Überprüft, wieviele {0} du hast.", MidnightBot.Config.CurrencyName)) .Parameter("all", ParameterType.Unparsed) .Do(async e => { var usr = e.Message.MentionedUsers.FirstOrDefault() ?? e.User; var pts = GetUserFlowers(usr.Id); var str = $"{usr.Name} hat {pts} {MidnightBot.Config.CurrencyName} {MidnightBot.Config.CurrencySign}"; await e.Channel.SendMessage(str).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "award") .Description(string.Format($"Gibt jemanden eine bestimmte Anzahl an {MidnightBot.Config.CurrencyName}. **Bot Owner Only!** | `{Prefix}award 5 @Benutzer`")) .AddCheck(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 != MidnightBot.Client.CurrentUser.Id); if (mentionedUser == null) { return; } await FlowersHandler.AddFlowersAsync(mentionedUser, $"Awarded by bot owner. ({e.User.Name}/{e.User.Id})", (int)amount).ConfigureAwait(false); await e.Channel.SendMessage($"{e.User.Mention} erfolgreich {amount} {MidnightBot.Config.CurrencyName} zu {mentionedUser.Mention} hinzugefügt!").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "dailymoney") .Description($"Tägliches Geld (20 Euro, wird um 0 Uhr zurückgesetzt.) | `{Prefix}dailymoney`") .Do(async e => { DateTime today = DateTime.Today; var uid = (long)e.User.Id; var sid = (long)e.Server.Id; var user = DbHandler.Instance.FindOne <DailyMoney>(dm => dm.UserId == uid && dm.ServerId == sid); if (user == null) { var data = new DailyMoney { UserId = (long)e.User.Id, LastTimeGotten = today.AddDays(-1), ServerId = (long)e.Server.Id }; DbHandler.Instance.InsertData(data); user = DbHandler.Instance.FindOne <DailyMoney>(dm => dm.UserId == uid && dm.ServerId == sid); } if (user.LastTimeGotten.Date.DayOfYear < today.Date.DayOfYear) { var data = DbHandler.Instance.FindAll <DailyMoney>(d => d.ServerId == sid && d.UserId == uid); DbHandler.Instance.UpdateAll <DailyMoney>(data.Select(i => { i.LastTimeGotten = today; return(i); })); await FlowersHandler.AddFlowersAsync(e.User, $"Daily Reward. ({e.User.Name}/{e.User.Id})", 20).ConfigureAwait(false); await e.Channel.SendMessage($"{e.User.Mention} hat sich seinen täglichen Anteil von 20 {MidnightBot.Config.CurrencyName} abgeholt."); return; } else { await e.Channel.SendMessage("Du hast deinen täglichen Anteil heute bereits abgeholt."); } }); cgb.CreateCommand(Prefix + "take") .Description(string.Format($"Entfernt eine bestimmte Anzahl an {MidnightBot.Config.CurrencyName} von jemanden. **Bot Owner Only!** | `{Prefix}take 1 \"@someguy\"`")) .AddCheck(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 != MidnightBot.Client.CurrentUser.Id); if (mentionedUser == null) { return; } await FlowersHandler.RemoveFlowers(mentionedUser, $"Taken by bot owner.({e.User.Name}/{e.User.Id})", (int)amount).ConfigureAwait(false); await e.Channel.SendMessage($"{e.User.Mention} erfolgreich {amount} {MidnightBot.Config.CurrencyName} von {mentionedUser.Mention} entfernt!").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "give") .Description($"Gibt jemanden eine Anzahl {MidnightBot.Config.CurrencyName}. |`{Prefix}give 1 \"@SomeGuy\"`") .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 != MidnightBot.Client.CurrentUser.Id && u.Id != e.User.Id); if (mentionedUser == null) { return; } var userFlowers = GetUserFlowers(e.User.Id); if (userFlowers < amount) { await e.Channel.SendMessage($"{e.User.Mention} Du hast nicht genug {MidnightBot.Config.CurrencyName}. Du hast nur {userFlowers} {MidnightBot.Config.CurrencySign}.").ConfigureAwait(false); return; } await FlowersHandler.RemoveFlowers(e.User, "Gift", (int)amount, true).ConfigureAwait(false); await FlowersHandler.AddFlowersAsync(mentionedUser, "Gift", (int)amount).ConfigureAwait(false); await e.Channel.SendMessage($"{e.User.Mention} erfolgreich {amount}{MidnightBot.Config.CurrencyName} gesendet an {mentionedUser.Mention}!").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "betroll") .Alias(Prefix + "br") .Description($"Wettet einen bestimmten Betrag an {MidnightBot.Config.CurrencyName} und wirft einen Würfel. Bei über 66 Punkten: x2 {MidnightBot.Config.CurrencyName}, über 90 Punkte: x3 und 100 x10. | `{Prefix}br 5`") .Parameter("amount", ParameterType.Required) .Do(async e => { var amountstr = e.GetArg("amount").Trim(); int amount; if (!int.TryParse(amountstr, out amount) || amount < 1) { return; } var userFlowers = GetUserFlowers(e.User.Id); if (userFlowers < amount) { await e.Channel.SendMessage($"{e.User.Mention} Du hast nicht genug {MidnightBot.Config.CurrencyName}. Du hast nur {userFlowers}{MidnightBot.Config.CurrencySign}.").ConfigureAwait(false); return; } await FlowersHandler.RemoveFlowers(e.User, "Betroll Gamble", (int)amount, true).ConfigureAwait(false); var rng = new Random().Next(0, 101); var str = $"{e.User.Mention} `Du hast folgende Punktzahl geworfen: {rng}` "; if (rng < 67) { str += "Viel Glück beim nächsten Mal."; } else if (rng < 90) { str += $"Glückwunsch! Du hast {amount * 2}{MidnightBot.Config.CurrencySign} für das erzielen von mehr als 66 Punkten gewonnen."; await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 2, true).ConfigureAwait(false); } else if (rng < 100) { str += $"Glückwunsch! Du hast {amount * 3}{MidnightBot.Config.CurrencySign} für das erzielen von mehr als 90 Punkten gewonnen."; await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 3, true).ConfigureAwait(false); } else { str += $"👑 Glückwunsch! Du hast {amount * 10}{MidnightBot.Config.CurrencySign} für das erzielen von **100** Punkten gewonnen. 👑"; await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 10, true).ConfigureAwait(false); } await e.Channel.SendMessage(str).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "leaderboard") .Alias(Prefix + "lb") .Description($"Displays bot currency leaderboard | {Prefix}lb") .Do(async e => { var richestTemp = DbHandler.Instance.GetTopRichest(); var richest = richestTemp as CurrencyState[] ?? richestTemp.ToArray(); if (richest.Length == 0) { return; } await e.Channel.SendMessage ( richest.Aggregate(new StringBuilder( $@"```xl ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓ ┃ Id ┃ $$$ ┃ "), (cur, cs) => cur.AppendLine( $@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━┫ ┃{(e.Server.Users.Where(u => u.Id == (ulong)cs.UserId).FirstOrDefault()?.Name.TrimTo(18, true) ?? cs.UserId.ToString()),-20} ┃ {cs.Value,5} ┃") ).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛```").ConfigureAwait(false); }); }); }
public override void Install(ModuleManager manager) { manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); cgb.CreateCommand(Prefix + "active") .Description($"Zeigt das aktive Pokemon von jemandem oder einem selbst | `{Prefix}active` oder `{Prefix}active @Someone`") .Parameter("target", ParameterType.Optional) .Do(async e => { var target = e.Server.FindUsers(e.GetArg("target")).DefaultIfEmpty(null).FirstOrDefault() ?? e.User; await e.Channel.SendMessage($"**{target.Mention}**:\n{ActivePokemon (target).PokemonString ()}"); }); cgb.CreateCommand(Prefix + "pokehelp") .Description($"Zeigt die Basis Hilfe für Pokemon Kämpfe | `{Prefix}pokehelp`") .Alias(Prefix + "ph") .Do(async e => { User user = null; try { user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); } catch (Exception) { user = e.User; } await e.User.SendMessage($">list um deine Pokemon anzuzeigen. >switch name um dein aktives Pokemon auszutauschen. >ml um seine Angriffe anzuzeigen. >attack move @person um anzugreifen.\n Du bekommst {MidnightBot.Config.CurrencySign} für das besiegen anderer Pokemon, welche als Tränke mit >heal oder als Pokebälle mit >catch benutzt werden können."); await e.Message.Delete().ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "movelist") .Alias(Prefix + "ml") .Description($"Zeigt eine Liste der verfügbaren Angriffe. | `{Prefix}movelist` oder `{Prefix}ml` oder `{Prefix}ml charmander`") .Parameter("name", ParameterType.Optional) .Do(async e => { var list = PokemonList(e.User); var pkm = list.Where(x => x.NickName == e.GetArg("name").Trim()).DefaultIfEmpty(null).FirstOrDefault() ?? ActivePokemon(e.User); await e.User.SendMessage($"{e.User.Mention}\n**{pkm.NickName}'s Angriffe:**\n{pkm.PokemonMoves()}"); }); cgb.CreateCommand(Prefix + "switch") .Description($"Setzt dein aktives Pokemon per Nickname | `{Prefix}switch mudkip`") .Parameter("name", ParameterType.Unparsed) .Do(async e => { var list = PokemonList(e.User); var toSet = list.Where(x => x.NickName == e.GetArg("name").Trim()).DefaultIfEmpty(null).FirstOrDefault(); if (toSet == null) { await e.Channel.SendMessage($"Konnte Pokemon mit Name \"{e.GetArg ("name").Trim ()}\" nicht finden."); return; } var trainerStats = UserStats.GetOrAdd(e.User.Id, new TrainerStats()); if (trainerStats.LastAttacked.Contains(e.User.Id)) { await e.Channel.SendMessage($"{e.User.Mention} kann sich nicht bewegen!"); return; } if (trainerStats.MovesMade > TrainerStats.MaxMoves) { await e.Channel.SendMessage($"{e.User.Mention} hat zu oft angegriffen und kann sich nicht bewegen!"); return; } switch (SwitchPokemon(e.User, toSet)) { case 0: { trainerStats.LastAttacked.Add(e.User.Id); trainerStats.MovesMade++; UserStats.AddOrUpdate(e.User.Id, trainerStats, (s, t) => trainerStats); await e.Channel.SendMessage($"Aktives Pokemon von {e.User.Mention} auf {toSet.NickName} gesetzt"); break; } case 2: { await e.Channel.SendMessage($"Das ausgetauschte Pokemon muss HP haben!"); break; } case 1: { await e.Channel.SendMessage($"Kein aktives Pokemon!"); break; } } }); cgb.CreateCommand(Prefix + "allmoves") .Description($"Sendet dir eine private Nachticht mit allen Attacken deiner Pokemon. | `{Prefix}allmoves` oder `{Prefix}am`") .Alias(Prefix + "am") .Do(async e => { var list = PokemonList(e.User); string str = $"{e.User.Mention}'s Pokemon sind:\n"; foreach (var pkm in list) { str += $"`{pkm.NickName}:` Level: {pkm.Level}\n{pkm.PokemonMoves ()}\n"; } var msg = await e.Channel.SendMessage($"{e.User.Mention} ich habe dir eine Liste aller deiner Angriffe geschickt."); await e.User.SendMessage(str); }); cgb.CreateCommand(Prefix + "list") .Description($"Gibt eine Liste deiner Pokemon (6) zurück (aktives Pokemon ist unterstrichen) | `{Prefix}list`") .Do(async e => { var list = PokemonList(e.User); string str = $"{e.User.Mention}'s Pokemon sind:\n"; foreach (var pkm in list) { if (pkm.HP <= 0) { str += $"~~**{pkm.NickName}** : *{pkm.GetSpecies().name}* HP: {pkm.HP}/{pkm.MaxHP}~~💀\nBildlink: {pkm.GetSpecies().imageLink}\n"; } else if (pkm.IsActive) { str += $"__**{pkm.NickName}** : *{pkm.GetSpecies().name}* HP: {pkm.HP}/{pkm.MaxHP}__\nBildlink: {pkm.GetSpecies ().imageLink}\n"; } else { str += $"**{pkm.NickName}** : *{pkm.GetSpecies ().name}* HP: {pkm.HP}/{pkm.MaxHP}\nBildlink: {pkm.GetSpecies ().imageLink}\n"; } } await e.User.SendMessage(str); }); cgb.CreateCommand(Prefix + "elite4") .Description($"Zeigt die 5 stärksten Pokemon. | `{Prefix}elite4`") .Alias(Prefix + "e4") .Do(async e => { var db = DbHandler.Instance.GetAllRows <PokemonSprite>(); var elites = db.OrderByDescending(i => i.XP).Take(4); string str = "**Top 4 Pokemon:**"; foreach (PokemonSprite elite in elites) { str += $"\n`Trainer:` <@{elite.OwnerId}>"; str += $"\n```Pokemon Name: {elite.NickName}"; str += $"\nPokemon Level: {elite.Level}```"; } await e.Channel.SendMessage(str); }); cgb.CreateCommand(Prefix + "heal") .Description($"Heilt dein angegebenes Pokemon (per Nicknamen) oder das aktive Pokemon der gegebenen Person. | `{Prefix}heal bulbasaur` oder `{Prefix}heal @user` oder `{Prefix}heal all`") .Parameter("args", ParameterType.Unparsed) .Do(async e => { var args = e.GetArg("args"); var target = e.Server.FindUsers(args).DefaultIfEmpty(null).FirstOrDefault() ?? e.User; if (target == e.User) { if (args == "all") { var pkms = PokemonList(target).Where(x => x.HP < x.MaxHP); string str = $"{target.Mention} geheilt:"; int count = pkms.Count(); if (count <= 0) { await e.Channel.SendMessage($"{e.User.Mention}, All of your pokemon are at full health!"); return; } if (await FlowersHandler.RemoveFlowers(target, "Healed pokemon", count)) { foreach (var pkm in pkms) { var hp = pkm.HP; pkm.HP = pkm.MaxHP; str += $"\n{pkm.NickName} um {pkm.HP - hp} HP"; //await e.Channel.SendMessage($"{target.Mention} successfully healed {pkm.NickName} for {pkm.HP - hp} HP for a {Uni.Config.CurrencySign}"); DbHandler.Instance.Save(pkm); //Heal your own userstats as well? } } else { await e.Channel.SendMessage($"Konnte {MidnightBot.Config.CurrencySign} nicht bezahlen.**"); return; } str += $"\n*Benutzte {count.ToString()} {MidnightBot.Config.CurrencySign}*"; await e.Channel.SendMessage(str); return; } var toHeal = PokemonList(target).Where(x => x.NickName == args.Trim()).DefaultIfEmpty(null).FirstOrDefault(); if (toHeal == null) { await e.Channel.SendMessage($"Konnte Pokemon mit Namen \"{e.GetArg ("args").Trim ()}\" nicht finden"); return; } if (await FlowersHandler.RemoveFlowers(target, "Healed pokemon", 1)) { var hp = toHeal.HP; toHeal.HP = toHeal.MaxHP; await e.Channel.SendMessage($"{target.Mention} hat {toHeal.NickName} erfolgreich um {toHeal.HP - hp} HP für einen {MidnightBot.Config.CurrencySign} geheilt."); DbHandler.Instance.Save(toHeal); //Heal your own userstats as well? } else { await e.Channel.SendMessage($"Konnte {MidnightBot.Config.CurrencySign} nicht zahlen."); } return; } var toHealn = ActivePokemon(target); if (toHealn == null) { await e.Channel.SendMessage($"Konnte Pokemon von {target.Name} nicht finden"); return; } if (await FlowersHandler.RemoveFlowers(target, "Healed pokemon", 1)) { var hp = toHealn.HP; toHealn.HP = toHealn.MaxHP; await e.Channel.SendMessage($"{target.Mention} hat {toHealn.NickName} erfolgreich um {toHealn.HP - hp} HP geheilt, für einen {MidnightBot.Config.CurrencySign}"); DbHandler.Instance.Save(toHealn); } else { await e.Channel.SendMessage($"Konnte {MidnightBot.Config.CurrencySign} nicht bezahlen."); } return; }); cgb.CreateCommand(Prefix + "rename") .Alias(Prefix + "rn") .Description($"Benennt dein aktives Pokemon um. | `{Prefix}rename dickbutt` oder `{Prefix}rn Mittens`") .Parameter("name", ParameterType.Unparsed) .Do(async e => { var newName = e.GetArg("name"); if (string.IsNullOrWhiteSpace(newName)) { await e.Channel.SendMessage("Name benötigt"); return; } var activePkm = ActivePokemon(e.User); activePkm.NickName = newName; DbHandler.Instance.Save(activePkm); await e.Channel.SendMessage($"Aktives Pokemon zu {newName} umbenannt"); }); cgb.CreateCommand(Prefix + "reset") .Description($"Setzt deine Pokemon zurück. KANN NICHT RÜCKGÄNGIG GEMACHT WERDEN | `{Prefix}reset true`") .Parameter("true", ParameterType.Unparsed) .Do(async e => { bool willReset; if (bool.TryParse(e.GetArg("true"), out willReset)) { if (willReset) { var db = DbHandler.Instance.GetAllRows <PokemonSprite>(); var row = db.Where(x => x.OwnerId == (long)e.User.Id); //var toDelete = DbHandler.Instance.FindAll<PokemonSprite>(s => s.OwnerId == (long)e.User.Id); foreach (var todel in row) { DbHandler.Instance.Delete <PokemonSprite>(todel.Id.Value); } await e.Channel.SendMessage("Deine Pokemon wurden gelöscht.\n\nGrauenhaft.\n\n\nIch habe keine Worte dafür."); } } else { await e.Channel.SendMessage($"Benutze `{Prefix}reset true` um deine Pokemon wirklich zu töten 🔫"); } }); Random rand = new Random(); cgb.CreateCommand(Prefix + "catch") .Description($"Versucht das derzeitige wilde Pokemon zu fangen. Du musst das Pokemon angeben, welches du ersetzen willst. Kostet einen {MidnightBot.Config.CurrencyName} | `{Prefix}catch MyMudkip`") .Parameter("replace", ParameterType.Unparsed) .Do(async e => { string str = ""; var list = PokemonList(e.User); var pkm = list.Where(x => x.NickName == e.GetArg("replace").Trim()).DefaultIfEmpty(null).FirstOrDefault(); if (pkm == null) { await e.Channel.SendMessage($"Konnte Pokemon mit Namen \"{e.GetArg("replace").Trim()}\" nicht finden."); return; } var defenderPokemon = ActivePokemon(e.Server.GetUser(MidnightBot.Creds.BotId)); var removed = FlowersHandler.RemoveFlowers(e.User, "Put a euro down.", 1).GetAwaiter().GetResult(); if (!removed) { await e.Channel.SendMessage($"{e.User.Mention}, es benötigt einen {MidnightBot.Config.CurrencySign} {MidnightBot.Config.CurrencyName} um einen Pokeball zu kaufen!"); return; } int rate = 1; int chance = ((3 * defenderPokemon.MaxHP - 2 * defenderPokemon.HP) * rate) / 3 * defenderPokemon.MaxHP; //str += chance.ToString() + "\n"; int randm = rand.Next(1, 255); //str += randm.ToString(); if (randm < chance) { pkm.NickName = defenderPokemon.NickName; pkm.HP = defenderPokemon.HP; pkm.SpeciesId = defenderPokemon.SpeciesId; pkm.Speed = defenderPokemon.Speed; pkm.Level = defenderPokemon.Level; pkm.Attack = defenderPokemon.Attack; pkm.Defense = defenderPokemon.Defense; pkm.SpecialAttack = defenderPokemon.SpecialAttack; pkm.SpecialDefense = defenderPokemon.SpecialDefense; pkm.XP = defenderPokemon.XP; pkm.MaxHP = defenderPokemon.MaxHP; DbHandler.Instance.Save(pkm); var db = DbHandler.Instance.GetAllRows <PokemonSprite>(); var row = db.Where(x => x.OwnerId == (long)MidnightBot.Creds.BotId); //var toDelete = DbHandler.Instance.FindAll<PokemonSprite>(s => s.OwnerId == (long)e.User.Id); foreach (var todel in row) { DbHandler.Instance.Delete <PokemonSprite>(todel.Id.Value); } str += $"{e.User.Mention} hat {defenderPokemon.NickName} gefangen!"; } else { str += $"{defenderPokemon.NickName} escaped!"; } await e.Channel.SendMessage(str); }); cgb.CreateCommand(Prefix + "attack") .Alias(Prefix) .Description($"Greift gegebenes Ziel mit gegebener Attacke an. | `{Prefix}attack hyperbeam @user oder, `{Prefix}attack @user flame-charge, {Prefix} sunny-day @user`") .Parameter("args", ParameterType.Unparsed) .Do(async e => { Regex regex = new Regex(@"<@!?(?<id>\d+)>"); var args = e.GetArg("args"); if (!regex.IsMatch(args)) { await e.Channel.SendMessage("Bitte gib Ziel ein"); return; } Match m = regex.Match(args); var id = ulong.Parse(m.Groups["id"].Value); if (id == MidnightBot.Creds.BotId) { } var target = e.Server.GetUser(id); if (target == null) { await e.Channel.SendMessage("Bitte gib Ziel ein"); return; } if (target == e.User) { await e.Channel.SendMessage("Du kannst dich nicht selbst angreifen!"); return; } var moveString = args.Replace(m.Value, string.Empty).Replace("\"", "").Trim(); string attstr = await Attack(e.User, target, moveString); await e.Channel.SendMessage(attstr); if (target.Id == MidnightBot.Creds.BotId && !attstr.Contains("Cannot use")) { string moves = ActivePokemon(target).PokemonMoves(true); string[] lines = moves.Split('\n'); int linenum = rand.Next(0, 3); string move = $"{lines[linenum]}"; move = move.Trim('\n', ' '); string output = $"{e.User.Mention}\n"; output += await Attack(target, e.User, move); await e.Channel.SendMessage(output); } }); }); }