Skip to content

Commit 673cc2e

Browse files
committed
feat(commands): /smelt slash command + help catalog rows
1 parent 15cd64b commit 673cc2e

6 files changed

Lines changed: 57 additions & 4 deletions

File tree

src/RustPlusBot.Features.Commands/Help/CommandHelpCatalog.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ internal static class CommandHelpCatalog
3232
new("decay", CommandGroup.ItemDb, "help.decay"),
3333
new("upkeep", CommandGroup.ItemDb, "help.upkeep"),
3434
new("durability", CommandGroup.ItemDb, "help.durability"),
35+
new("smelt", CommandGroup.ItemDb, "help.smelt"),
3536
];
3637

3738
/// <summary>The Discord slash commands, in display order.</summary>
@@ -47,5 +48,6 @@ internal static class CommandHelpCatalog
4748
new("decay", CommandGroup.ItemDb, "help.slash.decay"),
4849
new("upkeep", CommandGroup.ItemDb, "help.slash.upkeep"),
4950
new("durability", CommandGroup.ItemDb, "help.slash.durability"),
51+
new("smelt", CommandGroup.ItemDb, "help.slash.smelt"),
5052
];
5153
}

src/RustPlusBot.Features.Commands/Modules/ItemCommandModule.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace RustPlusBot.Features.Commands.Modules;
1313

14-
/// <summary>The /item, /recycle, /craft, /research, /decay, /upkeep, and /durability slash commands.</summary>
14+
/// <summary>The /item, /recycle, /craft, /research, /decay, /upkeep, /durability, and /smelt slash commands.</summary>
1515
/// <param name="scopeFactory">Creates a short-lived DI scope per interaction.</param>
1616
public sealed class ItemCommandModule(IServiceScopeFactory scopeFactory)
1717
: InteractionModuleBase<SocketInteractionContext>
@@ -69,6 +69,12 @@ public Task UpkeepAsync([Summary("item", "Item name or id")] string item) =>
6969
public Task DurabilityAsync([Summary("target", "Item, wall/door, or vehicle name")] string target) =>
7070
RespondForRaidAsync(target);
7171

72+
/// <summary>Shows what a smelter converts and its fuel/time cost.</summary>
73+
/// <param name="smelter">The smelter name or id.</param>
74+
[SlashCommand("smelt", "Show what a smelter converts and its fuel/time cost")]
75+
public Task SmeltAsync([Summary("smelter", "Furnace, Camp Fire, Electric Furnace, …")] string smelter) =>
76+
RespondForSmeltAsync(smelter);
77+
7278
private async Task RespondForAsync(
7379
string query,
7480
Func<IItemDatabase, DateOnly> dateSelector,
@@ -137,4 +143,37 @@ private async Task RespondForRaidAsync(string query)
137143
await RespondAsync(ephemeral: true, embed: embed).ConfigureAwait(false);
138144
}
139145
}
146+
147+
private async Task RespondForSmeltAsync(string query)
148+
{
149+
if (Context.Guild is null)
150+
{
151+
await RespondAsync("This command must be used in a server.", ephemeral: true).ConfigureAwait(false);
152+
return;
153+
}
154+
155+
var scope = scopeFactory.CreateAsyncScope();
156+
await using (scope.ConfigureAwait(false))
157+
{
158+
var db = scope.ServiceProvider.GetRequiredService<IItemDatabase>();
159+
var names = scope.ServiceProvider.GetRequiredService<IItemNameResolver>();
160+
var loc = scope.ServiceProvider.GetRequiredService<ILocalizer>();
161+
var workspace = scope.ServiceProvider.GetRequiredService<IWorkspaceStore>();
162+
var culture = await workspace.GetCultureAsync(Context.Guild.Id).ConfigureAwait(false);
163+
164+
var text = db.ResolveSmelter(query) switch
165+
{
166+
SmeltMatch.Found f => loc.Get("command.smelt.ok", culture, SmeltLine.Format(f.Smelter, names)),
167+
SmeltMatch.Ambiguous a => loc.Get("command.item.ambiguous", culture,
168+
string.Join(", ", a.Candidates.Select(c => c.Name))),
169+
_ => loc.Get("command.item.notfound", culture, query),
170+
};
171+
172+
var embed = new EmbedBuilder()
173+
.WithDescription(text)
174+
.WithFooter($"data as of {db.Sources.SmeltingAsOf:yyyy-MM-dd}")
175+
.Build();
176+
await RespondAsync(ephemeral: true, embed: embed).ConfigureAwait(false);
177+
}
178+
}
140179
}

src/RustPlusBot.Localization/Strings.fr.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@
396396
<data name="help.durability" xml:space="preserve">
397397
<value>Explosifs nécessaires pour détruire une cible</value>
398398
</data>
399+
<data name="help.smelt" xml:space="preserve">
400+
<value>Ce qu'un fondeur transforme, avec carburant et temps</value>
401+
</data>
399402
<data name="help.item" xml:space="preserve">
400403
<value>Afficher le nom, l'id, la pile et la disparition d'un objet</value>
401404
</data>
@@ -429,6 +432,9 @@
429432
<data name="help.slash.durability" xml:space="preserve">
430433
<value>Affiche les explosifs nécessaires pour détruire une cible.</value>
431434
</data>
435+
<data name="help.slash.smelt" xml:space="preserve">
436+
<value>Affiche ce qu'un fondeur transforme et son coût en carburant/temps.</value>
437+
</data>
432438
<data name="help.slash.help" xml:space="preserve">
433439
<value>Afficher ce message d'aide.</value>
434440
</data>

src/RustPlusBot.Localization/Strings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@
396396
<data name="help.durability" xml:space="preserve">
397397
<value>Explosives needed to destroy a target</value>
398398
</data>
399+
<data name="help.smelt" xml:space="preserve">
400+
<value>What a smelter converts, with fuel and time</value>
401+
</data>
399402
<data name="help.item" xml:space="preserve">
400403
<value>Look up an item's name, id, stack, and despawn</value>
401404
</data>
@@ -429,6 +432,9 @@
429432
<data name="help.slash.durability" xml:space="preserve">
430433
<value>Show the explosives needed to destroy a target.</value>
431434
</data>
435+
<data name="help.slash.smelt" xml:space="preserve">
436+
<value>Show what a smelter converts and its fuel/time cost.</value>
437+
</data>
432438
<data name="help.slash.help" xml:space="preserve">
433439
<value>Show this help message.</value>
434440
</data>

tests/RustPlusBot.Features.Commands.Tests/Help/CommandHelpCatalogTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace RustPlusBot.Features.Commands.Tests.Help;
55

66
public sealed class CommandHelpCatalogTests
77
{
8-
/// <summary>The 20 registered in-game handler names (see AddCommands / CommandRegistrationTests).</summary>
8+
/// <summary>The 21 registered in-game handler names (see AddCommands / CommandRegistrationTests).</summary>
99
private static readonly string[] HandlerNames =
1010
[
1111
"mute", "unmute", "uptime", "pop", "wipe", "time",
1212
"online", "offline", "team", "steamid", "alive", "afk", "prox",
13-
"item", "recycle", "craft", "research", "decay", "upkeep", "durability",
13+
"item", "recycle", "craft", "research", "decay", "upkeep", "durability", "smelt",
1414
];
1515

1616
[Fact]

tests/RustPlusBot.Localization.Tests/StringsResourceParityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public void English_covers_every_french_key()
4242
[Fact]
4343
public void Catalog_has_expected_key_count()
4444
{
45-
Assert.Equal(242, EnglishKeys().Count);
45+
Assert.Equal(244, EnglishKeys().Count);
4646
}
4747
}

0 commit comments

Comments
 (0)