forked from adiologydev/PenguBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
90 lines (86 loc) · 3.2 KB
/
main.js
File metadata and controls
90 lines (86 loc) · 3.2 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
89
90
const { CommandoClient } = require("discord.js-commando");
const readdir = require("util").promisify(require("fs").readdir);
const MySQL = require("mysql2/promise");
const MySQLProvider = require("./util/mysqlprovider.js");
const path = require("path");
class PenguClient extends CommandoClient { //eslint-disable-line
constructor(options) { //eslint-disable-line
super(options);
this.functions = require("./util/functions.js");
this.config = require("./config.json");
this.Util = new (require("./util/Util"));
this.cmdRun = {};
}
}
const client = new PenguClient({
commandPrefix: "p!",
owner: ["136549806079344640"],
unknownCommandResponse: false,
invite: "https://discord.gg/u8WYw5r",
disableEveryone: true,
messageCacheMaxSize: 150,
messageCacheLifetime: 4600,
messageSweepInterval: 2800,
disabledEvents: [
"RELATIONSHIP_REMOVE",
"RELATIONSHIP_ADD",
"TYPING_START",
"USER_SETTINGS_UPDATE",
"USER_NOTE_UPDATE",
"MESSAGE_REACTION_REMOVE_ALL",
"MESSAGE_REACTION_REMOVE",
"MESSAGE_REACTION_ADD",
"MESSAGE_DELETE_BULK",
"GUILD_SYNC",
"CHANNEL_PINS_UPDATE"],
commandEditableDuration: 15
});
// MySQL Connection for database
MySQL.createConnection({
host: client.config.DBIP,
user: client.config.DBUSER,
password: client.config.DBPASS,
database: client.config.DBDATABASE
}).then((db, err) => {
if (err) throw err;
client.setProvider(new MySQLProvider(db)).then(console.log("Database Connected! Hurray!")); // eslint-disable-line
client.login(client.config.BOT_TOKEN);
module.exports.database = db;
client.db = db;
setInterval(() => db.query('SELECT 1').catch(error => client.emit('error', error)), 60000); // eslint-disable-line
}).catch(console.log);
client.registry
.registerDefaultTypes()
.registerGroups([
["core", "Core Commands"],
["fun", "Fun Commands"],
["moderation", "Moderation Commands"],
["personal", "Personal Commands"],
["music", "Music Commands"],
["utilities", "Utility Commands"],
["nsfw", "Not Safe For Work (NSFW) Commands"],
["developers", "Developer Only Commands"],
["misc", "Misc commands"]
])
.registerDefaultGroups()
.registerDefaultCommands()
.registerCommandsIn(path.join(__dirname, "commands"));
const init = async () => {
try {
const evtFiles = await readdir("./events/");
console.log(`Loading a total of ${evtFiles.length} events.`);
evtFiles.forEach(file => {
const eventName = file.split(".")[0];
const event = require(`./events/${file}`);
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
} catch (e) {
console.error("Error in init function", e);
}
};
init();
process.on("unhandledRejection", error => console.log(`unhandledRejection:\n${error.stack}`))
.on("uncaughtException", error => console.log(`uncaughtException:\n${error.stack}`))
.on("error", error => console.log(`Error:\n${error.stack}`))
.on("warn", error => console.log(`Warning:\n${error.stack}`));