-
Notifications
You must be signed in to change notification settings - Fork 825
/
add.js
50 lines (46 loc) · 1.77 KB
/
add.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
let fetch = require('node-fetch')
let handler = async (m, { conn, text, participants, usedPrefix, command }) => {
if (!text) throw `uhm.. which number?\nexample:\n\n${usedPrefix + command + ' ' + global.owner[0]}`
let _participants = participants.map(user => user.jid)
let users = (await Promise.all(
text.split(',')
.map(v => v.replace(/[^0-9]/g, ''))
.filter(v => v.length > 4 && v.length < 20 && !_participants.includes(v + '@s.whatsapp.net'))
.map(async v => [
v,
await conn.isOnWhatsApp(v + '@s.whatsapp.net')
])
)).filter(v => v[1]).map(v => v[0] + '@c.us')
let response = await conn.groupAdd(m.chat, users)
if (response[users] == 408) throw `_Failed!_\n\nThe number has been dialed recently\nCan only enter via *${usedPrefix}link* grup`
let pp = await conn.getProfilePicture(m.chat).catch(_ => false)
let jpegThumbnail = pp ? await (await fetch(pp)).buffer() : false
for (let user of response.participants.filter(user => Object.values(user)[0].code == 403)) {
let [[jid, {
invite_code,
invite_code_exp
}]] = Object.entries(user)
let teks = `Inviting @${jid.split`@`[0]} using invitation...`
m.reply(teks, null, {
contextInfo: {
mentionedJid: conn.parseMention(teks)
}
})
await conn.sendGroupV4Invite(m.chat, jid, invite_code, invite_code_exp, false, 'Invitation to join my WhatsApp group', jpegThumbnail ? {
jpegThumbnail
} : {})
}
}
handler.help = ['add', '+'].map(v => v + ' number,number')
handler.tags = ['admin']
handler.command = /^(add|\+)$/i
handler.owner = false
handler.mods = false
handler.premium = false
handler.group = true
handler.private = false
handler.admin = true
handler.botAdmin = true
handler.fail = null
handler.limit = true
module.exports = handler