diff options
| author | Christopher Gwynn <[email protected]> | 2021-02-01 02:18:26 -0500 |
|---|---|---|
| committer | Christopher Gwynn <[email protected]> | 2021-02-01 02:18:26 -0500 |
| commit | fa746c9aa68c02eb0cfe06e69779c03ca2db079f (patch) | |
| tree | 3afc7a7d792a8cfb2ae8b3a9c0ef883ecf136ed4 | |
| parent | Add zone key (diff) | |
| download | wizard101-rpc-fa746c9aa68c02eb0cfe06e69779c03ca2db079f.tar.xz wizard101-rpc-fa746c9aa68c02eb0cfe06e69779c03ca2db079f.zip | |
read and print relevant info from logs
| -rw-r--r-- | index.js | 38 | ||||
| -rw-r--r-- | package.json | 8 | ||||
| -rw-r--r-- | yarn.lock | 61 | ||||
| -rw-r--r-- | zones.json | 2 |
4 files changed, 106 insertions, 3 deletions
@@ -0,0 +1,38 @@ +const fs = require("fs"); +const path = require("path"); +const readLastLine = require("read-last-line"); +const logPath = "C:\\ProgramData\\KingsIsle Entertainment\\Wizard101\\Bin\\WizardClient.log"; +const zones = require(path.join(__dirname, "./zones.json")); + +console.log(" _ _ __ ___ __ \n (_) | /_ |/ _ \\/_ | \n __ ___ ______ _ _ __ __| || | | | || |______ _ __ _ __ ___ \n \\ \\ /\\ / / |_ / _` | \'__/ _` || | | | || |______| \'__| \'_ \\ / __|\n \\ V V /| |/ / (_| | | | (_| || | |_| || | | | | |_) | (__ \n \\_/\\_/ |_/___\\__,_|_| \\__,_||_|\\___/ |_| |_| | .__/ \\___|\n | | \n "); + +let oldLineCount; +(async () => { oldLineCount = await countLines(); })(); +fs.watchFile(logPath, { interval: 100 }, async (_curr, _prev) => { + let currentLineCount = await countLines(); + await readLastLine.read(logPath, (currentLineCount - oldLineCount) * 2).then(async (logChunk) => { + try { + console.log(zones[/zone = (.+),/.exec(logChunk)[1]]); + } catch(_err) { /* No zone information found in this chunk */ } + + let health = /WizClientGameEf (.+): Updating health globe \(new health: (\d+), new health max: (\d+)\)/gm.exec(logChunk); + console.log(`new health: ${health[2]}, new max health: ${health[3]}`); + }).catch(() => { /* No health information found in this chunk */ }); + oldLineCount = currentLineCount; +}); + +function countLines() { + return new Promise((resolve, reject) => { + let lineCount = 0; + fs.createReadStream(logPath).on("data", (buffer) => { + let index = -1; + lineCount--; + do { + index = buffer.indexOf(10, index + 1); + lineCount++; + } while(index !== -1); + }).on("end", () => { + resolve(lineCount); + }).on("error", reject); + }); +} diff --git a/package.json b/package.json index 1f9f7d5..dcc54b1 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,12 @@ { "name": "wizard101-rpc", - "version": "0.2.0", + "version": "0.3.0", "description": "Discord Rich Presence for Wizard101!", "main": "index.js", "author": "Christopher Gwynn", - "license": "MIT" + "license": "MIT", + "dependencies": { + "discord-rpc": "^3.1.4", + "read-last-line": "^1.1.0" + } } diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..7ac8d0b --- /dev/null +++ b/yarn.lock @@ -0,0 +1,61 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +any-promise@^1.0.0: + version "1.3.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== + dependencies: + node-fetch "^2.6.1" + ws "^7.3.1" + +mz@^2.7.0: + version "2.7.0" + resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32" + integrity sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q== + dependencies: + any-promise "^1.0.0" + object-assign "^4.0.1" + thenify-all "^1.0.0" + +node-fetch@^2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" + integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== + +object-assign@^4.0.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" + integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= + +read-last-line@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/read-last-line/-/read-last-line-1.1.0.tgz#aa10d85568b28eddd4ff632f68fb5ef09bdce58a" + integrity sha512-XpM0ZE7uGidTV9YjZddIwow+jeKMFKdRosb0G/PZUFVpWMxTvvADhqKTDBpZ1FULInoXZWPRf8l9w/+2hfnZ5A== + dependencies: + mz "^2.7.0" + +thenify-all@^1.0.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/thenify-all/-/thenify-all-1.6.0.tgz#1a1918d402d8fc3f98fbf234db0bcc8cc10e9726" + integrity sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY= + dependencies: + thenify ">= 3.1.0 < 4" + +"thenify@>= 3.1.0 < 4": + version "3.3.1" + resolved "https://registry.yarnpkg.com/thenify/-/thenify-3.3.1.tgz#8932e686a4066038a016dd9e2ca46add9838a95f" + integrity sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw== + dependencies: + 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== @@ -2413,7 +2413,7 @@ "WizardCity/Tutorial_Exterior": "Tutorial", "WizardCity/Tutorial_Interior": "Tutorial", "WizardCity/WC_Duel_Arena": "Arena", - "WizardCity/WC_Duel_Arena_New": "Arena", + "WizardCity/WC_Duel_Arena_New": "Wizard City Arena", "WizardCity/WC_Golem_Tower": "Golem Tower", "WizardCity/WC_Hub": "The Commons", "WizardCity/WC_NightSide": "Nightside", |