Removed some stray console writelines

This commit is contained in:
Master Kwoth 2016-04-12 03:28:44 +02:00
parent cc89d37ba5
commit 3150b2da6b
3 changed files with 62 additions and 38 deletions

View File

@ -1,35 +1,40 @@
using System; using Discord.Commands;
using System.Collections.Generic; using System;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands;
namespace NadekoBot.Classes.ClashOfClans { namespace NadekoBot.Classes.ClashOfClans
internal class Caller { {
internal class Caller
{
public string CallUser { get; } public string CallUser { get; }
public DateTime TimeAdded { get; private set; } public DateTime TimeAdded { get; private set; }
public bool BaseDestroyed { get; internal set; } public bool BaseDestroyed { get; internal set; }
public Caller(string callUser, DateTime timeAdded, bool baseDestroyed) { public Caller(string callUser, DateTime timeAdded, bool baseDestroyed)
{
CallUser = callUser; CallUser = callUser;
TimeAdded = timeAdded; TimeAdded = timeAdded;
BaseDestroyed = baseDestroyed; BaseDestroyed = baseDestroyed;
} }
public void ResetTime() { public void ResetTime()
{
TimeAdded = DateTime.Now; TimeAdded = DateTime.Now;
} }
public void Destroy() { public void Destroy()
{
BaseDestroyed = true; BaseDestroyed = true;
} }
} }
internal class ClashWar { internal class ClashWar
{
private static TimeSpan callExpire => new TimeSpan(2, 0, 0); private static TimeSpan callExpire => new TimeSpan(2, 0, 0);
private CommandEventArgs e; private CommandEventArgs e;
@ -43,25 +48,29 @@ namespace NadekoBot.Classes.ClashOfClans {
public event Action OnWarEnded = delegate { }; public event Action OnWarEnded = delegate { };
public bool Started { get; set; } = false; public bool Started { get; set; } = false;
public ClashWar(string enemyClan, int size, CommandEventArgs e) { public ClashWar(string enemyClan, int size, CommandEventArgs e)
{
this.EnemyClan = enemyClan; this.EnemyClan = enemyClan;
this.Size = size; this.Size = size;
this.bases = new Caller[size]; this.bases = new Caller[size];
this.baseCancelTokens = new CancellationTokenSource[size]; this.baseCancelTokens = new CancellationTokenSource[size];
} }
internal void End() { internal void End()
{
if (endTokenSource.Token.IsCancellationRequested) return; if (endTokenSource.Token.IsCancellationRequested) return;
endTokenSource.Cancel(); endTokenSource.Cancel();
OnWarEnded(); OnWarEnded();
} }
internal void Call(string u, int baseNumber) { internal void Call(string u, int baseNumber)
{
if (baseNumber < 0 || baseNumber >= bases.Length) if (baseNumber < 0 || baseNumber >= bases.Length)
throw new ArgumentException("Invalid base number"); throw new ArgumentException("Invalid base number");
if (bases[baseNumber] != null) if (bases[baseNumber] != null)
throw new ArgumentException("That base is already claimed."); throw new ArgumentException("That base is already claimed.");
for (var i = 0; i < bases.Length; i++) { for (var i = 0; i < bases.Length; i++)
{
if (bases[i]?.BaseDestroyed == false && bases[i]?.CallUser == u) if (bases[i]?.BaseDestroyed == false && bases[i]?.CallUser == u)
throw new ArgumentException($"@{u} You already claimed a base #{i + 1}. You can't claim a new one."); throw new ArgumentException($"@{u} You already claimed a base #{i + 1}. You can't claim a new one.");
} }
@ -69,23 +78,31 @@ namespace NadekoBot.Classes.ClashOfClans {
bases[baseNumber] = new Caller(u.Trim(), DateTime.Now, false); bases[baseNumber] = new Caller(u.Trim(), DateTime.Now, false);
} }
internal async Task Start() { internal async Task Start()
{
if (Started) if (Started)
throw new InvalidOperationException(); throw new InvalidOperationException();
try { try
{
Started = true; Started = true;
foreach (var b in bases.Where(b => b != null)) { foreach (var b in bases.Where(b => b != null))
{
b.ResetTime(); b.ResetTime();
} }
Task.Run(async () => await ClearArray()).ConfigureAwait(false); Task.Run(async () => await ClearArray()).ConfigureAwait(false);
await Task.Delay(new TimeSpan(24, 0, 0), endTokenSource.Token); await Task.Delay(new TimeSpan(24, 0, 0), endTokenSource.Token);
} catch { } finally { }
catch { }
finally
{
End(); End();
} }
} }
internal int Uncall(string user) { internal int Uncall(string user)
{
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]?.CallUser != user) continue; if (bases[i]?.CallUser != user) continue;
bases[i] = null; bases[i] = null;
return i; return i;
@ -93,37 +110,47 @@ namespace NadekoBot.Classes.ClashOfClans {
throw new InvalidOperationException("You are not participating in that war."); throw new InvalidOperationException("You are not participating in that war.");
} }
private async Task ClearArray() { private async Task ClearArray()
while (!endTokenSource.IsCancellationRequested) { {
while (!endTokenSource.IsCancellationRequested)
{
await Task.Delay(5000); await Task.Delay(5000);
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.Now - bases[i].TimeAdded >= callExpire)
Console.WriteLine($"Removing user {bases[i].CallUser}"); {
OnUserTimeExpired(bases[i].CallUser); OnUserTimeExpired(bases[i].CallUser);
bases[i] = null; bases[i] = null;
} }
} }
} }
Console.WriteLine("Out of clear array");
} }
public string ShortPrint() => public string ShortPrint() =>
$"`{EnemyClan}` ({Size} v {Size})"; $"`{EnemyClan}` ({Size} v {Size})";
public override string ToString() { public override string ToString()
{
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.AppendLine($"🔰**WAR AGAINST `{EnemyClan}` ({Size} v {Size}) INFO:**"); sb.AppendLine($"🔰**WAR AGAINST `{EnemyClan}` ({Size} v {Size}) INFO:**");
if (!Started) if (!Started)
sb.AppendLine("`not started`"); sb.AppendLine("`not started`");
for (var i = 0; i < bases.Length; i++) { for (var i = 0; i < bases.Length; i++)
if (bases[i] == null) { {
if (bases[i] == null)
{
sb.AppendLine($"`{i + 1}.` ❌*unclaimed*"); sb.AppendLine($"`{i + 1}.` ❌*unclaimed*");
} else { }
if (bases[i].BaseDestroyed) { else
{
if (bases[i].BaseDestroyed)
{
sb.AppendLine($"`{i + 1}.` ✅ `{bases[i].CallUser}` ⭐ ⭐ ⭐"); sb.AppendLine($"`{i + 1}.` ✅ `{bases[i].CallUser}` ⭐ ⭐ ⭐");
} else { }
else
{
var left = Started ? callExpire - (DateTime.Now - bases[i].TimeAdded) : callExpire; var left = Started ? callExpire - (DateTime.Now - 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");
} }
@ -133,9 +160,11 @@ namespace NadekoBot.Classes.ClashOfClans {
return sb.ToString(); return sb.ToString();
} }
internal int FinishClaim(string user) { internal int FinishClaim(string user)
{
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;
return i; return i;

View File

@ -106,7 +106,6 @@ namespace NadekoBot
return; return;
try try
{ {
Console.WriteLine("Joined server.");
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {
using (var content = new FormUrlEncodedContent(new Dictionary<string, string> { using (var content = new FormUrlEncodedContent(new Dictionary<string, string> {
@ -118,9 +117,6 @@ namespace NadekoBot
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
var res = await client.PostAsync("https://www.carbonitex.net/discord/data/botdata.php", content); var res = await client.PostAsync("https://www.carbonitex.net/discord/data/botdata.php", content);
Console.WriteLine(res.ReasonPhrase);
Console.WriteLine(res.StatusCode);
}; };
} }
} }

View File

@ -23,7 +23,6 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
var remList = DbHandler.Instance.GetAllRows<Reminder>(); var remList = DbHandler.Instance.GetAllRows<Reminder>();
Console.WriteLine(string.Join("\n-", remList.Select(r => r.When.ToString())));
reminders = remList.Select(StartNewReminder).ToList(); reminders = remList.Select(StartNewReminder).ToList();
} }