-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
77 lines (70 loc) · 2.58 KB
/
bot.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
69
70
71
72
73
74
75
76
77
var bot = require('./discordClient.js');
var consts = require('./consts.js');
if (consts.CurrentSeason === undefined) {
console.log("Please provide a CURRENT_SEASON value");
process.exit(1);
}
var ladderCommand = require('./command/ladder.js');
var rankCommand = require('./command/rank.js');
var registerCommand = require('./command/register.js');
var updateCommand = require('./command/update.js');
var commandPrefix = '*';
// Create a database proxy, and connect straight away:
var db = require('./db.js');
db.connect();
// Configure logger settings
var logger = require('winston');
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// Add message handling for the bot:
bot.on('message', function (message) {
if (message.author.bot) return;
var discordName = message.member.displayName;
var discordID = message.member.id.toString();
if (message.content.substring(0, 1) === commandPrefix) {
var args = message.content.substring(1).split(' ');
var cmd = args[0];
var argsLeft = args.slice(1);
logger.info("Running command: " + cmd);
switch (cmd) {
case 'debug': {
logger.debug("Discord Name=" + discordName);
logger.debug("Discord Id=" + discordID);
logger.debug("Channel ID=" + message.channel.id);
logger.debug("Message=" + message.content);
break;
}
case 'shutup': {
message.channel.stopTyping(true);
break;
}
case 'stfu': {
message.channel.stopTyping(true);
break;
}
case 'update': {
updateCommand.run(discordName, discordID, message, argsLeft, () => message.channel.stopTyping(true));
break;
}
case 'rank': {
rankCommand.run(discordName, discordID, message, argsLeft, () => message.channel.stopTyping(true));
break;
}
case 'register': {
registerCommand.run(discordName, discordID, message, argsLeft, () => message.channel.stopTyping(true));
break;
}
case 'ladder': {
ladderCommand.run(discordName, discordID, message, argsLeft, () => message.channel.stopTyping(true));
break;
}
// Just add any case commands if you want to..
default: {
message.channel.stopTyping(true);
}
}
}
});