From 06740fc9ab076e772d6b71c36411a6cba1e84253 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 12 Jul 2017 16:03:33 +0200 Subject: [PATCH] Update StatsService.cs --- src/NadekoBot/Services/Impl/StatsService.cs | 31 ++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index ec8fa312..c34fe56c 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -8,6 +8,8 @@ using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using System.Security.Cryptography; +using System.Text; namespace NadekoBot.Services.Impl { @@ -34,6 +36,7 @@ namespace NadekoBot.Services.Impl public long CommandsRan => Interlocked.Read(ref _commandsRan); private Timer carbonitexTimer { get; } + private Timer _dataTimer { get; } public StatsService(DiscordShardedClient client, CommandHandler cmdHandler) { @@ -139,6 +142,32 @@ 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", _client.GetGuildCount().ToString() }, + { "version", BotVersion }, + { "platform", platform }})) + { + 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.FromSeconds(1), TimeSpan.FromHours(1)); } public void Initialize() @@ -171,4 +200,4 @@ Messages: {MessageCounter} [{MessagesPerSecond:F2}/sec] Heap: [{Heap} MB]"); return $"{time.Days} days{separator}{time.Hours} hours{separator}{time.Minutes} minutes"; } } -} \ No newline at end of file +}