-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bot.js
313 lines (279 loc) · 10.7 KB
/
Bot.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
const qrcode = require('qrcode-terminal');
const axios = require('axios')
const str_replace = require('str_replace');
const fs = require('fs')
const puppeteer = require('puppeteer')
const { Client, LocalAuth, MessageMedia, List, Buttons} = require('whatsapp-web.js');
const pup_me = ({
executablePath: '/usr/bin/google-chrome',
args: ['--no-sandbox']
// , headless: false
})
const client = new Client({
authStrategy: new LocalAuth(),
puppeteer: pup_me
});
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
client.on('qr', (qr) => {
qrcode.generate(qr, {small: true});
console.log('QR RECEIVED', qr);
});
client.on('authenticated', () => {
console.log('AUTHENTICATED');
});
client.on('auth_failure', msg => {
// Fired if session restore was unsuccessful
console.error('AUTHENTICATION FAILURE', msg);
});
client.on('ready', () => {
console.log('CLIENT IS CONNECTED');
});
client.on('message', async message => {
const chat = await message.getChat();
const isitek = message.body;
const contact = await message.getContact();
console.log(`Message : "${isitek}" , FROM : "${chat.name}"`);
if (isitek === '!notes') {
const contact = await message.getContact();
if (chat.isGroup) {
var noteslist =`!ping
!info
!media
!everyone
!meme
Anda dapat mengambil catatan ini dengan menggunakan !notename
Member Count: ${chat.participants.length}`;
chat.sendStateTyping();
let sections = [{title:'List Of Notes',
rows:[
{title:'!ping'},
{title:'!info'},
{title:'!media'},
{title:'!everyone'},
{title:'!meme'},
]}];
let list = new List(noteslist,'NOTES',sections,`*List of notes in ${chat.name} :*`,' ');
message.reply(list, message.from);
} else {
const info = await message.getContact();
var notepri =`!ping
!info
!media
!meme
Your Name : ${info.pushname}
Your Number : ${chat.name}
*Anda dapat mengambil catatan ini dengan menggunakan !notename*`;
chat.sendStateTyping();
//chat.sendMessage();
let sections = [{title:'List Of Notes',
rows:[
{title:'!ping'},
{title:'!info'},
{title:'!media'},
{title:'!meme'},
]}];
let list = new List(notepri,'NOTES',sections,`*List of notes in ${chat.name} :*`,' ');
message.reply(list, message.from);
}} else if (isitek.startsWith('!info')) {
if (isitek === '!info') {
info = await message.getContact();
} else if (message.body.includes('@')) {
console.log('it got @ alright.');
const nomoraja = isitek.split(' ')[1];
const contacthe = str_replace('@', '', nomoraja)
console.log(contacthe);
let mentions = await message.getMentions();
for (let contact of mentions) {
if (contact.number == contacthe) {
info = contact;
console.log(contact);}}}
console.log(info);
chat.sendStateTyping();
let vcard = `BEGIN:VCARD
VERSION:3.0
N:;${info.pushname};;;
FN:${info.pushname}
TEL;type=CELL;type=VOICE;waid=${info.number}:+${info.number}
END:VCARD`
let infoaja = `*☀️Info about you🗿 :*
User name : ${info.pushname}
Number : +${info.number}
Chat : wa.me/${info.number}`
await message.reply(infoaja, message.from);
await chat.sendMessage(vcard)
} else if (isitek === '!ping') {
const idnunm = client.getNumberId('6281382519681');
chat.sendStateTyping();
console.log(idnunm);
chat.sendMessage(`Hi @${contact.number} !`, {
mentions: [contact]
});
} else if (isitek === '!media') {
chat.sendStateTyping();
const media = MessageMedia.fromFilePath('img.jpg');
message.reply(media);
} else if (isitek === '!card') {
chat.sendStateTyping();
message.reply(`BEGIN:VCARD
VERSION:3.0
N:;Bot Wa JS Fatih;;;
FN:Bot Wa JS Fatih
TEL;type=CELL;type=VOICE;waid=6289514599099:+62 895-1459-9099
END:VCARD`);
} else if (isitek === '!video') {
chat.sendStateTyping();
let media = MessageMedia.fromFilePath('video.mp4');
message.reply(media);
} else if (isitek === '!last') {
const lastMessage = await chat.fetchMessages({ limit: 2 });
console.log(lastMessage);
if (lastMessage[0].fromMe !== true) return;
let messageLower = lastMessage[0].body.toLowerCase();
if (messageLower == "last message of the bot") {
console.log(`The last message of the bot was: ${lastMessage}`);
}
} else if (isitek === '!meme') {
chat.sendStateTyping();
const browser = await puppeteer.launch(pup_me)
try {
const url = 'https://1cak.com/shuffle';
console.log(`LOG : "Crawling ${url}"`)
const page = await browser.newPage()
await page.goto(url)
const selector = 'td > img'
await page.waitForSelector(selector)
const links = await page.$$eval(selector, am => am.filter(e => e.src).map(e => e.src))
titles = await page.$$eval(selector, am => am.filter(e => e.title).map(e => e.title))
const result = str_replace(',', '\n\n\n', links);
const resultt = str_replace(',', '\n\n\n', titles);
console.log(`LOG : "Image : ${result}"`)
console.log(`LOG : "Judul meme : ${resultt}"`)
// console.log(result);
const pageNew = await browser.newPage()
const response = await pageNew.goto(result, {timeout: 0, waitUntil: 'networkidle0'})
const imageBuffer = await response.buffer()
var name = 'meme-1cak';
await fs.promises.writeFile(name+'.jpg', imageBuffer)
await page.close()
await pageNew.close()
await browser.close()
} catch (err) {
console.log(err)
}
let mesent = await MessageMedia.fromFilePath('meme-1cak.jpg');
message.reply(mesent, message.from,{caption: `*"${titles}"*`});
} else if (isitek.startsWith('!profile ')) {
const nomoraja = isitek.split(' ')[1];
const contacthe = str_replace('@', '', nomoraja)
console.log(contacthe);
let mentions = await message.getMentions();
for (let contact of mentions) {
if (contact.number == contacthe) {
message.reply(`*PROFILE*
NUMBER: ${contact.number}
NAME: ${contact.pushname}
note: THIS IS YOUR PROFILE`)
} else if (contact.number == 'owner number') {
message.reply(`*PROFILE*
NUMBER: ${contact.number}
NAME: ${contact.pushname}
*OWNER*
note: THIS IS YOUR PROFILE`)
}
};
} else if (isitek.startsWith('!join ')) {
const inviteCode = isitek.split(' ')[1];
var invit = inviteCode;
if (inviteCode.startsWith("https")){
invit = inviteCode.slice(26);
} try {
await client.acceptInvite(invit);
message.reply('Joined the group!');
} catch (e) {
message.reply('That invite code seems to be invalid.');
}
} else if (isitek === '!delete') {
if (message.hasQuotedMsg) {
const quotedMsg = await message.getQuotedMessage();
// console.log(quotedMsg);
if (quotedMsg.fromMe) {
await sleep(1500);
quotedMsg.delete(true);
console.log(`LOG : "it is from me and i delete it"`);
} else {
message.reply('I can only delete my own messages');
}
}
} else if (isitek === '!leave') {
// Leave the group
let chat = await message.getChat();
if (chat.isGroup) {
chat.leave();
} else {
message.reply('This command can only be used in a group!');
}
} else if (isitek === '!resendmedia' && message.hasQuotedMsg) {
const quotedMsg = await message.getQuotedMessage();
if (quotedMsg.hasMedia) {
const attachmentData = await quotedMsg.downloadMedia();
message.reply(attachmentData, message.from, { caption: 'Here\'s your requested media.' });
}
} else if (isitek === '!pwsmanda fatih') {
chat.sendStateTyping();
await message.reply(`AUDITORIUM : 12345audit
operator : smandagenepbelas
RUANG KEPALA SEKOLAH : kepseksmanda
absen : absen12345
X MIPA 1~10 : 123456A(kelas)`
);
} else if (isitek === '!sticker'){
chat.sendStateTyping();
if (message.hasQuotedMsg){
chat.sendStateTyping();
const quotedMsg = await message.getQuotedMessage();
if (quotedMsg.hasMedia) {
const attachmentData = await quotedMsg.downloadMedia();
message.reply(attachmentData, message.from,{ sendMediaAsSticker: true });
}
} else {
const attachmentData = await message.downloadMedia();
message.reply(attachmentData, message.from,{ sendMediaAsSticker: true });
}
} else if (isitek === '!source') {
// Get Source Code , this File..
const media = MessageMedia.fromFilePath('index.js');
message.reply(media, message.from);
} else if(isitek === '!everyone') {
chat.sendStateTyping();
if (chat.isGroup) {
let text = "";
let mentions = [];
for(let participant of chat.participants) {
const contact = await client.getContactById(participant.id._serialized);
mentions.push(contact);
text += `@${participant.id.user} `;
}
await message.reply(text, message.from, { mentions });
} else {
message.reply('This command can only be used in a group!');
}}
});
client.on('media_uploaded', async msg => {
// Fired on all message creations, including your own
// console.log(msg);
await sleep(25000);
if (msg.body.endsWith('.js')) {
console.log(`LOG : "This is js file being sent i will not interupt"`);
}
if (msg.type === 'sticker') {
console.log(`LOG : "This is sticker file being sent i will not interupt"`);
}
else if (msg.fromMe) {
console.log(`LOG : "I Declare That the meesage is detected and it's from me .."`);
msg.delete(true);
console.log(`LOG : "I Have send delete command to the chat , it should be gone now"`);
}
});
client.initialize();