forked from PSWiFi/PipBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (33 loc) · 888 Bytes
/
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
const { Client } = require("ps-client");
const dotenv = require("dotenv");
dotenv.config();
const CACHE = {};
const { BOT_USERNAME: username, BOT_PASSWORD: password } = process.env;
const config = require("./config.js");
require("./globals.js");
const DB = require("./database.js");
const messageHandler = require("./messagehandler.js");
const client = new Client({
username,
password,
rooms: config.rooms,
debug: true,
});
client.connect();
client.on("message", async (message) => {
await messageHandler.handleMessage(message, client, DB);
});
// Attempt to rejoin room upon leave
client.on("leaveRoom", async (room) => {
if (config.rooms.includes(room)) {
client.send("|/j " + room);
}
});
// Unga bunga
client.on("connect", async () => {
setInterval(() => {
for (const room of config.rooms) {
client.send("|/j " + room);
}
}, 15 * 1000);
});