-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (51 loc) · 1.68 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
// importing modules
const Discord = require("discord.js");
const http = require("http");
// importing files
const config = require("./config.json") // config file
const tempus = require("./tempus.js"); // actually does the things
const helpers = require("./helpers.js"); // bunch of helper functions
// Connections
const client = new Discord.Client();
const server = http.createServer( (request, response) => {
console.log("I HAVE BEEN POKED");
if (request.method == "POST") {
// if POST method used
request.on("data", data => {
const commands = JSON.parse(data.toString());
commands.forEach(command => {
// find function
if (tempus.hasOwnProperty(command[0])) {
// stores the function
const func = tempus[command[0]];
// replaces the function name with the client
command[0] = client;
// applies args and executes
try { func.apply(null, command); }
catch (err) { console.error(`Error while executing ${command[0]}: ${err}`); }
} else
console.error(`Couldn't find function: ${command[0]}`);
});
});
}
});
var port = 3000;
var host = "127.0.0.1";
server.listen(port, host);
console.log(`Listening at http://${host}:${port}`);
// starting actions
client.on("ready", evnt => {
console.log("Bot started");
});
// load commands
client.on("message", message => {
if (message.content[0] !== config.prefix) return; // ignores non-commands
// "!roll test 1 2" => { "command": "roll", "args": ["test", 1, 2] }
const details = helpers.proccessCommand(message);
// actual running
helpers.run(details.command, client, message, details.args);
// logging
helpers.log(details.command, details.args);
});
// login
client.login(config.token);