forked from raymondpg/Discode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
88 lines (74 loc) · 2.34 KB
/
main.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
const DISCORD = require("discord.js");
// this is our discord bot!
const client = new DISCORD.Client();
const prefix = "~";
// importing the 'fs' package
const fs = require("fs");
client.commands = new DISCORD.Collection();
const commandfiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));
for (const file of commandfiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once("ready", () => {
console.log("Discode is online");
});
let ifStarted = false;
let currentQuestionID = -1;
let diff = 1;
let activeChannels = [];
client.on("message", (message) => {
if (message.author.bot) return;
if (message.content.startsWith("```")) {
message.content = message.content.replace("```", "");
message.content = message.content.replace("```", "");
message.content.trim();
// submit code
client.commands.get("submit").execute(message, {
activeChannels: activeChannels,
currentQuestionID: currentQuestionID,
});
}
if (!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).split(" ");
const command = args.shift().toLowerCase();
if (command === "help") {
client.commands.get("help").execute(message, args);
} else if (
command === "exit" &&
(activeChannels.includes(message.channel) ||
message.channel.name === "results")
) {
client.commands.get("exit").execute(message, args);
} else if (command === "diff") {
if (Number(args[0]) % 1 === 0 && args[0] >= 1 && args[0] <= 3) {
diff = args[0];
message.channel.send(`Difficulty has been set to ${diff}`);
} else {
message.channel.send(
"Not a valid difficulty. Valid difficulties lie between 1 and 3."
);
}
} else if (command === "begin") {
if (activeChannels.length != 0) {
message.channel.send("A competition is already in progress!");
} else {
getQuestion(message, args);
}
} else if (command === "ping") {
client.commands.get("ping").execute(message, args);
}
});
async function getQuestion(message, args) {
currentQuestionID = await client.commands.get("begin").execute(
{ message: message, client: client },
{
args: args,
activeChannels: activeChannels,
diff: diff,
}
);
}
let key = fs.readFileSync("key.txt", "utf8");