-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeliCommandHandler.cs
More file actions
36 lines (32 loc) · 1.49 KB
/
Copy pathHeliCommandHandler.cs
File metadata and controls
36 lines (32 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
using RustPlusBot.Abstractions.Time;
using RustPlusBot.Features.Commands.Dispatching;
using RustPlusBot.Features.Commands.Formatting;
using RustPlusBot.Features.Commands.Localization;
using RustPlusBot.Features.Connections.Listening;
using RustPlusBot.Features.Events.Formatting;
using RustPlusBot.Features.Events.State;
namespace RustPlusBot.Features.Commands.Handlers;
/// <summary>!heli — reports the patrol helicopter's current grid position, if any.</summary>
/// <param name="state">The live event state.</param>
/// <param name="localizer">The reply localizer.</param>
/// <param name="clock">For "how long ago".</param>
internal sealed class HeliCommandHandler(IEventState state, ICommandLocalizer localizer, IClock clock)
: ICommandHandler
{
/// <inheritdoc />
public string Name => "heli";
/// <inheritdoc />
public Task<string?> ExecuteAsync(CommandContext context, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(context);
var markers = state.GetActiveMarkers(context.GuildId, context.ServerId, MarkerKind.PatrolHelicopter);
if (markers.Count == 0)
{
return Task.FromResult<string?>(localizer.Get("command.heli.none", context.Culture));
}
var m = markers[0];
var grid = GridReference.From(m.X, m.Y, m.Dimensions);
var ago = DurationFormat.Compact(clock.UtcNow - m.SeenAtUtc);
return Task.FromResult<string?>(localizer.Get("command.heli.ok", context.Culture, grid, ago));
}
}