Some stats stuff for science

This commit is contained in:
Master Kwoth 2017-07-12 03:39:44 +02:00
parent 8a75c28d73
commit c0012e296e

View File

@ -6,6 +6,8 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -35,6 +37,7 @@ namespace NadekoBot.Services.Impl
public long CommandsRan => Interlocked.Read(ref _commandsRan); public long CommandsRan => Interlocked.Read(ref _commandsRan);
private readonly Timer _carbonitexTimer; private readonly Timer _carbonitexTimer;
private readonly Timer _dataTimer;
private readonly ShardsCoordinator _sc; private readonly ShardsCoordinator _sc;
public int GuildCount => public int GuildCount =>
@ -153,6 +156,31 @@ namespace NadekoBot.Services.Impl
// ignored // ignored
} }
}, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1)); }, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
_dataTimer = new Timer(async (state) =>
{
try
{
using (var http = new HttpClient())
{
using (var content = new FormUrlEncodedContent(
new Dictionary<string, string> {
{ "id", string.Concat(MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(_creds.ClientId.ToString())).Select(x => x.ToString("X2"))) },
{ "guildCount", sc.GuildCount.ToString() },
{ "version", BotVersion } }))
{
content.Headers.Clear();
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
await http.PostAsync("https://selfstats.nadekobot.me/", content).ConfigureAwait(false);
}
}
}
catch
{
// ignored
}
}, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
} }
} }