From c0012e296ec8478611095f3b4e74d97d5954725c Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 12 Jul 2017 03:39:44 +0200 Subject: [PATCH] Some stats stuff for science --- src/NadekoBot/Services/Impl/StatsService.cs | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 74bb561b..3b0eaf8f 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -6,6 +6,8 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Net.Http; +using System.Security.Cryptography; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -35,6 +37,7 @@ namespace NadekoBot.Services.Impl public long CommandsRan => Interlocked.Read(ref _commandsRan); private readonly Timer _carbonitexTimer; + private readonly Timer _dataTimer; private readonly ShardsCoordinator _sc; public int GuildCount => @@ -153,6 +156,31 @@ namespace NadekoBot.Services.Impl // ignored } }, 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 { + { "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)); } }