From cb69e8fd48784e5226242756937e8f4bd6694392 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Mon, 20 Jan 2020 13:45:01 +0100 Subject: [PATCH] router --- src/api/rx.js | 2 +- src/events.js | 2 +- src/handler/irc.js | 22 ++++++++++++++++++++-- src/router.js | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/api/rx.js b/src/api/rx.js index 1a35bc6..df0b466 100644 --- a/src/api/rx.js +++ b/src/api/rx.js @@ -7,7 +7,7 @@ const events = require("../events"); // mod -> web app.post('/', jsonParser, function(req, res){ - // delegate to events bus + // delegate to event bus events.emit("message-in", { type: "minetest", name: "minetest", diff --git a/src/events.js b/src/events.js index 022b8fb..d7519b9 100644 --- a/src/events.js +++ b/src/events.js @@ -16,7 +16,7 @@ Events: // the source username username: "SomeDude", - // the ingame channel: "#main", "#lag", etc + // the ingame channel: "main", "lag", etc channel: "main", //the actual message diff --git a/src/handler/irc.js b/src/handler/irc.js index 50b6ac2..8d7e7ec 100644 --- a/src/handler/irc.js +++ b/src/handler/irc.js @@ -32,8 +32,22 @@ module.exports = function(remote, events){ }); client.on('message', function(event) { - //TODO: mapping and events.emit("message-in", {}) - console.log("irc-message-in", event) + if (remote.debug){ + console.log("irc-event-in", event) + } + + if (event.type != "privmsg") + return; + + //TODO: map ingame channel + + events.emit("message-in", { + type: "irc", + name: remote.name, + username: event.nick, + channel: event.target, + message: event.message + }) }); events.on("message-out", function(event){ @@ -41,6 +55,10 @@ module.exports = function(remote, events){ //not meant for this remote, ignore return; + if (remote.debug){ + console.log("irc-message-out", event) + } + const channel = channels[event.channel] if (channel) { channel.say(`<${event.username}> ${event.message}`) diff --git a/src/router.js b/src/router.js index ebcbdf4..a6ab9c9 100644 --- a/src/router.js +++ b/src/router.js @@ -2,6 +2,21 @@ module.exports = function(remotes, events){ events.on("message-in", function(event){ // dispatch to other systems as message-out event with their names + + remotes.forEach(remote => { + if (event.name == remote.name){ + //skip self + return; + } + + events.emit("message-out", { + type: event.type, + name: remote.name, + username: event.username, + channel: event.channel, + message: event.message + }) + }); }); }