|
11 | 11 |
|
12 | 12 | namespace RustPlusBot.Features.Commands.Modules; |
13 | 13 |
|
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> |
15 | 15 | /// <param name="scopeFactory">Creates a short-lived DI scope per interaction.</param> |
16 | 16 | public sealed class ItemCommandModule(IServiceScopeFactory scopeFactory) |
17 | 17 | : InteractionModuleBase<SocketInteractionContext> |
@@ -69,6 +69,12 @@ public Task UpkeepAsync([Summary("item", "Item name or id")] string item) => |
69 | 69 | public Task DurabilityAsync([Summary("target", "Item, wall/door, or vehicle name")] string target) => |
70 | 70 | RespondForRaidAsync(target); |
71 | 71 |
|
| 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 | + |
72 | 78 | private async Task RespondForAsync( |
73 | 79 | string query, |
74 | 80 | Func<IItemDatabase, DateOnly> dateSelector, |
@@ -137,4 +143,37 @@ private async Task RespondForRaidAsync(string query) |
137 | 143 | await RespondAsync(ephemeral: true, embed: embed).ConfigureAwait(false); |
138 | 144 | } |
139 | 145 | } |
| 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 | + } |
140 | 179 | } |
0 commit comments