Skip to content

Commit

Permalink
top command should skip inactive...badly
Browse files Browse the repository at this point in the history
  • Loading branch information
RheaAyase committed Jul 10, 2024
1 parent 71fe155 commit bb75cc1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Modules/Karma.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ public List<Command> Init(IValkyrjaClient iClient)
n = 20;

ServerContext dbContext = ServerContext.Create(this.Client.DbConnectionString);
IEnumerable<UserData> 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<UserData> 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());
Expand Down

0 comments on commit bb75cc1

Please sign in to comment.