forked from FlippedCodes/agent-black
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
88 lines (74 loc) · 2.54 KB
/
index.js
File metadata and controls
88 lines (74 loc) · 2.54 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
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
88
// init Discord
const Discord = require('discord.js');
// init Discord client
const client = new Discord.Client({ disableEveryone: true });
// init sequelize
// const sequelize = require('sequelize');
// init filesystem
const fs = require('fs');
// init config
const config = require('./config/main.json');
// create new collections in client and config
client.functions = new Discord.Collection();
client.commands = new Discord.Collection();
config.env = new Discord.Collection();
// import Functions and Commands
config.setup.startupFunctions.forEach((FCN) => {
const INIT = require(`./functions/${FCN}.js`);
INIT.run(client, fs, config);
});
// Login the bot
client.login(config.env.get('token'));
client.on('ready', async () => {
// confirm user logged in
console.log(`[${config.name}] Logged in as "${client.user.tag}"!`);
// setup tables
console.log('[DB] Syncing tables...');
// eslint-disable-next-line no-undef
await sequelize.sync();
await console.log('[DB] Done syncing!');
// run startup functions
config.setup.setupFunctions.forEach((FCN) => {
client.functions.get(FCN).run(client, config);
});
});
client.once('ready', async () => {
// set bot player status
config.setup.setupFunctionsOnce.forEach((FCN) => {
client.functions.get(FCN).run(client, config);
});
});
// EVENT user gets banned
client.on('guildBanAdd', async (guild, user) => {
if (await client.functions.get('FUNC_checkServer').run(guild.id, true)) {
client.functions.get('EVENT_guildBanAdd').run(guild, user);
}
});
// EVENT user gets unbanned
client.on('guildBanRemove', async (guild, user) => {
if (await client.functions.get('FUNC_checkServer').run(guild.id, true)) {
client.functions.get('EVENT_guildBanRemove').run(guild, user);
}
});
// user joins the server
client.on('guildMemberAdd', async (member) => {
if (await client.functions.get('FUNC_checkServer').run(member.guild.id, false)) {
client.functions.get('EVENT_guildMemberAdd').run(client, member);
}
});
// bot joins the server
client.on('guildCreate', async (guild) => {
client.functions.get('EVENT_guildCreate').run(client, guild);
});
// bot leaves the server
client.on('guildDelete', async (guild) => {
if (await client.functions.get('FUNC_checkServer').run(guild.id, true)) {
client.functions.get('EVENT_guildDelete').run(client, guild);
}
});
client.on('message', async (message) => {
client.functions.get('EVENT_message').run(client, message, config);
});
// logging errors
client.on('error', (e) => console.error(e));
client.on('warn', (e) => console.warn(e));