From ee6aacc5193cdf735c1c956aaafcc12d0ca2142c Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Sun, 13 Oct 2019 20:42:59 +0200 Subject: [PATCH] working bidirectional msg --- package-lock.json | 106 +++++++++++++++++++++++----------------------- readme.md | 4 +- src/irc_client.js | 9 +++- src/tx.js | 9 +++- start.sh | 5 ++- 5 files changed, 73 insertions(+), 60 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8b9a49f..b7d3805 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", "requires": { - "mime-types": "~2.1.24", + "mime-types": "2.1.24", "negotiator": "0.6.2" } }, @@ -24,15 +24,15 @@ "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", "requires": { "bytes": "3.1.0", - "content-type": "~1.0.4", + "content-type": "1.0.4", "debug": "2.6.9", - "depd": "~1.1.2", + "depd": "1.1.2", "http-errors": "1.7.2", "iconv-lite": "0.4.24", - "on-finished": "~2.3.0", + "on-finished": "2.3.0", "qs": "6.7.0", "raw-body": "2.4.0", - "type-is": "~1.6.17" + "type-is": "1.6.18" } }, "bytes": { @@ -116,36 +116,36 @@ "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", "requires": { - "accepts": "~1.3.7", + "accepts": "1.3.7", "array-flatten": "1.1.1", "body-parser": "1.19.0", "content-disposition": "0.5.3", - "content-type": "~1.0.4", + "content-type": "1.0.4", "cookie": "0.4.0", "cookie-signature": "1.0.6", "debug": "2.6.9", - "depd": "~1.1.2", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "~1.1.2", + "depd": "1.1.2", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "etag": "1.8.1", + "finalhandler": "1.1.2", "fresh": "0.5.2", "merge-descriptors": "1.0.1", - "methods": "~1.1.2", - "on-finished": "~2.3.0", - "parseurl": "~1.3.3", + "methods": "1.1.2", + "on-finished": "2.3.0", + "parseurl": "1.3.3", "path-to-regexp": "0.1.7", - "proxy-addr": "~2.0.5", + "proxy-addr": "2.0.5", "qs": "6.7.0", - "range-parser": "~1.2.1", + "range-parser": "1.2.1", "safe-buffer": "5.1.2", "send": "0.17.1", "serve-static": "1.14.1", "setprototypeof": "1.1.1", - "statuses": "~1.5.0", - "type-is": "~1.6.18", + "statuses": "1.5.0", + "type-is": "1.6.18", "utils-merge": "1.0.1", - "vary": "~1.1.2" + "vary": "1.1.2" } }, "fast-text-encoding": { @@ -159,12 +159,12 @@ "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", "requires": { "debug": "2.6.9", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "on-finished": "~2.3.0", - "parseurl": "~1.3.3", - "statuses": "~1.5.0", - "unpipe": "~1.0.0" + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "on-finished": "2.3.0", + "parseurl": "1.3.3", + "statuses": "1.5.0", + "unpipe": "1.0.0" } }, "forwarded": { @@ -187,10 +187,10 @@ "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", "requires": { - "depd": "~1.1.2", + "depd": "1.1.2", "inherits": "2.0.3", "setprototypeof": "1.1.1", - "statuses": ">= 1.5.0 < 2", + "statuses": "1.5.0", "toidentifier": "1.0.0" } }, @@ -199,7 +199,7 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "requires": { - "safer-buffer": ">= 2.1.2 < 3" + "safer-buffer": "2.1.2" } }, "inherits": { @@ -217,15 +217,15 @@ "resolved": "https://registry.npmjs.org/irc-framework/-/irc-framework-4.4.0.tgz", "integrity": "sha512-81ZjeFg0J+OdwGO4S90f8/GpwNwIcP9KaCt0lvRqt1GueT7cKPX2v1yiRML3cJXofkz/MsVZqJCnAEThYYaTUQ==", "requires": { - "core-js": "^3.0.1", - "eventemitter3": "^2.0.2", - "grapheme-splitter": "^1.0.4", - "iconv-lite": "^0.4.24", - "isomorphic-textencoder": "^1.0.1", - "lodash": "^4.17.11", - "middleware-handler": "^0.2.0", - "regenerator-runtime": "^0.13.2", - "socksjs": "^0.5.0" + "core-js": "3.2.0", + "eventemitter3": "2.0.3", + "grapheme-splitter": "1.0.4", + "iconv-lite": "0.4.24", + "isomorphic-textencoder": "1.0.1", + "lodash": "4.17.15", + "middleware-handler": "0.2.0", + "regenerator-runtime": "0.13.3", + "socksjs": "0.5.0" } }, "isomorphic-textencoder": { @@ -233,7 +233,7 @@ "resolved": "https://registry.npmjs.org/isomorphic-textencoder/-/isomorphic-textencoder-1.0.1.tgz", "integrity": "sha512-676hESgHullDdHDsj469hr+7t3i/neBKU9J7q1T4RHaWwLAsaQnywC0D1dIUId0YZ+JtVrShzuBk1soo0+GVcQ==", "requires": { - "fast-text-encoding": "^1.0.0" + "fast-text-encoding": "1.0.0" } }, "lodash": { @@ -312,7 +312,7 @@ "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", "integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==", "requires": { - "forwarded": "~0.1.2", + "forwarded": "0.1.2", "ipaddr.js": "1.9.0" } }, @@ -358,18 +358,18 @@ "integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==", "requires": { "debug": "2.6.9", - "depd": "~1.1.2", - "destroy": "~1.0.4", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "etag": "~1.8.1", + "depd": "1.1.2", + "destroy": "1.0.4", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "etag": "1.8.1", "fresh": "0.5.2", - "http-errors": "~1.7.2", + "http-errors": "1.7.2", "mime": "1.6.0", "ms": "2.1.1", - "on-finished": "~2.3.0", - "range-parser": "~1.2.1", - "statuses": "~1.5.0" + "on-finished": "2.3.0", + "range-parser": "1.2.1", + "statuses": "1.5.0" }, "dependencies": { "ms": { @@ -384,9 +384,9 @@ "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz", "integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==", "requires": { - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "parseurl": "~1.3.3", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "parseurl": "1.3.3", "send": "0.17.1" } }, @@ -426,7 +426,7 @@ "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", "requires": { "media-typer": "0.3.0", - "mime-types": "~2.1.24" + "mime-types": "2.1.24" } }, "unpipe": { diff --git a/readme.md b/readme.md index 1878cc3..af4d67e 100644 --- a/readme.md +++ b/readme.md @@ -12,5 +12,5 @@ apt install libicu-dev curl -X POST \ -H "Content-Type: application/json" \ -d '{"channel":"main","playername":"somedude","message":"rant about lag!"}' \ - http://127.0.0.1:8080/api/message -``` \ No newline at end of file + http://127.0.0.1:8080/ +``` diff --git a/src/irc_client.js b/src/irc_client.js index 5d08374..5872bcb 100644 --- a/src/irc_client.js +++ b/src/irc_client.js @@ -4,6 +4,7 @@ const IRC = require('irc-framework'); const IRC_HOST = process.env.IRC_HOST const IRC_USERNAME = process.env.IRC_USERNAME const IRC_PASSWORD = process.env.IRC_PASSWORD +const ENABLE_DEBUG = process.env.ENABLE_DEBUG const client = new IRC.Client(); @@ -14,4 +15,10 @@ client.connect({ auto_reconnect: true }); -module.exports = client; \ No newline at end of file +if (ENABLE_DEBUG == "true") { + client.on("debug", function(e){ + console.log(e) + }) +} + +module.exports = client; diff --git a/src/tx.js b/src/tx.js index 558a0cc..2c85857 100644 --- a/src/tx.js +++ b/src/tx.js @@ -13,6 +13,7 @@ client.on('message', function(event) { if (event.type != "privmsg") return; + buffer.push(event) events.emit("message", event); }); @@ -26,6 +27,10 @@ app.get('/', function(req, res){ } function sendEvent(event){ + if (!event) { + return + } + var channel; var direct = false; @@ -57,13 +62,13 @@ app.get('/', function(req, res){ // async event case function evtHandler(e){ clearTimeout(handle); - sendEvent(e); + sendEvent(buffer.shift()); } // timeout case handle = setTimeout(() => { res.json({}); - events.off("message", evtHandler); + events.removeListener("message", evtHandler); }, 20000); events.once("message", evtHandler); diff --git a/start.sh b/start.sh index 5e39934..1d6c3f2 100755 --- a/start.sh +++ b/start.sh @@ -1,8 +1,9 @@ #!/bin/sh export IRC_HOST=chat.freenode.net -export IRC_CHANNEL=#pandorabox -export IRC_USERNAME=pandorabot +export IRC_CHANNEL=pandorabox-test +export IRC_USERNAME=pandorabot_test export IRC_PASSWORD=xyz +export ENABLE_DEBUG=true node src/index.js