dev: .whosplaying code cleanup

This commit is contained in:
Kwoth
2024-08-16 23:46:16 +00:00
parent f66c105cc0
commit d0aa80a004
3 changed files with 30 additions and 21 deletions

View File

@@ -9,5 +9,3 @@ public class UserXpStats : DbEntity
public long AwardedXp { get; set; } public long AwardedXp { get; set; }
public XpNotificationLocation NotifyOnLevelUp { get; set; } public XpNotificationLocation NotifyOnLevelUp { get; set; }
} }
public enum XpNotificationLocation { None, Dm, Channel }

View File

@@ -0,0 +1,7 @@
namespace NadekoBot.Db.Models;
public enum XpNotificationLocation
{
None,
Dm,
}

View File

@@ -112,28 +112,32 @@ public partial class Utility : NadekoModule
return; return;
} }
var rng = new NadekoRandom();
var arr = await Task.Run(() => socketGuild.Users var userNames = new List<IUser>(socketGuild.Users.Count / 100);
.Where(u => u.Activities.Any(x foreach (var user in socketGuild.Users)
=> x.Name is not null && x.Name.ToUpperInvariant() == game)) {
.Select(u => u.Username) if (user.Activities.Any(x => x.Name is not null && x.Name.ToUpperInvariant() == game))
.OrderBy(_ => rng.Next()) {
.Take(60) userNames.Add(user);
.ToArray()); }
}
userNames.Shuffle();
var i = 0; var i = 0;
if (arr.Length == 0) if (userNames.Count == 0)
await Response().Error(strs.nobody_playing_game).SendAsync();
else
{ {
await Response() await Response().Error(strs.nobody_playing_game).SendAsync();
.Confirm("```css\n" return;
+ string.Join("\n",
arr.GroupBy(_ => i++ / 2)
.Select(ig => string.Concat(ig.Select(el => $"• {el,-27}"))))
+ "\n```")
.SendAsync();
} }
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] [Cmd]