-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWipeCommandHandler.cs
More file actions
38 lines (33 loc) · 1.41 KB
/
Copy pathWipeCommandHandler.cs
File metadata and controls
38 lines (33 loc) · 1.41 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.Abstractions.Connections;
using RustPlusBot.Abstractions.Formatting;
using RustPlusBot.Abstractions.Time;
using RustPlusBot.Features.Commands.Dispatching;
using RustPlusBot.Localization;
namespace RustPlusBot.Features.Commands.Handlers;
/// <summary>!wipe — reports how long ago the server last wiped.</summary>
/// <param name="query">The live server query.</param>
/// <param name="localizer">The reply localizer.</param>
/// <param name="clock">The clock used to compute the elapsed time since wipe.</param>
internal sealed class WipeCommandHandler(IRustServerQuery query, ILocalizer localizer, IClock clock)
: ICommandHandler
{
/// <inheritdoc />
public string Name => "wipe";
/// <inheritdoc />
public async Task<string?> ExecuteAsync(CommandContext context, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(context);
var info = await query.GetServerInfoAsync(context.GuildId, context.ServerId, cancellationToken)
.ConfigureAwait(false);
if (info is null)
{
return localizer.Get("command.notconnected", context.Culture);
}
if (info.WipeTimeUtc is null)
{
return localizer.Get("command.wipe.unknown", context.Culture);
}
return localizer.Get("command.wipe.ok", context.Culture,
DurationFormat.Compact(clock.UtcNow - info.WipeTimeUtc.Value));
}
}