Wow!
This commit is contained in:
parent
1ba9890227
commit
16e46a4ccb
9 changed files with 95 additions and 97 deletions
13
.env.example
13
.env.example
|
@ -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
|
|
@ -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.`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { createBot, Intents, logger } from "@discordeno/bot";
|
||||
import { createBot } from "@discordeno/bot";
|
||||
|
||||
import EventHandler from "./lib/handlers/EventHandler";
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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}`);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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) {}
|
|
@ -1,3 +0,0 @@
|
|||
export async function getMod(id) {}
|
||||
|
||||
export async function downloadMod(id) {}
|
Loading…
Reference in a new issue