From d79514305b77b37201e396eca251acfef2153174 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Tue, 12 Apr 2016 00:18:56 +0200 Subject: [PATCH] Able to send botdata to carbon now (if compliant?). --- NadekoBot/Classes/JSONModels/_JSONModels.cs | 1 + NadekoBot/Classes/NadekoStats.cs | 28 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/NadekoBot/Classes/JSONModels/_JSONModels.cs b/NadekoBot/Classes/JSONModels/_JSONModels.cs index 43fb37da..b8f9b086 100644 --- a/NadekoBot/Classes/JSONModels/_JSONModels.cs +++ b/NadekoBot/Classes/JSONModels/_JSONModels.cs @@ -13,5 +13,6 @@ namespace NadekoBot.Classes.JSONModels public string SoundCloudClientID = ""; public string MashapeKey = ""; public string LOLAPIKey = ""; + public string CarbonKey = ""; } } \ No newline at end of file diff --git a/NadekoBot/Classes/NadekoStats.cs b/NadekoBot/Classes/NadekoStats.cs index b8d98e0f..0e7ff053 100644 --- a/NadekoBot/Classes/NadekoStats.cs +++ b/NadekoBot/Classes/NadekoStats.cs @@ -4,8 +4,10 @@ using NadekoBot.Extensions; using NadekoBot.Modules; using NadekoBot.Modules.Administration.Commands; using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Net.Http; using System.Reflection; using System.Threading.Tasks; using System.Timers; @@ -27,6 +29,7 @@ namespace NadekoBot public int VoiceChannelsCount { get; private set; } = 0; private readonly Timer commandLogTimer = new Timer() { Interval = 10000 }; + private readonly Timer carbonStatusTimer = new Timer() { Interval = 3600000 }; static NadekoStats() { } @@ -93,8 +96,31 @@ namespace NadekoBot } 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 { + { "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() => DateTime.Now - Process.GetCurrentProcess().StartTime;