Able to send botdata to carbon now (if compliant?).

This commit is contained in:
Master Kwoth 2016-04-12 00:18:56 +02:00
parent 2a625451b0
commit d79514305b
2 changed files with 28 additions and 1 deletions

View File

@ -13,5 +13,6 @@ namespace NadekoBot.Classes.JSONModels
public string SoundCloudClientID = ""; public string SoundCloudClientID = "";
public string MashapeKey = ""; public string MashapeKey = "";
public string LOLAPIKey = ""; public string LOLAPIKey = "";
public string CarbonKey = "";
} }
} }

View File

@ -4,8 +4,10 @@ using NadekoBot.Extensions;
using NadekoBot.Modules; using NadekoBot.Modules;
using NadekoBot.Modules.Administration.Commands; using NadekoBot.Modules.Administration.Commands;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers; using System.Timers;
@ -27,6 +29,7 @@ namespace NadekoBot
public int VoiceChannelsCount { get; private set; } = 0; public int VoiceChannelsCount { get; private set; } = 0;
private readonly Timer commandLogTimer = new Timer() { Interval = 10000 }; private readonly Timer commandLogTimer = new Timer() { Interval = 10000 };
private readonly Timer carbonStatusTimer = new Timer() { Interval = 3600000 };
static NadekoStats() { } static NadekoStats() { }
@ -93,8 +96,31 @@ namespace NadekoBot
} }
catch { } catch { }
}; };
}
if (!string.IsNullOrWhiteSpace(NadekoBot.Creds.CarbonKey))
{
carbonStatusTimer.Elapsed += (s, e) =>
{
try
{
using (var client = new HttpClient())
{
client.PostAsync("https://www.carbonitex.net/discord/data/botdata.php",
new FormUrlEncodedContent(new Dictionary<string, string> {
{ "servercount", NadekoBot.Client.Servers.Count().ToString() },
{ "key", NadekoBot.Creds.CarbonKey }
}));
}
}
catch (Exception ex)
{
Console.WriteLine("Failed sending status update to carbon.");
Console.WriteLine(ex);
}
};
carbonStatusTimer.Start();
}
}
public TimeSpan GetUptime() => public TimeSpan GetUptime() =>
DateTime.Now - Process.GetCurrentProcess().StartTime; DateTime.Now - Process.GetCurrentProcess().StartTime;