-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpEmbedRenderer.cs
More file actions
57 lines (50 loc) · 2.29 KB
/
Copy pathHelpEmbedRenderer.cs
File metadata and controls
57 lines (50 loc) · 2.29 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Globalization;
using Discord;
using RustPlusBot.Localization;
namespace RustPlusBot.Features.Commands.Help;
/// <summary>Builds the <c>/help</c> embed from the catalog, the server prefix, and the guild culture.</summary>
/// <param name="localizer">Resolves the title, group headings, and per-command descriptions.</param>
internal sealed class HelpEmbedRenderer(ILocalizer localizer)
{
internal static readonly (CommandGroup Group, string HeadingKey)[] GroupOrder =
[
(CommandGroup.Control, "help.group.control"),
(CommandGroup.Server, "help.group.server"),
(CommandGroup.TeamIntel, "help.group.teamintel"),
(CommandGroup.Bot, "help.group.bot"),
(CommandGroup.ItemDb, "help.group.itemdb"),
];
/// <summary>Renders the help embed.</summary>
/// <param name="prefix">The in-game command prefix to display (e.g. "!").</param>
/// <param name="culture">The guild culture ("en"/"fr").</param>
/// <param name="showPrefixNote">True to add the multi-server prefix note to the description.</param>
/// <returns>The built embed.</returns>
public Embed Render(string prefix, string culture, bool showPrefixNote)
{
var embed = new EmbedBuilder()
.WithTitle(localizer.Get("help.title", culture))
.WithColor(Color.Blue);
if (showPrefixNote)
{
embed.WithDescription(localizer.Get("help.prefixnote", culture));
}
foreach (var (group, headingKey) in GroupOrder)
{
var lines = CommandHelpCatalog.InGame
.Where(e => e.Group == group)
.Select(e => string.Create(CultureInfo.InvariantCulture,
$"`{prefix}{e.Name}` — {localizer.Get(e.DescriptionKey, culture)}"))
.ToList();
if (lines.Count > 0)
{
embed.AddField(localizer.Get(headingKey, culture), string.Join('\n', lines));
}
}
var slashLines = CommandHelpCatalog.Slash
.Select(e => string.Create(CultureInfo.InvariantCulture,
$"`/{e.Name}` — {localizer.Get(e.DescriptionKey, culture)}"))
.ToList();
embed.AddField(localizer.Get("help.group.slash", culture), string.Join('\n', slashLines));
return embed.Build();
}
}