-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
169 lines (151 loc) · 4.68 KB
/
index.ts
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
const BOOT = new Date().getTime();
import { SlashCommandBuilder } from "@discordjs/builders";
import { REST } from "@discordjs/rest";
import { ChannelType, Routes } from "discord-api-types/v10";
import { ActivityType, Client, IntentsBitField } from "discord.js";
import { readFileSync, readdirSync } from "fs";
import type { Config, ExtendedClient } from "./types";
import Logger from "./utils/Logger";
import Webserver from "./utils/Webserver";
import prisma from "./lib/prisma";
const bot: ExtendedClient = new Client({
presence: {
status: "online",
activities: [
{
name: `SpigotMC`,
type: ActivityType.Watching,
},
],
},
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildEmojisAndStickers,
],
}) as ExtendedClient;
bot.version = "1.3";
bot.config = JSON.parse(readFileSync("config.json", "utf-8")) as Config;
bot.logger = new Logger(console.log);
bot.commands = [
new SlashCommandBuilder()
.setName("plugin")
.setDescription("Retrieves the information of a plugin")
.addStringOption((option) =>
option
.setName("plugin")
.setDescription("The plugin name")
.setRequired(true)
)
.toJSON(),
new SlashCommandBuilder()
.setName("add")
.setDescription("Adds a plugin to the list to check")
.addIntegerOption((option) =>
option.setName("plugin").setDescription("The plugin id").setRequired(true)
)
.addChannelOption((option) =>
option
.setName("channel")
.setDescription("The channel id")
.setRequired(true)
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildNews)
)
.addRoleOption((option) =>
option
.setName("ping")
.setDescription("The role to ping when a new update is released")
.setRequired(false)
)
.toJSON(),
new SlashCommandBuilder()
.setName("remove")
.setDescription("Removes a plugin from the list to check")
.addIntegerOption((option) =>
option.setName("plugin").setDescription("The plugin id").setRequired(true)
)
.toJSON(),
new SlashCommandBuilder()
.setName("list")
.setDescription("Retrieves the list that the bot checks")
.toJSON(),
new SlashCommandBuilder()
.setName("addowner")
.setDescription("Adds all the plugins of an user to the list to check")
.addIntegerOption((option) =>
option.setName("user").setDescription("The user id").setRequired(true)
)
.addChannelOption((option) =>
option
.setName("channel")
.setDescription("The channel id")
.setRequired(true)
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildNews)
)
.addRoleOption((option) =>
option
.setName("ping")
.setDescription("The role to ping when a new update is released")
.setRequired(false)
)
.toJSON(),
new SlashCommandBuilder()
.setName("checknow")
.setDescription("Forces the check of updates")
.toJSON(),
new SlashCommandBuilder()
.setName("status")
.setDescription("Retrieves the stauts of the bot")
.toJSON(),
];
bot.restAPI = new REST({ version: "9" }).setToken(bot.config.token);
bot.on("ready", () => {
bot.logger.info(`Logged in as ${bot.user?.tag}.`);
bot.logger.info(
`You can invite the bot with the following link: https://discord.com/api/oauth2/authorize?client_id=${
bot.user!.id
}&permissions=537151488&scope=bot%20applications.commands`
);
readdirSync("modules")
.map((mod) => {
bot.logger.info("[+] Loaded " + mod);
return `./modules/${mod}`;
})
.map((mod) => require(mod))
.forEach((mod) => mod.default(bot));
(async () => {
bot.guilds.cache.forEach((guild) => {
try {
bot.restAPI
.put(Routes.applicationGuildCommands(bot.user!.id, guild.id), {
body: bot.commands,
})
.catch((err) =>
bot.logger.error(
"Error while trying to load commands. Are you missing the Commands permission?"
)
);
} catch (error) {
bot.logger.error(
"Error while trying to load commands. Are you missing the Commands permission?"
);
}
});
bot.logger.info("[+] Loaded commands");
})();
if (bot.config.api.enabled) {
bot.logger.info("[+] Starting API server");
bot.pluginCount = 0;
prisma.plugin.count().then((count) => {
bot.pluginCount = count;
});
new Webserver(bot).start();
}
bot.logger.info("[+] Loaded all modules");
bot.logger.info(
"[+] Ready in " + (new Date().getTime() - BOOT) / 1000 + " seconds!"
);
});
prisma.$connect().then(() => {
bot.login(bot.config.token);
});