Created
June 29, 2022 21:04
-
-
Save apacheli/b01556bbb4dd057e67fff3c84d44e981 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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