-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
52 lines (42 loc) · 1.43 KB
/
server.js
File metadata and controls
52 lines (42 loc) · 1.43 KB
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
// Global objects
import Discord from "discord.js";
import { adminChannelName, token } from "./config/config.json";
import RoleMaster from "./src/RoleMaster";
import AdminChatHandler from "./src/AdminChatHandler";
import { Client } from "pg";
// const { Client } = require("pg");
const discordClient = new Discord.Client();
global.pgClient = new Client({
connectionString: process.env.DATABASE_URL
});
discordClient.on("ready", () => {
console.log("Booting complete!");
console.log("Bot online!");
});
discordClient.on("message", message => {
// Don't respond to other bots or private messages
if (message.author.bot) return;
if (message.guild == null) return;
if (message.channel.name == adminChannelName) {
console.log("Incoming admin message...");
new AdminChatHandler(message).getResponse().then(response => {
message.channel.send(response);
});
}
});
discordClient.on("presenceUpdate", (_, newMember) => {
if (newMember.user.bot === true) return;
const presence = newMember.presence;
if (presence.status == "online" && presence.game != null) {
new RoleMaster().attemptRoleAdd(newMember, presence.game.name);
console.log(newMember.displayName, "is now playing:", presence.game.name);
}
});
const init = () => {
console.log("Booting up...");
console.log("Logging in to Discord...");
discordClient.login(token);
console.log("Connecting to postgres...");
global.pgClient.connect();
};
init();