-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmessage.js
More file actions
585 lines (548 loc) · 21.4 KB
/
Copy pathmessage.js
File metadata and controls
585 lines (548 loc) · 21.4 KB
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
/*
* Source By Rasya R. - @chocoopys
* My Github: github.com/Rasya25
* My Instagram: @r.rdtyptr
* My Tiktok: @r.rdtyptrr
* Don't sell this
*/
import { delay, jidNormalizedUser } from '@chocoopy/baileys';
import util from 'util';
import { exec } from 'child_process';
import fs from 'fs';
import * as Func from './lib/function.js';
import Color from './lib/color.js';
import serialize, { getContentType } from './lib/serialize.js';
import axios from 'axios';
/**
*
* @param {import('@whiskeysockets/baileys').WASocket} sockk
* @param {any} store
* @param {import('@whiskeysockets/baileys').WAMessage} m
*/
export default async function message(sockk, store, m) {
try {
let quoted = m.isQuoted ? m.quoted : m;
let downloadM = async filename => await sockk.downloadMediaMessage(quoted, filename);
let isCommand = (m.prefix && m.body.startsWith(m.prefix)) || false;
// mengabaikan pesan dari bot
if (m.isBot) return;
// memunculkan ke log
if (m.message && !m.isBot) {
console.log(Color.cyan('Dari'), Color.cyan(sockk.getName(m.from)), Color.blueBright(m.from));
console.log(Color.yellowBright('Chat'), Color.yellowBright(m.isGroup ? `Grup (${m.sender} : ${sockk.getName(m.sender)})` : 'Pribadi'));
console.log(Color.greenBright('Pesan :'), Color.greenBright(m.body || m.type));
}
// command
switch (isCommand ? m.command.toLowerCase() : false) {
case 'menu':
{
let menu = {
main: ['menu', 'info', 'delete', 'quoted', 'chocoai'],
tools: ['rvo', 'exif', 'tourl', 'sticker', 'tweetc'],
ai: ['luminai'],
owner: ['upsw', 'restart', 'eval', 'exec', 'delsesi', 'listsw', 'getsw'],
group: ['link'],
};
let text = `*Halo Dek @${m.sender.split`@`[0]},* \nAku assistant e chocopy, seng ramah yo mbe developer ku. btw total menuku enek sakmene le : ${Object.values(menu)
.map(a => a.length)
.reduce((total, num) => total + num, 0)}\n\n`;
Object.entries(menu)
.map(([type, command]) => {
text += `*${Func.toUpper(type)} Command le :*\n`;
text += `* ${command.map(a => `${m.prefix + a}`).join('\n* ')}\n`;
text += '\n\n';
})
.join('\n\n');
await m.reply(text, { mentions: [m.sender] });
}
break;
case 'runtime':
case 'rtm':{
let os = (await import('os')).default;
m.reply(`
*_Runtime OS_*
${Func.runtime(os.uptime())}
*_Runtime Bot_*
${Func.runtime(process.uptime())}
`)
}
break;
case 'infoserver':
case 'info':
case 'serverinfo':
{
let os = (await import('os')).default;
let v8 = (await import('v8')).default;
let { performance } = (await import('perf_hooks')).default;
let eold = performance.now();
const used = process.memoryUsage();
const cpus = os.cpus().map(cpu => {
cpu.total = Object.keys(cpu.times).reduce((last, type) => last + cpu.times[type], 0);
return cpu;
});
const cpu = cpus.reduce(
(last, cpu, _, { length }) => {
last.total += cpu.total;
last.speed += cpu.speed / length;
last.times.user += cpu.times.user;
last.times.nice += cpu.times.nice;
last.times.sys += cpu.times.sys;
last.times.idle += cpu.times.idle;
last.times.irq += cpu.times.irq;
return last;
},
{
speed: 0,
total: 0,
times: {
user: 0,
nice: 0,
sys: 0,
idle: 0,
irq: 0,
},
}
);
let heapStat = v8.getHeapStatistics();
let neow = performance.now();
let teks = `
*Ping :* *_${Number(neow - eold).toFixed(2)} milisecond(s)_*
💻 *_Info Server_*
*- Hostname :* ${os.hostname() || sockk.user?.name}
*- Platform :* ${os.platform()}
*- OS :* ${os.version()} / ${os.release()}
*- Arch :* ${os.arch()}
*- RAM :* ${Func.formatSize(os.totalmem() - os.freemem(), false)} / ${Func.formatSize(os.totalmem(), false)}
*_Runtime OS_*
${Func.runtime(os.uptime())}
*_Runtime Bot_*
${Func.runtime(process.uptime())}
*_NodeJS Memory Usage_*
${Object.keys(used)
.map((key, _, arr) => `*- ${key.padEnd(Math.max(...arr.map(v => v.length)), ' ')} :* ${Func.formatSize(used[key])}`)
.join('\n')}
*- Heap Executable :* ${Func.formatSize(heapStat?.total_heap_size_executable)}
*- Physical Size :* ${Func.formatSize(heapStat?.total_physical_size)}
*- Available Size :* ${Func.formatSize(heapStat?.total_available_size)}
*- Heap Limit :* ${Func.formatSize(heapStat?.heap_size_limit)}
*- Malloced Memory :* ${Func.formatSize(heapStat?.malloced_memory)}
*- Peak Malloced Memory :* ${Func.formatSize(heapStat?.peak_malloced_memory)}
*- Does Zap Garbage :* ${Func.formatSize(heapStat?.does_zap_garbage)}
*- Native Contexts :* ${Func.formatSize(heapStat?.number_of_native_contexts)}
*- Detached Contexts :* ${Func.formatSize(heapStat?.number_of_detached_contexts)}
*- Total Global Handles :* ${Func.formatSize(heapStat?.total_global_handles_size)}
*- Used Global Handles :* ${Func.formatSize(heapStat?.used_global_handles_size)}
${
cpus[0]
? `
*_Total CPU Usage_*
${cpus[0].model.trim()} (${cpu.speed} MHZ)\n${Object.keys(cpu.times)
.map(type => `*- ${(type + '*').padEnd(6)}: ${((100 * cpu.times[type]) / cpu.total).toFixed(2)}%`)
.join('\n')}
*_CPU Core(s) Usage (${cpus.length} Core CPU)_*
${cpus
.map(
(cpu, i) =>
`${i + 1}. ${cpu.model.trim()} (${cpu.speed} MHZ)\n${Object.keys(cpu.times)
.map(type => `*- ${(type + '*').padEnd(6)}: ${((100 * cpu.times[type]) / cpu.total).toFixed(2)}%`)
.join('\n')}`
)
.join('\n\n')}`
: ''
}
`.trim();
await m.reply(teks);
}
break;
case 'quoted':
case 'q':
if (!m.isQuoted) throw 'Reply Pesan';
try {
var message = await serialize(sockk, await store.loadMessage(m.from, m.quoted.id), store);
if (!message.isQuoted) throw 'Pesan quoted gaada';
await m.reply({ forward: message.quoted, force: true });
} catch (e) {
throw 'Pesan gaada';
}
break;
case 'rvo':
if (!quoted.msg.viewOnce) throw 'Reply Pesan Sekali Lihat';
quoted.msg.viewOnce = false;
await m.reply({ forward: quoted, force: true });
break;
case 'getsw':
case 'sw':
{
if (!m.isOwner) return m.reply('lhu saha');
if (!store.messages['status@broadcast'].array.length === 0) throw 'Gaada 1 status pun';
let contacts = Object.values(store.contacts);
let [who, value] = m.text.split(/[,|\-+&]/);
value = value?.replace(/\D+/g, '');
let sender;
if (m.mentions.length !== 0) sender = m.mentions[0];
else if (m.text) sender = contacts.find(v => [v.name, v.verifiedName, v.notify].some(name => name && name.toLowerCase().includes(who.toLowerCase())))?.id;
let stories = store.messages['status@broadcast'].array;
let story = stories.filter(v => (v.key && v.key.participant === sender) || v.participant === sender).filter(v => v.message && v.message.protocolMessage?.type !== 0);
if (story.length === 0) throw 'Gaada sw nya';
if (value) {
if (story.length < value) throw 'Jumlahnya ga sampe segitu';
await m.reply({ forward: story[value - 1], force: true });
} else {
for (let msg of story) {
await delay(1500);
await m.reply({ forward: msg, force: true });
}
}
}
break;
case 'listsw':
{
if (!m.isOwner) return m.reply('lhu saha');
if (!store.messages['status@broadcast'].array.length === 0) throw 'Gaada 1 status pun';
let stories = store.messages['status@broadcast'].array;
let story = stories.filter(v => v.message && v.message.protocolMessage?.type !== 0);
if (story.length === 0) throw 'Status gaada';
const result = {};
story.forEach(obj => {
let participant = obj.key.participant || obj.participant;
participant = jidNormalizedUser(participant === 'status_me' ? sockk.user.id : participant);
if (!result[participant]) {
result[participant] = [];
}
result[participant].push(obj);
});
let type = mType => (getContentType(mType) === 'extendedTextMessage' ? 'text' : getContentType(mType).replace('Message', ''));
let text = '';
for (let id of Object.keys(result)) {
if (!id) return;
text += `*- ${sockk.getName(id)}*\n`;
text += `${result[id].map((v, i) => `${i + 1}. ${type(v.message)}`).join('\n')}\n\n`;
}
await m.reply(text.trim(), { mentions: Object.keys(result) });
}
break;
case 'upsw':
if (!m.isOwner) return m.reply('lhu saha');
if (m.isOwner) {
let statusJidList = [
jidNormalizedUser(sockk.user.id),
...Object.values(store.contacts)
.filter(v => v.isContact)
.map(v => v.id),
];
let colors = ['#7ACAA7', '#6E257E', '#5796FF', '#7E90A4', '#736769', '#57C9FF', '#25C3DC', '#FF7B6C', '#55C265', '#FF898B', '#8C6991', '#C69FCC', '#B8B226', '#EFB32F', '#AD8774', '#792139', '#C1A03F', '#8FA842', '#A52C71', '#8394CA', '#243640'];
let fonts = [0, 1, 2, 6, 7, 8, 9, 10];
if (!quoted.isMedia) {
let text = m.text || m.quoted?.body || '';
if (!text) throw 'Mana text?';
await sockk.sendMessage(
'status@broadcast',
{ text },
{
backgroundColor: colors[Math.floor(Math.random() * colors.length)],
textArgb: 0xffffffff,
font: fonts[Math.floor(Math.random() * colors.length)],
statusJidList,
}
);
await m.reply(`Up status ke : ${statusJidList.length} Kontak`);
} else if (/audio/.test(quoted.msg.mimetype)) {
await sockk.sendMessage(
'status@broadcast',
{
audio: await downloadM(),
mimetype: 'audio/mp4',
ptt: true,
waveform: [100, 0, 100, 0, 100, 0, 100],
},
{ backgroundColor: colors[Math.floor(Math.random() * colors.length)], statusJidList }
);
await m.reply(`Up status ke : ${statusJidList.length} Kontak`);
} else {
let type = /image/.test(quoted.msg.mimetype) ? 'image' : /video/.test(quoted.msg.mimetype) ? 'video' : false;
if (!type) throw 'Type tidak didukung';
await sockk.sendMessage(
'status@broadcast',
{
[type]: await downloadM(),
caption: m.text || m.quoted?.body || '',
},
{ statusJidList }
);
await m.reply(`Up status ke : ${statusJidList.length} Kontak`);
}
}
break;
/* case "qc": {
if (!m.isQuoted){
const getname = m.pushName
const json = {
"type": "quote",
"format": "png",
"backgroundColor": "#FFFFFF",
"width": 512,
"height": 768,
"scale": 2,
"messages": [
{
"entities": [],
"avatar": true,
"from": {
"id": 1,
"name": getname,
"photo": {
"url": ppuser
}
},
"text": quotedMsg.chats,
"replyMessage": {}
}
]
};
const response = axios.post('https://bot.lyo.su/quote/generate', json, {
headers: {'Content-Type': 'application/json'}
}).then(res => {
const buffer = Func.fetchBuffer(res.data.result.image, 'base64')
let sticker = await (await import('./lib/sticker.js')).writeExif(buffer, { packName: process.env.packName, packPublish: process.env.packPublish });
await m.reply({ sticker });
});
} else if (m.text) {
const json = {
"type": "quote",
"format": "png",
"backgroundColor": "#FFFFFF",
"width": 512,
"height": 768,
"scale": 2,
"messages": [
{
"entities": [],
"avatar": true,
"from": {
"id": 1,
"name": m.pushName,
"photo": {
"url": ppuser
}
},
"text": m.text,
"replyMessage": {}
}
]
};
const response = axios.post('https://bot.lyo.su/quote/generate', json, {
headers: {'Content-Type': 'application/json'}
}).then(res => {
const buffer = Func.fetchBuffer(res.data.result.image, 'base64')
let sticker = await (await import('./lib/sticker.js')).writeExif(buffer, { packName: process.env.packName, packPublish: process.env.packPublish });
await m.reply({ sticker });
});
} else {
m.reply(`Kirim perintah ${prefix+command} text atau reply pesan dengan perintah ${prefix+command}`)
}
}
break;*/
/*case 'smeme':
case 'stickmeme':
case 'stikmeme':
case 'stickermeme':
case 'stikermeme': {
try {
let respon = `Send/reply image/sticker with caption ${m.prefix + m.command} text1|text2`
if (!m.quoted && !m.isMedia) return m.reply(respon)
if (!m.text) return m.reply(respon)
let media = m.quoted ? m.quoted : m
if (!media.isMedia) return m.reply(respon)
let mediaData = await downloadM();
let bg = await Func.upload.telegra(mediaData)
let atas = m.text.split('|')[0] ? m.text.split('|')[0] : '-'
let bawah = m.text.split('|')[1] ? m.text.split('|')[1] : '-'
/*let bawah = m.text.split("|")[0] ? m.text.split("|")[0] : ""
let atas = m.text.split("|")[1] ? m.text.split("|")[1] : ""*/
/****let api = await Func.fetchBuffer(`https://api.memegen.link/images/custom/${encodeURIComponent(bawah)}/${encodeURIComponent(atas)}.png?background=${bg}`)
let sticker = await (await import('./lib/sticker.js')).writeExif(api, { packName: process.env.packName, packPublish: process.env.packPublish });
await m.reply({ sticker });
} catch (e) {
m.reply("An error occurred while processing the image.")
}
}
break;*/
case 'sticker':
case 's':
if (/image|video|webp/.test(quoted.msg.mimetype)) {
let media = await downloadM();
if (quoted.msg?.seconds > 10) throw 'Video diatas durasi 10 detik gabisa';
let exif;
if (m.text) {
let [packname, author] = m.text.split(/[,|\-+&]/);
exif = { packName: packname ? packname : '', packPublish: author ? author : '' };
} else {
exif = { packName: process.env.packName, packPublish: process.env.packPublish };
}
let sticker = await (await import('./lib/sticker.js')).writeExif({ mimetype: quoted.msg.mimetype, data: media }, exif);
await m.reply({ sticker });
} else if (m.mentions.length !== 0) {
for (let id of m.mentions) {
await delay(1500);
let url = await sockk.profilePictureUrl(id, 'image');
let media = await Func.fetchBuffer(url);
let sticker = await (await import('./lib/sticker.js')).writeExif(media, { packName: process.env.packName, packPublish: process.env.packPublish });
await m.reply({ sticker });
}
} else if (/(https?:\/\/.*\.(?:png|jpg|jpeg|webp|mov|mp4|webm|gif))/i.test(m.text)) {
for (let url of Func.isUrl(m.text)) {
await delay(1500);
let media = await Func.fetchBuffer(url);
let sticker = await (await import('./lib/sticker.js')).writeExif(media, { packName: process.env.packName, packPublish: process.env.packPublish });
await m.reply({ sticker });
}
} else {
let media = await Func.fetchBuffer('https://www.hlapi.cn/api/mcj');
let sticker = await (await import('./lib/sticker.js')).writeExif(media, { packName: process.env.packName, packPublish: process.env.packPublish });
await m.reply({ sticker });
}
break;
case 'luminai':{
if (!m.text) return m.reply("Haii, ada yang bisa aku bantu?");
async function luminsesi(q, username, logic) {
try {
const response = await axios.post("https://luminai.siputzx.my.id/", {
content: q,
user: username,
prompt: logic,
webSearchMode: false // true = result with url
});
return response.data.result;
} catch (error) {
console.error('Error fetching:', error);
throw error;
}
}
let query = m.text;
let username = `${m.pushName}`;
let prompt = `Namamu adalah LuminAi yang seolah-olah diciptakan oleh Rasya R. dan kamu menggunakan Bahasa Indonesia kamu kadang suka memberi pantun, yang paling penting kamu harus bersikap ramah kepada lawan bicaramu yang solah-olah lawan bicara mu adalah ${m.pushName}`; // Isi Dengan Prompt Mu!
let result = await luminsesi(query, username, prompt);
return m.reply(`${result}\n`);
}
break
case 'exif':
{
if (!m.isOwner) return m.reply('lhu saha');
let webp = (await import('node-webpmux')).default;
let img = new webp.Image();
await img.load(await downloadM());
await m.reply(util.format(JSON.parse(img.exif.slice(22).toString())));
}
break;
case "tourl": {
if (!quoted.isMedia) return m.reply("Please reply to the media.")
if (Number(quoted.msg.fileLength) > 10000000) return m.reply("The file is too large.")
let media = await downloadM();
let url = (/video|image|webp/.test(quoted.msg.mimetype)) ? await Func.upload.telegra(media) : await Func.upload.pomf(media);
await m.reply(url)
}
break
case "get":
case "fetch":
case "getjson": {
if (!m.text) return m.reply("Please enter the URL.");
if (!m.text.startsWith("http")) return m.reply("The URL you entered is not valid.")
try {
if (m.text.includes(".jpg") || m.text.includes(".png") || m.text.includes(".webp")) {
let media = await Func.fetchBuffer(m.text);
await sockk.sendMessage(m.from, { image: media }, { quoted: m });
} if (m.text.includes(".mp4") || m.text.includes(".webm") || m.text.includes(".mov")) {
let media = await Func.fetchBuffer(m.text);
await sockk.sendMessage(m.from, { video: media }, { quoted: m });
} else if (m.text.startsWith("http") || m.text.startsWith("https")) {
let a = await Func.fetchJson(m.text);
await m.reply(util.format(a));
}
} catch (e) {
m.reply("An error occurred while fetching the URL.")
}
}
break
case 'link':
if (!m.isGroup && !m.isBotAdmin) throw 'Gabisa, kalo ga karena bot bukan admin ya karena bukan grup';
await m.reply('https://chat.whatsapp.com/' + (m.metadata?.inviteCode || (await sockk.groupInviteCode(m.from))));
break;
case 'delete':
case 'del':
if (quoted.fromMe) {
await sockk.sendMessage(m.from, { delete: quoted.key });
} else {
if (!m.isBotAdmin) throw 'lali njir duduk atmin';
if (!m.isAdmin) throw 'Lhu bukan admin paok 😂';
await sockk.sendMessage(m.from, { delete: quoted.key });
}
break;
case 'restart':
if (!m.isOwner) return m.reply('lhu saha');
exec('npm run restart:pm2', err => {
if (err) return process.send('reset');
});
break;
case 'sc':
await m.reply('Lapo le, wa o own ku');
break;
case "tweetc": {
if (!m.text) return m.reply("Please enter the text.")
let replies = Math.floor(Math.random() * 100) + 1
let likes = Math.floor(Math.random() * 1000) + 1
let retweets = Math.floor(Math.random() * 100) + 1
let api = `https://some-random-api.com/canvas/misc/tweet?displayname=${m.pushName}&username=${m.pushName}&avatar=https://i.pinimg.com/564x/8a/e9/e9/8ae9e92fa4e69967aa61bf2bda967b7b.jpg&comment=${m.text}&replies=${replies + 'k'}&likes=${likes + 'k'}&retweets=${retweets + "k"}&theme=dark`
await sockk.sendMessage(m.from, { image: { url: api } }, { quoted: m })
}
break
case "delsesi":
case "clearsesi":
case "csesi":
case "resetsesi": {
if (!m.isOwner) return m.reply("Sorry, this feature is reserved for owners only. Owner's privilege!");
await fs.readdir("./session", async function (err, files) {
if (err) {
console.error(err)
return m.reply("An error occurred while deleting the session.")
}
let file = await files.filter(item => item.startsWith('pre-key') || item.startsWith('sender-key') || item.startsWith('session-') || item.startsWith('app-state'))
await file.forEach(function (a) {
fs.unlinkSync(`./session/${a}`)
})
})
m.reply("Session has been successfully deleted.")
}
break
default:
if (['>', 'eval', '=>'].some(a => m.command.toLowerCase().startsWith(a)) && m.isOwner) {
let evalCmd = '';
try {
evalCmd = /await/i.test(m.text) ? eval('(async() => { ' + m.text + ' })()') : eval(m.text);
} catch (e) {
evalCmd = e;
}
new Promise((resolve, reject) => {
try {
resolve(evalCmd);
} catch (err) {
reject(err);
}
})
?.then(res => m.reply(util.format(res)))
?.catch(err => m.reply(util.format(err)));
}
if (['$', 'exec'].some(a => m.command.toLowerCase().startsWith(a)) && m.isOwner) {
try {
exec(m.text, async (err, stdout) => {
if (err) return m.reply(util.format(err));
if (stdout) return m.reply(util.format(stdout));
});
} catch (e) {
await m.reply(util.format(e));
}
}
}
} catch (err) {
await m.reply(util.format(err));
}
}