split into files
This commit is contained in:
parent
de1d26fce3
commit
c36969c68e
16
client_map.js
Normal file
16
client_map.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const client = require('./irc_client');
|
||||||
|
const channel_map = require("./channel_map');
|
||||||
|
|
||||||
|
var channels = {}; // name -> channelObj
|
||||||
|
|
||||||
|
|
||||||
|
client.on('registered', function() {
|
||||||
|
Object.keys(channel_map).forEach(name => {
|
||||||
|
var channel = client.channel("#" + name);
|
||||||
|
channel.join();
|
||||||
|
channel.say(`beerchat_proxy connected! ingame-channel: ${name}`);
|
||||||
|
channels[name] = channel;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = channels;
|
7
src/app.js
Normal file
7
src/app.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
const express = require('express')
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
app.use(express.static('public'));
|
||||||
|
app.disable('etag');
|
||||||
|
|
||||||
|
module.exports = app;
|
10
src/channel_map.js
Normal file
10
src/channel_map.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
// TODO: config
|
||||||
|
// ingame -> irc
|
||||||
|
var channel_map = {
|
||||||
|
"main": "pandorabox",
|
||||||
|
"de": "pandorabox-de",
|
||||||
|
"mod": "pandorabox-mod"
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = channel_map;
|
66
src/index.js
66
src/index.js
@ -1,66 +1,6 @@
|
|||||||
const express = require('express')
|
const app = require("./app");
|
||||||
const bodyParser = require('body-parser')
|
|
||||||
const jsonParser = bodyParser.json()
|
|
||||||
|
|
||||||
const IRC = require('irc-framework');
|
require("/rx.js");
|
||||||
|
require("/tx.js");
|
||||||
const app = express();
|
|
||||||
app.use(express.static('public'));
|
|
||||||
app.disable('etag');
|
|
||||||
|
|
||||||
|
|
||||||
const IRC_HOST = process.env.IRC_HOST
|
|
||||||
const IRC_USERNAME = process.env.IRC_USERNAME
|
|
||||||
const IRC_PASSWORD = process.env.IRC_PASSWORD
|
|
||||||
|
|
||||||
const client = new IRC.Client();
|
|
||||||
client.connect({
|
|
||||||
host: IRC_HOST,
|
|
||||||
port: 6667,
|
|
||||||
nick: IRC_USERNAME,
|
|
||||||
auto_reconnect: true
|
|
||||||
});
|
|
||||||
|
|
||||||
var channels = {}; // name -> channelObj
|
|
||||||
|
|
||||||
// TODO: config
|
|
||||||
var channel_map = {
|
|
||||||
"main": "pandorabox",
|
|
||||||
"de": "pandorabox-de",
|
|
||||||
"mod": "pandorabox-mod"
|
|
||||||
};
|
|
||||||
|
|
||||||
client.on('registered', function() {
|
|
||||||
Object.keys(channel_map).forEach(name => {
|
|
||||||
var channel = client.channel("#" + name);
|
|
||||||
channel.join();
|
|
||||||
channel.say(`beerchat_proxy connected! ingame-channel: ${name}`);
|
|
||||||
channels[name] = channel;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// mod -> web
|
|
||||||
app.post('/api/message', jsonParser, function(req, res){
|
|
||||||
|
|
||||||
// req.body = { channel = "", playername = "", message = "" }
|
|
||||||
|
|
||||||
if (!req.body.channel)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const channel = channels[req.body.channel];
|
|
||||||
if (channel) {
|
|
||||||
channel.say(
|
|
||||||
(req.body.playername ? `<${req.body.playername}> ` : "") +
|
|
||||||
req.body.message
|
|
||||||
);
|
|
||||||
}
|
|
||||||
res.end();
|
|
||||||
});
|
|
||||||
|
|
||||||
client.on('message', function(event) {
|
|
||||||
// event = { message }
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: web -> mod
|
|
||||||
|
|
||||||
app.listen(8080, () => console.log('Listening on http://127.0.0.1:8080'));
|
app.listen(8080, () => console.log('Listening on http://127.0.0.1:8080'));
|
||||||
|
16
src/irc_client.js
Normal file
16
src/irc_client.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
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 client = new IRC.Client();
|
||||||
|
client.connect({
|
||||||
|
host: IRC_HOST,
|
||||||
|
port: 6667,
|
||||||
|
nick: IRC_USERNAME,
|
||||||
|
auto_reconnect: true
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = client
|
24
src/rx.js
Normal file
24
src/rx.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
const bodyParser = require('body-parser')
|
||||||
|
const jsonParser = bodyParser.json()
|
||||||
|
|
||||||
|
const app = require("./app");
|
||||||
|
|
||||||
|
const client_map = require("./client_map");
|
||||||
|
|
||||||
|
// mod -> web
|
||||||
|
app.post('/', jsonParser, function(req, res){
|
||||||
|
|
||||||
|
// req.body = { channel = "", playername = "", message = "" }
|
||||||
|
|
||||||
|
if (!req.body.channel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const channel = client_map[req.body.channel];
|
||||||
|
if (channel) {
|
||||||
|
channel.say(
|
||||||
|
(req.body.playername ? `<${req.body.playername}> ` : "") +
|
||||||
|
req.body.message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
res.end();
|
||||||
|
});
|
13
src/tx.js
Normal file
13
src/tx.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const app = require("./app");
|
||||||
|
|
||||||
|
const client = require('./irc_client');
|
||||||
|
|
||||||
|
client.on('message', function(event) {
|
||||||
|
// event = { message }
|
||||||
|
console.log("message", event);//XXX
|
||||||
|
});
|
||||||
|
|
||||||
|
// web -> mod
|
||||||
|
app.get('/', function(req, res){
|
||||||
|
setTimeout(() => res.json({}), 10000)
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user