-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (55 loc) · 2.29 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
66
67
68
require('dotenv').config();
const Discord = require('discord.js');
const config = require('./config');
const fs = require('fs');
const Enmap = require("enmap");
const mongoose = require('mongoose');
const publicIp = require('public-ip');
const discordClient = new Discord.Client();
// read in all of our configurations
discordClient.config = config;
discordClient.speechEnabled = false;
// for hot swapping server specific settings
const Keyv = require('keyv');
const prefixes = new Keyv('mongodb://localhost/rin', {namespace: 'prefixes'});
const defaultTextChannels = new Keyv('mongodb://localhost/rin', {namespace: 'defaultTextChannels'});
const defaultVoiceChannels = new Keyv('mongodb://localhost/rin', {namespace: 'defaultVoiceChannels'});
const defaultWelcomeChannels = new Keyv('mongodb://localhost/rin', {namespace: 'defaultWelcomeChannels'});
discordClient.prefixes = prefixes;
discordClient.defaultTextChannels = defaultTextChannels;
discordClient.defaultVoiceChannels = defaultVoiceChannels;
discordClient.defaultWelcomeChannels = defaultWelcomeChannels;
// link all the events
// explanation for how this works can be found here:
// https://anidiots.guide/first-bot/a-basic-command-handler
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
discordClient.on(eventName, event.bind(null, discordClient));
});
});
discordClient.commands = new Enmap();
// read in all the custom commands
fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
discordClient.commands.set(commandName, props);
});
});
// connect to a db called mongoose_basics
mongoose.connect('mongodb://localhost/rin', function (err) {
if (err) throw err;
console.log('Successfully connected');
});
(async () => {
if(await publicIp.v4() === config.PROD_IP) {
discordClient.login(config.prod_discordApiToken);
} else {
discordClient.login(config.dev_discordApiToken);
}
})();