-
Notifications
You must be signed in to change notification settings - Fork 10
/
resetspesificdb.js
55 lines (51 loc) · 2.3 KB
/
resetspesificdb.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
50
51
52
53
54
55
let confirmation = {}
let timeout = 60
let handler = async (m, { usedPrefix, command, conn, text }) => {
if (m.sender in confirmation) return conn.reply(m.chat, 'Confirm this first', confirmation[m.sender].message)
let isChat = /chat/gi.test(command)
let number = isChat ? text ? text.replace(/\s/g, '').replace(/([+-])/g, '') : m.chat : m.mentionedJid.length ? m.mentionedJid[0] : m.quoted && m.quoted.sender ? m.quoted.sender : text ? text.replace(/\s/g, '').replace(/([+-])/g, '') : ''
if (!number) throw `Use format: ${usedPrefix}${command} <jid>
Example: ${usedPrefix}${command} 62xxxxxx
`.trim()
if (!isChat && !/@s\.whatsapp\.net/i.test(number)) number = number + '@s.whatsapp.net'
else if (isChat && !/@g\.us|@s\.whatsapp\.net/i.test(number)) {
number = number + '@g.us'
let isGroup = await conn.groupMetadata(number).catch(_ => false)
if (!isGroup) number = number.replace(/@g\.us/i, '') + '@s.whatsapp.net'
}
let db = global.DATABASE._data[isChat ? 'chats' : 'users']
if (!(number in db)) throw 'Jid not in database!'
confirmation[m.sender] = {
id: new Date() * 1, m, isChat, number,
message: await conn.sendButton(m.chat, `
Are you sure want delete ${isChat ? 'chat' : 'user'} ${number} from database?
Y/N timeout ${timeout}s
`.trim(), '', null, [
['Yes'],
['No']
], m),
timeout: setTimeout(() => (delete confirmation[m.sender]), timeout * 1000)
}
}
handler.all = (m) => {
if (!(m.sender in confirmation)) return !1
let { m: message, isChat, timeout, number } = confirmation[m.sender]
if (m.id == message.id) return !1
if (!m.text) return !1
let isYes = /y(es)/gi.test(m.text)
let isNo = /n(o)/gi.test(m.text)
if (isYes || isNo) {
if (isYes) {
global.DATABASE._data[isChat ? 'chats' : 'users'][number] = {}
m.reply(`Succes delete ${isChat ? 'chat' : 'user'} ${number} from database!`)
} else m.reply(`Cancel delete ${isChat ? 'chat' : 'user'} ${number} from database!`)
clearTimeout(timeout)
delete confirmation[m.sender]
}
return
}
handler.help = ['user', 'chat'].map(v => 'reset' + v + ' <jid>')
handler.tags = ['owner']
handler.command = /^reset(user|chat)(d(atabase|b))?$/i
handler.rowner = true
module.exports = handler