This repository has been archived by the owner on Sep 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
247 lines (216 loc) · 7.97 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
const fs = require("node:fs");
const path = require("node:path");
const {
Client,
Collection,
GatewayIntentBits,
EmbedBuilder,
ModalBuilder,
TextInputBuilder,
TextInputStyle,
ActionRowBuilder,
ActivityType,
PermissionsBitField,
} = require("discord.js");
const { success } = require("./functions/logger");
const {
loadJiraJavaVersions,
updateJiraJavaVersions,
} = require("./functions/jira-java");
/*const {
loadJiraBedrockVersions,
updateJiraBedrockVersions,
} = require("./functions/jira-bedrock");*/
const { loadJavaVersions, updateJavaVersions } = require("./functions/java");
const {
loadBedrockVersions,
updateBedrockVersions,
} = require("./functions/bedrock");
const { sendErrorMessage } = require("./functions/errorHandler");
require("dotenv").config();
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.commands = new Collection();
const commandsPath = path.join(__dirname, "commands");
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
}
client.once("ready", async () => {
if (!fs.existsSync("./data")) {
fs.mkdirSync("./data");
}
fs.writeFile("./data/data.sqlite", "", { flag: "wx" }, function (err) {
if (err) {
return;
}
});
console.log(`${success} ${client.user.tag} is online`);
client.user.setActivity('/track-updates', { type: ActivityType.Listening });
if (process.env.DISABLE_UPDATE_CHECKER.toLowerCase() == "false") {
await loadJiraJavaVersions();
//await loadJiraBedrockVersions();
await loadJavaVersions();
await loadBedrockVersions();
setInterval(async () => {
await updateJiraJavaVersions(client);
//await updateJiraBedrockVersions(client);
await updateBedrockVersions(client);
}, 60000);
setInterval(async () => {
await updateJavaVersions(client);
}, 120000);
}
});
client.on("guildCreate", async (guild) => {
const embed = new EmbedBuilder()
.setTitle(`Thanks for adding me to ${guild.name}!`)
.setDescription("Use the /track-updates command to get started")
.setColor("#5865f2")
.setThumbnail(client.user.displayAvatarURL())
.setTimestamp();
if (!guild.members.me.permissions.has([PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.EmbedLinks, PermissionsBitField.Flags.AttachFiles, PermissionsBitField.Flags.ReadMessageHistory, PermissionsBitField.Flags.UseExternalEmojis])) {
embed
.setDescription("You didn't give me enough permissions to work properly on this server, please remove and invite me again")
.setColor("#ff6666")
}
if (guild.systemChannel && guild.systemChannel.permissionsFor(guild.members.me).has([PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.EmbedLinks, PermissionsBitField.Flags.ViewChannel]))
guild.systemChannel.send({ embeds: [embed] })
else {
// If the bot doesn't have enough permissions or the system channel doesn't exist, try to DM the server owner
try {
const guildOwner = await client.users.fetch(guild.ownerId);
guildOwner.send({ embeds: [embed] })
}
catch (e) {
// If the server owner has DM's disabled, try to send the welcome message to the first channel it can find
// if that fails, then the bot inviter was so stupid that they literally didn't give the bot any permissions
const firstChannel = guild.channels.cache.find(channel => channel.type === 'GUILD_TEXT' && channel.permissionsFor(guild.members.me).has([PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.EmbedLinks, PermissionsBitField.Flags.ViewChannel]))
if (firstChannel) firstChannel.send({ embeds: [embed] })
}
}
})
client.on("interactionCreate", async (interaction) => {
if (interaction.isChatInputCommand()) {
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, client);
} catch (error) {
const embed = new EmbedBuilder()
.setTitle(
`There has been an error while executing this command!`
)
.setDescription(
"The error has been sent to the developers.\n\nIf you know what exactly caused the error, please create a bug report using the `/feedback` command."
)
.setColor("#ff6666")
.setTimestamp();
await interaction.reply({
embeds: [embed],
ephemeral: true,
});
await sendErrorMessage(
client,
error,
`command: ${interaction.commandName}`
);
}
} else if (interaction.isButton()) {
if (interaction.channel.id !== process.env.REPORTS_CHANNEL) return;
const origin_channel_id =
interaction.message.embeds[0].footer.text.split(" - ")[0];
const origin_message_id =
interaction.message.embeds[0].footer.text.split(" - ")[1];
const origin_message = await client.channels.cache
.get(origin_channel_id)
.messages.fetch(origin_message_id);
let embed_user = new EmbedBuilder(
origin_message.embeds[0].data
).setTimestamp();
let embed_dev = new EmbedBuilder(
interaction.message.embeds[0].data
).setTimestamp();
if (interaction.customId === "implemented") {
embed_user
.setTitle("Feedback status: implemented")
.setColor("#42b983")
.setFooter({ text: "\u200B" });
embed_dev.setColor("#42b983");
await interaction.reply({
content: "Feedback status has been set to `implemented`",
ephemeral: true,
});
} else if (interaction.customId === "close") {
const modal = new ModalBuilder()
.setCustomId("reasonModal")
.setTitle("Reason for closing");
const reasonInput = new TextInputBuilder()
.setCustomId("reasonInput")
.setLabel("Reason")
.setStyle(TextInputStyle.Short);
const actionRow = new ActionRowBuilder().addComponents(reasonInput);
modal.addComponents(actionRow);
await interaction.showModal(modal);
const submitted = await interaction.awaitModalSubmit({
time: 60000 * 3,
filter: (i) => i.user.id === interaction.user.id,
});
if (submitted) {
embed_user.setDescription(
`Reason for closing: \`${submitted.fields.getTextInputValue(
"reasonInput"
)}\`\n\n${origin_message.embeds[0].data.description}`
);
submitted.reply({
content: "Reason for closing has been sent.",
ephemeral: true,
});
}
embed_user
.setTitle("Feedback status: closed")
.setColor("#ff6666")
.setFooter({ text: "\u200B" });
embed_dev.setColor("#ff6666");
} else {
// "in progress" button
embed_user
.setTitle("Feedback status: in progress")
.setColor("#5865f2");
embed_dev.setColor("#5865f2");
interaction.reply({
content: "Feedback status has been set to `in progress`",
ephemeral: true,
});
}
await origin_message.edit({ embeds: [embed_user] });
await interaction.message.edit({ embeds: [embed_dev] });
} else return;
});
client.on("messageCreate", async (message) => {
if (message.author.bot) return;
if (message.author.id !== process.env.OWNER_ID) return;
if (message.content.startsWith("m!eval")) {
const clean = async (text) => {
if (text && text.constructor.name === "Promise") text = await text;
if (typeof text !== "string") text = require("util").inspect(text, { depth: 1 });
text = text
.replaceAll(process.env.TOKEN, "[CENSORED]")
.replaceAll(process.env.ERROR_CHANNEL, "[CENSORED]")
.replaceAll(process.env.REPORTS_CHANNEL, "[CENSORED]")
.replace(/`/g, "`" + String.fromCharCode(8203))
.replace(/@/g, "@" + String.fromCharCode(8203));
return text;
};
const code = message.content.slice(6)
const evaluated = await eval(`(async () => { try { return await (async () => {${code.includes('return') ? code : `return ${code}`}})() } catch (e) { return e } })()`);
await message.reply({ content: `\`\`\`js\n${(await clean(evaluated)).slice(0, 4085)}\`\`\`` })
}
})
process.on("uncaughtException", async function (error) {
await sendErrorMessage(client, error);
});
client.login(process.env.TOKEN);