diff --git a/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index 6576ce3d..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 @@ -40,7 +36,7 @@ namespace NadekoBot.Classes.ClashOfClans public void ResetTime() { - TimeAdded = DateTime.Now; + TimeAdded = DateTime.UtcNow; } public void Destroy() @@ -59,12 +55,12 @@ 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; } 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() @@ -101,7 +97,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 +108,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 +151,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..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 { @@ -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,23 +76,24 @@ 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) { List obj; ClashWars.TryRemove(cw.Key, out obj); - } else + } + else { ClashWars.AddOrUpdate(cw.Key, newVal, (x, s) => newVal); } @@ -130,7 +130,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; @@ -138,11 +138,6 @@ namespace NadekoBot.Modules.ClashOfClans } } - - - - - #region commands public override void Install(ModuleManager manager) { @@ -181,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") @@ -243,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); 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