LuckyYam / Chitoge

Just a Fork of Void. Not maintained anymore
GNU Affero General Public License v3.0
80 stars 257 forks source link

Help.ts #3

Closed LuckyYam closed 3 years ago

LuckyYam commented 3 years ago

import MessageHandler from '../../Handlers/MessageHandler' import BaseCommand from '../../lib/BaseCommand' import WAClient from '../../lib/WAClient' import request from '../../lib/request' import { MessageType } from '@adiwajshing/baileys'

import { ICommand, IParsedArgs, ISimplifiedMessage } from '../../typings'

export default class Command extends BaseCommand { constructor(client: WAClient, handler: MessageHandler) { super(client, handler, { command: 'help', description: 'Displays the help menu or shows the info of the command provided', category: 'general', usage: ${client.config.prefix}help (command_name), dm: true, aliases: ['h'] }) }

run = async (M: ISimplifiedMessage, parsedArgs: IParsedArgs): Promise<void> => {
    if (!parsedArgs.joined) {
        const commands = this.handler.commands.keys()
        const categories: { [key: string]: ICommand[] } = {}
        for (const command of commands) {
            const info = this.handler.commands.get(command)
            if (!command) continue
            if (!info?.config?.category || info.config.category === 'dev') continue
            if (Object.keys(categories).includes(info.config.category)) categories[info.config.category].push(info)
            else {
                categories[info.config.category] = []
                categories[info.config.category].push(info)
            }
        }
        let text = `🌟 *Chitoge's Command List* 🌟\n\n`
        const keys = Object.keys(categories)
        for (const key of keys)
            text += `${this.emojis[keys.indexOf(key)]} *${this.client.util.capitalize(key)}*\nā \`\`\`${categories[
                key
            ]
                .map((command) => command.config?.command)
                .join(', ')}\`\`\`\n\n`
        return void M.reply( await request.buffer('https://static.wikia.nocookie.net/loveinterest/images/a/a2/Chitoge_Key_Visual.png/revision/latest?cb=20140806185340'),  
                            MessageType.image,            
                            undefined,
                            undefined,
            `${text} šŸ“ *Note: Use ${this.client.config.prefix}help <command_name> to view the command info*`
        )
    }
    const key = parsedArgs.joined.toLowerCase()
    const command = this.handler.commands.get(key) || this.handler.aliases.get(key)
    if (!command) return void M.reply(`No Command of Alias Found | "${key}"`)
    const state = await this.client.DB.disabledcommands.findOne({ command: command.config.command })
    M.reply(
        `šŸš€ *Command:* ${this.client.util.capitalize(command.config?.command)}\nšŸ“‰ *Status:* ${
            state ? 'Disabled' : 'Available'
        }\n⛩ *Category:* ${this.client.util.capitalize(command.config?.category || '')}${
            command.config.aliases
                ? `\nā™¦ļø *Aliases:* ${command.config.aliases.map(this.client.util.capitalize).join(', ')}`
                : ''
        }\nšŸŽ *Group Only:* ${this.client.util.capitalize(
            JSON.stringify(!command.config.dm ?? true)
        )}\nšŸ’Ž *Usage:* ${command.config?.usage || ''}\n\nšŸ“’ *Description:* ${command.config?.description || ''}`
    )
}

emojis = ['šŸŒ€', 'ā™»ļø', '🌈', 'šŸŽµ', 'ā„', 'šŸ‘‘', '🚫', 'ā™¦ļø', '✨']

}