From 449db92e01d48b262fa0c1774e93bf996e1b3dd6 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 01:44:01 +1000 Subject: [PATCH 01/34] wss testing --- package-lock.json | 20 +++++++++++++++----- package.json | 3 ++- plugins/wss.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 plugins/wss.js diff --git a/package-lock.json b/package-lock.json index 1b70928..8d4b634 100644 --- a/package-lock.json +++ b/package-lock.json @@ -401,6 +401,17 @@ "snekfetch": "^3.6.4", "tweetnacl": "^1.0.0", "ws": "^4.0.0" + }, + "dependencies": { + "ws": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz", + "integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==", + "requires": { + "async-limiter": "~1.0.0", + "safe-buffer": "~5.1.0" + } + } } }, "duplexify": { @@ -1831,12 +1842,11 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "ws": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz", - "integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", + "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", "requires": { - "async-limiter": "~1.0.0", - "safe-buffer": "~5.1.0" + "async-limiter": "~1.0.0" } }, "xtend": { diff --git a/package.json b/package.json index 14b5bbf..5fff010 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "ping": "^0.2.2", "promise-mysql": "^3.3.1", "readline": "^1.3.0", - "request": "^2.88.0" + "request": "^2.88.0", + "ws": "^6.2.1" }, "devDependencies": {}, "scripts": { diff --git a/plugins/wss.js b/plugins/wss.js new file mode 100644 index 0000000..ab0ec15 --- /dev/null +++ b/plugins/wss.js @@ -0,0 +1,32 @@ +const fs = require('fs'); +const https = require('https'); +const WebSocket = require('ws'); + +const fs = require("fs") + + +module.exports = { + name: "Websockets Server (8080)", + init: (dclient) => { + client = dclient + + + const server = https.createServer({ + cert: fs.readFileSync('./cert.pem'), + key: fs.readFileSync('./privkey.pem') + }); + const wss = new WebSocket.Server({ server }); + + wss.on('connection', function connection(ws) { + ws.on('message', function incoming(message) { + console.log('received: %s', message); + ws.send(`something ${message}`); + }); + + ws.send('something'); + }); + + server.listen(8080); + + } +} \ No newline at end of file From fca68c2ded9dd6b30186c83c6f26f5269d65f8c8 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 01:47:54 +1000 Subject: [PATCH 02/34] whoops --- plugins/wss.js | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index ab0ec15..7fd2466 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -2,7 +2,6 @@ const fs = require('fs'); const https = require('https'); const WebSocket = require('ws'); -const fs = require("fs") module.exports = { From 12c20c38a2491099ada9c24b0935821ceb7e718b Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 01:50:33 +1000 Subject: [PATCH 03/34] copying certs --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index a3a3e30..1ba3bfe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,8 @@ RUN npm install # We then copy the rest of our application # to the app direcoty COPY . /app +COPY /etc/letsencrypt/live/litruv.com-0001/privkey.pem /app +COPY /etc/letsencrypt/live/litruv.com-0001/cert.pem /app # We start our application by calling # npm start. CMD ["npm", "start"] \ No newline at end of file From 7a608b759c62e6ebc6a90e9105c9087370d0f7ea Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 01:55:51 +1000 Subject: [PATCH 04/34] apparently not the way to copy.. --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1ba3bfe..a3a3e30 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,8 +21,6 @@ RUN npm install # We then copy the rest of our application # to the app direcoty COPY . /app -COPY /etc/letsencrypt/live/litruv.com-0001/privkey.pem /app -COPY /etc/letsencrypt/live/litruv.com-0001/cert.pem /app # We start our application by calling # npm start. CMD ["npm", "start"] \ No newline at end of file From 536c9b32f7909bb8c076061910dc1fce1917604b Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 03:21:06 +1000 Subject: [PATCH 05/34] stopping tripple message bs. --- plugins/autovoicechannel.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/plugins/autovoicechannel.js b/plugins/autovoicechannel.js index bfcb551..2393d7d 100644 --- a/plugins/autovoicechannel.js +++ b/plugins/autovoicechannel.js @@ -21,9 +21,7 @@ module.exports = { .then(chan => { chan.setParent(autoparent) chan.setTopic(cid) - chan.send(newMember + " **Hey**, this is the Text channel for your voice chat.\r\n **IT WILL BE DELETED ONCE EVERYONE LEAVES**") - chan.send("If you would like to **share screens** or use your **webcam**: ****") - chan.send("*⁽ᵗʰᶦˢ ᶠᵉᵃᵗᵘʳᵉ ᶦˢ ᵒⁿˡʸ ᵃᵛᵃᶦˡᵃᵇˡᵉ ᶦᶠ ʸᵒᵘ'ʳᵉ ᶦⁿ ᵗʰᵉ ᶜʰᵃᵗ⁾*") + chan.send(newMember + " **Hey**, this is the Text channel for your voice chat.\r\n **IT WILL BE DELETED ONCE EVERYONE LEAVES**\nIf you would like to **share screens** or use your **webcam**: ****\n*⁽ᵗʰᶦˢ ᶠᵉᵃᵗᵘʳᵉ ᶦˢ ᵒⁿˡʸ ᵃᵛᵃᶦˡᵃᵇˡᵉ ᶦᶠ ʸᵒᵘ'ʳᵉ ᶦⁿ ᵗʰᵉ ᶜʰᵃᵗ⁾*") //chan.send("https://gfycat.com/RadiantFoolishAmmonite") console.log("Made a Auto Channel Set: " + newMember.presence.game.name + " - " + newMember.displayName) @@ -45,9 +43,7 @@ module.exports = { .then(chan => { chan.setParent(autoparent) chan.setTopic(cid) - chan.send(newMember + " **Hey**, this is the Text channel for your voice chat.\r\n **IT WILL BE DELETED ONCE EVERYONE LEAVES**") - chan.send("\\***NEW**\\* If you would like to **share screens** or use your **webcam**: ****") - chan.send("*⁽ᵗʰᶦˢ ᶠᵉᵃᵗᵘʳᵉ ᶦˢ ᵒⁿˡʸ ᵃᵛᵃᶦˡᵃᵇˡᵉ ᶦᶠ ʸᵒᵘ'ʳᵉ ᶦⁿ ᵗʰᵉ ᶜʰᵃᵗ⁾*") + chan.send(newMember + " **Hey**, this is the Text channel for your voice chat.\r\n **IT WILL BE DELETED ONCE EVERYONE LEAVES**\nIf you would like to **share screens** or use your **webcam**: ****\n*⁽ᵗʰᶦˢ ᶠᵉᵃᵗᵘʳᵉ ᶦˢ ᵒⁿˡʸ ᵃᵛᵃᶦˡᵃᵇˡᵉ ᶦᶠ ʸᵒᵘ'ʳᵉ ᶦⁿ ᵗʰᵉ ᶜʰᵃᵗ⁾*") // chan.send("https://gfycat.com/RadiantFoolishAmmonite") console.log("Made a Auto Channel Set: General - " + newMember.displayName) From d2c1ebabf28a02e0ea9a0e0d89a926da2fe0ae9d Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 03:26:26 +1000 Subject: [PATCH 06/34] server setting perhaps? --- plugins/wss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index 7fd2466..a927f43 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -25,7 +25,7 @@ module.exports = { ws.send('something'); }); - server.listen(8080); + server.listen(8080, "0.0.0.0"); } } \ No newline at end of file From dbc507900c8874687c92785dee632611a93dada2 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 03:49:51 +1000 Subject: [PATCH 07/34] more wss testing --- .gitignore | 2 ++ plugins/wss.js | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d71c927..b0640bc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ googleapi\.json setup.json merged.mp3 output.mp3 +privkey.pem +cert.pem diff --git a/plugins/wss.js b/plugins/wss.js index a927f43..a396a4a 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -18,14 +18,16 @@ module.exports = { wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { - console.log('received: %s', message); + if (message == "name") + ws.send({ name: dclient.user.username }) ws.send(`something ${message}`); }); + ws.send('something'); }); - server.listen(8080, "0.0.0.0"); + server.listen(8080); } } \ No newline at end of file From 9019f9d82b7f99c827f5ae1f547b483cc589f653 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 03:51:58 +1000 Subject: [PATCH 08/34] =?UTF-8?q?=C2=AF\=5F(=E3=83=84)=5F/=C2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/wss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index a396a4a..90809b5 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -19,7 +19,7 @@ module.exports = { wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { if (message == "name") - ws.send({ name: dclient.user.username }) + ws.send({ name: "dclient.user.username" }) ws.send(`something ${message}`); }); From 2b1baa6f5d36da71d61a8d9dba04b1292edcc02c Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 03:57:08 +1000 Subject: [PATCH 09/34] json perhaps lmao --- plugins/wss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index 90809b5..eb9961a 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -19,7 +19,7 @@ module.exports = { wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { if (message == "name") - ws.send({ name: "dclient.user.username" }) + ws.send(JSON.stringify({ name: "dclient.user.username" })) ws.send(`something ${message}`); }); From 730e0cbfd407e8401b04dd0512614e5c43ae3410 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 03:58:02 +1000 Subject: [PATCH 10/34] and not a string :D --- plugins/wss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index eb9961a..e9423b5 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -19,7 +19,7 @@ module.exports = { wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { if (message == "name") - ws.send(JSON.stringify({ name: "dclient.user.username" })) + ws.send(JSON.stringify({ name: dclient.user.username })) ws.send(`something ${message}`); }); From 1d3e39d002ab4be33de7986ae4ef52c047e62709 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 04:15:46 +1000 Subject: [PATCH 11/34] added starterpack to the wss --- plugins/wss.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index e9423b5..1440f4a 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -19,8 +19,7 @@ module.exports = { wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { if (message == "name") - ws.send(JSON.stringify({ name: dclient.user.username })) - ws.send(`something ${message}`); + ws.send(JSON.stringify({ type: 'starterpack', user: dclient.user })) }); From 8d26d738fa93c5568ce8f1fa9e2a6c97fec2f465 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 04:25:37 +1000 Subject: [PATCH 12/34] starterpack v2 --- plugins/wss.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index 1440f4a..d8b8454 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -7,7 +7,6 @@ const WebSocket = require('ws'); module.exports = { name: "Websockets Server (8080)", init: (dclient) => { - client = dclient const server = https.createServer({ @@ -19,7 +18,28 @@ module.exports = { wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { if (message == "name") - ws.send(JSON.stringify({ type: 'starterpack', user: dclient.user })) + ws.send(JSON.stringify( + { + type: 'starterpack', + user: { + avatar: dclient.avatar, + avatarURL: dclient.avatarURL, + bot: dclient.bot, + client: dclient.client, + createdAt: dclient.createdAt, + createdTimestamp: dclient.createdTimestamp, + defaultAvatarURL: dclient.defaultAvatarURL, + discriminator: dclient.discriminator, + displayAvatarURL: dclient.displayAvatarURL, + id: dclient.id, + lastMessage: dclient.lastMessage, + lastMessageID: dclient.lastMessageID, + presence: dclient.presence, + tag: dclient.tag, + username: dclient.username, + verified: dclient.verified + } + })) }); From e13276fbbea998bccdf1208aca7514c4b864b3ad Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 04:26:33 +1000 Subject: [PATCH 13/34] v3.. --- plugins/wss.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index d8b8454..d4d259b 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -22,22 +22,22 @@ module.exports = { { type: 'starterpack', user: { - avatar: dclient.avatar, - avatarURL: dclient.avatarURL, - bot: dclient.bot, - client: dclient.client, - createdAt: dclient.createdAt, - createdTimestamp: dclient.createdTimestamp, - defaultAvatarURL: dclient.defaultAvatarURL, - discriminator: dclient.discriminator, - displayAvatarURL: dclient.displayAvatarURL, - id: dclient.id, - lastMessage: dclient.lastMessage, - lastMessageID: dclient.lastMessageID, - presence: dclient.presence, - tag: dclient.tag, - username: dclient.username, - verified: dclient.verified + avatar: dclient.user.avatar, + avatarURL: dclient.user.avatarURL, + bot: dclient.user.bot, + client: dclient.user.client, + createdAt: dclient.user.createdAt, + createdTimestamp: dclient.user.createdTimestamp, + defaultAvatarURL: dclient.user.defaultAvatarURL, + discriminator: dclient.user.discriminator, + displayAvatarURL: dclient.user.displayAvatarURL, + id: dclient.user.id, + lastMessage: dclient.user.lastMessage, + lastMessageID: dclient.user.lastMessageID, + presence: dclient.user.presence, + tag: dclient.user.tag, + username: dclient.user.username, + verified: dclient.user.verified } })) }); From 5bd5df673531ea9e74d765edf522e659bd726847 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 04:31:43 +1000 Subject: [PATCH 14/34] circular refs --- plugins/wss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index d4d259b..c199307 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -25,7 +25,7 @@ module.exports = { avatar: dclient.user.avatar, avatarURL: dclient.user.avatarURL, bot: dclient.user.bot, - client: dclient.user.client, + // client: dclient.user.client, createdAt: dclient.user.createdAt, createdTimestamp: dclient.user.createdTimestamp, defaultAvatarURL: dclient.user.defaultAvatarURL, From c14d83641006f2ce67da6a268be199346b41173e Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 04:47:42 +1000 Subject: [PATCH 15/34] debugging messages --- plugins/wss.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/wss.js b/plugins/wss.js index c199307..d6d15fd 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -46,6 +46,12 @@ module.exports = { ws.send('something'); }); + + + dclient.on('debug', (message) => { + wss.send(message) + } + server.listen(8080); } From 0ffdd9a7a91441a398cdd252646b8489aba3d18b Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 04:49:49 +1000 Subject: [PATCH 16/34] missing closing ) .. --- plugins/wss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index d6d15fd..7bbcb4f 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -50,7 +50,7 @@ module.exports = { dclient.on('debug', (message) => { wss.send(message) - } + }) server.listen(8080); From d1e0296caadac9f00428531ee2dc61be830fbcbc Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 04:51:47 +1000 Subject: [PATCH 17/34] added an s --- plugins/wss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index 7bbcb4f..78c84f1 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -49,7 +49,7 @@ module.exports = { dclient.on('debug', (message) => { - wss.send(message) + ws.send(message) }) server.listen(8080); From 406846626af17aeefcc05f627ec30dad63e5c592 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 04:53:27 +1000 Subject: [PATCH 18/34] no clue what I'm doing --- plugins/wss.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index 78c84f1..5756989 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -40,6 +40,10 @@ module.exports = { verified: dclient.user.verified } })) + + dclient.on('debug', (message) => { + ws.send(message) + }) }); @@ -48,9 +52,6 @@ module.exports = { - dclient.on('debug', (message) => { - ws.send(message) - }) server.listen(8080); From 51e04895e6b0c7ad7d5fe2763a15776154de0630 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 04:57:27 +1000 Subject: [PATCH 19/34] on message, wonder if it sends its own --- plugins/wss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index 5756989..3f75251 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -41,7 +41,7 @@ module.exports = { } })) - dclient.on('debug', (message) => { + dclient.on('message', (message) => { ws.send(message) }) }); From f9d25e211ac58cd5f5af8d90b3ebcae3e89c6548 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 05:02:14 +1000 Subject: [PATCH 20/34] more circles. --- plugins/wss.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index 3f75251..18abcea 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -32,7 +32,7 @@ module.exports = { discriminator: dclient.user.discriminator, displayAvatarURL: dclient.user.displayAvatarURL, id: dclient.user.id, - lastMessage: dclient.user.lastMessage, + //lastMessage: dclient.user.lastMessage, lastMessageID: dclient.user.lastMessageID, presence: dclient.user.presence, tag: dclient.user.tag, @@ -42,7 +42,7 @@ module.exports = { })) dclient.on('message', (message) => { - ws.send(message) + ws.send(message.cleanContent) }) }); From 1251f2918c9a99223881ab165068ad3c492b9f75 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 05:44:07 +1000 Subject: [PATCH 21/34] stringify message with flatted --- package-lock.json | 5 +++++ package.json | 1 + plugins/wss.js | 5 ++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8d4b634..c113805 100644 --- a/package-lock.json +++ b/package-lock.json @@ -516,6 +516,11 @@ "escape-string-regexp": "^1.0.5" } }, + "flatted": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.0.tgz", + "integrity": "sha512-R+H8IZclI8AAkSBRQJLVOsxwAoHd6WC40b4QTNWIjzAa6BXOBfQcM587MXDTVPeYaopFNWHUFLx7eNmHDSxMWg==" + }, "fluent-ffmpeg": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz", diff --git a/package.json b/package.json index 5fff010..9e64ed0 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "@google-cloud/vision": "^0.25.0", "colors": "^1.3.3", "discord.js": "^11.4.2", + "flatted": "^2.0.0", "fluent-ffmpeg": "^2.1.2", "inquirer": "^6.2.2", "mysql": "^2.16.0", diff --git a/plugins/wss.js b/plugins/wss.js index 18abcea..8748d24 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -1,8 +1,7 @@ const fs = require('fs'); const https = require('https'); const WebSocket = require('ws'); - - +const { parse, stringify } = require('flatted/cjs'); module.exports = { name: "Websockets Server (8080)", @@ -42,7 +41,7 @@ module.exports = { })) dclient.on('message', (message) => { - ws.send(message.cleanContent) + ws.send(stringify(message)) }) }); From 816d1d3211283cdfb48160a17e7dc7301f0e67da Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 05:56:23 +1000 Subject: [PATCH 22/34] get rid of 'something' --- plugins/wss.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index 8748d24..6892125 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -17,7 +17,7 @@ module.exports = { wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { if (message == "name") - ws.send(JSON.stringify( + ws.send(stringify( { type: 'starterpack', user: { @@ -46,7 +46,7 @@ module.exports = { }); - ws.send('something'); + // ws.send('something'); }); From acdcac3ab31d36a69dd1056a142f5aa269415a99 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 06:37:24 +1000 Subject: [PATCH 23/34] don't have to message server first --- plugins/wss.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index 6892125..b1ab739 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -40,12 +40,12 @@ module.exports = { } })) - dclient.on('message', (message) => { - ws.send(stringify(message)) - }) + }); - + dclient.on('message', (message) => { + ws.send(stringify(message)) + }) // ws.send('something'); }); From 2724bfe858c935711b6d9a31505481c83772952b Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 06:40:50 +1000 Subject: [PATCH 24/34] more wss stabilizations --- plugins/wss.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index b1ab739..6167857 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -44,7 +44,12 @@ module.exports = { }); dclient.on('message', (message) => { - ws.send(stringify(message)) + wss.clients.forEach(function each(client) { + if (client !== ws && client.readyState === WebSocket.OPEN) { + client.send(stringify(message)) + } + } + }) // ws.send('something'); }); From 063dd42dab09442c89d3dbd69c0b77048f2ddc37 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 06:41:44 +1000 Subject: [PATCH 25/34] always a singlular bracket. --- plugins/wss.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index 6167857..0fd51c3 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -48,8 +48,8 @@ module.exports = { if (client !== ws && client.readyState === WebSocket.OPEN) { client.send(stringify(message)) } - } - + }) + }) // ws.send('something'); }); From b20cf372c4fa42d05d697bd7f3ecbf5bd3fc58a4 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 06:55:12 +1000 Subject: [PATCH 26/34] more wss stuff --- plugins/wss.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/wss.js b/plugins/wss.js index 0fd51c3..4e64f69 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -15,6 +15,8 @@ module.exports = { const wss = new WebSocket.Server({ server }); wss.on('connection', function connection(ws) { + ws.isAlive = true; + ws.on('message', function incoming(message) { if (message == "name") ws.send(stringify( @@ -43,6 +45,8 @@ module.exports = { }); + ws.on('pong', heartbeat); + dclient.on('message', (message) => { wss.clients.forEach(function each(client) { if (client !== ws && client.readyState === WebSocket.OPEN) { @@ -54,8 +58,20 @@ module.exports = { // ws.send('something'); }); + function noop() { } + function heartbeat() { + this.isAlive = true; + } + const interval = setInterval(function ping() { + wss.clients.forEach(function each(ws) { + if (ws.isAlive === false) return ws.terminate(); + + ws.isAlive = false; + ws.ping(noop); + }); + }, 5000); server.listen(8080); From c13ec65079eb7b7a906cdb3c2cf79434fa181a23 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 26 Apr 2019 06:58:47 +1000 Subject: [PATCH 27/34] ditch clients --- plugins/wss.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index 4e64f69..574de77 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -14,6 +14,12 @@ module.exports = { }); const wss = new WebSocket.Server({ server }); + function noop() { } + + function heartbeat() { + this.isAlive = true; + } + wss.on('connection', function connection(ws) { ws.isAlive = true; @@ -58,11 +64,6 @@ module.exports = { // ws.send('something'); }); - function noop() { } - - function heartbeat() { - this.isAlive = true; - } const interval = setInterval(function ping() { wss.clients.forEach(function each(ws) { From a78d70df77a3bb063d5dbf7481e1867f42e84f11 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Sat, 27 Apr 2019 00:30:41 +1000 Subject: [PATCH 28/34] new implementation testing --- plugins/wss.js | 62 +++++++++----------------------------------------- 1 file changed, 11 insertions(+), 51 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index 574de77..596ad9a 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -14,65 +14,25 @@ module.exports = { }); const wss = new WebSocket.Server({ server }); - function noop() { } - - function heartbeat() { - this.isAlive = true; - } wss.on('connection', function connection(ws) { - ws.isAlive = true; - ws.on('message', function incoming(message) { - if (message == "name") - ws.send(stringify( - { - type: 'starterpack', - user: { - avatar: dclient.user.avatar, - avatarURL: dclient.user.avatarURL, - bot: dclient.user.bot, - // client: dclient.user.client, - createdAt: dclient.user.createdAt, - createdTimestamp: dclient.user.createdTimestamp, - defaultAvatarURL: dclient.user.defaultAvatarURL, - discriminator: dclient.user.discriminator, - displayAvatarURL: dclient.user.displayAvatarURL, - id: dclient.user.id, - //lastMessage: dclient.user.lastMessage, - lastMessageID: dclient.user.lastMessageID, - presence: dclient.user.presence, - tag: dclient.user.tag, - username: dclient.user.username, - verified: dclient.user.verified - } - })) - - + console.log('received: %s', message); }); - ws.on('pong', heartbeat); - - dclient.on('message', (message) => { - wss.clients.forEach(function each(client) { - if (client !== ws && client.readyState === WebSocket.OPEN) { - client.send(stringify(message)) - } - }) - - }) - // ws.send('something'); + ws.send('Connected'); }); - - const interval = setInterval(function ping() { - wss.clients.forEach(function each(ws) { - if (ws.isAlive === false) return ws.terminate(); - - ws.isAlive = false; - ws.ping(noop); + setInterval(() => { //heartbeat + wss.clients.forEach(client => { + if (client.readyState == client.OPEN) { + client.send(JSON.stringify({ type: "heartbeat", time: new Date().getTime() })) + client.ping() + } }); - }, 5000); + console.log("Broadcasting to " + wss.clients.size + " clients") + n++; + }, 30000); server.listen(8080); From f1b06afd44f82e7e16b34b378f0b6afb3a3d17c8 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Sat, 27 Apr 2019 00:34:37 +1000 Subject: [PATCH 29/34] n is not defined --- plugins/wss.js | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index 596ad9a..c10486b 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -31,7 +31,6 @@ module.exports = { } }); console.log("Broadcasting to " + wss.clients.size + " clients") - n++; }, 30000); server.listen(8080); From b6439fcea9dfea433c446100ee126427498d4a80 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Sat, 27 Apr 2019 04:59:22 +1000 Subject: [PATCH 30/34] data response --- plugins/wss.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index c10486b..4e44c78 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -6,20 +6,37 @@ const { parse, stringify } = require('flatted/cjs'); module.exports = { name: "Websockets Server (8080)", init: (dclient) => { - - const server = https.createServer({ cert: fs.readFileSync('./cert.pem'), key: fs.readFileSync('./privkey.pem') }); const wss = new WebSocket.Server({ server }); - wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { console.log('received: %s', message); - }); + var data = parse(message) + var response = { + type: "data", + data: new Array() + } + + if (data.type == "request") { + for (var i = 0; i < data.requests.length; i++) { + var resp = "" + if (data.requests[i] == "name") + resp = dclient.user.username + if (data.requests[i] == "id") + resp = dclient.user.id + if (data.requests[i] == "discriminator") + resp = dclient.user.discriminator + response.data.push({ type: data.requests[i], data: resp }) + } + + ws.send(response) + } + }); ws.send('Connected'); }); @@ -30,7 +47,6 @@ module.exports = { client.ping() } }); - console.log("Broadcasting to " + wss.clients.size + " clients") }, 30000); server.listen(8080); From 12e089115da6c2e25028aaec8b81ea5b6c3c89ac Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Sat, 27 Apr 2019 05:05:10 +1000 Subject: [PATCH 31/34] make sure it's actual data now.. --- plugins/wss.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/plugins/wss.js b/plugins/wss.js index 4e44c78..9148ce7 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -15,27 +15,34 @@ module.exports = { wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { console.log('received: %s', message); - var data = parse(message) - var response = { - type: "data", - data: new Array() - } + try { + var data = parse(message) - if (data.type == "request") { - for (var i = 0; i < data.requests.length; i++) { - var resp = "" - if (data.requests[i] == "name") - resp = dclient.user.username - if (data.requests[i] == "id") - resp = dclient.user.id - if (data.requests[i] == "discriminator") - resp = dclient.user.discriminator - response.data.push({ type: data.requests[i], data: resp }) + var response = { + type: "data", + data: new Array() } - ws.send(response) + if (data.type == "request") { + for (var i = 0; i < data.requests.length; i++) { + var resp = "" + if (data.requests[i] == "name") + resp = dclient.user.username + if (data.requests[i] == "id") + resp = dclient.user.id + if (data.requests[i] == "discriminator") + resp = dclient.user.discriminator + response.data.push({ type: data.requests[i], data: resp }) + } + + ws.send(response) + } } + catch (error) { + console.log(error) + } + }); ws.send('Connected'); }); From b676a178f432d3a0118de8a2223dd6b130c4345f Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Sat, 27 Apr 2019 05:07:26 +1000 Subject: [PATCH 32/34] Stringify of course --- plugins/wss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index 9148ce7..80c6005 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -36,7 +36,7 @@ module.exports = { response.data.push({ type: data.requests[i], data: resp }) } - ws.send(response) + ws.send(stringify(response)) } } catch (error) { From 20d19c82333858b871851577b1d02641e91aa0ba Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Sat, 27 Apr 2019 05:12:51 +1000 Subject: [PATCH 33/34] perhaps json will help, lmao --- plugins/wss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wss.js b/plugins/wss.js index 80c6005..0321acf 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -36,7 +36,7 @@ module.exports = { response.data.push({ type: data.requests[i], data: resp }) } - ws.send(stringify(response)) + ws.send(JSON.stringify(response)) } } catch (error) { From 65de9928bb6a50ff8d2774455c030141e76b752f Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Sat, 27 Apr 2019 05:47:16 +1000 Subject: [PATCH 34/34] added avatar to request --- plugins/wss.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/wss.js b/plugins/wss.js index 0321acf..b004a5b 100644 --- a/plugins/wss.js +++ b/plugins/wss.js @@ -33,6 +33,8 @@ module.exports = { resp = dclient.user.id if (data.requests[i] == "discriminator") resp = dclient.user.discriminator + if (data.requests[i] == "avatar") + resp = dclient.user.avatarURL response.data.push({ type: data.requests[i], data: resp }) }