This commit is contained in:
Kwoth 2016-07-27 03:03:27 +02:00
parent 135c00823d
commit 7147d2f0b1
2 changed files with 9 additions and 10 deletions

View File

@ -40,7 +40,7 @@ namespace NadekoBot.Classes.ClashOfClans
public void ResetTime() public void ResetTime()
{ {
TimeAdded = DateTime.Now; TimeAdded = DateTime.UtcNow;
} }
public void Destroy() public void Destroy()
@ -59,7 +59,7 @@ namespace NadekoBot.Classes.ClashOfClans
public Caller[] Bases { get; set; } public Caller[] Bases { get; set; }
public WarState WarState { get; set; } = WarState.Created; public WarState WarState { get; set; } = WarState.Created;
//public bool Started { get; set; } = false; //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 bool Ended { get; private set; } = false;
public ulong ServerId { get; set; } 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."); 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() internal void Start()
@ -112,7 +112,7 @@ namespace NadekoBot.Classes.ClashOfClans
// throw new InvalidOperationException(); // throw new InvalidOperationException();
//Started = true; //Started = true;
WarState = WarState.Started; WarState = WarState.Started;
StartedAt = DateTime.Now; StartedAt = DateTime.UtcNow;
foreach (var b in Bases.Where(b => b != null)) foreach (var b in Bases.Where(b => b != null))
{ {
b.ResetTime(); b.ResetTime();
@ -155,7 +155,7 @@ namespace NadekoBot.Classes.ClashOfClans
} }
else 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"); sb.AppendLine($"`{i + 1}.` ✅ `{Bases[i].CallUser}` {left.Hours}h {left.Minutes}m {left.Seconds}s left");
} }
} }

View File

@ -58,7 +58,6 @@ namespace NadekoBot.Modules.ClashOfClans
//Can't this be disabled if the modules is disabled too :) //Can't this be disabled if the modules is disabled too :)
var callExpire = new TimeSpan(2, 0, 0); var callExpire = new TimeSpan(2, 0, 0);
var warExpire = new TimeSpan(23, 0, 0); var warExpire = new TimeSpan(23, 0, 0);
bool changed = false;
while (true) while (true)
{ {
try try
@ -77,16 +76,16 @@ namespace NadekoBot.Modules.ClashOfClans
if (w.WarState != WarState.Ended) if (w.WarState != WarState.Ended)
{ {
//and B: the war has not expired //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); 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)) 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) if (newVal.Count == 0)
@ -130,7 +129,7 @@ namespace NadekoBot.Modules.ClashOfClans
for (var i = 0; i < Bases.Length; i++) for (var i = 0; i < Bases.Length; i++)
{ {
if (Bases[i] == null) continue; 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); await war.Channel.SendMessage($"❗🔰**Claim from @{Bases[i].CallUser} for a war against {war.ShortPrint()} has expired.**").ConfigureAwait(false);
Bases[i] = null; Bases[i] = null;