-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
65 lines (58 loc) · 2.16 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
/* eslint-disable no-undef */
const { prefix, owner } = require("./config.json");
const whatsapp = require("@open-wa/wa-automate");
const fs = require("fs");
const moment = require("moment-timezone");
moment.tz.setDefault("Asia/Jakarta").locale("id");
const availableCommands = new Set();
fs.readdir("./commands", (e, files) => {
if (e) return console.error(e);
files.forEach(commandFile => {
availableCommands.add(commandFile.replace(".js", ""));
});
});
whatsapp.create({
blockCrashLogs: true,
chromiumArgs: ["--no-sandbox", "--disable-setuid-sandbox"],
disableSpins: true,
headless: true,
hostNotificationLang: "ENGB",
logConsole: false,
// popup: true,
qrTimeout: 0,
sessionId: "dvstBot",
useChrome: true
}).then(bot => start(bot));
let args;
let command;
function start(bot) {
console.log("[BOT] dvstBot is now running!");
bot.onStateChanged(async state => {
if (state === "CONFLICT" || state === "UNLAUNCHED") bot.forceRefocus();
console.log("[CLIENT]", state);
});
bot.onMessage(async message => {
try {
message.restTimestamp = Date.now();
cmd = message.caption || message.body || "";
const isOwner = owner.includes(message.sender.id);
if (cmd.startsWith(prefix)) {
args = cmd.slice(prefix.length).trim().split(/ +/g);
command = args.shift().toLowerCase();
sender = message.sender.pushname;
if (availableCommands.has(command)) {
console.log(`[EXEC] ${message.chat.name || message.chat.formattedTitle}: ${sender}: ${command} [${args.length}] ${moment(message.t * 1000).format("DD/MM/YY HH:mm:ss")}`);
require(`./commands/${command}`).run(bot, message, args, isOwner);
}
}
} catch (err) {
console.log("[ERROR]", err);
}
});
bot.onIncomingCall(async callData => {
await bot.sendText(callData.peerJid, "*Beep boop!*\nCan't receive call for now.\n\n```- dvstBot```")
.then(async () => {
await bot.contactBlock(callData.peerJid);
});
});
}