Exception-proofing external statistics

This commit is contained in:
Noi 2020-10-05 22:26:29 -07:00
parent 0eb63c26f5
commit 6efc436717

View file

@ -184,9 +184,10 @@ namespace BirthdayBot
/// </summary>
private async Task SendExternalStatistics(int count, ulong botId, CancellationToken token)
{
// TODO protect against exceptions
var dbotsToken = Config.DBotsToken;
if (dbotsToken != null)
{
try
{
const string dBotsApiUrl = "https://discord.bots.gg/api/v1/bots/{0}/stats";
const string Body = "{{ \"guildCount\": {0} }}";
@ -198,7 +199,12 @@ namespace BirthdayBot
await Task.Delay(80); // Discord Bots rate limit for this endpoint is 20 per second
await _httpClient.SendAsync(post, token);
Log("Discord Bots: Count sent successfully.");
Log("Discord Bots: Update successful.");
}
catch (Exception ex)
{
Log("Discord Bots: Exception encountered during update: " + ex.Message);
}
}
}
#endregion