This commit is contained in:
cirroskais 2024-03-06 01:28:47 -05:00
parent 1ba9890227
commit 16e46a4ccb
No known key found for this signature in database
GPG key ID: 5FC73EBF2678E33D
9 changed files with 95 additions and 97 deletions

View file

@ -1 +1,12 @@
TOKEN= DISCORD_TOKEN=
MINECRAFT_VERSION=
MOD_LOADER=
# Modloaders
# 0 = Any
# 1 = Forge
# 2 = Cauldron
# 3 = LiteLoader
# 4 = Fabric
# 5 = Quilt
# 6 = NeoForge

View file

@ -1,33 +1,33 @@
import BaseCommand from "../lib/classes/BaseCommand" import BaseCommand from "../lib/classes/BaseCommand";
import { addMod, getAllMods, getAttribute, removeMod, updateAttribute, updateChangelog } from "../lib/database" import { addMod, getAttribute, removeMod, updateAttribute, updateChangelog } from "../lib/database";
import { staged } from "../lib/modpack" import { staged } from "../lib/modpack";
export default class Command extends BaseCommand { export default class Command extends BaseCommand {
static type = 1 static type = 1;
static name = "publish" static name = "publish";
static description = "Publish the changes from staging" static description = "Publish the changes from staging";
constructor(data) { constructor(data) {
super(data) super(data);
} }
async run(interaction) { async run(interaction) {
if (!staged.size) return interaction.respond("There is nothing to publish.") if (!staged.size) return interaction.respond("There is nothing to publish.");
const currentVersion = Number(getAttribute.get("version").value) const currentVersion = Number(getAttribute.get("version").value);
const nextVersion = currentVersion + 1 const nextVersion = currentVersion + 1;
let changelog = [] let changelog = [];
for (let [key, value] of staged.entries()) { for (let [key, value] of staged.entries()) {
if (value.action == "remove") removeMod.run(value.modId) if (value.action == "remove") removeMod.run(value.modId);
if (value.action == "add") addMod.run(key, Number(value.modId), Number(value.fileId)) if (value.action == "add") addMod.run(key, Number(value.modId), Number(value.fileId));
updateChangelog.run(key, nextVersion, value.action == "remove" ? 0 : 1) updateChangelog.run(key, nextVersion, value.action == "remove" ? 0 : 1);
staged.delete(key) staged.delete(key);
} }
updateAttribute.run("version", nextVersion) updateAttribute.run("version", nextVersion);
interaction.respond(`Version **${nextVersion}** was published.`) interaction.respond(`Version **${nextVersion}** was published.`);
} }
} }

View file

@ -1,37 +1,37 @@
import { InteractionResponseTypes } from "@discordeno/types" import * as curseforge from "../lib/curseforge";
import * as curseforge from "../lib/curseforge" import { staged } from "../lib/modpack";
import REST from "../lib/handlers/RESTHandler" import { getMod } from "../lib/database";
import { staged } from "../lib/modpack"
import { getMod } from "../lib/database"
export default class Command { export default class Command {
static name = "addMod" static name = "addMod";
constructor(data) {} constructor(data) {}
async run(interaction) { async run(interaction) {
const params = new URLSearchParams(interaction.data.customId) const params = new URLSearchParams(interaction.data.customId);
const modId = params.get("modId") const modId = params.get("modId");
const fileId = params.get("fileId") const fileId = params.get("fileId");
const provider = params.get("provider") const provider = params.get("provider");
if (provider == "curseforge") { if (provider == "curseforge") {
const mod = await curseforge.getModFromId(modId) 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 (staged.get(mod.data.name))
if (getMod.get(mod.data.name)) return interaction.respond(`**${mod.data.name}** is already in the modpack.`, { isPrivate: true }) 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, { staged.set(mod.data.name, {
modId, modId,
fileId, fileId,
provider, provider,
url: mod.data.links.websiteUrl, url: mod.data.links.websiteUrl,
action: "add", action: "add",
}) });
interaction.respond(`Added **${mod.data.name}** to the staged mods.`) interaction.respond(`Added **${mod.data.name}** to the staged mods.`);
} else { } else {
interaction.respond("Not implemented for provider " + provider) interaction.respond("Not implemented for provider " + provider);
} }
} }
} }

View file

@ -1,4 +1,4 @@
import { createBot, Intents, logger } from "@discordeno/bot"; import { createBot } from "@discordeno/bot";
import EventHandler from "./lib/handlers/EventHandler"; import EventHandler from "./lib/handlers/EventHandler";

View file

@ -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" const Commands = new CommandHandler();
import AutocompleteHandler from "../lib/handlers/AutocompleteHandler"
import ComponentHandler from "../lib/handlers/ComponentHandler"
const Commands = new CommandHandler()
await Commands.load((cmd) => { 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) => { 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) => { await Autocomplete.load((comp) => {
console.log("Loaded autocomplete response " + comp.name) console.log("Loaded autocomplete response " + comp.name);
}) });
export default async function (client, interaction) { export default async function (client, interaction) {
if (interaction.type == 2) return Commands.check(client, interaction) if (interaction.type == 2) return Commands.check(client, interaction);
if (interaction.type == 3) return Components.check(client, interaction) if (interaction.type == 3) return Components.check(client, interaction);
if (interaction.type == 4) return Autocomplete.check(client, interaction) if (interaction.type == 4) return Autocomplete.check(client, interaction);
} }

View file

@ -1,5 +1,3 @@
import { logger } from "@discordeno/utils"
export default async function (client, payload) { 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}`);
} }

View file

@ -1,14 +1,17 @@
import { cfModCache, cfModFilesCache, cfModIdCache, cfModFileCache } from "./cache"; import { cfModCache, cfModFilesCache, cfModIdCache, cfModFileCache } from "./cache";
const BASE_URL = "https://api.curseforge.com"; 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 SEARCH_MODS = "/v1/mods/search";
const GET_FILES = "/v1/mods/{modId}/files"; const GET_FILES = "/v1/mods/{modId}/files";
const GET_MOD = "/v1/mods/{modId}"; const GET_MOD = "/v1/mods/{modId}";
const GET_FILE = "/v1/mods/{modId}/files/{fileId}"; const GET_FILE = "/v1/mods/{modId}/files/{fileId}";
const GAME_ID = 432; export async function getMod(url) {
export async function getMod(url, gameVersion = "1.18.2", modLoaderType = 1) {
url = url.split("/"); url = url.split("/");
const slug = url[url.length - 1]; 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("gameId", GAME_ID);
query.append("slug", slug); query.append("slug", slug);
query.append("pageSize", 1); query.append("pageSize", 1);
if (gameVersion) query.append("gameVersion", gameVersion); query.append("gameVersion", GAME_VERSION);
if (modLoaderType) query.append("modLoaderType", modLoaderType); query.append("modLoaderType", MOD_LOADER);
const response = await fetch(BASE_URL + SEARCH_MODS + "?" + query.toString(), { const response = await fetch(BASE_URL + SEARCH_MODS + "?" + query.toString(), {
headers: { headers: {
"x-api-key": import.meta.env.CURSEFORGE_API, "x-api-key": API_KEY,
}, },
}).catch((e) => console.log(e)); }).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), { const response = await fetch(BASE_URL + GET_MOD.replace("{modId}", modId), {
headers: { headers: {
"x-api-key": import.meta.env.CURSEFORGE_API, "x-api-key": API_KEY,
}, },
}).catch((e) => console.log(e)); }).catch((e) => console.log(e));
@ -47,16 +50,16 @@ export async function getModFromId(modId) {
return data; 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); if (cfModFilesCache.get(modId)) return cfModFilesCache.get(modId);
const query = new URLSearchParams(); const query = new URLSearchParams();
if (gameVersion) query.append("gameVersion", gameVersion); query.append("gameVersion", GAME_VERSION);
if (modLoaderType) query.append("modLoaderType", modLoaderType); query.append("modLoaderType", MOD_LOADER);
const response = await fetch(BASE_URL + GET_FILES.replace("{modId}", modId) + "?" + query.toString(), { const response = await fetch(BASE_URL + GET_FILES.replace("{modId}", modId) + "?" + query.toString(), {
headers: { headers: {
"x-api-key": import.meta.env.CURSEFORGE_API, "x-api-key": API_KEY,
}, },
}).catch((e) => console.log(e)); }).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), { const response = await fetch(BASE_URL + GET_FILE.replace("{modId}", modId).replace("{fileId}", fileId), {
headers: { headers: {
"x-api-key": import.meta.env.CURSEFORGE_API, "x-api-key": API_KEY,
}, },
}).catch((e) => console.log(e)); }).catch((e) => console.log(e));

View file

@ -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) {}

View file

@ -1,3 +0,0 @@
export async function getMod(id) {}
export async function downloadMod(id) {}