<commit_before>package me.mrkirby153.KirBot.command.executors.msc

import me.mrkirby153.KirBot.command.*
import me.mrkirby153.KirBot.command.args.Arguments
import me.mrkirby153.KirBot.command.args.CommandContext
import me.mrkirby153.KirBot.utils.Context
import me.mrkirby153.KirBot.utils.botUrl
import me.mrkirby153.KirBot.utils.embed.link
import me.mrkirby153.KirBot.utils.embed.u
import me.mrkirby153.KirBot.utils.mdEscape
import java.awt.Color

@Command("help,?")
class CommandHelp : BaseCommand(CommandCategory.MISCELLANEOUS, Arguments.string("command", false)) {

    override fun execute(context: Context, cmdContext: CommandContext) {
        if (!cmdContext.has("command")) {
            displayAllCommands(context)
        } else {
            val command = CommandExecutor.commands.firstOrNull { cmdContext.get<String>("command")!!.toLowerCase() in it.aliases } ?: throw CommandException("No command was found with that name")
            displayHelpForCommand(context, command)
        }
    }

    private fun displayAllCommands(context: Context) {
        context.send().embed("Help") {
            color = Color.BLUE
            val prefix = cmdPrefix.mdEscape()
            description {
                +"The command prefix for this server is: `${context.shard.serverSettings[context.guild.id]?.cmdDiscriminator ?: "!"}` \n\n"
                +"Below is a list of all the commands available. \n Type `$cmdPrefix$aliasUsed <command>` for more info"
                +"\n\nFor a full list of custom commands available on this server, "
                +("Click Here" link (botUrl("${context.guild.id}/customCommands")))
            }
            fields {
                for ((category, commands) in CommandExecutor.getCommandsByCategory()) {
                    field {
                        title = category.friendlyName
                        inline = true
                        description {
                            commands.forEach {
                                +("$prefix${it.aliases.first().mdEscape()}" link ".")
                                +"\n"
                            }
                        }
                    }
                }
                if (context.shard.customCommands[context.guild.id].isNotEmpty()) {
                    field {
                        title = "Other Commands"
                        inline = true
                        description {
                            context.shard.customCommands[context.guild.id].forEach {
                                +("$prefix${it.name.mdEscape()}" link ".")
                                +"\n"
                            }
                        }
                    }
                }
            }
        }.rest().queue()
    }

    private fun displayHelpForCommand(context: Context, spec: CommandSpec) {
        val prefix = cmdPrefix.mdEscape()
        val help = CommandExecutor.helpManager.get(spec.aliases.first())
        context.send().embed("Help: ${spec.aliases.first().mdEscape()}") {
            description {
                appendln(u("Command Name"))
                appendln("  $prefix${spec.aliases[0]}")
                +"\n"
                appendln(u("Description"))
                appendln("  ${help?.description ?: "No description provided"}")
                appendln(u("Usage"))
                val params = buildString {
                    spec.arguments.forEach {<commit_msg>Show aliases in the help menu<commit_after>package me.mrkirby153.KirBot.command.executors.msc

import me.mrkirby153.KirBot.command.*
import me.mrkirby153.KirBot.command.args.Arguments
import me.mrkirby153.KirBot.command.args.CommandContext
import me.mrkirby153.KirBot.utils.Context
import me.mrkirby153.KirBot.utils.botUrl
import me.mrkirby153.KirBot.utils.embed.link
import me.mrkirby153.KirBot.utils.embed.u
import me.mrkirby153.KirBot.utils.mdEscape
import java.awt.Color

@Command("help,?")
class CommandHelp : BaseCommand(CommandCategory.MISCELLANEOUS, Arguments.string("command", false)) {

    override fun execute(context: Context, cmdContext: CommandContext) {
        if (!cmdContext.has("command")) {
            displayAllCommands(context)
        } else {
            val command = CommandExecutor.commands.firstOrNull { cmdContext.get<String>("command")!!.toLowerCase() in it.aliases } ?: throw CommandException("No command was found with that name")
            displayHelpForCommand(context, command)
        }
    }

    private fun displayAllCommands(context: Context) {
        context.send().embed("Help") {
            color = Color.BLUE
            val prefix = cmdPrefix.mdEscape()
            description {
                +"The command prefix for this server is: `${context.shard.serverSettings[context.guild.id]?.cmdDiscriminator ?: "!"}` \n\n"
                +"Below is a list of all the commands available. \n Type `$cmdPrefix$aliasUsed <command>` for more info"
                +"\n\nFor a full list of custom commands available on this server, "
                +("Click Here" link (botUrl("${context.guild.id}/customCommands")))
            }
            fields {
                for ((category, commands) in CommandExecutor.getCommandsByCategory()) {
                    field {
                        title = category.friendlyName
                        inline = true
                        description {
                            commands.forEach {
                                +("$prefix${it.aliases.first().mdEscape()}" link ".")
                                +"\n"
                            }
                        }
                    }
                }
                if (context.shard.customCommands[context.guild.id].isNotEmpty()) {
                    field {
                        title = "Other Commands"
                        inline = true
                        description {
                            context.shard.customCommands[context.guild.id].forEach {
                                +("$prefix${it.name.mdEscape()}" link ".")
                                +"\n"
                            }
                        }
                    }
                }
            }
        }.rest().queue()
    }

    private fun displayHelpForCommand(context: Context, spec: CommandSpec) {
        val prefix = cmdPrefix.mdEscape()
        val help = CommandExecutor.helpManager.get(spec.aliases.first())
        context.send().embed("Help: ${spec.aliases.first().mdEscape()}") {
            description {
                appendln(u("Command Name"))
                appendln("  $prefix${spec.aliases[0]}")
                +"\n"
                appendln(u("Description"))
                appendln("  ${help?.description ?: "No description provided"}")
                if(spec.aliases.size > 1){
                    appendln("\n"+u("Aliases"))
                    appendln("   - ${spec.aliases.drop(1).joinToString(", ").mdEscape()}")
                    +"\n"
                }
                appendln(u("Usage"))
                val params = buildString {
                    spec.arguments.forEach {
{'fraction_non_alphanumeric': 0.11486486486486487, 'fraction_numerical': 0.008164414414414414, 'mean_word_length': 1.5959079283887467, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4232278', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1831, 'n_words': 340}