forked from brunohash/Personal.WaAutomate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messageHandler.js
82 lines (73 loc) · 1.96 KB
/
messageHandler.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
const comandos = require("./commands.js");
module.exports = msgHandler = async (client, message) => {
try {
const {
sender,
isGroupMsg,
chat,
caption,
} = message;
let { body } = message;
const { formattedTitle } = chat;
let { pushname, verifiedName } = sender;
pushname = pushname || verifiedName;
const commands = caption || body || "";
const falas = commands.toLowerCase();
const command = commands.toLowerCase().split(" ")[0] || "";
const args = commands.split(" ");
const msgs = (message) => {
if (command.startsWith("!")) {
if (message.length >= 10) {
return `${message.substr(0, 15)}`;
} else {
return `${message}`;
}
}
};
if (!isGroupMsg && command.startsWith("/"))
console.log(
"\x1b[1;31m~\x1b[1;37m>",
"[\x1b[1;32mEXEC\x1b[1;37m]",
msgs(command),
"from",
pushname
);
if (isGroupMsg && command.startsWith("/"))
console.log(
"\x1b[1;31m~\x1b[1;37m>",
"[\x1b[1;32mEXEC\x1b[1;37m]",
msgs(command),
"from",
pushname,
"in",
formattedTitle
);
if (isGroupMsg && !command.startsWith("/"))
console.log(
"\x1b[1;33m~\x1b[1;37m>",
"[\x1b[1;31mMSG\x1b[1;37m]",
body,
"from",
pushname,
"in",
formattedTitle
);
console.log("FROM ===>", pushname);
console.log("FROM_ID ===>", chat.id);
console.log("ARGUMENTOS ===>", args);
console.log("FALAS ===>", falas);
console.log("COMANDO ===>", command);
function getComands(commands) {
if (comandos[commands]?.status) {
comandos[commands].pasta(client, args, message);
}
}
if (command) {
getComands(command);
}
} catch (err) {
await client.sendText(`Erro: ${err}`);
console.log(("[ERROR]", "red"), err);
client.kill().then((a) => console.log(a));
}
};