Skip to content

Instantly share code, notes, and snippets.

@apacheli
Created June 29, 2022 21:04
Show Gist options
  • Save apacheli/b01556bbb4dd057e67fff3c84d44e981 to your computer and use it in GitHub Desktop.
Save apacheli/b01556bbb4dd057e67fff3c84d44e981 to your computer and use it in GitHub Desktop.
const APPDATA = Deno.env.get("APPDATA");
const VERSION = 2;
while (true) {
const input = prompt("Search for a mod:");
if (input === null) {
continue;
}
console.log("Searching...");
const response = await fetch(`https://api.modrinth.com/v${VERSION}/search?limit=1&query=${encodeURIComponent(input)}`);
const mods = await response.json();
if (mods.hits.length === 0) {
console.log("Could not find that mod. Please try again.");
continue;
}
const mod = mods.hits[0];
while (true) {
const answer = prompt(`Download ${mod.title}? (Y/N)`)?.toLowerCase();
if (answer === "y") {
console.log("Obtaining versions info...");
const response2 = await fetch(`https://api.modrinth.com/v${VERSION}/project/${mod.project_id}/version?game_version=1.19&loaders=fabric`);
const versions = await response2.json();
console.log("Downloading...");
const response3 = await fetch(versions[0].files[0].url);
const binary = new Uint8Array(await response3.arrayBuffer());
await Deno.writeFile(APPDATA + `/.minecraft/mods/${versions[0].files[0].filename}`, binary);
console.log("Done.");
break;
} else if (answer === "n") {
console.log("Okay. The mod will not be downloaded.");
break;
} else {
continue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment