-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathindex_old.js
500 lines (418 loc) · 14.4 KB
/
index_old.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
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
const qrcode = require("qrcode-terminal");
const moment = require("moment");
const cheerio = require("cheerio");
const fs = require("fs");
const dl = require("./lib/downloadImage.js");
const fetch = require('node-fetch');
const urlencode = require("urlencode");
const axios = require("axios");
const imageToBase64 = require('image-to-base64');
const menu = require("./menu.js");
const { exec } = require("child_process");
const
{
WAConnection,
MessageType,
Presence,
MessageOptions,
Mimetype,
WALocationMessage,
WA_MESSAGE_STUB_TYPES,
ReconnectMode,
ProxyAgent,
waChatKey,
} = require("@adiwajshing/baileys");
var jam = moment().format("HH:mm");
function foreach(arr, func)
{
for (var i in arr)
{
func(i, arr[i]);
}
}
const conn = new WAConnection()
conn.on('qr', qr =>
{
qrcode.generate(qr,
{
small: true
});
console.log(`[ ${moment().format("HH:mm:ss")} ] Please Scan QR with app!`);
});
conn.on('credentials-updated', () =>
{
// save credentials whenever updated
console.log(`credentials updated!`)
const authInfo = conn.base64EncodedAuthInfo() // get all the auth info we need to restore this session
fs.writeFileSync('./session.json', JSON.stringify(authInfo, null, '\t')) // save this info to a file
})
fs.existsSync('./session.json') && conn.loadAuthInfo('./session.json')
// uncomment the following line to proxy the connection; some random proxy I got off of: https://proxyscrape.com/free-proxy-list
//conn.connectOptions.agent = ProxyAgent ('http://1.0.180.120:8080')
conn.connect();
conn.on('user-presence-update', json => console.log(json.id + ' presence is ' + json.type))
conn.on('message-status-update', json =>
{
const participant = json.participant ? ' (' + json.participant + ')' : '' // participant exists when the message is from a group
console.log(`${json.to}${participant} acknlowledged message(s) ${json.ids} as ${json.type}`)
})
conn.on('message-new', async(m) =>
{
const messageContent = m.message
const text = m.message.conversation
let id = m.key.remoteJid
const messageType = Object.keys(messageContent)[0] // message will always contain one key signifying what kind of message
let imageMessage = m.message.imageMessage;
console.log(`[ ${moment().format("HH:mm:ss")} ] (${id.split("@s.whatsapp.net")[0]} => ${text}`);
// Groups
if (text.includes("!buatgrup"))
{
var nama = text.split("!buatgrup")[1].split("-nomor")[0];
var nom = text.split("-nomor")[1];
var numArray = nom.split(",");
for ( var i = 0; i < numArray.length; i++ ) {
numArray[i] = numArray[i] +"@s.whatsapp.net";
}
var str = numArray.join("");
console.log(str)
const group = await conn.groupCreate (nama, str)
console.log ("created group with id: " + group.gid)
conn.sendMessage(group.gid, "hello everyone", MessageType.extendedText) // say hello to everyone on the group
}
// FF
if(text.includes("!cek")){
var num = text.replace(/!cek/ , "")
var idn = num.replace("0","+62");
console.log(id);
const gg = idn+'@s.whatsapp.net'
const exists = await conn.isOnWhatsApp (gg)
console.log(exists);
conn.sendMessage(id ,`${gg} ${exists ? " exists " : " does not exist"} on WhatsApp`, MessageType.text)
}
if (text == '!menu'){
conn.sendMessage(id, menu.menu ,MessageType.text);
}
else if (text == '!menu1'){
conn.sendMessage(id, menu.menu1 ,MessageType.text);
}
else if (text == '!menu2'){
conn.sendMessage(id, menu.menu2 ,MessageType.text);
}
else if (text == '!menu3'){
conn.sendMessage(id, menu.menu3 ,MessageType.text);
}
if (messageType == 'imageMessage')
{
let caption = imageMessage.caption.toLocaleLowerCase()
const buffer = await conn.downloadMediaMessage(m) // to decrypt & use as a buffer
if (caption == '!sticker')
{
const stiker = await conn.downloadAndSaveMediaMessage(m) // to decrypt & save to file
const
{
exec
} = require("child_process");
exec('cwebp -q 50 ' + stiker + ' -o temp/' + jam + '.webp', (error, stdout, stderr) =>
{
let stik = fs.readFileSync('temp/' + jam + '.webp')
conn.sendMessage(id, stik, MessageType.sticker)
});
}
}
if (messageType === MessageType.text)
{
let is = m.message.conversation.toLocaleLowerCase()
if (is == '!pantun')
{
fetch('https://raw.githubusercontent.com/pajaar/grabbed-results/master/pajaar-2020-pantun-pakboy.txt')
.then(res => res.text())
.then(body =>
{
let tod = body.split("\n");
let pjr = tod[Math.floor(Math.random() * tod.length)];
let pantun = pjr.replace(/pjrx-line/g, "\n");
conn.sendMessage(id, pantun, MessageType.text)
});
}
}
if (text.includes("!yt"))
{
const url = text.replace(/!yt/, "");
const exec = require('child_process').exec;
var videoid = url.match(/(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/);
const ytdl = require("ytdl-core")
if (videoid != null)
{
console.log("video id = ", videoid[1]);
}
else
{
conn.sendMessage(id, "gavalid", MessageType.text)
}
ytdl.getInfo(videoid[1]).then(info =>
{
if (info.length_seconds > 1000)
{
conn.sendMessage(id, " videonya kepanjangan", MessageType.text)
}
else
{
console.log(info.length_seconds)
function os_func()
{
this.execCommand = function (cmd)
{
return new Promise((resolve, reject) =>
{
exec(cmd, (error, stdout, stderr) =>
{
if (error)
{
reject(error);
return;
}
resolve(stdout)
});
})
}
}
var os = new os_func();
os.execCommand('ytdl ' + url + ' -q highest -o mp4/' + videoid[1] + '.mp4').then(res =>
{
const buffer = fs.readFileSync("mp4/"+ videoid[1] +".mp4")
conn.sendMessage(id, buffer, MessageType.video)
}).catch(err =>
{
console.log("os >>>", err);
})
}
});
}
if (text.includes("!nulis"))
{
const
{
spawn
} = require("child_process");
console.log("writing...")
const teks = text.replace(/!nulis/, "")
const split = teks.replace(/(\S+\s*){1,10}/g, "$&\n")
const fixedHeight = split.split("\n").slice(0, 25).join("\\n")
console.log(split)
spawn("convert", [
"./assets/paper.jpg",
"-font",
"Indie-Flower",
"-size",
"700x960",
"-pointsize",
"18",
"-interline-spacing",
"3",
"-annotate",
"+170+222",
fixedHeight,
"./assets/result.jpg"
])
.on("error", () => console.log("error"))
.on("exit", () =>
{
const buffer = fs.readFileSync("assets/result.jpg") // can send mp3, mp4, & ogg -- but for mp3 files the mimetype must be set to ogg
conn.sendMessage(id, buffer, MessageType.image)
console.log("done")
})
}
if (text.includes("!quotes"))
{
var url = 'https://jagokata.com/kata-bijak/acak.html'
axios.get(url)
.then((result) =>
{
let $ = cheerio.load(result.data);
var author = $('a[class="auteurfbnaam"]').contents().first().text();
var kata = $('q[class="fbquote"]').contents().first().text();
conn.sendMessage(
id,
`
_${kata}_
*~${author}*
`, MessageType.text
);
});
}
if (text.includes("!ptl"))
{
var items = ["ullzang girl", "cewe cantik", "hijab cantik", "korean girl"];
var cewe = items[Math.floor(Math.random() * items.length)];
var url = "https://api.fdci.se/rep.php?gambar=" + cewe;
axios.get(url)
.then((result) => {
var b = JSON.parse(JSON.stringify(result.data));
var cewek = b[Math.floor(Math.random() * b.length)];
imageToBase64(cewek) // Path to the image
.then(
(response) => {
var buf = Buffer.from(response, 'base64'); // Ta-da
conn.sendMessage(
id,
buf,MessageType.image)
}
)
.catch(
(error) => {
console.log(error); // Logs an error if there was one
}
)
});
}
if (text.includes("!ig"))
{
var post = text.replace(/!ig/, "");
const axios = require("axios");
var regExp = /\/p\/(.*?)\//;
var ids = post.match(regExp);
var url = `https://www.instagram.com/p/${ids[1]}/?__a=1`;
console.log(url)
axios.get(url)
.then((result) =>
{
var data = result.data.graphql.shortcode_media;
if (data.is_video == true){
console.log("true")
exec('wget "' + data.video_url + '" -O mp4/fbvid.mp4', (error, stdout, stderr) => {
const buffer = fs.readFileSync("mp4/fbvid.mp4")
conn.sendMessage(id, buffer, MessageType.video)
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
} else if (data.is_video == false){
imageToBase64(data.display_url) // Path to the image
.then(
(response) => {
var buf = Buffer.from(response, 'base64'); // Ta-da
conn.sendMessage(
id,
buf,MessageType.image)
}
)
.catch(
(error) => {
console.log(error); // Logs an error if there was one
}
)
}
});
}
// search chord
if (text.includes("!chord"))
{
var hal = text.replace(/!chord/, "");
var url = "http://app.chordindonesia.com/?json=get_search_results&exclude=date,modified,attachments,comment_count,comment_status,thumbnail,thumbnail_images,author,excerpt,content,categories,tags,comments,custom_fields&search="+ hal;
axios.get(url)
.then((result) => {
var d = JSON.parse(JSON.stringify(result.data));
if (d.count == "0"){
msg.reply("maaf lirik tidak ditemukan");
}else{
//console.log(d)
var result =[];
var y = 0;
var nomor ="";
foreach(d.posts, function(i, v){
var no = d.posts[i].id;
nomor += y++;
result += " ID *["+ no + "]* Judul : "+ d.posts[i].title +"\n\n";
});
var g = result.replace(/–/g, " - ");
conn.sendMessage(id, `
*Hasil Pencarian Yang Ditemukan*
- ${g}
Silahkan pilih lagu , lalu ketik
*!getchord ID nya*
`, MessageType.text)
}
})
.catch((err) => {
console.log(err);
})
}
// Get Chord
if (text.includes("!getchord"))
{
var nomor = text.replace(/!getchord/, "");
const htmlToText = require('html-to-text');
var url = "http://app.chordindonesia.com/?json=get_post&id="+ nomor;
axios.get(url)
.then((result) => {
var d = JSON.parse(JSON.stringify(result.data));
var html = d.post.content;
const text = htmlToText.fromString(html, {
noLinkBrackets: true,
ignoreHref: true,
ignoreImage:true
});
conn.sendMessage(id, text, MessageType.text)
});
}
if (text.includes("!randomanime"))
{
var items = ["anime girl", "anime cantik", "anime", "anime aesthetic"];
var cewe = items[Math.floor(Math.random() * items.length)];
var url = "https://api.fdci.se/rep.php?gambar=" + cewe;
axios.get(url)
.then((result) => {
var b = JSON.parse(JSON.stringify(result.data));
var cewek = b[Math.floor(Math.random() * b.length)];
imageToBase64(cewek) // Path to the image
.then(
(response) => {
var buf = Buffer.from(response, 'base64'); // Ta-da
conn.sendMessage(
id,
buf,MessageType.image)
}
)
.catch(
(error) => {
console.log(error); // Logs an error if there was one
}
)
});
}
if (text.includes("!scdl")){
const fs = require("fs");
const scdl = require("./lib/scdl");
scdl.setClientID("iZIs9mchVcX5lhVRyQGGAYlNPVldzAoX");
scdl("https://m.soundcloud.com/abdul-muttaqin-701361735/lucid-dreams-gustixa-ft-vict-molina")
.pipe(fs.createWriteStream("mp3/song.mp3"));
}
else if (text.includes("!tts")) {
var teks = text.split("!ttsid ")[1];
var path = require('path');
var text1 = teks.slice(6);
text1 = suara;
var suara = text.replace(/!ttsid/g, text1);
var filepath = 'mp3/bacot.wav';
/*
* save audio file
*/
gtts.save(filepath, suara, function() {
console.log(`${filepath} MP3 SAVED!`)
});
await new Promise(resolve => setTimeout(resolve, 500));
if(suara.length > 200){ // check longness of text, because otherways google translate will give me a empty file
msg.reply("Text to long, split in text of 200 characters")
}else{
const buffer = fs.readFileSync(filepath)
conn.sendMessage(id , buffer , MessageType.audio);
};
}
// end of file
})