2021-11-22 21:32:30 +00:00
|
|
|
|
using System.Text;
|
2020-06-04 01:56:45 +00:00
|
|
|
|
|
2021-11-22 21:32:30 +00:00
|
|
|
|
namespace BirthdayBot.UserInterface;
|
2020-06-04 01:56:45 +00:00
|
|
|
|
|
2021-11-22 21:32:30 +00:00
|
|
|
|
internal class CommandDocumentation {
|
|
|
|
|
public string[] Commands { get; }
|
|
|
|
|
public string Usage { get; }
|
|
|
|
|
public string? Examples { get; }
|
|
|
|
|
|
|
|
|
|
public CommandDocumentation(IEnumerable<string> commands, string usage, string? examples) {
|
|
|
|
|
var cmds = new List<string>();
|
|
|
|
|
foreach (var item in commands) cmds.Add(CommandsCommon.CommandPrefix + item);
|
|
|
|
|
if (cmds.Count == 0) throw new ArgumentException(null, nameof(commands));
|
|
|
|
|
Commands = cmds.ToArray();
|
|
|
|
|
Usage = usage ?? throw new ArgumentException(null, nameof(usage));
|
|
|
|
|
Examples = examples;
|
|
|
|
|
}
|
2020-06-04 01:56:45 +00:00
|
|
|
|
|
2021-11-22 21:32:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a string that can be inserted into a help or usage message.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Export() {
|
|
|
|
|
var result = new StringBuilder();
|
|
|
|
|
foreach (var item in Commands) result.Append(", `" + item + "`");
|
|
|
|
|
result.Remove(0, 2);
|
|
|
|
|
result.Insert(0, '●');
|
|
|
|
|
result.AppendLine();
|
|
|
|
|
result.Append("» " + Usage);
|
|
|
|
|
if (Examples != null) {
|
2020-06-04 01:56:45 +00:00
|
|
|
|
result.AppendLine();
|
2021-11-22 21:32:30 +00:00
|
|
|
|
result.Append("» Examples: " + Examples);
|
2020-06-04 01:56:45 +00:00
|
|
|
|
}
|
2021-11-22 21:32:30 +00:00
|
|
|
|
return result.ToString();
|
2020-06-04 01:56:45 +00:00
|
|
|
|
}
|
2021-11-22 21:32:30 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates an embeddable message containing the command documentation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Embed UsageEmbed => new EmbedBuilder() {
|
|
|
|
|
Author = new EmbedAuthorBuilder() { Name = "Usage" },
|
|
|
|
|
Description = Export()
|
|
|
|
|
}.Build();
|
2020-06-04 01:56:45 +00:00
|
|
|
|
}
|