diff --git a/src/NadekoBot/Modules/Searches/OsuCommands.cs b/src/NadekoBot/Modules/Searches/Osu/OsuCommands.cs similarity index 100% rename from src/NadekoBot/Modules/Searches/OsuCommands.cs rename to src/NadekoBot/Modules/Searches/Osu/OsuCommands.cs diff --git a/src/NadekoBot/Modules/Searches/OsuService.cs b/src/NadekoBot/Modules/Searches/Osu/OsuService.cs similarity index 100% rename from src/NadekoBot/Modules/Searches/OsuService.cs rename to src/NadekoBot/Modules/Searches/Osu/OsuService.cs diff --git a/src/NadekoBot/Modules/Searches/SearchesService.cs b/src/NadekoBot/Modules/Searches/SearchesService.cs index c0f34fa34..3a69f0d72 100644 --- a/src/NadekoBot/Modules/Searches/SearchesService.cs +++ b/src/NadekoBot/Modules/Searches/SearchesService.cs @@ -21,9 +21,7 @@ public class SearchesService : INService public List 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 _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(); diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 0e66c4721..81cc1add5 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -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(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]