예제 #1
0
        public async Task <Embed> HelpAsync(ICommandContext context, string query, SearchContext searchContext)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (query is null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            var commands = (await SearchCommands(context, query, searchContext)).ToList();

            if (commands.Count == 0)
            {
                var ts = await TranslationManager.CreateFor(context.Channel);

                return(EmbedFactory.CreateNeutral()
                       .WithTitle(ts.GetMessage("help:embed_title"))
                       .WithDescription(ts.GetMessage("help:command_not_found"))
                       .Build());
            }

            // NOTE: This system breaks when there are two commands with the same alias. Avoid using same aliases
            if (commands.Count > 1)
            {
                var ts = await TranslationManager.CreateFor(context.Channel);

                return(EmbedFactory.CreateNeutral()
                       .WithTitle(ts.GetMessage("help:embed_title"))
                       .WithDescription($"{ts.GetMessage("help:multiple_matches")}\n{String.Join("\n", commands.Select(x => Format.Code(x.GetUsage())))}")
                       .Build());
            }
            else
            {
                return(await commands[0].CreateHelpEmbedAsync(context));
            }
        }