From 488ebfa163d23fa361e0cae3cac4d7c912be89ed Mon Sep 17 00:00:00 2001 From: Noi Date: Mon, 22 Nov 2021 13:32:30 -0800 Subject: [PATCH] Update style, add nullable --- UserInterface/CommandDocumentation.cs | 85 ++++++++++++--------------- 1 file changed, 38 insertions(+), 47 deletions(-) diff --git a/UserInterface/CommandDocumentation.cs b/UserInterface/CommandDocumentation.cs index 27ba3c7..b51d55f 100644 --- a/UserInterface/CommandDocumentation.cs +++ b/UserInterface/CommandDocumentation.cs @@ -1,52 +1,43 @@ -using Discord; -using System; -using System.Collections.Generic; -using System.Text; +using System.Text; -namespace BirthdayBot.UserInterface -{ - internal class CommandDocumentation - { - public string[] Commands { get; } - public string Usage { get; } - public string Examples { get; } +namespace BirthdayBot.UserInterface; - public CommandDocumentation(IEnumerable commands, string usage, string examples) - { - var cmds = new List(); - 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; - } +internal class CommandDocumentation { + public string[] Commands { get; } + public string Usage { get; } + public string? Examples { get; } - /// - /// Returns a string that can be inserted into a help or usage message. - /// - 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(); - } - - /// - /// Creates an embeddable message containing the command documentation. - /// - public Embed UsageEmbed => new EmbedBuilder() - { - Author = new EmbedAuthorBuilder() { Name = "Usage" }, - Description = Export() - }.Build(); + public CommandDocumentation(IEnumerable commands, string usage, string? examples) { + var cmds = new List(); + 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; } + + /// + /// Returns a string that can be inserted into a help or usage message. + /// + 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(); + } + + /// + /// Creates an embeddable message containing the command documentation. + /// + public Embed UsageEmbed => new EmbedBuilder() { + Author = new EmbedAuthorBuilder() { Name = "Usage" }, + Description = Export() + }.Build(); }