Skip to content

Commit

Permalink
- Fix string.IsNullOrEmpty(), having an incorrect value (DblApiToken)…
Browse files Browse the repository at this point in the history
… when it should be DiscordBotsApiToken.

- Catch NullReferenceException in IDblSelfBot.GetMeAsync(), this can happen when a bot is not listed in DBL or the token is invalid.
  • Loading branch information
d4n3436 committed Nov 20, 2020
1 parent 16ad661 commit 4485437
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/FergunClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,17 @@ private async Task ClientReady()

if (string.IsNullOrEmpty(Config.DblApiToken))
{
await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Stats", $"Top.gg API token is empty or has not been established. Bot server count will not be sent to the API."));
await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Stats", "Top.gg API token is empty or has not been established. Bot server count will not be sent to the API."));
}
else
{
_dblApi = new AuthDiscordBotListApi(_client.CurrentUser.Id, Config.DblApiToken);
DblBotPage = $"https://top.gg/bot/{_client.CurrentUser.Id}";
}

if (string.IsNullOrEmpty(Config.DblApiToken))
if (string.IsNullOrEmpty(Config.DiscordBotsApiToken))
{
await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Stats", $"DiscordBots API token is empty or has not been established. Bot server count will not be sent to the API."));
await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Stats", "DiscordBots API token is empty or has not been established. Bot server count will not be sent to the API."));
}
else
{
Expand Down Expand Up @@ -578,9 +578,22 @@ private async Task UpdateBotListStatsAsync()
{
try
{
if (_dblApi != null)
if (_dblApi != null && _dblBot == null)
{
try
{
_dblBot = await _dblApi.GetMeAsync();
}
catch (NullReferenceException)
{
_dblApi = null;
await _logService.LogAsync(new LogMessage(LogSeverity.Warning, "Stats", "Could not get the bot info from DBL API, make sure the bot is listed in DBL and the token is valid"));
await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Stats", "Bot server count will not be sent to DBL API."));
}
}

if (_dblBot != null)
{
_dblBot ??= await _dblApi.GetMeAsync();
await _dblBot.UpdateStatsAsync(_client.Guilds.Count);
}
if (_discordBots != null)
Expand Down

0 comments on commit 4485437

Please sign in to comment.