This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
49 lines (43 loc) · 1.8 KB
/
index.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
const { create, Client } = require('@open-wa/wa-automate')
const { color, options } = require('./utils')
const msgHandler = require('./handlers')
async function start(client = new Client()) {
console.log('[LYDIA]', color('Lydia is now ready!'))
// Force to keep the current session
client.onStateChanged((state) => {
console.log('[LYDIA STATE]', state)
if (state === 'UNPAIRED') client.forceRefocus()
if (state === 'CONFLICT') client.forceRefocus()
if (state === 'UNLAUNCHED') client.forceRefocus()
})
// Set all received messages to seen
client.onAck((x) => {
const { to } = x
if (x !== 3) client.sendSeen(to)
})
// Listening to incoming messages
client.onMessage((message) => {
client.getAmountOfLoadedMessages()
.then((msg) => {
if (msg >= 3000) {
console.log('[LYDIA]', color(`Message cache reached ${msg}, deleting message cache...`, 'yellow'))
client.cutMsgCache()
.then(() => console.log('[LYDIA]', color('Cache deleted.', 'yellow')))
}
})
// Message handler
msgHandler(client, message)
})
// Detect incoming calls and block the person
client.onIncomingCall(async (callData) => {
await client.sendText(callData.peerJid, 'I don\'t receiving *ANY* calls.\nYou have been blocked because breaking the rules.')
await client.contactBlock(callData.peerJid)
.then(() => {
console.log(color('[BLOCK]', 'red'), color(`${callData.peerJid} has been blocked. Reason:`, 'yellow'), color('CALLING THE BOT', 'cyan'))
})
})
}
// Creating the session
create(options(start))
.then((client) => start(client))
.catch((err) => new Error(err))