
let war = global.maxwarn
let handler = async (m, { conn, text, args, groupMetadata, usedPrefix, command }) => {      
        let who
        if (m.isGroup) who = m.mentionedJid[0] ? m.mentionedJid[0] : m.quoted ? m.quoted.sender : false
        else who = m.chat
        if (!who) throw `‚ú≥Ô∏è Tag or mention someone\n\nüìå Example : ${usedPrefix + command} @user`
        if (!(who in global.db.data.users)) throw `‚ú≥Ô∏è The user is not found in my database`
        let name = conn.getName(m.sender)
        let warn = global.db.data.users[who].warn
        if (warn < war) {
            global.db.data.users[who].warn += 1
            m.reply(`
‚ö†Ô∏è *Warned User* ‚ö†Ô∏è

‚ñ¢ *Admin:* ${name}
‚ñ¢ *User:* @${who.split`@`[0]}
‚ñ¢ *Warns:* ${warn + 1}/${war}
‚ñ¢ *Reason:* ${text}`, null, { mentions: [who] }) 
            m.reply(`
‚ö†Ô∏è *caution* ‚ö†Ô∏è
You received a warning from an admin

‚ñ¢ *Warns:* ${warn + 1}/${war} 
if you receive *${war}* warnings you will be automatically removed from the group`, who)
        } else if (warn == war) {
            global.db.data.users[who].warn = 0
            m.reply(`‚õî The user exceeded the *${war}* warnings will therefore be removed`)
            await time(3000)
            await conn.groupParticipantsUpdate(m.chat, [who], 'remove')
            m.reply(`‚ôªÔ∏è You were removed from the group *${groupMetadata.subject}* because you have been warned *${war}* times`, who)
        }
}
handler.help = ['warn @user']
handler.tags = ['group']
handler.command = ['warn'] 
handler.group = true
handler.admin = true
handler.botAdmin = true

export default handler

const time = async (ms) => {
            return new Promise(resolve => setTimeout(resolve, ms));
        }
