-
Notifications
You must be signed in to change notification settings - Fork 9
/
bot.js
88 lines (80 loc) · 2.92 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
78
79
80
81
82
83
84
85
86
87
88
var Discord = require("discord.js");
var fs = require("fs");
var path = require("path");
var __dirname = "/home/brickbot/brickbot/commands";
fs.readdirSync(__dirname).forEach(function (file) {
module.exports[path.basename(file, ".js")] = require(path.join(__dirname, file));
});
var commands = module.exports;
var helpers = require("./helpers/helpers.js");
var bot = new Discord.Client();
bot.on("message", (receivedMessage) => {
if (receivedMessage.author == bot.user) {
return;
}
if (receivedMessage.content.startsWith("!")) {
processCommand(receivedMessage);
}
});
function processCommand(receivedMessage) {
let fullCommand = receivedMessage.content.substr(1);
let splitCommand = fullCommand.split(" ");
let primaryCommand = splitCommand[0];
let args = splitCommand.slice(1);
console.log("Command received: " + primaryCommand);
console.log("args: " + args);
switch (primaryCommand) {
case "help":
commands.help.helpCommand(bot, args, receivedMessage);
break;
case "bus":
commands.bus.busCommand(bot, args, receivedMessage);
break;
case "coinflip":
commands.coinflip.coinflipCommand(bot, args, receivedMessage);
break;
case "info":
commands.info.infoCommand(bot, args, receivedMessage);
break;
case "isitup":
commands.isitup.isitupCommand(bot, args, receivedMessage);
break;
case "luas":
commands.luas.luasCommand(bot, args, receivedMessage);
break;
case "nslookup":
commands.nslookup.nslookupCommand(bot, args, receivedMessage);
break;
case "pwgen":
commands.pwgen.pwgenCommand(bot, args, receivedMessage);
break;
case "pwned":
commands.pwned.pwnedCommand(bot, args, receivedMessage);
break;
case "register":
commands.register.registerCommand(bot, args, receivedMessage);
break;
case "room":
commands.room.roomCommand(bot, args, receivedMessage);
break;
case "ssl":
commands.ssl.sslCommand(bot, args, receivedMessage);
break;
case "uptime":
commands.uptime.uptimeCommand(bot, args, receivedMessage);
break;
case "verify":
commands.verify.verifyCommand(bot, args, receivedMessage);
break;
case "weather":
commands.weather.command(bot, args, receivedMessage);
break;
case "wiki":
commands.wiki.wikiCommand(bot, args, receivedMessage);
break;
default:
receivedMessage.channel.send(helpers.embedify(bot, "I don't understand the command. Try `!help [command]`"));
}
}
var bot_secret_token = fs.readFileSync("/etc/brickbot.token", "utf-8").replace(/\n$/, "");
bot.login(bot_secret_token);