mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-24 01:14:12 +00:00
Update style, add nullable
This commit is contained in:
parent
f8350fed53
commit
488ebfa163
1 changed files with 38 additions and 47 deletions
|
@ -1,52 +1,43 @@
|
||||||
using Discord;
|
using System.Text;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace BirthdayBot.UserInterface
|
namespace BirthdayBot.UserInterface;
|
||||||
{
|
|
||||||
internal class CommandDocumentation
|
|
||||||
{
|
|
||||||
public string[] Commands { get; }
|
|
||||||
public string Usage { get; }
|
|
||||||
public string Examples { get; }
|
|
||||||
|
|
||||||
public CommandDocumentation(IEnumerable<string> commands, string usage, string examples)
|
internal class CommandDocumentation {
|
||||||
{
|
public string[] Commands { get; }
|
||||||
var cmds = new List<string>();
|
public string Usage { get; }
|
||||||
foreach (var item in commands) cmds.Add(CommandsCommon.CommandPrefix + item);
|
public string? Examples { get; }
|
||||||
if (cmds.Count == 0) throw new ArgumentException(null, nameof(commands));
|
|
||||||
Commands = cmds.ToArray();
|
|
||||||
Usage = usage ?? throw new ArgumentException(null, nameof(usage));
|
|
||||||
Examples = examples;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
public CommandDocumentation(IEnumerable<string> commands, string usage, string? examples) {
|
||||||
/// Returns a string that can be inserted into a help or usage message.
|
var cmds = new List<string>();
|
||||||
/// </summary>
|
foreach (var item in commands) cmds.Add(CommandsCommon.CommandPrefix + item);
|
||||||
public string Export()
|
if (cmds.Count == 0) throw new ArgumentException(null, nameof(commands));
|
||||||
{
|
Commands = cmds.ToArray();
|
||||||
var result = new StringBuilder();
|
Usage = usage ?? throw new ArgumentException(null, nameof(usage));
|
||||||
foreach (var item in Commands) result.Append(", `" + item + "`");
|
Examples = examples;
|
||||||
result.Remove(0, 2);
|
|
||||||
result.Insert(0, '●');
|
|
||||||
result.AppendLine();
|
|
||||||
result.Append("» " + Usage);
|
|
||||||
if (Examples != null)
|
|
||||||
{
|
|
||||||
result.AppendLine();
|
|
||||||
result.Append("» Examples: " + Examples);
|
|
||||||
}
|
|
||||||
return result.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an embeddable message containing the command documentation.
|
|
||||||
/// </summary>
|
|
||||||
public Embed UsageEmbed => new EmbedBuilder()
|
|
||||||
{
|
|
||||||
Author = new EmbedAuthorBuilder() { Name = "Usage" },
|
|
||||||
Description = Export()
|
|
||||||
}.Build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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) {
|
||||||
|
result.AppendLine();
|
||||||
|
result.Append("» Examples: " + Examples);
|
||||||
|
}
|
||||||
|
return result.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates an embeddable message containing the command documentation.
|
||||||
|
/// </summary>
|
||||||
|
public Embed UsageEmbed => new EmbedBuilder() {
|
||||||
|
Author = new EmbedAuthorBuilder() { Name = "Usage" },
|
||||||
|
Description = Export()
|
||||||
|
}.Build();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue