From bb75cc1b83819342316fbe6e68b312a9a4aa5859 Mon Sep 17 00:00:00 2001 From: RheaAyase Date: Thu, 11 Jul 2024 00:21:27 +0100 Subject: [PATCH] top command should skip inactive...badly --- Modules/Karma.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Modules/Karma.cs b/Modules/Karma.cs index 4001f05..a10e3e7 100644 --- a/Modules/Karma.cs +++ b/Modules/Karma.cs @@ -56,13 +56,19 @@ public List Init(IValkyrjaClient iClient) n = 20; ServerContext dbContext = ServerContext.Create(this.Client.DbConnectionString); - IEnumerable userData = dbContext.UserDatabase.Where(u => u.ServerId == e.Server.Id && u.KarmaCount > 0).OrderByDescending(u => u.KarmaCount).Take(maxUsers).SkipWhile(u => e.Server.Guild.GetUser(u.UserId) == null).Take(n); + IEnumerable users = dbContext.UserDatabase.Where(u => u.ServerId == e.Server.Id && u.KarmaCount > 0).OrderByDescending(u => u.KarmaCount).Take(maxUsers); - int i = 1; + int i = 0; StringBuilder response = new StringBuilder($"Here is the top {n} {e.Server.Config.KarmaCurrencySingular} holders:"); - foreach( UserData user in userData ) + foreach( UserData userData in users ) { - response.AppendLine($"**{i++})** {e.Server.Guild.GetUser(user.UserId)?.GetNickname().Replace("@everyone", "@-everyone").Replace("@here", "@-here")} : `{user.KarmaCount}`"); + if( i++ == n ) + return; + + SocketGuildUser user = null; + if( (user = e.Server.Guild.GetUser(userData.UserId)) == null ) + continue; + response.AppendLine($"**{i})** {user.GetNickname().Replace("@everyone", "@-everyone").Replace("@here", "@-here")} : `{userData.KarmaCount}`"); } await e.SendReplySafe(response.ToString());