Beispiel #1
0
    /// <summary>
    /// Adding a command
    /// </summary>
    /// <param name="command">Command</param>
    /// <param name="onCommand">Adding a command overload</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task AddCommand(Command command, Func <StringBuilder, Task> onCommand)
    {
        if (command.Overloads?.Any() == true)
        {
            var sb = new StringBuilder();

            foreach (var ovl in command.Overloads.OrderByDescending(x => x.Priority))
            {
                sb.Append('`').Append(command.QualifiedName);

                foreach (var arg in ovl.Arguments)
                {
                    sb.Append(arg.IsOptional || arg.IsCatchAll ? " [" : " <")
                    .Append(_localizationGroup.GetText($"{command.QualifiedName} {arg.Name}", arg.Name))
                    .Append(arg.IsCatchAll ? "..." : string.Empty)
                    .Append(arg.IsOptional || arg.IsCatchAll ? ']' : '>');
                }

                sb.Append("` " + _localizationGroup.GetText(command.QualifiedName, string.Empty) + "\n");

                foreach (var arg in ovl.Arguments)
                {
                    sb.Append("` - ")
                    .Append(_localizationGroup.GetText($"{command.QualifiedName} {arg.Name}", arg.Name));

                    if (_localizationGroup.TryGetText($"{command.QualifiedName} {arg.Name} format", out var format))
                    {
                        sb.Append(" (")
                        .Append(format)
                        .Append(')');
                    }

                    sb.Append("`");

                    if (_localizationGroup.TryGetText($"{command.QualifiedName} {arg.Name} description", out var description))
                    {
                        sb.Append(" : ")
                        .Append(description);
                    }

                    sb.Append("\n");
                }
            }

            await onCommand(sb).ConfigureAwait(false);
        }
    }