const decache = require('decache');

module.exports = {
    commands: async (bot, msg, input) => {
        const userMention = "<a href=\"tg:\/\/user?id=" + msg.from.id + "\">@" + msg.from.first_name + "<\/a> "
        let commands = require('../../group/commands')
        for (const x of commands) {
            if (x.NAME === input) {
                let n = x.NAME
                let t = x.TEXT
                for (const m of t) {
                    let a = userMention.concat(m)
                    await bot.sendMessage(msg.chat.id, a, { parse_mode: "HTML" })
                }
                decache('../../group/commands');
                commands = require('../../group/commands')
            }
        }
    },
    chat: async (bot, msg, input) => {
        const userMention = "<a href=\"tg:\/\/user?id=" + msg.from.id + "\">@" + msg.from.first_name + "<\/a> "
        let commands = require('../../group/commands')
        let navigation = require('../../group/FAQ')
        let chat = require('../../group/chat')
        let jointArray = commands.concat(navigation, chat)

        for (const x of jointArray) {
            if (x.NAME === input) {
                let n = x.NAME
                let t = x.TEXT
                let m = JSON.parse(x.MENU)
                for (const d of t) {
                    let a = userMention.concat(m)
                    await bot.sendMessage(msg.chat.id, d, {
                        parse_mode: "HTML",
                        "reply_markup": {
                            "keyboard": m
                        }
                    })
                }
                decache('../../group/commands');
                decache('../../group/chat');
                commands = require('../../group/commands')
                commands = require('../../group/FAQ')
            }
        }
    }
};