-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (53 loc) · 1.86 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
const qrcode = require('qrcode-terminal');
const client = require('./config/client'); // Importe a autenticação
require('dotenv').config();
const PrivateMessage = require('./service/PrivateMessage');
const CommandHandler = require('./handlers/commandHandler');
const DisableCommand = require('./middleware/DisableCommand');
const messageHandler = require('./handlers/messageHandler');
const InstagramReelsUseCase = require('./useCases/InstagramReelsUseCase')
// const client = new Client({
// authStrategy: new LocalAuth(),
// puppeteer: { headless: true, args: ['--no-sandbox'] }
// });
client.on('qr', (qr) => {
qrcode.generate(qr, { small: true });
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.on('message', async msg => {
const command = msg.body.split(' ')[0];
let chat = await msg.getChat();
if (isHttpsLink(command)) {
messageHandler.handle(msg, client, InstagramReelsUseCase);
return;
}
// if (await DisableCommand(chat.id.user)) {
// console.log("Grupo com comandos desativos", await DisableCommand(chat.id.user))
// return;
// }
if (!chat.isGroup) {
await handlePrivateMessage(msg, client);
} else {
const commandHandler = new CommandHandler(client);
if (typeof commandHandler[command] === 'function') {
commandHandler[command](msg, client);
}
}
})
// client.on('message_create', async msg => {
// });
client.initialize();
const handlePrivateMessage = async (msg, client) => {
try {
const privateMessageHandler = new PrivateMessage(client);
await privateMessageHandler.runner(msg);
} catch (error) {
console.error('Erro ao lidar com a mensagem privada:', error);
}
}
function isHttpsLink(str) {
const httpsLinkRegex = /^https:\/\/[^ "]+$/;
return httpsLinkRegex.test(str);
}