This repository has been archived by the owner on Jan 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
62 lines (52 loc) · 1.75 KB
/
app.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
'use strict';
process.title = 'DSP-BOT';
var ConfigManager, config;
try {
ConfigManager = require('./lib/ConfigManager.js');
ConfigManager.loadConfig();
config = ConfigManager.config;
} catch (e) {
console.log('Could not load config file:\n' + e.message);
process.exit();
}
var Discord = require('discord.js'),
utils = require('./lib/utils.js'),
logger = require('./lib/logger.js'),
server = require('./server/server.js'),
commands = require('./commands/'),
os = require('os');
ConfigManager.setLogger(logger);
var bot = new Discord.Client();
initialize();
function initialize() {
bot.login(config.bot.token);
server.start(commands, config);
setListeners();
}
function setListeners() {
bot.on('ready', onReady);
bot.on('message', onMessage);
}
function onReady() {
//bot.user.setPresence({ game: { name: `Hosting: ${os.hostname()}`} });
bot.user.setPresence({ game: { name: `${config.settings.prefix}help`} });
logger.info('DSP BOT: All packed up and ready to go!');
}
function onMessage(message) {
if (utils.isCommandMessage(message)) {
var commArr = message.content.split(' ');
var command = commArr.shift().substring(1); //remove prefix
var params = commArr.join(' ');
if (!utils.isNativeCode(commands[command]) && commands[command]) {
try {
commands[command].execute(message, params);
} catch (error) {
logger.warn(error.toString());
message.channel.send(error.toString());
}
} else {
logger.warn(`User ${message.author.username} tried to invoke undefined command ${command}`);
message.channel.send(`_${command}_ is not a command!`);
}
}
}