コード例 #1
0
ファイル: Program.cs プロジェクト: QuantumToasted/Shine
        private static void GenerateCommandMarkdown(CommandService commandService)
        {
            var builder = new StringBuilder();

            foreach (var module in commandService.TopLevelModules.OrderBy(x => x.Name))
            {
                builder.AppendNewline($"## {module.Name}")
                .AppendNewline(module.Description)
                .AppendNewline("|Command|Description|")
                .AppendNewline("|---|---|");

                foreach (var command in CommandUtilities.EnumerateAllCommands(module))
                {
                    builder.Append('|')
                    .Append(string.Join("<br>",
                                        command.FullAliases.Select(x => Markdown.Code($"{PREFIX}{x}{command.FormatArguments()}"))))
                    .Append('|')
                    .Append(command.Description.Replace("\n", "<br>"));

                    foreach (var parameter in command.Parameters)
                    {
                        builder.Append("<br>")
                        .Append(Markdown.Code(parameter.Name))
                        .Append(": ")
                        .Append(parameter.Description.Replace("\n", "<br>"))
                        .Append(parameter.IsOptional ? $" {Markdown.Bold("(optional)")}" : string.Empty);
                    }

                    builder.AppendNewline("|");
                }
            }

            Directory.CreateDirectory("docs");
            File.WriteAllText("docs/Command-List.md", builder.ToString());
        }
コード例 #2
0
ファイル: TagModule.cs プロジェクト: k-boyle/Espeon
            public async Task CreateTagAsync(
                [Example("espeon")] string name,
                [Example("is really cool")][Remainder] string value)
            {
                var module = Context.Command.Module;
                var paths  = module.FullAliases.Select(alias => string.Concat(alias, " ", name));

                if (CommandUtilities.EnumerateAllCommands(module).Any(
                        command => command.FullAliases.Any(
                            alias => paths.Any(path => path.Equals(alias, StringComparison.CurrentCultureIgnoreCase)))))
                {
                    await ReplyAsync(TAG_RESERVED_WORD, name);

                    return;
                }

                var guildTags = await DbContext.IncludeAndFindAsync <GuildTags, GuildTag, ulong>(
                    Context.Guild.Id.RawValue,
                    tags => tags.Values);

                var tag = guildTags.Values
                          .FirstOrDefault(tag1 => tag1.Key.Equals(name, StringComparison.CurrentCultureIgnoreCase));

                if (tag != null)
                {
                    await ReplyAsync(GUILDTAG_ALREADY_EXISTS, name);

                    return;
                }

                guildTags.Values.Add(new GuildTag(Context.Guild.Id, name, value, Context.User.Id));
                await DbContext.UpdateAsync(guildTags);

                await ReplyAsync(TAG_CREATED, name);
            }
コード例 #3
0
        public async ValueTask <AdminCommandResult> GetCommandsAsync(Module module)
        {
            var commands = CommandUtilities.EnumerateAllCommands(module);
            var groups   = commands.GroupBy(x => x.FullAliases[0]).ToList();

            var pages = DefaultPaginator.GeneratePages(groups, 1024, group => new StringBuilder()
                                                       .Append(Markdown.Bold(FormatCommands(group)))
                                                       .AppendNewline(Localize($"info_command_{group.Key.Replace(' ', '_')}")).ToString(),
                                                       builderFunc: () => new LocalEmbedBuilder().WithSuccessColor()
                                                       .WithTitle(Localize("info_module_commands", Markdown.Code(module.Name))));

            /*
             * var pages = DefaultPaginator.GeneratePages(groups, 15, group => new EmbedFieldBuilder()
             *  //    .WithName(new StringBuilder(Config.DefaultPrefix)
             *  //        .AppendJoin($"\n{Config.DefaultPrefix}", group.First().FullAliases).Tag)
             *  .WithName(FormatCommands(group))
             *  .WithValue(Localize($"info_command_{group.Key.Replace(' ', '_')}")),
             *  embedFunc: builder => builder.WithSuccessColor()
             *      .WithTitle(Localize("info_module_commands", Format.Code(module.Name))));
             */

            if (pages.Count > 1)
            {
                await Pagination.SendPaginatorAsync(Context.Channel, new DefaultPaginator(pages, 0), pages[0]);

                return(CommandSuccess());
            }

            return(CommandSuccess(embed: pages[0].Embed));
        }
コード例 #4
0
ファイル: HelpModule.cs プロジェクト: TheNoodleMummy/Imposter
        public async Task HelpAsync()
        {
            var options = PaginatedAppearanceOptions.Default;
            var msg     = new PaginatedMessage {
                Options = options
            };
            var infoemb = new LocalEmbedBuilder();

            infoemb.AddField("optional", $"*value*", true);
            infoemb.AddField("remainder", "__value__", true);
            infoemb.AddField("required", "**value**", true);
            infoemb.WithDescription("for example: !command __*cookies this can contain spaces*__ this  means the command take a optional remainder");

            msg.Pages.Add(infoemb);

            foreach (var module in Commands.GetAllModules())
            {
                try
                {
                    var modulecheck = await module.RunChecksAsync(Context);

                    if (modulecheck.IsSuccessful)
                    {
                        if (module.Commands.Count == 0)
                        {
                            continue; //skip module if commands are 0
                        }
                        if (module.Parent != null)
                        {
                            continue;
                        }

                        var emb = new LocalEmbedBuilder();
                        emb.WithTitle(module.Name);
                        emb.WithAuthor(Context.User.DisplayName, Context.User.GetAvatarUrl());
                        var sb       = new StringBuilder();
                        var commands = CommandUtilities.EnumerateAllCommands(module);
                        foreach (var command in commands)
                        {
                            var checks = await command.RunChecksAsync(Context);

                            if (checks.IsSuccessful)
                            {
                                sb.Append(Context.PrefixUsed).Append(command.Name).Append(" ");
                                foreach (var parameter in command.Parameters)
                                {
                                    if (parameter.IsOptional && parameter.IsRemainder)//optional remiander
                                    {
                                        sb.Append($"__*{parameter.Name}*__ ");
                                    }
                                    else if (parameter.IsOptional && !parameter.IsRemainder)//optional
                                    {
                                        sb.Append($"*{parameter.Name}* ");
                                    }
                                    else if (!parameter.IsOptional && parameter.IsRemainder) //required remainder
                                    {
                                        sb.Append($"__**{parameter.Name}**__ ");
                                    }
                                    else if (!parameter.IsOptional && !parameter.IsRemainder)//required
                                    {
                                        sb.Append($"**{parameter.Name}** ");
                                    }
                                }
                                sb.AppendLine();
                            }
                        }
                        emb.WithDescription(sb.ToString());

                        msg.Pages.Add(emb);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            await new PaginatedMessageCallback(Iservice, Context, msg, new EnsureReactionFromUser(Context.User)).DisplayAsync();
        }