diff --git a/.env.example b/.env.example index f74c661..628d717 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,12 @@ -TOKEN= \ No newline at end of file +DISCORD_TOKEN= +MINECRAFT_VERSION= +MOD_LOADER= + +# Modloaders +# 0 = Any +# 1 = Forge +# 2 = Cauldron +# 3 = LiteLoader +# 4 = Fabric +# 5 = Quilt +# 6 = NeoForge \ No newline at end of file diff --git a/src/commands/publish.js b/src/commands/publish.js index f494793..d109fe1 100644 --- a/src/commands/publish.js +++ b/src/commands/publish.js @@ -1,33 +1,33 @@ -import BaseCommand from "../lib/classes/BaseCommand" -import { addMod, getAllMods, getAttribute, removeMod, updateAttribute, updateChangelog } from "../lib/database" -import { staged } from "../lib/modpack" +import BaseCommand from "../lib/classes/BaseCommand"; +import { addMod, getAttribute, removeMod, updateAttribute, updateChangelog } from "../lib/database"; +import { staged } from "../lib/modpack"; export default class Command extends BaseCommand { - static type = 1 - static name = "publish" - static description = "Publish the changes from staging" + static type = 1; + static name = "publish"; + static description = "Publish the changes from staging"; - constructor(data) { - super(data) - } + constructor(data) { + super(data); + } - async run(interaction) { - if (!staged.size) return interaction.respond("There is nothing to publish.") + async run(interaction) { + if (!staged.size) return interaction.respond("There is nothing to publish."); - const currentVersion = Number(getAttribute.get("version").value) - const nextVersion = currentVersion + 1 + const currentVersion = Number(getAttribute.get("version").value); + const nextVersion = currentVersion + 1; - let changelog = [] + let changelog = []; - for (let [key, value] of staged.entries()) { - if (value.action == "remove") removeMod.run(value.modId) - if (value.action == "add") addMod.run(key, Number(value.modId), Number(value.fileId)) - updateChangelog.run(key, nextVersion, value.action == "remove" ? 0 : 1) - staged.delete(key) - } + for (let [key, value] of staged.entries()) { + if (value.action == "remove") removeMod.run(value.modId); + if (value.action == "add") addMod.run(key, Number(value.modId), Number(value.fileId)); + updateChangelog.run(key, nextVersion, value.action == "remove" ? 0 : 1); + staged.delete(key); + } - updateAttribute.run("version", nextVersion) + updateAttribute.run("version", nextVersion); - interaction.respond(`Version **${nextVersion}** was published.`) - } + interaction.respond(`Version **${nextVersion}** was published.`); + } } diff --git a/src/components/addMod.js b/src/components/addMod.js index f94b17b..1a18516 100644 --- a/src/components/addMod.js +++ b/src/components/addMod.js @@ -1,37 +1,37 @@ -import { InteractionResponseTypes } from "@discordeno/types" -import * as curseforge from "../lib/curseforge" -import REST from "../lib/handlers/RESTHandler" -import { staged } from "../lib/modpack" -import { getMod } from "../lib/database" +import * as curseforge from "../lib/curseforge"; +import { staged } from "../lib/modpack"; +import { getMod } from "../lib/database"; export default class Command { - static name = "addMod" + static name = "addMod"; - constructor(data) {} + constructor(data) {} - async run(interaction) { - const params = new URLSearchParams(interaction.data.customId) - const modId = params.get("modId") - const fileId = params.get("fileId") - const provider = params.get("provider") + async run(interaction) { + const params = new URLSearchParams(interaction.data.customId); + const modId = params.get("modId"); + const fileId = params.get("fileId"); + const provider = params.get("provider"); - if (provider == "curseforge") { - const mod = await curseforge.getModFromId(modId) + if (provider == "curseforge") { + const mod = await curseforge.getModFromId(modId); - if (staged.get(mod.data.name)) return interaction.respond(`**${mod.data.name}** is already in the staged mods.`, { isPrivate: true }) - if (getMod.get(mod.data.name)) return interaction.respond(`**${mod.data.name}** is already in the modpack.`, { isPrivate: true }) + if (staged.get(mod.data.name)) + return interaction.respond(`**${mod.data.name}** is already in the staged mods.`, { isPrivate: true }); + if (getMod.get(mod.data.name)) + return interaction.respond(`**${mod.data.name}** is already in the modpack.`, { isPrivate: true }); - staged.set(mod.data.name, { - modId, - fileId, - provider, - url: mod.data.links.websiteUrl, - action: "add", - }) + staged.set(mod.data.name, { + modId, + fileId, + provider, + url: mod.data.links.websiteUrl, + action: "add", + }); - interaction.respond(`Added **${mod.data.name}** to the staged mods.`) - } else { - interaction.respond("Not implemented for provider " + provider) - } - } + interaction.respond(`Added **${mod.data.name}** to the staged mods.`); + } else { + interaction.respond("Not implemented for provider " + provider); + } + } } diff --git a/src/discord.js b/src/discord.js index 2fbec83..0bb83fb 100644 --- a/src/discord.js +++ b/src/discord.js @@ -1,4 +1,4 @@ -import { createBot, Intents, logger } from "@discordeno/bot"; +import { createBot } from "@discordeno/bot"; import EventHandler from "./lib/handlers/EventHandler"; diff --git a/src/events/interactionCreate.js b/src/events/interactionCreate.js index 332a4d5..2a42546 100644 --- a/src/events/interactionCreate.js +++ b/src/events/interactionCreate.js @@ -1,26 +1,24 @@ -import { logger } from "@discordeno/utils" +import CommandHandler from "../lib/handlers/CommandHandler"; +import AutocompleteHandler from "../lib/handlers/AutocompleteHandler"; +import ComponentHandler from "../lib/handlers/ComponentHandler"; -import CommandHandler from "../lib/handlers/CommandHandler" -import AutocompleteHandler from "../lib/handlers/AutocompleteHandler" -import ComponentHandler from "../lib/handlers/ComponentHandler" - -const Commands = new CommandHandler() +const Commands = new CommandHandler(); await Commands.load((cmd) => { - console.log("Loaded command " + cmd.name) -}) + console.log("Loaded command " + cmd.name); +}); -const Components = new ComponentHandler() +const Components = new ComponentHandler(); await Components.load((comp) => { - console.log("Loaded component response " + comp.name) -}) + console.log("Loaded component response " + comp.name); +}); -const Autocomplete = new AutocompleteHandler() +const Autocomplete = new AutocompleteHandler(); await Autocomplete.load((comp) => { - console.log("Loaded autocomplete response " + comp.name) -}) + console.log("Loaded autocomplete response " + comp.name); +}); export default async function (client, interaction) { - if (interaction.type == 2) return Commands.check(client, interaction) - if (interaction.type == 3) return Components.check(client, interaction) - if (interaction.type == 4) return Autocomplete.check(client, interaction) + if (interaction.type == 2) return Commands.check(client, interaction); + if (interaction.type == 3) return Components.check(client, interaction); + if (interaction.type == 4) return Autocomplete.check(client, interaction); } diff --git a/src/events/ready.js b/src/events/ready.js index b0ed572..f495f0f 100644 --- a/src/events/ready.js +++ b/src/events/ready.js @@ -1,5 +1,3 @@ -import { logger } from "@discordeno/utils" - export default async function (client, payload) { - console.log(`Logged into ${payload.user.username} on shard ${payload.shardId}`) + console.log(`Logged into ${payload.user.username} on shard ${payload.shardId}`); } diff --git a/src/lib/curseforge.js b/src/lib/curseforge.js index d904dff..d34fbae 100644 --- a/src/lib/curseforge.js +++ b/src/lib/curseforge.js @@ -1,14 +1,17 @@ import { cfModCache, cfModFilesCache, cfModIdCache, cfModFileCache } from "./cache"; const BASE_URL = "https://api.curseforge.com"; +const API_KEY = "$2a$10$bL4bIL5pUWqfcO7KQtnMReakwtfHbNKh6v1uTpKlzhwoueEJQnPnm"; +const GAME_ID = 432; +const GAME_VERSION = import.meta.env.GAME_VERSION; +const MOD_LOADER = import.meta.env.MOD_LOADER; + const SEARCH_MODS = "/v1/mods/search"; const GET_FILES = "/v1/mods/{modId}/files"; const GET_MOD = "/v1/mods/{modId}"; const GET_FILE = "/v1/mods/{modId}/files/{fileId}"; -const GAME_ID = 432; - -export async function getMod(url, gameVersion = "1.18.2", modLoaderType = 1) { +export async function getMod(url) { url = url.split("/"); const slug = url[url.length - 1]; @@ -18,12 +21,12 @@ export async function getMod(url, gameVersion = "1.18.2", modLoaderType = 1) { query.append("gameId", GAME_ID); query.append("slug", slug); query.append("pageSize", 1); - if (gameVersion) query.append("gameVersion", gameVersion); - if (modLoaderType) query.append("modLoaderType", modLoaderType); + query.append("gameVersion", GAME_VERSION); + query.append("modLoaderType", MOD_LOADER); const response = await fetch(BASE_URL + SEARCH_MODS + "?" + query.toString(), { headers: { - "x-api-key": import.meta.env.CURSEFORGE_API, + "x-api-key": API_KEY, }, }).catch((e) => console.log(e)); @@ -37,7 +40,7 @@ export async function getModFromId(modId) { const response = await fetch(BASE_URL + GET_MOD.replace("{modId}", modId), { headers: { - "x-api-key": import.meta.env.CURSEFORGE_API, + "x-api-key": API_KEY, }, }).catch((e) => console.log(e)); @@ -47,16 +50,16 @@ export async function getModFromId(modId) { return data; } -export async function getModFiles(modId, gameVersion = "1.18.2", modLoaderType = 1) { +export async function getModFiles(modId) { if (cfModFilesCache.get(modId)) return cfModFilesCache.get(modId); const query = new URLSearchParams(); - if (gameVersion) query.append("gameVersion", gameVersion); - if (modLoaderType) query.append("modLoaderType", modLoaderType); + query.append("gameVersion", GAME_VERSION); + query.append("modLoaderType", MOD_LOADER); const response = await fetch(BASE_URL + GET_FILES.replace("{modId}", modId) + "?" + query.toString(), { headers: { - "x-api-key": import.meta.env.CURSEFORGE_API, + "x-api-key": API_KEY, }, }).catch((e) => console.log(e)); @@ -71,7 +74,7 @@ export async function downloadMod(modId, fileId) { const response = await fetch(BASE_URL + GET_FILE.replace("{modId}", modId).replace("{fileId}", fileId), { headers: { - "x-api-key": import.meta.env.CURSEFORGE_API, + "x-api-key": API_KEY, }, }).catch((e) => console.log(e)); diff --git a/src/lib/modpack.js b/src/lib/modpack.js deleted file mode 100644 index 324a0aa..0000000 --- a/src/lib/modpack.js +++ /dev/null @@ -1,9 +0,0 @@ -import * as modrinth from "./modrinth" -import * as curseforge from "./curseforge" - -export let staged = new Map() -export let cache = new Map() - -export async function publishChanges() {} - -export async function getChanges(x, y) {} diff --git a/src/lib/modrinth.js b/src/lib/modrinth.js deleted file mode 100644 index f4ddaf9..0000000 --- a/src/lib/modrinth.js +++ /dev/null @@ -1,3 +0,0 @@ -export async function getMod(id) {} - -export async function downloadMod(id) {}