-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDurabilityCommandHandler.cs
More file actions
35 lines (32 loc) · 1.5 KB
/
Copy pathDurabilityCommandHandler.cs
File metadata and controls
35 lines (32 loc) · 1.5 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
using RustPlusBot.Features.Commands.Dispatching;
using RustPlusBot.Features.Commands.Formatting;
using RustPlusBot.Features.ItemData;
using RustPlusBot.Features.ItemData.Lookup;
using RustPlusBot.Features.ItemData.Naming;
using RustPlusBot.Localization;
namespace RustPlusBot.Features.Commands.Handlers;
/// <summary>!durability — lists the explosives needed to destroy a target.</summary>
/// <param name="database">The item database.</param>
/// <param name="names">Resolves tool ids to names.</param>
/// <param name="localizer">The reply localizer.</param>
internal sealed class DurabilityCommandHandler(IItemDatabase database, IItemNameResolver names, ILocalizer localizer)
: ICommandHandler
{
/// <inheritdoc />
public string Name => "durability";
/// <inheritdoc />
public Task<string?> ExecuteAsync(CommandContext context, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(context);
var query = string.Join(' ', context.Args);
var reply = database.ResolveRaidTarget(query) switch
{
RaidMatch.Found f =>
localizer.Get("command.durability.ok", context.Culture, DurabilityLine.Format(f.Target, names)),
RaidMatch.Ambiguous a => localizer.Get("command.item.ambiguous", context.Culture,
string.Join(", ", a.Candidates.Select(c => c.Name))),
_ => localizer.Get("command.item.notfound", context.Culture, query),
};
return Task.FromResult<string?>(reply);
}
}