From 02030779e34a845e2f1cf722dedd12432010ee9b Mon Sep 17 00:00:00 2001 From: Ryan Omasta <22267679+elementemerald@users.noreply.github.com> Date: Wed, 3 Aug 2022 23:49:12 -0600 Subject: [PATCH] Initial commit --- .gitignore | 1 + LICENSE | 21 +++++++++++++++++++++ README.md | 1 + index.js | 35 +++++++++++++++++++++++++++++++++++ package-lock.json | 44 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 14 ++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d747a7a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 EmeraldSys Media Ltd + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5d16245 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# lanyard-client \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..d599cd5 --- /dev/null +++ b/index.js @@ -0,0 +1,35 @@ +let IDS = ["660292639412846621"]; + +const { WebSocket } = require("ws"); + +const ws = new WebSocket("wss://api.lanyard.rest/socket"); + +ws.on("open", () => { + console.log("Connected"); +}); + +ws.on("message", data => { + let json = JSON.parse(data); + + if (json.op === 0) + { + console.log(json); + } + else if (json.op === 1) + { + let dataToSend = JSON.stringify({ + op: 2, + d: { + subscribe_to_ids: IDS + } + }); + + ws.send(dataToSend); + + setInterval(() => { + console.log("HB"); + let hb = JSON.stringify({ op: 3 }); + ws.send(hb); + }, json.d.heartbeat_interval); + } +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..dee5da1 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,44 @@ +{ + "name": "lanyard-client", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "lanyard-client", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "ws": "^8.8.1" + } + }, + "node_modules/ws": { + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.8.1.tgz", + "integrity": "sha512-bGy2JzvzkPowEJV++hF07hAD6niYSr0JzBNo/J29WsB57A2r7Wlc1UFcTR9IzrPvuNVO4B8LGqF8qcpsVOhJCA==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + } + }, + "dependencies": { + "ws": { + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.8.1.tgz", + "integrity": "sha512-bGy2JzvzkPowEJV++hF07hAD6niYSr0JzBNo/J29WsB57A2r7Wlc1UFcTR9IzrPvuNVO4B8LGqF8qcpsVOhJCA==", + "requires": {} + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..d478881 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "lanyard-client", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "ws": "^8.8.1" + } +}