From 7147d2f0b1ac815c632ea812ed0fe9354831b7a7 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 27 Jul 2016 03:03:27 +0200 Subject: [PATCH 1/3] More CoC --- NadekoBot/Modules/ClashOfClans/ClashOfClans.cs | 10 +++++----- NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index 6576ce3d..de3e3079 100644 --- a/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -40,7 +40,7 @@ namespace NadekoBot.Classes.ClashOfClans public void ResetTime() { - TimeAdded = DateTime.Now; + TimeAdded = DateTime.UtcNow; } public void Destroy() @@ -59,7 +59,7 @@ namespace NadekoBot.Classes.ClashOfClans public Caller[] Bases { get; set; } public WarState WarState { get; set; } = WarState.Created; //public bool Started { get; set; } = false; - public DateTime StartedAt { get; private set; } + public DateTime StartedAt { get; set; } //public bool Ended { get; private set; } = false; public ulong ServerId { get; set; } @@ -101,7 +101,7 @@ namespace NadekoBot.Classes.ClashOfClans throw new ArgumentException($"@{u} You already claimed base #{i + 1}. You can't claim a new one."); } - Bases[baseNumber] = new Caller(u.Trim(), DateTime.Now, false); + Bases[baseNumber] = new Caller(u.Trim(), DateTime.UtcNow, false); } internal void Start() @@ -112,7 +112,7 @@ namespace NadekoBot.Classes.ClashOfClans // throw new InvalidOperationException(); //Started = true; WarState = WarState.Started; - StartedAt = DateTime.Now; + StartedAt = DateTime.UtcNow; foreach (var b in Bases.Where(b => b != null)) { b.ResetTime(); @@ -155,7 +155,7 @@ namespace NadekoBot.Classes.ClashOfClans } else { - var left =(WarState == WarState.Started) ? callExpire - (DateTime.Now - Bases[i].TimeAdded) : callExpire; + var left =(WarState == WarState.Started) ? callExpire - (DateTime.UtcNow - Bases[i].TimeAdded) : callExpire; sb.AppendLine($"`{i + 1}.` ✅ `{Bases[i].CallUser}` {left.Hours}h {left.Minutes}m {left.Seconds}s left"); } } diff --git a/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs b/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs index 69ed1163..847d97f4 100644 --- a/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs +++ b/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs @@ -58,7 +58,6 @@ namespace NadekoBot.Modules.ClashOfClans //Can't this be disabled if the modules is disabled too :) var callExpire = new TimeSpan(2, 0, 0); var warExpire = new TimeSpan(23, 0, 0); - bool changed = false; while (true) { try @@ -77,16 +76,16 @@ namespace NadekoBot.Modules.ClashOfClans if (w.WarState != WarState.Ended) { //and B: the war has not expired - if ((w.WarState == WarState.Started && DateTime.Now - w.StartedAt <= warExpire) || w.WarState == WarState.Created) + if ((w.WarState == WarState.Started && DateTime.UtcNow - w.StartedAt <= warExpire) || w.WarState == WarState.Created) { newVal.Add(w); } } } - //var newVal = cw.Value.Where(w => !(w.Ended || DateTime.Now - w.StartedAt >= warExpire)).ToList(); + //var newVal = cw.Value.Where(w => !(w.Ended || DateTime.UtcNow - w.StartedAt >= warExpire)).ToList(); foreach (var exWar in cw.Value.Except(newVal)) { - await exWar.Channel.SendMessage($"War against {exWar.EnemyClan} has ended"); + await exWar.Channel.SendMessage($"War against {exWar.EnemyClan} ({exWar.Size}v{exWar.Size}) has ended"); } if (newVal.Count == 0) @@ -130,7 +129,7 @@ namespace NadekoBot.Modules.ClashOfClans for (var i = 0; i < Bases.Length; i++) { if (Bases[i] == null) continue; - if (!Bases[i].BaseDestroyed && DateTime.Now - Bases[i].TimeAdded >= callExpire) + if (!Bases[i].BaseDestroyed && DateTime.UtcNow - Bases[i].TimeAdded >= callExpire) { await war.Channel.SendMessage($"❗🔰**Claim from @{Bases[i].CallUser} for a war against {war.ShortPrint()} has expired.**").ConfigureAwait(false); Bases[i] = null; From f025a5a06286e0041ec44d2ec16a551e82792cec Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 27 Jul 2016 03:10:36 +0200 Subject: [PATCH 2/3] format --- .../Modules/ClashOfClans/ClashOfClans.cs | 12 +++----- .../ClashOfClans/ClashOfClansModule.cs | 28 ++++++++----------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index de3e3079..1ae491ad 100644 --- a/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -1,11 +1,7 @@ -using Discord.Commands; +using Newtonsoft.Json; using System; using System.Linq; using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Collections.Generic; -using Newtonsoft.Json; //using Manatee.Json.Serialization; namespace NadekoBot.Classes.ClashOfClans @@ -64,7 +60,7 @@ namespace NadekoBot.Classes.ClashOfClans public ulong ServerId { get; set; } public ulong ChannelId { get; set; } - + [JsonIgnore] public Discord.Channel Channel { get; internal set; } @@ -80,7 +76,7 @@ namespace NadekoBot.Classes.ClashOfClans this.Bases = new Caller[size]; this.ServerId = serverId; this.ChannelId = channelId; - this.Channel = NadekoBot.Client.Servers.FirstOrDefault(s=>s.Id == serverId)?.TextChannels.FirstOrDefault(c => c.Id == channelId); + this.Channel = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id == serverId)?.TextChannels.FirstOrDefault(c => c.Id == channelId); } internal void End() @@ -155,7 +151,7 @@ namespace NadekoBot.Classes.ClashOfClans } else { - var left =(WarState == WarState.Started) ? callExpire - (DateTime.UtcNow - Bases[i].TimeAdded) : callExpire; + var left = (WarState == WarState.Started) ? callExpire - (DateTime.UtcNow - Bases[i].TimeAdded) : callExpire; sb.AppendLine($"`{i + 1}.` ✅ `{Bases[i].CallUser}` {left.Hours}h {left.Minutes}m {left.Seconds}s left"); } } diff --git a/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs b/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs index 847d97f4..37443900 100644 --- a/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs +++ b/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs @@ -1,15 +1,15 @@ using Discord.Commands; using Discord.Modules; using NadekoBot.Classes.ClashOfClans; +using NadekoBot.Modules.Permissions.Classes; +using Newtonsoft.Json; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Text; using System.Threading.Tasks; -using NadekoBot.Modules.Permissions.Classes; -using System.Linq; -using System.IO; -using Newtonsoft.Json; namespace NadekoBot.Modules.ClashOfClans { @@ -87,12 +87,13 @@ namespace NadekoBot.Modules.ClashOfClans { await exWar.Channel.SendMessage($"War against {exWar.EnemyClan} ({exWar.Size}v{exWar.Size}) has ended"); } - + if (newVal.Count == 0) { List obj; ClashWars.TryRemove(cw.Key, out obj); - } else + } + else { ClashWars.AddOrUpdate(cw.Key, newVal, (x, s) => newVal); } @@ -137,11 +138,6 @@ namespace NadekoBot.Modules.ClashOfClans } } - - - - - #region commands public override void Install(ModuleManager manager) { @@ -180,13 +176,13 @@ namespace NadekoBot.Modules.ClashOfClans var cw = new ClashWar(enemyClan, size, e.Server.Id, e.Channel.Id); - //cw.Start(); + //cw.Start(); - wars.Add(cw); + wars.Add(cw); await e.Channel.SendMessage($"❗🔰**CREATED CLAN WAR AGAINST {cw.ShortPrint()}**").ConfigureAwait(false); Save(); - //war with the index X started. - }); + //war with the index X started. + }); cgb.CreateCommand(Prefix + "startwar") .Alias(Prefix + "sw") @@ -242,7 +238,7 @@ namespace NadekoBot.Modules.ClashOfClans } await e.Channel.SendMessage(sb.ToString()).ConfigureAwait(false); return; - + } //if number is not null, print the war needed var warsInfo = GetInfo(e); From 6f6453e430bc10730384357a4ce90921a00214c8 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 27 Jul 2016 07:22:36 +0200 Subject: [PATCH 3/3] updated discord.net --- discord.net | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord.net b/discord.net index 3e519b5e..3a337311 160000 --- a/discord.net +++ b/discord.net @@ -1 +1 @@ -Subproject commit 3e519b5e0b33175e5a5ca247322b7082de484e15 +Subproject commit 3a33731135f1b7dd2efdb51b16158c84bb22da66