router
This commit is contained in:
parent
715e007cdd
commit
cb69e8fd48
@ -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",
|
||||
|
@ -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
|
||||
|
@ -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}`)
|
||||
|
@ -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
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user