router
This commit is contained in:
parent
715e007cdd
commit
cb69e8fd48
@ -7,7 +7,7 @@ const events = require("../events");
|
|||||||
// mod -> web
|
// mod -> web
|
||||||
app.post('/', jsonParser, function(req, res){
|
app.post('/', jsonParser, function(req, res){
|
||||||
|
|
||||||
// delegate to events bus
|
// delegate to event bus
|
||||||
events.emit("message-in", {
|
events.emit("message-in", {
|
||||||
type: "minetest",
|
type: "minetest",
|
||||||
name: "minetest",
|
name: "minetest",
|
||||||
|
@ -16,7 +16,7 @@ Events:
|
|||||||
// the source username
|
// the source username
|
||||||
username: "SomeDude",
|
username: "SomeDude",
|
||||||
|
|
||||||
// the ingame channel: "#main", "#lag", etc
|
// the ingame channel: "main", "lag", etc
|
||||||
channel: "main",
|
channel: "main",
|
||||||
|
|
||||||
//the actual message
|
//the actual message
|
||||||
|
@ -32,8 +32,22 @@ module.exports = function(remote, events){
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on('message', function(event) {
|
client.on('message', function(event) {
|
||||||
//TODO: mapping and events.emit("message-in", {})
|
if (remote.debug){
|
||||||
console.log("irc-message-in", event)
|
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){
|
events.on("message-out", function(event){
|
||||||
@ -41,6 +55,10 @@ module.exports = function(remote, events){
|
|||||||
//not meant for this remote, ignore
|
//not meant for this remote, ignore
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (remote.debug){
|
||||||
|
console.log("irc-message-out", event)
|
||||||
|
}
|
||||||
|
|
||||||
const channel = channels[event.channel]
|
const channel = channels[event.channel]
|
||||||
if (channel) {
|
if (channel) {
|
||||||
channel.say(`<${event.username}> ${event.message}`)
|
channel.say(`<${event.username}> ${event.message}`)
|
||||||
|
@ -2,6 +2,21 @@
|
|||||||
module.exports = function(remotes, events){
|
module.exports = function(remotes, events){
|
||||||
events.on("message-in", function(event){
|
events.on("message-in", function(event){
|
||||||
// dispatch to other systems as message-out event with their names
|
// 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