-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
80 lines (68 loc) · 1.93 KB
/
index.ts
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
import qrcode from 'qrcode-terminal';
import pkg from 'whatsapp-web.js';
import { connect } from 'mongoose';
import 'dotenv/config';
const { Client, LocalAuth } = pkg;
/**
* @module Client
* @class Client
* Entry point for the WhatsApp bot.
*
* Initializes the WhatsApp client, connects to the MongoDB database,
* and handles QR code generation for authentication when the bot is ready.
*
* **Other things:**
* - Loading command and event handlers when the bot is ready.
* - Handling uncaught exceptions and signals for graceful shutdown.
*/
const client = new Client({
authStrategy: new LocalAuth(),
puppeteer: {
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-web-security',
'--disable-gpu',
'--hide-scrollbars',
'--disable-cache',
'--disable-application-cache',
'--disable-gpu-driver-bug-workarounds',
'--disable-accelerated-2d-canvas',
],
headless: true,
executablePath: process.env.CHROME_PATH,
},
});
client.initialize();
connect(process.env.MONGODB_URI)
.then(() => {
console.log('Connected to the database!');
})
.catch((err: unknown) => {
console.log(err);
});
client.on('qr', qr => {
qrcode.generate(qr, { small: true });
});
import('./init.js');
client.on('ready', (_: any) => {
const handlers = ['command_handler.js', 'event_handler.js'];
handlers.forEach((handler: string) => {
import(`./src/handlers/${handler}`).then(module => module.default(client));
});
console.log("Problems with microsoft-cognitiveservices-speech-sdk for gemspeak.ts can be fixed by removing gradio")
});
process.on('unhandledRejection', (err: Error) => {
console.log(err.stack ? err.stack : err);
});
process.on('uncaughtException', (err: Error, origin: string) => {
if (origin === 'unhandledRejection') {
return;
}
console.log(err.stack ? err.stack : err);
});
process.on('SIGINT', async function () {
await client.destroy();
});
export default client;