Skip to content

Commit dbf4a1a

Browse files
authored
Create 1.21.js
1 parent e49a1f0 commit dbf4a1a

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

src/commands/1.21.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
const { Command } = require('@sapphire/framework');
2+
const { PermissionFlagsBits, EmbedBuilder } = require('discord.js');
3+
const fs = require('fs');
4+
const path = require('path');
5+
const { curseforgeApiKey } = require('../config.json');
6+
const { ModrinthV2Client } = require('@xmcl/modrinth');
7+
const { Curseforge } = require('node-curseforge');
8+
const mods = JSON.parse(fs.readFileSync(path.join(__dirname, '../mods.json'), 'utf8'));
9+
const client = new ModrinthV2Client();
10+
let cf = new Curseforge(curseforgeApiKey);
11+
12+
class UserCommand extends Command {
13+
/**
14+
* @param {Command.LoaderContext} context
15+
*/
16+
constructor(context) {
17+
super(context, {
18+
// Any Command options you want here
19+
name: 'update-check',
20+
description: 'List mods for 1.21'
21+
});
22+
}
23+
24+
/**
25+
* @param {Command.Registry} registry
26+
*/
27+
registerApplicationCommands(registry) {
28+
registry.registerChatInputCommand((builder) =>
29+
builder //
30+
.setName(this.name)
31+
.setDescription(this.description)
32+
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
33+
);
34+
}
35+
36+
/**
37+
* @param {Command.ChatInputCommandInteraction} interaction
38+
*/
39+
async chatInputRun(interaction) {
40+
// Initialize an empty array to hold mod status messages
41+
let mod_status = [];
42+
43+
// Process each mod asynchronously using Promise.all to wait for all to complete
44+
await Promise.all(
45+
mods.map(async (mod) => {
46+
if (mod.source === 'curseforge') {
47+
try {
48+
const addon = await cf.get_mod(mod.id);
49+
if (addon.latestFiles[0].gameVersions[0].includes('1.21')) {
50+
mod_status.push(`✅- Mod ${addon.name} has a 1.21 version`);
51+
} else {
52+
mod_status.push(`❌-Mod ${addon.name} does not have a 1.21 version`);
53+
}
54+
} catch (err) {
55+
console.error(err);
56+
}
57+
} else if (mod.source === 'modrinth') {
58+
try {
59+
const data = await client.getProject(mod.id);
60+
if (data.game_versions.includes('1.21.6')) {
61+
mod_status.push(`✅- Mod ${data.title} has a 1.21 version`);
62+
} else {
63+
mod_status.push(`❌- Mod ${data.title} does not have a 1.21 version`);
64+
}
65+
} catch (err) {
66+
console.error(err);
67+
}
68+
}
69+
})
70+
);
71+
72+
// Write the final mod_status array to the 1.21.json file
73+
fs.writeFileSync(path.join(__dirname, '../1.21.json'), JSON.stringify(mod_status, null, 2));
74+
75+
// sort the array by mod status
76+
mod_status.sort();
77+
78+
// Create an embed with the mod status messages
79+
const embed = new EmbedBuilder().setTitle('Mods for 1.21').setDescription(`${mod_status.join('\n')}`);
80+
81+
// Reply with the embed
82+
await interaction.reply({ embeds: [embed] });
83+
}
84+
}
85+
86+
module.exports = {
87+
UserCommand
88+
};

0 commit comments

Comments
 (0)