-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
65 lines (54 loc) · 2.08 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
require("dotenv").config();
const fs = require("fs");
const Discord = require("discord.js");
const prefix = "-";
const client = new Discord.Client();
const commandFiles = fs.readdirSync("./commands").filter((file) => file.endsWith(".js"));
client.commands = new Discord.Collection();
const db = require("./database");
const { Octokit } = require("@octokit/core");
const { restEndpointMethods } = require("@octokit/plugin-rest-endpoint-methods");
const MyOctokit = Octokit.plugin(restEndpointMethods);
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once("ready", () => {
console.log("GitCord Bot is online");
});
// taking in the commands
client.on("message", (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(" ");
const command = args.shift().toLowerCase();
// Message and Command logging
console.log("Message is:", message.content);
console.log("Command is:", command);
if (!client.commands.has(command)) {
console.log("Command does not exist.");
return;
}
if (command !== "lighthouse" && command !== "tech-stack" && command !== "help" && command !== "github-info" && command !== 'github-delete-token') {
try {
db.fetchGit(message.author.id)
.then((result) => {
// fetch GitHub token and initialize Octokit
let octokit = new MyOctokit({ auth: result });
client.commands.get(command).execute(command, message, args, octokit);
})
.catch((err) => {
console.error(err);
return message.reply(
"Your GitHub token isn't on file. Run -github-info, specifying your GitHub token (and then try this again)"
);
});
} catch (error) {
console.error(error);
message.reply("There was an error trying to execute that command. Please try again.");
}
} else {
client.commands.get(command).execute(command, message, args);
}
});
// bot token
client.login(process.env.DISCORD_TOKEN);