From 1c88dea796ea9c5ad91f6db6be20d10bca1823eb Mon Sep 17 00:00:00 2001 From: Runebaas Date: Thu, 15 Feb 2018 00:07:11 +0100 Subject: [PATCH] Don't error in rank when no entries are found or bot is not included --- Geekbot.net/Commands/Rank.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Geekbot.net/Commands/Rank.cs b/Geekbot.net/Commands/Rank.cs index 516c2aa..8c11171 100644 --- a/Geekbot.net/Commands/Rank.cs +++ b/Geekbot.net/Commands/Rank.cs @@ -56,9 +56,18 @@ namespace Geekbot.net.Commands } 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 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); var highscoreUsers = new Dictionary();