-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
103 lines (83 loc) · 2.75 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//ESSE SCRIPT FOI DISPONIBILIZADO OFICIALMENTE POR: @LEVISCD NO INSTAGRAM E GITHUB.
const connect = require('./connection')
const fs = require("fs")
const axios = require('axios');
const { exec } = require('child_process')
const path = require('path')
function evalAsync(code) {
return new Promise((resolve, reject) => {
try {
const result = eval(code);
resolve(result);
} catch (error) {
reject(error);
}
});
}
async function start() {
const client = await connect()
client.ev.on('messages.upsert', async ({ messages }) => {
const body = messages[0];
const jid = body.key.remoteJid
const Owner = ["seunumero@s.whatsapp.net"]
const messageId = body.key.id
const fromMe = body.key.fromMe
const isGroup = body.key.remoteJid.endsWith('@g.us')
const prefix = '/'
const nome = body.pushName || "Usuário(a)"
console.log(body) //opcional
function reply(text) {
// Enviar uma mensagem para o jid, usando o text e o id do body como quoted no caso isso seria p tipo que enviar de forma simples marcando a mensagem
client.sendMessage(jid, {text: text}, {quoted: body})
}
const messageText = body.message && body.message.conversation || '';
const extendedText = body.message?.extendedTextMessage?.text || '';
const buttonsResponse = body.message?.buttonsResponseMessage?.selectedDisplayText || '';
const imageCaption = body.message?.imageMessage?.caption || '';
const documentCaption = body.message?.documentMessage?.caption || '';
const videoCaption = body.message?.videoMessage?.caption || '';
const messageOptions = {
messageText,
extendedText,
buttonsResponse,
imageCaption,
documentCaption,
videoCaption
};
const textuser = messageOptions.messageText || messageOptions.extendedText || messageOptions.buttonsResponse || messageOptions.imageCaption || messageOptions.documentCaption || messageOptions.videoCaption;
const command = textuser.split(prefix)[1];
const args = textuser.split(' ').slice(1);
// ...
if (/^(oi|ou|opa|olá|tudo bem\??|bom|boa|dia|noite|tarde)$/.test(textuser)) {
async function sendMessages() {
await client.sendMessage(jid, {
react: {
text: `👋🏻`,
key: body.key
}
});
}
await client.sendMessage(jid, {
text: `😊 *Olá, ${nome}, eu sou um bot desenvolvido para testes.`,
}, { quoted: body });
sendMessages();
}
// ...
switch (command) {
case 'restart':
case 'r':
case 'reiniciar':
exec('node index.js', (error, stdout, stderr) => {
if (error) {
console.error(`Erro ao reiniciar o bot: ${error}`);
} else {
console.log('Bot reiniciado com sucesso.');
}
});
break
default:
break;
}
})
}
start();