ClashOfClans - Added ,cfw1 ,cfw2 and alias to cf - ,cf3 to finish claims with a certain number of stars. (1/2/3)
This commit is contained in:
		@@ -7,6 +7,10 @@ using System.Threading.Tasks;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Classes.ClashOfClans
 | 
					namespace NadekoBot.Classes.ClashOfClans
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    public enum DestroyStars
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        One, Two, Three
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    internal class Caller
 | 
					    internal class Caller
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public string CallUser { get; }
 | 
					        public string CallUser { get; }
 | 
				
			||||||
@@ -15,6 +19,9 @@ namespace NadekoBot.Classes.ClashOfClans
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public bool BaseDestroyed { get; internal set; }
 | 
					        public bool BaseDestroyed { get; internal set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public int Stars { get; set; } = 3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public Caller(string callUser, DateTime timeAdded, bool baseDestroyed)
 | 
					        public Caller(string callUser, DateTime timeAdded, bool baseDestroyed)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            CallUser = callUser;
 | 
					            CallUser = callUser;
 | 
				
			||||||
@@ -148,7 +155,7 @@ namespace NadekoBot.Classes.ClashOfClans
 | 
				
			|||||||
                {
 | 
					                {
 | 
				
			||||||
                    if (bases[i].BaseDestroyed)
 | 
					                    if (bases[i].BaseDestroyed)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        sb.AppendLine($"`{i + 1}.` ✅ `{bases[i].CallUser}` ⭐ ⭐ ⭐");
 | 
					                        sb.AppendLine($"`{i + 1}.` ✅ `{bases[i].CallUser}` {new string('⭐', bases[i].Stars)}");
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else
 | 
					                    else
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
@@ -161,13 +168,14 @@ namespace NadekoBot.Classes.ClashOfClans
 | 
				
			|||||||
            return sb.ToString();
 | 
					            return sb.ToString();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        internal int FinishClaim(string user)
 | 
					        internal int FinishClaim(string user, int stars = 3)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            user = user.Trim();
 | 
					            user = user.Trim();
 | 
				
			||||||
            for (var i = 0; i < bases.Length; i++)
 | 
					            for (var i = 0; i < bases.Length; i++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (bases[i]?.BaseDestroyed != false || bases[i]?.CallUser != user) continue;
 | 
					                if (bases[i]?.BaseDestroyed != false || bases[i]?.CallUser != user) continue;
 | 
				
			||||||
                bases[i].BaseDestroyed = true;
 | 
					                bases[i].BaseDestroyed = true;
 | 
				
			||||||
 | 
					                bases[i].Stars = stars;
 | 
				
			||||||
                return i;
 | 
					                return i;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            throw new InvalidOperationException($"@{user} You are either not participating in that war, or you already destroyed a base.");
 | 
					            throw new InvalidOperationException($"@{user} You are either not participating in that war, or you already destroyed a base.");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@ using System;
 | 
				
			|||||||
using System.Collections.Concurrent;
 | 
					using System.Collections.Concurrent;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Modules.ClashOfClans
 | 
					namespace NadekoBot.Modules.ClashOfClans
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -179,33 +180,26 @@ namespace NadekoBot.Modules.ClashOfClans
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                cgb.CreateCommand(Prefix + "claimfinish")
 | 
					                cgb.CreateCommand(Prefix + "claimfinish")
 | 
				
			||||||
                    .Alias(Prefix + "cf")
 | 
					                    .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("number", ParameterType.Required)
 | 
				
			||||||
                    .Parameter("other_name", ParameterType.Unparsed)
 | 
					                    .Parameter("other_name", ParameterType.Unparsed)
 | 
				
			||||||
                    .Do(async e =>
 | 
					                    .Do(e => FinishClaim(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");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        var war = warInfo.Item1[warInfo.Item2];
 | 
					                cgb.CreateCommand(Prefix + "claimfinish2")
 | 
				
			||||||
                        try
 | 
					                    .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]")
 | 
				
			||||||
                            var baseNum = war.FinishClaim(usr);
 | 
					                    .Parameter("number", ParameterType.Required)
 | 
				
			||||||
                            await e.Channel.SendMessage($"❗🔰{e.User.Mention} **DESTROYED** a base #{baseNum + 1} in a war against {war.ShortPrint()}").ConfigureAwait(false);
 | 
					                    .Parameter("other_name", ParameterType.Unparsed)
 | 
				
			||||||
                        }
 | 
					                    .Do(e => FinishClaim(e, 2));
 | 
				
			||||||
                        catch (Exception ex)
 | 
					
 | 
				
			||||||
                        {
 | 
					                cgb.CreateCommand(Prefix + "claimfinish1")
 | 
				
			||||||
                            await e.Channel.SendMessage($"💢🔰 {ex.Message}").ConfigureAwait(false);
 | 
					                    .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")
 | 
					                cgb.CreateCommand(Prefix + "unclaim")
 | 
				
			||||||
                    .Alias(Prefix + "uncall")
 | 
					                    .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<List<ClashWar>, int> GetInfo(CommandEventArgs e)
 | 
					        private static Tuple<List<ClashWar>, int> GetInfo(CommandEventArgs e)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            //check if there are any wars
 | 
					            //check if there are any wars
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user