Update StatsService.cs

This commit is contained in:
Master Kwoth 2017-07-12 16:03:33 +02:00 committed by GitHub
parent cb0d4111d6
commit 06740fc9ab

View File

@ -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<string, string> {
{ "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";
}
}
}
}