1
Fork 0
mirror of https://gitlab.com/Kwoth/nadekobot.git synced 2024-10-02 12:09:07 +00:00

dev: cleaed up inrole and whosplaying commands a little

This commit is contained in:
Kwoth 2024-08-14 00:32:36 +00:00
parent 8b40f97a3d
commit 2a528cb3d6
4 changed files with 23 additions and 30 deletions

View file

@ -21,9 +21,7 @@ public class SearchesService : INService
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 NadekoRandom _rng;
private readonly List<string> _yomamaJokes;
@ -34,7 +32,6 @@ public class SearchesService : INService
public SearchesService(
IGoogleApiService google,
IImageCache images,
IBotCache c,
IHttpClientFactory factory,
FontProvider fonts,
@ -42,9 +39,7 @@ public class SearchesService : INService
{
_httpFactory = factory;
_google = google;
_imgs = images;
_c = c;
_fonts = fonts;
_creds = creds;
_rng = new();

View file

@ -31,7 +31,6 @@ public partial class Utility : NadekoModule
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 : NadekoModule
var rng = new NadekoRandom();
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 : NadekoModule
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 : NadekoModule
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 : NadekoModule
}
[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]