-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
329 lines (301 loc) · 13.6 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
319
320
321
322
323
324
325
326
327
328
329
const { Client, MessageMedia } = require('whatsapp-web.js');
const { RemoteAuth } = require('whatsapp-web.js-remote-auth-fixed');
const qrcode = require('qrcode-terminal');
const { MongoStore } = require('wwebjs-mongo');
const mongoose = require('mongoose');
const express = require('express');
require("dotenv").config();
const qrimage = require('qr-image');
const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');
const MongoClient = require('mongodb').MongoClient;
//import Commands
const startCommand = require('./commands/start');
const pingCommand = require('./commands/ping');
const helpCommand = require('./commands/help');
const stickerCommand = require('./commands/sticker');
const tlCommand = require('./commands/telegraph');
const trCommand = require('./commands/translate');
const repoCommand = require('./commands/repo');
const gptCommand = require('./commands/gpt');
const bardCommand = require('./commands/bard');
const echoCommand = require('./commands/echo');
const imagineCommand = require('./commands/imagine');
const { termCommand, evalCommand } = require('./commands/term');
const infoCommand = require('./commands/info');
const { AudioDownloadYouTube,
GetYouTubeInfo,
VideoDownloadYouTube
} = require('./commands/ytdl');
const quoteCommand = require('./commands/quotely');
const pasteCommand = require('./commands/paste');
const extractCommand = require('./commands/extract');
const instaCommand = require('./commands/insta');
const { chatbotCommand, chatbottoggleCommand } = require('./commands/chatbot');
const { codeCommand, palmCommand } = require('./commands/code');
const enhanceCommand = require('./commands/enhance');
const wantedCommand = require('./commands/wanted');
const ttsCommand = require('./commands/tts');
const ppCommand = require('./commands/pp');
const sauceCommand = require('./commands/sauce');
const delCommand = require('./commands/del');
const tinyCommand = require('./commands/tinyurl');
const rmbgCommand = require('./commands/rmbg');
const carbonCommand = require('./commands/carbon');
const { promoteCommand, demoteCommand, kickCommand, inviteCommand, reportCommand, revokeCommand, supportCommand, idCommand, tagallCommand, pinCommand, unpinCommand } = require('./commands/group');
const { toanimeCommand, toanime3dCommand } = require('./commands/toanime');
const emojiCommand = require('./commands/emojimix');
const hbarCommand = require('./commands/hbar');
const pintCommand = require('./commands/pinterest');
const wikiCommand = require('./commands/wiki');
const ownerCommand = require('./commands/owner');
const drawCommand = require('./commands/draw');
const getpromptCommand = require('./commands/getprompt');
const memeCommand = require('./commands/meme');
const jokeCommand = require('./commands/joke');
const { addsudoCommand, delsudoCommand, listsudoCommand } = require('./commands/sudo');
const truecallerCommand = require('./commands/truecaller');
//Code
const app = express();
const port = process.env.PORT || 3000;
const puppeteerExecutablePath =
process.env.NODE_ENV === 'production'
? process.env.PUPPETEER_EXECUTABLE_PATH
: puppeteer.executablePath();
const mongoURI = process.env.MONGODB_URI + '/session';
if (!mongoURI) {
console.error('MONGODB_URI is required');
process.exit(1);
}
mongoose.connect(mongoURI).then(() => {
const store = new MongoStore({ mongoose: mongoose });
const client = new Client({
// ffmpegPath: '/app/vendor/ffmpeg',
authStrategy: new RemoteAuth({
store: store,
backupSyncIntervalMs: 300000
}),
puppeteer: {
args: ['--no-sandbox',
'--disable-setuid-sandbox'
],
executablePath: puppeteerExecutablePath,
headless: true,
}
});
let qrText;
let isClientReady = false;
app.get('/', (req, res) => {
if (qrText && !isClientReady) {
// If QR code is available and client is not ready
fs.readFile('index.html', 'utf8', (err, data) => {
const qr_code = qrimage.imageSync(qrText, { type: 'svg' });
const modifiedHTML = data.replace('<div class="loading-animation"></div>', qr_code).replace('<!-- pfp -->', '<img class="github-pfp" src="logo.gif" alt="GitHub PFP">').replace('Please wait Qr code is being generated', 'Scan the QR code using your WhatsApp app');
res.send(modifiedHTML);
});
} else if (isClientReady) {
// If client is ready
fs.readFile('index.html', 'utf8', (err, data) => {
const modifiedHTML = data.replace('<div class="loading-animation"></div>', '<div class="scanning-complete">Scanning complete ✅</div>').replace('Please wait Qr code is being generated', 'Scan completed!');
res.send(modifiedHTML);
});
} else {
// If neither QR code nor client is ready
fs.readFile('index.html', 'utf8', (err, data) => {
res.send(data);
});
}
});
app.get('/alive', (req, res) => {
res.json({ status: "I am alive😶🌫️👍" });
});
client.on('qr', async (text) => {
qrText = text; // Store the QR code text
console.log('QR RECEIVED', qrText);
qrcode.generate(qrText, { small: true });
console.log('Visit the server URL to scan the code');
});
client.on('remote_session_saved', async () => {
console.log('SESSION SAVED');
})
client.on('authenticated', async (session) => {
console.log('WHATSAPP WEB => Authenticated');
});
client.on('ready', async () => {
console.log('Miko bot started successfully!');
isClientReady = true;
});
// Watcher
client.on('group_join', async (notification) => {
// console.log('Group join event', notification);
const joinedUser = notification.id.participant;
const chat = await client.getChatById(notification.id.remote);
const participants = await chat.participants;
const chatName = chat.name;
const description = chat.description == undefined ? 'no description' : chat.description;
const owner = chat.owner._serialized;
const welcomeMsg = process.env.WELCOME_MSG || 'Welcome to the group';
const joinMsg = `*${chatName}*\n\nHello @${joinedUser.replace('@c.us', '')}, ${welcomeMsg}\n\n💠 Group Description: ${description}\n\n👤 Members: ${participants.length}\n\n💈 Owner: @${owner.replace('@c.us', '')}`;
client.sendMessage(notification.id.remote, joinMsg, { mentions: [joinedUser, owner] });
});
client.on('group_leave', async (notification) => {
// console.log(notification);
const leftUser = notification.id.participant;
const leaveMsg = `Goodbye @${leftUser.replace('@c.us', '')}!`;
client.sendMessage(notification.id.remote, leaveMsg, { mentions: [leftUser] });
});
// Commands here
client.on('message', async message => {
let message_body = message.body;
const prefix = process.env.PREFIX || '.';
if (message_body.startsWith(prefix + 'start')) {
startCommand(client, message);
} else if (message_body.startsWith(prefix + "ping")) {
pingCommand(client, message);
} else if (message_body.startsWith(prefix + "help")) {
helpCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "sticker")) {
stickerCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "truecaller")) {
truecallerCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "tl") || message_body.startsWith(prefix + "telegraph")) {
tlCommand(client, message);
} else if (message_body.startsWith(prefix + "tr")) {
trCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "revoke")) {
revokeCommand(client, message);
} else if (message_body.startsWith(prefix + "report")) {
reportCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "repo")) {
repoCommand(client, message);
} else if (message_body.startsWith(prefix + "gpt")) {
gptCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "bard")) {
bardCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "code")) {
codeCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "echo")) {
echoCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + 'imagine')) {
imagineCommand(client, message, prefix, prefix);
} else if (message_body.startsWith(prefix + "term")) {
termCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "eval")) {
evalCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "info")) {
infoCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "song")) {
AudioDownloadYouTube(client, message, prefix);
} else if (message_body.startsWith(prefix + "video")) {
VideoDownloadYouTube(client, message, prefix);
} else if (message_body.startsWith(prefix + "detail")) {
GetYouTubeInfo(client, message, prefix);
} else if (message_body.startsWith(prefix + "q") || message_body.startsWith(prefix + "quote")) {
quoteCommand(client, message);
} else if (message_body.startsWith(prefix + "paste")) {
pasteCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "palm")) {
palmCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "extract")) {
extractCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "insta")) {
instaCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "enhance") || message_body.startsWith(prefix + "upscale")) {
enhanceCommand(client, message);
} else if (message_body.startsWith(prefix + "wanted")) {
wantedCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "tts")) {
ttsCommand(client, message);
} else if (message_body.startsWith(prefix + "pp")) {
ppCommand(client, message);
} else if (message_body.startsWith(prefix + "sauce")) {
sauceCommand(client, message);
} else if (message_body.startsWith(prefix + "tiny")) {
tinyCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "rmbg")) {
rmbgCommand(client, message);
} else if (message_body.startsWith(prefix + "carbon")) {
carbonCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "promote")) {
promoteCommand(client, message);
} else if (message_body.startsWith(prefix + "demote")) {
demoteCommand(client, message);
} else if (message_body.startsWith(prefix + "kick")) {
kickCommand(client, message);
} else if (message_body.startsWith(prefix + "invite")) {
inviteCommand(client, message);
} else if (message_body.startsWith(prefix + "support")) {
supportCommand(client, message);
} else if (message_body.startsWith(prefix + "toanime")) {
toanimeCommand(client, message);
} else if (message_body.startsWith(prefix + "toanime3d")) {
toanime3dCommand(client, message);
} else if (message_body.startsWith(prefix + "emoji")) {
emojiCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "hbar")) {
hbarCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "pint")) {
pintCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "wiki")) {
wikiCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "id")) {
idCommand(client, message);
} else if (message_body.startsWith(prefix + "addsudo")) {
addsudoCommand(client, message);
} else if (message_body.startsWith(prefix + "delsudo")) {
delsudoCommand(client, message);
} else if (message_body.startsWith(prefix + "sudos")) {
listsudoCommand(client, message);
} else if (message_body.startsWith(prefix + "del")) {
delCommand(client, message);
} else if (message_body.startsWith(prefix + "chatbot")) {
chatbottoggleCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "owner")) {
ownerCommand(client, message);
} else if (message_body.startsWith(prefix + "draw")) {
drawCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "getprompt")) {
getpromptCommand(client, message);
} else if (message_body.startsWith(prefix + "meme")) {
memeCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "joke")) {
jokeCommand(client, message, prefix);
} else if (message_body.startsWith(prefix + "tagall")) {
tagallCommand(client, message);
} else if (message_body.startsWith(prefix + "pin")) {
pinCommand(client, message);
} else if (message_body.startsWith(prefix + "unpin")) {
unpinCommand(client, message);
} else {
//else it will run chatbot
chatbotCommand(client, message);
}
});
app.get('/logo.gif', (req, res) => {
const gifPath = path.resolve('logo.gif');
if (fs.existsSync(gifPath)) {
res.setHeader('Content-Type', 'image/gif');
res.sendFile(gifPath);
} else {
res.status(404).send('File not found');
}
});
app.get('/logout', async (req, res) => {
await store.delete({ session: 'RemoteAuth' });
res.json({ status: "Logged out" });
})
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
client.initialize();
console.log("Initializing...");
client.on("auth_failure", () => {
console.error(
"There is a problem in authentication, Kindly set the env var again and restart the app"
);
});
client.on("disconnected", (reason) => {
console.log("Client was logged out", reason);
});
});