-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAfkCommandHandler.cs
More file actions
38 lines (33 loc) · 1.49 KB
/
Copy pathAfkCommandHandler.cs
File metadata and controls
38 lines (33 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using RustPlusBot.Features.Commands.Dispatching;
using RustPlusBot.Features.Commands.Formatting;
using RustPlusBot.Features.Commands.Localization;
using RustPlusBot.Features.Connections.Listening;
namespace RustPlusBot.Features.Commands.Handlers;
/// <summary>!afk — lists team members who have been still (online + alive) past the AFK threshold.</summary>
/// <param name="afk">The live AFK state.</param>
/// <param name="localizer">The reply localizer.</param>
internal sealed class AfkCommandHandler(IAfkState afk, ICommandLocalizer localizer) : ICommandHandler
{
/// <inheritdoc />
public string Name => "afk";
/// <inheritdoc />
public async Task<string?> ExecuteAsync(CommandContext context, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(context);
var members = await afk.GetAfkMembersAsync(context.GuildId, context.ServerId, cancellationToken)
.ConfigureAwait(false);
if (members is null)
{
return localizer.Get("command.notconnected", context.Culture);
}
if (members.Count == 0)
{
return localizer.Get("command.afk.none", context.Culture);
}
var parts = members
.OrderByDescending(m => m.StillFor)
.Select(m => localizer.Get(
"command.afk.member", context.Culture, m.Name, DurationFormat.Compact(m.StillFor)));
return localizer.Get("command.afk.ok", context.Culture, string.Join(", ", parts));
}
}