Merge remote-tracking branch 'refs/remotes/Kwoth/master' into num

This commit is contained in:
appelemac 2016-07-29 15:10:15 +02:00
commit c14556ffc1
3 changed files with 25 additions and 34 deletions

View File

@ -1,11 +1,7 @@
using Discord.Commands; using Newtonsoft.Json;
using System; using System;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
//using Manatee.Json.Serialization; //using Manatee.Json.Serialization;
namespace NadekoBot.Classes.ClashOfClans namespace NadekoBot.Classes.ClashOfClans
@ -40,7 +36,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 +55,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; }
@ -80,7 +76,7 @@ namespace NadekoBot.Classes.ClashOfClans
this.Bases = new Caller[size]; this.Bases = new Caller[size];
this.ServerId = serverId; this.ServerId = serverId;
this.ChannelId = channelId; 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() 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."); 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 +108,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 +151,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

@ -1,15 +1,15 @@
using Discord.Commands; using Discord.Commands;
using Discord.Modules; using Discord.Modules;
using NadekoBot.Classes.ClashOfClans; using NadekoBot.Classes.ClashOfClans;
using NadekoBot.Modules.Permissions.Classes;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using NadekoBot.Modules.Permissions.Classes;
using System.Linq;
using System.IO;
using Newtonsoft.Json;
namespace NadekoBot.Modules.ClashOfClans namespace NadekoBot.Modules.ClashOfClans
{ {
@ -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,23 +76,24 @@ 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)
{ {
List<ClashWar> obj; List<ClashWar> obj;
ClashWars.TryRemove(cw.Key, out obj); ClashWars.TryRemove(cw.Key, out obj);
} else }
else
{ {
ClashWars.AddOrUpdate(cw.Key, newVal, (x, s) => newVal); ClashWars.AddOrUpdate(cw.Key, newVal, (x, s) => newVal);
} }
@ -130,7 +130,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;
@ -138,11 +138,6 @@ namespace NadekoBot.Modules.ClashOfClans
} }
} }
#region commands #region commands
public override void Install(ModuleManager manager) public override void Install(ModuleManager manager)
{ {

@ -1 +1 @@
Subproject commit 3e519b5e0b33175e5a5ca247322b7082de484e15 Subproject commit 3a33731135f1b7dd2efdb51b16158c84bb22da66