Don't error in rank when no entries are found or bot is not included

This commit is contained in:
Runebaas 2018-02-15 00:07:11 +01:00
parent d40d89506e
commit 1c88dea796
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6

View file

@ -56,9 +56,18 @@ namespace Geekbot.net.Commands
} }
var messageList = _redis.HashGetAll($"{Context.Guild.Id}:{type}"); var messageList = _redis.HashGetAll($"{Context.Guild.Id}:{type}");
if (messageList.Length == 0)
{
await ReplyAsync($"No {type.ToLowerInvariant()} found on this server");
return;
}
var sortedList = messageList.OrderByDescending(e => e.Value).ToList(); var sortedList = messageList.OrderByDescending(e => e.Value).ToList();
var guildMessages = (int) sortedList.First().Value; var guildMessages = (int) sortedList.First().Value;
sortedList.Remove(sortedList.Single(e => e.Name.ToString().Equals(_client.CurrentUser.Id.ToString()))); var theBot = sortedList.FirstOrDefault(e => e.Name.ToString().Equals(_client.CurrentUser.Id.ToString()));
if (!string.IsNullOrEmpty(theBot.Name))
{
sortedList.Remove(theBot);
}
if (type == "Messages") sortedList.RemoveAt(0); if (type == "Messages") sortedList.RemoveAt(0);
var highscoreUsers = new Dictionary<RankUserPolyfill, int>(); var highscoreUsers = new Dictionary<RankUserPolyfill, int>();