cleaned up inrole and whosplaying commands a little
This commit is contained in:
parent
3e9d3d9655
commit
1c9c8af2c5
4 changed files with 23 additions and 31 deletions
|
@ -21,9 +21,7 @@ public class SearchesService : IEService
|
||||||
public List<MagicItem> MagicItems { get; } = [];
|
public List<MagicItem> MagicItems { get; } = [];
|
||||||
private readonly IHttpClientFactory _httpFactory;
|
private readonly IHttpClientFactory _httpFactory;
|
||||||
private readonly IGoogleApiService _google;
|
private readonly IGoogleApiService _google;
|
||||||
private readonly IImageCache _imgs;
|
|
||||||
private readonly IBotCache _c;
|
private readonly IBotCache _c;
|
||||||
private readonly FontProvider _fonts;
|
|
||||||
private readonly IBotCredsProvider _creds;
|
private readonly IBotCredsProvider _creds;
|
||||||
private readonly EllieRandom _rng;
|
private readonly EllieRandom _rng;
|
||||||
private readonly List<string> _yomamaJokes;
|
private readonly List<string> _yomamaJokes;
|
||||||
|
@ -34,17 +32,13 @@ public class SearchesService : IEService
|
||||||
|
|
||||||
public SearchesService(
|
public SearchesService(
|
||||||
IGoogleApiService google,
|
IGoogleApiService google,
|
||||||
IImageCache images,
|
|
||||||
IBotCache c,
|
IBotCache c,
|
||||||
IHttpClientFactory factory,
|
IHttpClientFactory factory,
|
||||||
FontProvider fonts,
|
|
||||||
IBotCredsProvider creds)
|
IBotCredsProvider creds)
|
||||||
{
|
{
|
||||||
_httpFactory = factory;
|
_httpFactory = factory;
|
||||||
_google = google;
|
_google = google;
|
||||||
_imgs = images;
|
|
||||||
_c = c;
|
_c = c;
|
||||||
_fonts = fonts;
|
|
||||||
_creds = creds;
|
_creds = creds;
|
||||||
_rng = new();
|
_rng = new();
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ public partial class Utility : EllieModule
|
||||||
PropertyNamingPolicy = LowerCaseNamingPolicy.Default
|
PropertyNamingPolicy = LowerCaseNamingPolicy.Default
|
||||||
};
|
};
|
||||||
|
|
||||||
private static SemaphoreSlim sem = new(1, 1);
|
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly ICoordinator _coord;
|
private readonly ICoordinator _coord;
|
||||||
private readonly IStatsService _stats;
|
private readonly IStatsService _stats;
|
||||||
|
@ -115,10 +114,8 @@ public partial class Utility : EllieModule
|
||||||
|
|
||||||
var rng = new EllieRandom();
|
var rng = new EllieRandom();
|
||||||
var arr = await Task.Run(() => socketGuild.Users
|
var arr = await Task.Run(() => socketGuild.Users
|
||||||
.Where(u => u.Activities.FirstOrDefault()
|
.Where(u => u.Activities.Any(x
|
||||||
?.Name?.Trim()
|
=> x.Name is not null && x.Name.ToUpperInvariant() == game))
|
||||||
.ToUpperInvariant()
|
|
||||||
== game)
|
|
||||||
.Select(u => u.Username)
|
.Select(u => u.Username)
|
||||||
.OrderBy(_ => rng.Next())
|
.OrderBy(_ => rng.Next())
|
||||||
.Take(60)
|
.Take(60)
|
||||||
|
@ -154,9 +151,16 @@ public partial class Utility : EllieModule
|
||||||
CacheMode.CacheOnly
|
CacheMode.CacheOnly
|
||||||
);
|
);
|
||||||
|
|
||||||
var roleUsers = users.Where(u => role is null ? u.RoleIds.Count == 1 : u.RoleIds.Contains(role.Id))
|
users = role is null
|
||||||
.Select(u => $"{u.Mention} {Format.Spoiler(Format.Code(u.Username))}")
|
? users
|
||||||
.ToArray();
|
: 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()
|
await Response()
|
||||||
.Paginated()
|
.Paginated()
|
||||||
|
@ -168,10 +172,11 @@ public partial class Utility : EllieModule
|
||||||
if (pageUsers.Count == 0)
|
if (pageUsers.Count == 0)
|
||||||
return _sender.CreateEmbed().WithOkColor().WithDescription(GetText(strs.no_user_on_this_page));
|
return _sender.CreateEmbed().WithOkColor().WithDescription(GetText(strs.no_user_on_this_page));
|
||||||
|
|
||||||
|
var roleName = Format.Bold(role?.Name ?? "No Role");
|
||||||
|
|
||||||
return _sender.CreateEmbed()
|
return _sender.CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle(GetText(strs.inrole_list(Format.Bold(role?.Name ?? "No Role"),
|
.WithTitle(GetText(strs.inrole_list(roleName, roleUsers.Count)))
|
||||||
roleUsers.Length)))
|
|
||||||
.WithDescription(string.Join("\n", pageUsers));
|
.WithDescription(string.Join("\n", pageUsers));
|
||||||
})
|
})
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
|
@ -674,24 +679,17 @@ public partial class Utility : EllieModule
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
[Ratelimit(3)]
|
||||||
public async Task Ping()
|
public async Task Ping()
|
||||||
{
|
{
|
||||||
await sem.WaitAsync(5000);
|
var sw = Stopwatch.StartNew();
|
||||||
try
|
var msg = await Response().Text("🏓").SendAsync();
|
||||||
{
|
sw.Stop();
|
||||||
var sw = Stopwatch.StartNew();
|
msg.DeleteAfter(0);
|
||||||
var msg = await Response().Text("🏓").SendAsync();
|
|
||||||
sw.Stop();
|
|
||||||
msg.DeleteAfter(0);
|
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm($"{Format.Bold(ctx.User.ToString())} 🏓 {(int)sw.Elapsed.TotalMilliseconds}ms")
|
.Confirm($"{Format.Bold(ctx.User.ToString())} 🏓 {(int)sw.Elapsed.TotalMilliseconds}ms")
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
sem.Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
|
Loading…
Reference in a new issue