diff options
| author | Christopher Gwynn <[email protected]> | 2021-05-15 23:37:16 -0400 |
|---|---|---|
| committer | Christopher Gwynn <[email protected]> | 2021-05-15 23:37:16 -0400 |
| commit | 259b082e366e7b17d7861061371aba7ec2e2db1f (patch) | |
| tree | ea300a531c496b0f50736df5500252ee9a7a54f4 | |
| parent | update zones.json (diff) | |
| download | wizard101-rpc-259b082e366e7b17d7861061371aba7ec2e2db1f.tar.xz wizard101-rpc-259b082e366e7b17d7861061371aba7ec2e2db1f.zip | |
auto updates
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | index.js | 59 | ||||
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | yarn.lock | 40 |
4 files changed, 82 insertions, 25 deletions
@@ -29,14 +29,14 @@ If a log file can't be found where expected from these locations, you will be pr The startup setting will default to `quick`, meaning Wizard101 will quick launch when Wizard101 RPC starts. ### Commands -You can type in commands to change various settings. Type in the command name, followed by an expected value. +You can type in commands to change various settings. Type in the command name followed by an expected value. - #### `path <path to wizard101>` - - Change the path of where Wizard101 RPC will read information from if it's valid + - Change the path of where Wizard101 RPC will read information from if valid - default: default location, if it exists - example: `path D:\Steam\steamapps\common\Wizard101` - #### `startup <quick|normal|none>` - - How Wizard101 will launch when Wizard101 RPC is started + - Sets how Wizard101 will launch when Wizard101 RPC is started - quick: quick launch (skip patching, instant login screen) - normal: normal launch - none: will not launch @@ -1,11 +1,13 @@ const fs = require("fs"); const path = require("path"); const readline = require("readline"); +const https = require("https"); const { exec } = require("child_process"); const readLastLines = require("read-last-lines"); const DiscordRPC = require("discord-rpc"); const zones = require(path.join(__dirname, "./zones.json")); const settings = require(path.join(__dirname, "./settings.json")); +const package = require(path.join(__dirname, "./package.json")); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, @@ -14,6 +16,7 @@ const rl = readline.createInterface({ let rpc; console.log(" _ _ __ ___ __ \n (_) | /_ |/ _ \\/_ | \n __ ___ ______ _ _ __ __| || | | | || |______ _ __ _ __ ___ \n \\ \\ /\\ / / |_ / _` | \'__/ _` || | | | || |______| \'__| \'_ \\ / __|\n \\ V V /| |/ / (_| | | | (_| || | |_| || | | | | |_) | (__ \n \\_/\\_/ |_/___\\__,_|_| \\__,_||_|\\___/ |_| |_| | .__/ \\___|\n | | \n "); +console.log("https://github.com/Bacon1661/wizard101-rpc\n"); function setPresence() { let oldLineCount, zone, world, health, activity, currentTime; @@ -22,7 +25,7 @@ function setPresence() { fs.watchFile(settings.path, { interval: 100 }, async (_curr, _prev) => { let currentLineCount = await countLines(); readLastLines.read(settings.path, currentLineCount - oldLineCount).then(async (logChunk) => { - // Get zone + // Get zone const zoneRegex = new RegExp(/zone = (.+),|CHARACTER LIST/gm); let tempZone = logChunk.match(zoneRegex); @@ -81,7 +84,43 @@ function countLines() { }); } -(async function configureSettings() { +(function updates() { + console.log("Checking for updates..."); + getJSON("https://raw.githubusercontent.com/Bacon1661/wizard101-rpc/master/package.json"); + + function getJSON(url, runConf) { + https.get(url, (res) => { + let body = ""; + + res.on("data", (data) => body += data); + + res.on("end", async () => { + try { + let file; + file = JSON.parse(body); + if(runConf) { + console.log("Updating zones.json..."); + if(file.zoneNames) await fs.writeFile(path.join(__dirname, "./zones.json"), JSON.stringify(file, null, 4), () => { /* do nothing */ }); + configureSettings(); + } else { + if(file.version !== package.version) console.log(`Version ${file.version} is available! Go here to download it: https://github.com/Bacon1661/wizard101-rpc/releases\n`); + getJSON("https://raw.githubusercontent.com/Bacon1661/wizard101-rpc/master/zones.json", true); + } + } catch(err) { + console.error(`Error accessing the GitHub repository: ${err.message}`); + if(runConf) return configureSettings(); + getJSON("https://raw.githubusercontent.com/Bacon1661/wizard101-rpc/master/zones.json", true); + } + }); + }).on("error", (err) => { + console.error(`Error accessing the GitHub repository: ${err.message}`); + if(runConf) return configureSettings(); + getJSON("https://raw.githubusercontent.com/Bacon1661/wizard101-rpc/master/zones.json", true); + }); + } +}()); + +async function configureSettings() { const defaultPath = "C:\\ProgramData\\KingsIsle Entertainment\\Wizard101\\Bin\\WizardClient.log"; const defaultSteamPath = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Wizard101\\Bin\\WizardClient.log"; @@ -97,7 +136,7 @@ function countLines() { // handle command inputs if(!settings.startup) { - console.log("No startup settings detected, using the 'quick' startup setting!\nIn the future when you want to play Wizard101 and have Discord RPC working, run this program instead and Wizard101-rpc will quick launch Wizard101 for you.\n\nYou can change this by using the 'startup' command.\nUsage: startup <quick|normal|none>\nExample Usage:\nstartup quick - Set wizard101-rpc to quick launch (skip patching, instant login) Wizard101 on startup.\nstartup normal - Set wizard101-rpc to launch Wizard101 normally on startup.\nstartup none - Set wizard101-rpc to not launch Wizard101 on startup.\n"); + console.log("No startup settings detected, using the 'quick' startup setting!\nIn the future, run this program instead and Wizard101-RPC will quick launch Wizard101 for you.\n\nYou can change this by using the 'startup' command.\nUsage: startup <quick|normal|none>\nExample Usage:\nstartup quick - Set Wizard101-RPC to quick launch (skip patching, instant login) Wizard101 on startup.\nstartup normal - Set Wizard101-RPC to launch Wizard101 normally on startup.\nstartup none - Set Wizard101-RPC to not launch Wizard101 on startup.\n"); settings.startup = "quick"; await fs.writeFile(path.join(__dirname, "./settings.json"), JSON.stringify(settings), () => { /* do nothing */ }); } @@ -115,16 +154,16 @@ function countLines() { }); async function pathCommand(args, init) { - if(args && !args[1]) return console.log("\nSets a path to the Wizard101 folder of the client that wizard101-rpc will report from.\nUsage: path <path>\nExample Usage: path D:\\Steam\\steamapps\\common\\Wizard101"); - if(!fs.existsSync(`${init || args[1]}\\Bin\\WizardClient.log`)) return console.log(init ? `\nCould not find Wizard101 at the path "${init || args[1]}".\nA valid path will need to be supplied to the Wizard101 folder before wizard101-rpc can run properly. Make sure you've ran the game at least once. Please try again.\nExample path (does not have to be steam): D:\\Steam\\steamapps\\common\\Wizard101` : `\nCould not find Wizard101 at the path "${init || args[1]}".\nUsage: path <path>\nExample usage: path D:\\Steam\\steamapps\\common\\Wizard101`); + if(args && !args[1]) return console.log("\nChange the path of where Wizard101-RPC will read information from if valid.\nUsage: path <path>\nExample Usage: path D:\\Steam\\steamapps\\common\\Wizard101"); + if(!fs.existsSync(`${init || args[1]}\\Bin\\WizardClient.log`)) return console.log(init ? `\nCould not find Wizard101 at the path "${init || args[1]}".\nA valid path will need to be supplied to the Wizard101 folder before Wizard101-RPC can run properly. Make sure you've ran the game at least once. Please try again.\nExample path (does not have to be steam): D:\\Steam\\steamapps\\common\\Wizard101` : `\nCould not find Wizard101 at the path "${init || args[1]}".\nUsage: path <path>\nExample usage: path D:\\Steam\\steamapps\\common\\Wizard101`); settings.path = `${init || args[1]}\\Bin\\WizardClient.log`; await fs.writeFile(path.join(__dirname, "./settings.json"), JSON.stringify(settings), () => { /* do nothing */ }); - console.log(`\nNew path set to "${init || args[1]}". If a path was already set, wizard101-rpc won't read from the new path until restarted.`); + console.log(`\nNew path set to "${init || args[1]}". If a path was already set, Wizard101-RPC won't read from the new path until its has been restarted.`); } async function startupCommand(args) { - if(!args[1]) return console.log("\nSets how wizard101-rpc will start Wizard101, if at all.\nUsage: startup <quick|normal|none>\n\nExample Usage:\nstartup quick - Set wizard101-rpc to quick launch Wizard101 on startup.\nstartup normal - Set wizard101-rpc to launch Wizard101 normally on startup.\nstartup none - Set wizard101-rpc to not launch Wizard101 on startup."); + if(!args[1]) return console.log("\nSets how Wizard101-RPC will start Wizard101, if at all.\nUsage: startup <quick|normal|none>\n\nExample Usage:\nstartup quick - Set Wizard101-RPC to quick launch Wizard101 on startup.\nstartup normal - Set Wizard101-RPC to launch Wizard101 normally on startup.\nstartup none - Set Wizard101-RPC to not launch Wizard101 on startup."); args[1] = args[1].toLowerCase(); if(args[1] === "quick" || args[1] === "normal" || args[1] === "none") { @@ -136,7 +175,7 @@ function countLines() { } } if(settings.path) connectDiscord(); -}()); +} let reconnect; function connectDiscord() { @@ -146,7 +185,7 @@ function connectDiscord() { rpc = new DiscordRPC.Client({ transport: "ipc" }); rpc.once("ready", () => { - console.log("Successfully connected to Discord!\nWizard101-rpc is ready! Information will be shown on your Discord profile on game startup or the next zone change."); + console.log("Successfully connected to Discord!\nWizard101-RPC is ready! Information will be shown on your Discord profile when the game starts, or when the zone changes."); clearInterval(reconnect); setPresence(); rl.resume(); @@ -154,7 +193,7 @@ function connectDiscord() { // Launch wiz if(settings.startup === "none") return; process.chdir(settings.path.slice(0, settings.path.length - (settings.startup === "quick" ? 17 : 21))); - settings.startup === "quick" ? exec("WizardGraphicalClient.exe -L 165.193.63.4 12000", (err) => console.log(`\nQuick launched Wizard101!\nIf you encounter an error in-game, try running Wizard101 normally.\n${err ? err : ""}`)) : settings.startup === "normal" ? exec("Wizard101.exe", _err /* an error will always be made, even when successful*/ => console.log("\nLaunched Wizard101!")) : null; + settings.startup === "quick" ? exec("WizardGraphicalClient.exe -L 165.193.63.4 12000", (err) => console.log(`\nQuick launched Wizard101!\nIf you encounter an issue, try running Wizard101 normally.\n${err ? err : ""}`)) : settings.startup === "normal" ? exec("Wizard101.exe", _err /* an error will always be made, even when successful*/ => console.log("\nLaunched Wizard101!")) : null; }); rpc.login({ clientId: "799404226081849345" }).then(() => { diff --git a/package.json b/package.json index a42510c..2ec63a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wizard101-rpc", - "version": "0.7.2", + "version": "1.0.0", "description": "Discord Rich Presence for Wizard101!", "main": "index.js", "author": "Christopher Gwynn", @@ -7,20 +7,26 @@ any-promise@^1.0.0: resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f" integrity sha1-q8av7tzqUugJzcA3au0845Y10X8= -discord-rpc@^3.1.4: - version "3.1.4" - resolved "https://registry.yarnpkg.com/discord-rpc/-/discord-rpc-3.1.4.tgz#6d449a682e6a0dec4f0444d5f36f9ebfabaccf91" - integrity sha512-QaBu+gHica2SzgRAmTpuJ4J8DX9+fDwAqhvaie3hcbkU9WPqewEPh21pWdd/7vTI/JNuapU7PFm2ZKg3BTkbGg== +bindings@^1.3.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" + integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ== dependencies: - node-fetch "^2.6.1" - ws "^7.3.1" + file-uri-to-path "1.0.0" discord-rpc@discordjs/rpc: - version "3.1.4" - resolved "https://codeload.github.com/discordjs/rpc/tar.gz/cbdd31f98b20de0222a793ae0b14018f8119cfb2" + version "3.2.0" + resolved "https://codeload.github.com/discordjs/rpc/tar.gz/32f1b9f8c47cf82ab87a83391ca9a9115513f01e" dependencies: node-fetch "^2.6.1" ws "^7.3.1" + optionalDependencies: + register-scheme "github:devsnek/node-register-scheme" + + version "1.0.0" + resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" + integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== mz@^2.7.0: version "2.7.0" @@ -31,6 +37,11 @@ mz@^2.7.0: object-assign "^4.0.1" thenify-all "^1.0.0" +node-addon-api@^1.3.0: + version "1.7.2" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-1.7.2.tgz#3df30b95720b53c24e59948b49532b662444f54d" + integrity sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg== + node-fetch@^2.6.1: version "2.6.1" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" @@ -48,6 +59,13 @@ read-last-lines@^1.8.0: dependencies: mz "^2.7.0" +"register-scheme@github:devsnek/node-register-scheme": + version "0.0.2" + resolved "https://codeload.github.com/devsnek/node-register-scheme/tar.gz/e7cc9a63a1f512565da44cb57316d9fb10750e17" + dependencies: + bindings "^1.3.0" + node-addon-api "^1.3.0" + thenify-all@^1.0.0: version "1.6.0" resolved "https://registry.yarnpkg.com/thenify-all/-/thenify-all-1.6.0.tgz#1a1918d402d8fc3f98fbf234db0bcc8cc10e9726" @@ -63,6 +81,6 @@ thenify-all@^1.0.0: any-promise "^1.0.0" ws@^7.3.1: - version "7.4.2" - resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.2.tgz#782100048e54eb36fe9843363ab1c68672b261dd" - integrity sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA== + version "7.4.5" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.5.tgz#a484dd851e9beb6fdb420027e3885e8ce48986c1" + integrity sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g== |