forked from bunnykek/Cheems-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
executable file
·87 lines (70 loc) · 2.95 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
const qrcode = require('qrcode-terminal');
const { Client, LocalAuth } = require('whatsapp-web.js');
const fs = require('fs');
const logo =' /$$$$$$ /$$ /$$ /$$ \n /$$__ $$| $$ | $$ | $$ \n| $$ \\__/| $$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$$ | $$$$$$$ /$$$$$$ /$$$$$$ \n| $$ | $$__ $$ /$$__ $$ /$$__ $$| $$_ $$_ $$ /$$_____//$$$$$$| $$__ $$ /$$__ $$|_ $$_/ \n| $$ | $$ \\ $$| $$$$$$$$| $$$$$$$$| $$ \\ $$ \\ $$| $$$$$$|______/| $$ \\ $$| $$ \\ $$ | $$ \n| $$ $$| $$ | $$| $$_____/| $$_____/| $$ | $$ | $$ \\____ $$ | $$ | $$| $$ | $$ | $$ /$$\n| $$$$$$/| $$ | $$| $$$$$$$| $$$$$$$| $$ | $$ | $$ /$$$$$$$/ | $$$$$$$/| $$$$$$/ | $$$$/\n \\______/ |__/ |__/ \\_______/ \\_______/|__/ |__/ |__/|_______/ |_______/ \\______/ \\___/ \n A modular WhatsApp bot\n --by @bunnykek'
console.log(logo);
console.log("Loading the modules...");
// importing modules from a directory
const directoryPath = './modules';
const modules = fs.readdirSync(directoryPath)
const moduleObjects = [];
for (const module of modules) {
console.log(module);
moduleClass = require(`${directoryPath}/${module}/interface.js`);
moduleObjects.push(new moduleClass()); // Assuming no constructor arguments
}
let state = {
'count': { 'next_num': null, 'warned': false }
};
const client = new Client({
authStrategy: new LocalAuth(),
puppeteer: {
executablePath: '/usr/bin/google-chrome-stable',
args: ['--no-sandbox', '--disable-setuid-sandbox'],
},
});
client.on('qr', (qr) => {
qrcode.generate(qr, { small: true });
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.on('disconnected', () => {
console.log('Client is disconnected!');
});
client.on('authenticated', () => {
console.log('Client is authenticated!');
});
client.on('auth_failure', () => {
console.log('Client is auth_failure!');
});
client.on('message', msg => {
if (msg.body == '!ping') {
msg.reply('pong!');
}
if (msg.body == '!alive') {
msg.reply('beep boop!');
}
if (msg.body == '!help') {
let helpstring = `*Cheems bot*\n\n`
moduleObjects.forEach(obj => {
for (i = 0; i < obj.command.length; i++) {
helpstring += `*${obj.command[i]}:* ${obj.description[i]}\n\n`
}
})
msg.reply(helpstring);
}
for (const obj of moduleObjects) {
for (const cmd of obj.command) {
if (msg.body.includes(cmd)) {
obj.operate(client, msg, state)
.catch(error => {
console.log(error);
msg.reply("_Could not process your request :/_")
})
break;
}
}
}
});
client.initialize();