Skip to content

Commit

Permalink
feat: gettoyId
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamiKafune committed Jan 26, 2025
1 parent a431dd7 commit a45d11d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"async-mutex": "^0.5.0",
"console-table-printer": "^2.12.1",
"cross-fetch": "^4.1.0",
"node-osc": "^9.1.4",
"socket.io-client": "2.3.1"
Expand Down
41 changes: 41 additions & 0 deletions toyid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { printTable } = require("console-table-printer");
const fetch = require("cross-fetch")
const path = require("node:path")
const fs = require("fs")

async function getToy() {
const raw = await fetch(getGlobalConfig().server.lovense_connect.connecturl + "/command", {
method: "POST",
"Content-Type": "application/json",
body: JSON.stringify({
"command": "GetToys"
})
})
let data = await raw.json()
if (data.code == 200) {
try {
let toyData = JSON.parse(data.data.toys)
const formattedData = Object.values(toyData).map(device => ({
Name: device.name,
ID: device.id,
Version: device.version,
Status: device.status,
Battery: device.battery,
Nickname: device.nickName || "N/A"
}));

printTable(formattedData);
} catch (error) {
console.log("[ERROR] ",error)
}
} else {
console.log("[ERROR] i can't find your toy data...")
}
}

getToy()


function getGlobalConfig() {
return JSON.parse(fs.readFileSync(path.join(process.cwd(), "/manager/config.json")))
}

0 comments on commit a45d11d

Please sign in to comment.