diff --git a/README.md b/README.md index 30a1226..ce245a3 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ Add functions, ChatTriggers modules & more! It's an all-in-one Housing importer! | Command | Purpose | -------------------- | ------------------------------------------------------ | `/hpm` | Opens a list of all commands -| `/hpm add ` | Adds a package from the HPM Action Library, these are curated heavily +| ~~`/hpm add `~~ | ~~Adds a package from the HPM Action Library, these are curated heavily~~ +| `/hpm atlas` | Browse the mod atlas to manage your mods! | `/hpm import ` | Checks the mod atlas and downloads the mod if it's on there | `/hpm reload` | Fetches the updated version of the mod link atlas (you won't need this, unless imports break) diff --git a/index.js b/index.js index 4e273b1..5a094a4 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,15 @@ import { installModule } from './src/modImporter'; import axios from './modules/axios'; +import { formatAtlasToChat } from './src/modExplorer'; +import { viewModReleases } from './src/modReleases'; const helpMessage = new Message([ '\n', '&7&l■ HPM Commands\n', - '&7 | &e/hpm reload &8- &7Reload HPM\'s atlas to check for new mods\n', - '&7 | &e/hpm import &8- &7Import a ChatTriggers module from our atlas\n', - '&7 | &e&m/hpm install&8 -&7 &mInstall a HPM Package from our Action Library\n', - '' + '&7 | &e/hpm atlas&8 - &7Manage your HPM Atlas modules\n', + '&7 | &e/hpm import&8 - &7Import a HPM Atlas module\n', + '&7 | &e/hpm delete&8 - &7Delete a HPM Atlas module\n', + '&7 | &e&m/hpm package&8 - &7&mImport an Action Package\n' ]) let atlas = { loaded: false }; @@ -35,11 +37,20 @@ register('command', (subcommand, ...args) => { case 'import': installModule(atlas, args[0]?.toLowerCase() || undefined) break; + case 'atlas': + if (!args[0]) return formatAtlasToChat(atlas) + viewModReleases(atlas, args[0]) + break; case 'reload': ChatLib.chat('&cReloading HPM...') initialise(true) break; case 'delete': + if (args[0]=="hpm") return ChatLib.chat(new Message([ + new TextComponent("\n&cAre you sure you want to delete HPM? You'll lose out on critical patches, easy installing of modules & more!\n"), + new TextComponent('&c&lDELETE HPM\n').setHover('show_text','&cDelete HPM').setClick('run_command','/ct delete hpm') + ])) + ChatLib.command(`ct delete ${...args}`) break; default: diff --git a/src/modExplorer.js b/src/modExplorer.js new file mode 100644 index 0000000..7dc0b24 --- /dev/null +++ b/src/modExplorer.js @@ -0,0 +1,37 @@ +export function formatAtlasToChat(atlas) { + if (!atlas.loaded) return ChatLib.chat('&cHPM Atlas hasn\'t loaded yet! Please wait!') + delete atlas.loaded // Fucks with iteration, gtfo + + let components = [] + components.push('\n&7&l■ Module Atlas\n') + + Object.values(atlas).forEach(moduleData => { + components.push(`&7 | `) + + if (FileLib.exists(`./config/ChatTriggers/modules/${moduleData.name}`)) { + components.push( + new TextComponent('&c&lx ') + .setHover('show_text','&cDelete Module') + .setClick('run_command',`/hpm delete ${moduleData.name}`), + new TextComponent('&a&l+ ') + .setHover('show_text','&aCheck for Updates') + .setClick('run_command',`/hpm import ${moduleData.name}`), + ) + } else { + components.push( + new TextComponent('&8&lx ').setHover('show_text', '&7&mDelete Module'), + new TextComponent('&a&l+ ') + .setHover('show_text', '&aImport Module') + .setClick('run_command', `/hpm import ${moduleData.name}`) + ) + } + components.push( + new TextComponent(`&7| &b${moduleData.name}\n`) // kill me + .setHover('show_text', `&a${moduleData.name}\n&7by &b${moduleData.creator}\n\n&eClick to view ${Object.keys(moduleData.releases).length} release${Object.keys(moduleData.releases).length == 1 ? '' : 's'}!`) + .setClick('run_command',`/hpm atlas ${moduleData.name}`) + ) + }) + + ChatLib.chat(new Message(components).setChatLineId(694201337)) + atlas.loaded = true +} \ No newline at end of file diff --git a/src/modImporter.js b/src/modImporter.js index 6343d3b..c2d8291 100644 --- a/src/modImporter.js +++ b/src/modImporter.js @@ -8,7 +8,7 @@ export function installModule(atlas, moduleName) { moduleName = moduleName.split(':') if (!atlas[moduleName[0]]) return ChatLib.chat('&cThis module doesn\'t exist!') - let release = atlas[moduleName].releases[moduleName[1] || '$main'] // Multi version support + let release = atlas[moduleName].releases[moduleName[1] || '$default'] // Multi version support const tempId = Date.now() FileUtilities.urlToFile(release.url, `./config/ChatTriggers/modules/hpm-temp-${tempId}.zip`, 5000, 5000) diff --git a/src/modReleases.js b/src/modReleases.js new file mode 100644 index 0000000..9dd7cd0 --- /dev/null +++ b/src/modReleases.js @@ -0,0 +1,29 @@ +export function viewModReleases(atlas, moduleName) { + if (!atlas.loaded) return ChatLib.chat('&cHPM Atlas hasn\'t loaded yet! Please wait!') + if (!moduleName) return ChatLib.chat('&cPlease input a module name!') + + moduleName = moduleName.split(':')[0].toLowerCase() + const moduleData = atlas[moduleName] + + if (!moduleData) return ChatLib.chat('&cThis module doesn\'t exist!') + + let components = [ + new TextComponent('\n&7 ✖').setClick('run_command','/hpm atlas').setHover('show_text','&7Click to return to the atlas!'), + ` &7&l${moduleData.name}\n`, + `&7 | Created by: ${moduleData.creator}\n`, + ] + + Object.keys(moduleData.releases).forEach(releaseName => { + const releaseData = moduleData.releases[releaseName] + + components.push('&7 | ') + components.push( + new TextComponent('&a&l+') + .setClick('run_command',`/hpm import ${moduleName}:${releaseName}`) + .setHover('show_text', `&aImport ${moduleName}:${releaseName}`) + ) + components.push(` &7| &b${releaseName} ${releaseData.unstable ? '&6(Unstable)' : ''}\n`) + }) + + ChatLib.chat(new Message(components).setChatLineId(694201337)) +} \ No newline at end of file