From ba993a1bab51c5bf8bb2c07f8f4b763c1deb38c7 Mon Sep 17 00:00:00 2001 From: Toastie Date: Sat, 17 Aug 2024 19:02:58 +1200 Subject: [PATCH] .whosplaying code cleanup --- src/EllieBot/Db/Models/xp/UserXpStats.cs | 4 +- .../Db/Models/xp/XpNotificationLocation.cs | 7 ++++ src/EllieBot/Modules/Utility/Utility.cs | 42 ++++++++++--------- 3 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 src/EllieBot/Db/Models/xp/XpNotificationLocation.cs diff --git a/src/EllieBot/Db/Models/xp/UserXpStats.cs b/src/EllieBot/Db/Models/xp/UserXpStats.cs index d603360..f34ab26 100644 --- a/src/EllieBot/Db/Models/xp/UserXpStats.cs +++ b/src/EllieBot/Db/Models/xp/UserXpStats.cs @@ -8,6 +8,4 @@ public class UserXpStats : DbEntity public long Xp { get; set; } public long AwardedXp { get; set; } public XpNotificationLocation NotifyOnLevelUp { get; set; } -} - -public enum XpNotificationLocation { None, Dm, Channel } \ No newline at end of file +} \ No newline at end of file diff --git a/src/EllieBot/Db/Models/xp/XpNotificationLocation.cs b/src/EllieBot/Db/Models/xp/XpNotificationLocation.cs new file mode 100644 index 0000000..0a9356f --- /dev/null +++ b/src/EllieBot/Db/Models/xp/XpNotificationLocation.cs @@ -0,0 +1,7 @@ +namespace EllieBot.Db.Models; + +public enum XpNotificationLocation +{ + None, + Dm, +} \ No newline at end of file diff --git a/src/EllieBot/Modules/Utility/Utility.cs b/src/EllieBot/Modules/Utility/Utility.cs index d670707..154daba 100644 --- a/src/EllieBot/Modules/Utility/Utility.cs +++ b/src/EllieBot/Modules/Utility/Utility.cs @@ -112,28 +112,32 @@ public partial class Utility : EllieModule return; } - var rng = new EllieRandom(); - var arr = await Task.Run(() => socketGuild.Users - .Where(u => u.Activities.Any(x - => x.Name is not null && x.Name.ToUpperInvariant() == game)) - .Select(u => u.Username) - .OrderBy(_ => rng.Next()) - .Take(60) - .ToArray()); - var i = 0; - if (arr.Length == 0) - await Response().Error(strs.nobody_playing_game).SendAsync(); - else + var userNames = new List(socketGuild.Users.Count / 100); + foreach (var user in socketGuild.Users) { - await Response() - .Confirm("```css\n" - + string.Join("\n", - arr.GroupBy(_ => i++ / 2) - .Select(ig => string.Concat(ig.Select(el => $"• {el,-27}")))) - + "\n```") - .SendAsync(); + if (user.Activities.Any(x => x.Name is not null && x.Name.ToUpperInvariant() == game)) + { + userNames.Add(user); + } } + + userNames.Shuffle(); + + var i = 0; + if (userNames.Count == 0) + { + await Response().Error(strs.nobody_playing_game).SendAsync(); + return; + } + + var users = userNames.GroupBy(_ => i++ / 2) + .Select(ig => string.Concat(ig.Select(el => $"• {el,-27}"))) + .Join('\n'); + + await Response() + .Confirm(Format.Code(users)) + .SendAsync(); } [Cmd]