From 8e917172419ec2b4b4065402cdba2331e0a7ab01 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Thu, 7 Jul 2016 16:41:24 +0200 Subject: [PATCH] ClashOfClans - Added ,cfw1 ,cfw2 and alias to cf - ,cf3 to finish claims with a certain number of stars. (1/2/3) --- .../Modules/ClashOfClans/ClashOfClans.cs | 12 +++- .../ClashOfClans/ClashOfClansModule.cs | 67 ++++++++++++------- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index 85168971..668afd73 100644 --- a/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -7,6 +7,10 @@ using System.Threading.Tasks; namespace NadekoBot.Classes.ClashOfClans { + public enum DestroyStars + { + One, Two, Three + } internal class Caller { public string CallUser { get; } @@ -15,6 +19,9 @@ namespace NadekoBot.Classes.ClashOfClans public bool BaseDestroyed { get; internal set; } + public int Stars { get; set; } = 3; + + public Caller(string callUser, DateTime timeAdded, bool baseDestroyed) { CallUser = callUser; @@ -148,7 +155,7 @@ namespace NadekoBot.Classes.ClashOfClans { if (bases[i].BaseDestroyed) { - sb.AppendLine($"`{i + 1}.` ✅ `{bases[i].CallUser}` ⭐ ⭐ ⭐"); + sb.AppendLine($"`{i + 1}.` ✅ `{bases[i].CallUser}` {new string('⭐', bases[i].Stars)}"); } else { @@ -161,13 +168,14 @@ namespace NadekoBot.Classes.ClashOfClans return sb.ToString(); } - internal int FinishClaim(string user) + internal int FinishClaim(string user, int stars = 3) { user = user.Trim(); for (var i = 0; i < bases.Length; i++) { if (bases[i]?.BaseDestroyed != false || bases[i]?.CallUser != user) continue; bases[i].BaseDestroyed = true; + bases[i].Stars = stars; return i; } throw new InvalidOperationException($"@{user} You are either not participating in that war, or you already destroyed a base."); diff --git a/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs b/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs index a96a7347..297c4b34 100644 --- a/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs +++ b/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Text; +using System.Threading.Tasks; namespace NadekoBot.Modules.ClashOfClans { @@ -179,33 +180,26 @@ namespace NadekoBot.Modules.ClashOfClans cgb.CreateCommand(Prefix + "claimfinish") .Alias(Prefix + "cf") - .Description($"Finish your claim if you destroyed a base. Optional second argument finishes for someone else.\n**Usage**: {Prefix}cf [war_number] [optional_other_name]") + .Alias(Prefix + "cf3") + .Alias(Prefix + "claimfinish3") + .Description($"Finish your claim with 3 stars if you destroyed a base. Optional second argument finishes for someone else.\n**Usage**: {Prefix}cf [war_number] [optional_other_name]") .Parameter("number", ParameterType.Required) .Parameter("other_name", ParameterType.Unparsed) - .Do(async e => - { - var warInfo = GetInfo(e); - if (warInfo == null || warInfo.Item1.Count == 0) - { - await e.Channel.SendMessage("💢🔰 **That war does not exist.**").ConfigureAwait(false); - return; - } - var usr = - string.IsNullOrWhiteSpace(e.GetArg("other_name")) ? - e.User.Name : - e.GetArg("other_name"); + .Do(e => FinishClaim(e)); - var war = warInfo.Item1[warInfo.Item2]; - try - { - var baseNum = war.FinishClaim(usr); - await e.Channel.SendMessage($"❗🔰{e.User.Mention} **DESTROYED** a base #{baseNum + 1} in a war against {war.ShortPrint()}").ConfigureAwait(false); - } - catch (Exception ex) - { - await e.Channel.SendMessage($"💢🔰 {ex.Message}").ConfigureAwait(false); - } - }); + cgb.CreateCommand(Prefix + "claimfinish2") + .Alias(Prefix + "cf2") + .Description($"Finish your claim with 2 stars if you destroyed a base. Optional second argument finishes for someone else.\n**Usage**: {Prefix}cf [war_number] [optional_other_name]") + .Parameter("number", ParameterType.Required) + .Parameter("other_name", ParameterType.Unparsed) + .Do(e => FinishClaim(e, 2)); + + cgb.CreateCommand(Prefix + "claimfinish1") + .Alias(Prefix + "cf1") + .Description($"Finish your claim with 1 stars if you destroyed a base. Optional second argument finishes for someone else.\n**Usage**: {Prefix}cf [war_number] [optional_other_name]") + .Parameter("number", ParameterType.Required) + .Parameter("other_name", ParameterType.Unparsed) + .Do(e => FinishClaim(e, 1)); cgb.CreateCommand(Prefix + "unclaim") .Alias(Prefix + "uncall") @@ -257,6 +251,31 @@ namespace NadekoBot.Modules.ClashOfClans }); } + private async Task FinishClaim(CommandEventArgs e, int stars = 3) + { + var warInfo = GetInfo(e); + if (warInfo == null || warInfo.Item1.Count == 0) + { + await e.Channel.SendMessage("💢🔰 **That war does not exist.**").ConfigureAwait(false); + return; + } + var usr = + string.IsNullOrWhiteSpace(e.GetArg("other_name")) ? + e.User.Name : + e.GetArg("other_name"); + + var war = warInfo.Item1[warInfo.Item2]; + try + { + var baseNum = war.FinishClaim(usr, stars); + await e.Channel.SendMessage($"❗🔰{e.User.Mention} **DESTROYED** a base #{baseNum + 1} in a war against {war.ShortPrint()}").ConfigureAwait(false); + } + catch (Exception ex) + { + await e.Channel.SendMessage($"💢🔰 {ex.Message}").ConfigureAwait(false); + } + } + private static Tuple, int> GetInfo(CommandEventArgs e) { //check if there are any wars