-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
318 lines (305 loc) · 11.2 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
require("./config");
const {
default: AnyWASocket,
makeInMemoryStore,
downloadContentFromMessage,
DisconnectReason,
useSingleFileAuthState,
} = require("@adiwajshing/baileys");
const fs = require("fs");
const P = require("pino");
const { Boom } = require("@hapi/boom");
const axios = require("axios");
const util = require("util");
const fetch = require("node-fetch");
const BodyForm = require("form-data");
const mimetype = require("mime-types");
const speed = require("performance-now");
const moment = require("moment-timezone");
const { color } = require("./lib/color");
const { fetchJson } = require("./lib/fetcher");
const { fromBuffer } = require("file-type");
const { banner, banner2 } = require("./lib/functions");
const hour = moment.tz(timezone).format("HH:mm:ss");
const date = moment.tz(timezone).format("DD/MM/YY");
const telegraph = require("./lib/telegraph");
const { isFiltered, addFilter } = require("./lib/spam");
const girastamp = speed();
const latensi = speed() - girastamp;
async function start() {
const store = makeInMemoryStore({
logger: P().child({ level: "debug", stream: "store" }),
});
const { state, saveState } = useSingleFileAuthState("./session.json");
const clearState = () => fs.unlink("./session.json");
console.log(banner.string);
console.log(banner2.string);
const client = AnyWASocket({
logger: P({ level: "fatal" }),
printQRInTerminal: true,
browser: [botName, "Firefox", "4.0.0"],
auth: state,
});
client.ev.on("creds.update", saveState);
client.ev.on("connection.update", async (update) => {
const { connection, lastDisconnect } = update;
if (update.qr) {
console.log(
color("[", "white"),
color("!", "red"),
color("]", "white"),
color(`Escanea el código QR`, "blue")
);
}
if (connection === "close") {
const { statusCode } = new Boom(lastDisconnect?.error).output;
if (statusCode !== DisconnectReason.loggedOut) {
console.log("Conectando...");
setTimeout(() => start(), 3000);
} else {
console.log("Disconnected.", true);
clearState();
console.log("Starting...");
setTimeout(() => start(), 3000);
}
}
if (connection === "connecting") {
client.state = "connecting";
console.log("Conectando a WhatsApp...");
}
if (connection === "open") {
client.state = "open";
console.log("🤖", color(`${botName} está listo!!`, "green"));
}
});
client.ev.on("messages.upsert", async (msg) => {
m = msg;
try {
const getRandom = (ext) => {
return `${Math.floor(Math.random() * 10000)}${ext}`;
};
const getExtension = async (type) => {
return await mimetype.extension(type);
};
const getBuffer = (url, options) =>
new Promise(async (resolve, reject) => {
options ? options : {};
await axios({
method: "get",
url,
headers: { DNT: 1, "Upgrade-Insecure-Request": 1 },
...options,
responseType: "arraybuffer",
})
.then((res) => {
resolve(res.data);
})
.catch(reject);
});
//***************[ FUNÇÕES ]***************//
const info = msg.messages[0];
if (!info.message) return;
if (info.key && info.key.remoteJid == "status@broadcast") return;
const type =
Object.keys(info.message)[0] == "senderKeyDistributionMessage"
? Object.keys(info.message)[2]
: Object.keys(info.message)[0] == "messageContextInfo"
? Object.keys(info.message)[1]
: Object.keys(info.message)[0];
const content = JSON.stringify(info.message);
const altpdf = Object.keys(info.message);
const from = info.key.remoteJid;
var body =
type === "conversation"
? info.message.conversation
: type == "imageMessage"
? info.message.imageMessage.caption
: type == "videoMessage"
? info.message.videoMessage.caption
: type == "extendedTextMessage"
? info.message.extendedTextMessage.text
: type == "buttonsResponseMessage"
? info.message.buttonsResponseMessage.selectedButtonId
: type == "listResponseMessage"
? info.message.listResponseMessage.singleSelectReply.selectedRowId
: type == "templateButtonReplyMessage"
? info.message.templateButtonReplyMessage.selectedId
: "";
const budy =
type === "conversation"
? info.message.conversation
: type === "extendedTextMessage"
? info.message.extendedTextMessage.text
: "";
var pes =
type === "conversation" && info.message.conversation
? info.message.conversation
: type == "imageMessage" && info.message.imageMessage.caption
? info.message.imageMessage.caption
: type == "videoMessage" && info.message.videoMessage.caption
? info.message.videoMessage.caption
: type == "extendedTextMessage" &&
info.message.extendedTextMessage.text
? info.message.extendedTextMessage.text
: "";
const args = body.trim().split(/ +/).slice(1);
const isCmd = body.startsWith(prefix);
const comando = isCmd
? body.slice(1).trim().split(/ +/).shift().toLocaleLowerCase()
: null;
bidy = budy.toLowerCase();
///////////////
const getFileBuffer = async (mediakey, MediaType) => {
const stream = await downloadContentFromMessage(mediakey, MediaType);
let buffer = Buffer.from([]);
for await (const chunk of stream) {
buffer = Buffer.concat([buffer, chunk]);
}
return buffer;
};
const mentions = (teks, memberr, id) => {
id == null || id == undefined || id == false
? client.sendMessage(from, { text: teks.trim(), mentions: memberr })
: client.sendMessage(from, { text: teks.trim(), mentions: memberr });
};
const getGroupAdmins = (participants) => {
admins = [];
for (let i of participants) {
if (i.admin == "admin") admins.push(i.id);
if (i.admin == "superadmin") admins.push(i.id);
}
return admins;
};
const messagesC = pes.slice(0).trim().split(/ +/).shift().toLowerCase();
const arg = body.substring(body.indexOf(" ") + 1);
const botNum = client.user.id.split(":")[0];
const argss = body.split(/ +/g);
const testat = body;
const ants = body;
const isGroup = info.key.remoteJid.endsWith("@g.us");
const q = args.join(" ");
const sender = isGroup ? info.key.participant : info.key.remoteJid;
const pushname = info.pushName ? info.pushName : "";
const groupMetadata = isGroup ? await client.groupMetadata(from) : "";
const groupName = isGroup ? groupMetadata.subject : "";
const groupDesc = isGroup ? groupMetadata.desc : "";
const groupMembers = isGroup ? groupMetadata.participants : "";
const groupAdmins = isGroup ? getGroupAdmins(groupMembers) : "";
const text = args.join(" ");
const enviar = (texto) => {
client.sendMessage(from, { text: texto }, { quoted: info });
};
const quoted = info.quoted ? info.quoted : info;
const mime = (quoted.info || quoted).mimetype || "";
const isBot = info.key.fromMe ? true : false;
const isBotGroupAdmins = groupAdmins.includes(botNum) || false;
const isGroupAdmins = groupAdmins.includes(sender) || false;
const isOwner = sender.includes(ownerNum);
const groupId = isGroup ? groupMetadata.jid : "";
banChats = true;
const argis = bidy.trim().split(/ +/);
// Consts isQuoted
const isImage = type == "imageMessage";
const isVideo = type == "videoMessage";
const isAudio = type == "audioMessage";
const isSticker = type == "stickerMessage";
const isContact = type == "contactMessage";
const isLocation = type == "locationMessage";
const isProduct = type == "productMessage";
const isMedia =
type === "imageMessage" ||
type === "videoMessage" ||
type === "audioMessage";
typeMessage = body.substr(0, 50).replace(/\n/g, "");
if (isImage) typeMessage = "Image";
else if (isVideo) typeMessage = "Video";
else if (isAudio) typeMessage = "Audio";
else if (isSticker) typeMessage = "Sticker";
else if (isContact) typeMessage = "Contact";
else if (isLocation) typeMessage = "Location";
else if (isProduct) typeMessage = "Product";
const isQuotedMsg =
type === "extendedTextMessage" && content.includes("textMessage");
const isQuotedImage =
type === "extendedTextMessage" && content.includes("imageMessage");
const isQuotedVideo =
type === "extendedTextMessage" && content.includes("videoMessage");
const isQuotedDocument =
type === "extendedTextMessage" && content.includes("documentMessage");
const isQuotedAudio =
type === "extendedTextMessage" && content.includes("audioMessage");
const isQuotedSticker =
type === "extendedTextMessage" && content.includes("stickerMessage");
const isQuotedContact =
type === "extendedTextMessage" && content.includes("contactMessage");
const isQuotedLocation =
type === "extendedTextMessage" && content.includes("locationMessage");
const isQuotedProduct =
type === "extendedTextMessage" && content.includes("productMessage");
// message logging
if (!isGroup && isCmd)
console.log(
color("Comando:", "blue"),
`${comando}`,
"\n",
color("De:", "blue"),
`${sender.split("@")[0]}`,
"\n"
);
if (!isGroup && !isCmd)
console.log(
color("Mensaje", "blue"),
"\n",
color("De:", "blue"),
`${sender.split("@")[0]}`,
"\n"
);
if (isCmd && isGroup)
console.log(
color("Comando:", "blue"),
`${comando}`,
"\n",
color("De:", "blue"),
`${sender.split("@")[0]}`,
"\n",
color("En:", "blue"),
`${groupName}`,
"\n"
);
if (!isCmd && isGroup)
console.log(
color("Mensaje", "blue"),
color("De:", "blue"),
`${sender.split("@")[0]}`,
"\n",
color("En:", "blue"),
`${groupName}`,
"\n"
);
switch (comando) {
// comienzo de comandos con prefix
case "attp":
try {
attp = args.join(" ");
url = encodeURI(`https://kurupi.onrender.com/attp?texto=${attp}`);
attp = await getBuffer(url);
client.sendMessage(from, { sticker: attp }, { quoted: info });
} catch (e) {
enviar("Error");
console.log(e);
}
break;
// fin de comandos con prefix
default:
// comienzo de comandos sin prefix
if (isCmd) {
enviar("*Este comando no existe*");
}
// fin de comandos sin prefix
}
} catch (e) {
console.log(e);
}
});
}
start();