cleaned up inrole and whosplaying commands a little

This commit is contained in:
Toastie 2024-08-17 18:45:31 +12:00
parent 3e9d3d9655
commit 1c9c8af2c5
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
4 changed files with 23 additions and 31 deletions

View file

@ -21,9 +21,7 @@ public class SearchesService : IEService
public List<MagicItem> MagicItems { get; } = [];
private readonly IHttpClientFactory _httpFactory;
private readonly IGoogleApiService _google;
private readonly IImageCache _imgs;
private readonly IBotCache _c;
private readonly FontProvider _fonts;
private readonly IBotCredsProvider _creds;
private readonly EllieRandom _rng;
private readonly List<string> _yomamaJokes;
@ -34,17 +32,13 @@ public class SearchesService : IEService
public SearchesService(
IGoogleApiService google,
IImageCache images,
IBotCache c,
IHttpClientFactory factory,
FontProvider fonts,
IBotCredsProvider creds)
{
_httpFactory = factory;
_google = google;
_imgs = images;
_c = c;
_fonts = fonts;
_creds = creds;
_rng = new();

View file

@ -31,7 +31,6 @@ public partial class Utility : EllieModule
PropertyNamingPolicy = LowerCaseNamingPolicy.Default
};
private static SemaphoreSlim sem = new(1, 1);
private readonly DiscordSocketClient _client;
private readonly ICoordinator _coord;
private readonly IStatsService _stats;
@ -115,10 +114,8 @@ public partial class Utility : EllieModule
var rng = new EllieRandom();
var arr = await Task.Run(() => socketGuild.Users
.Where(u => u.Activities.FirstOrDefault()
?.Name?.Trim()
.ToUpperInvariant()
== game)
.Where(u => u.Activities.Any(x
=> x.Name is not null && x.Name.ToUpperInvariant() == game))
.Select(u => u.Username)
.OrderBy(_ => rng.Next())
.Take(60)
@ -154,9 +151,16 @@ public partial class Utility : EllieModule
CacheMode.CacheOnly
);
var roleUsers = users.Where(u => role is null ? u.RoleIds.Count == 1 : u.RoleIds.Contains(role.Id))
.Select(u => $"{u.Mention} {Format.Spoiler(Format.Code(u.Username))}")
.ToArray();
users = role is null
? users
: users.Where(u => u.RoleIds.Contains(role.Id)).ToList();
var roleUsers = new List<string>(users.Count);
foreach (var u in users)
{
roleUsers.Add($"{u.Mention} {Format.Spoiler(Format.Code(u.Username))}");
}
await Response()
.Paginated()
@ -168,10 +172,11 @@ public partial class Utility : EllieModule
if (pageUsers.Count == 0)
return _sender.CreateEmbed().WithOkColor().WithDescription(GetText(strs.no_user_on_this_page));
var roleName = Format.Bold(role?.Name ?? "No Role");
return _sender.CreateEmbed()
.WithOkColor()
.WithTitle(GetText(strs.inrole_list(Format.Bold(role?.Name ?? "No Role"),
roleUsers.Length)))
.WithTitle(GetText(strs.inrole_list(roleName, roleUsers.Count)))
.WithDescription(string.Join("\n", pageUsers));
})
.SendAsync();
@ -674,24 +679,17 @@ public partial class Utility : EllieModule
}
[Cmd]
[Ratelimit(3)]
public async Task Ping()
{
await sem.WaitAsync(5000);
try
{
var sw = Stopwatch.StartNew();
var msg = await Response().Text("🏓").SendAsync();
sw.Stop();
msg.DeleteAfter(0);
var sw = Stopwatch.StartNew();
var msg = await Response().Text("🏓").SendAsync();
sw.Stop();
msg.DeleteAfter(0);
await Response()
.Confirm($"{Format.Bold(ctx.User.ToString())} 🏓 {(int)sw.Elapsed.TotalMilliseconds}ms")
.SendAsync();
}
finally
{
sem.Release();
}
await Response()
.Confirm($"{Format.Bold(ctx.User.ToString())} 🏓 {(int)sw.Elapsed.TotalMilliseconds}ms")
.SendAsync();
}
[Cmd]