const utils = require('./utils');
module.exports = {
    commands: async (bot, msg, input, logger) => {
        logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " did - " + input);
        const userMention = "@" + msg.from.first_name + "<\/a> "
        let commands = utils.loadCommands();
        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" })
                }
                commands = utils.loadCommands();
            }
        }
    },
    chat: async (bot, msg, input, logger) => {
        logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " asked - " + input);
        const userMention = "@" + msg.from.first_name + "<\/a> "
        let commands = utils.loadCommands();
        let navigation = utils.loadFAQ();
        let chat = utils.loadChat();
        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
                        },
                        disable_web_page_preview: true
                    })
                }
                commands = utils.loadCommands();
                navigation = utils.loadFAQ();
            }
        }
    }
};