shutdown hoook
This commit is contained in:
parent
e36bce5a86
commit
3ba8fb6706
@ -1,6 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
"remotes": [{
|
"remotes": [{
|
||||||
"debug": true,
|
"debug": false,
|
||||||
|
"announce_channel": false,
|
||||||
"name": "IRC",
|
"name": "IRC",
|
||||||
"type": "irc",
|
"type": "irc",
|
||||||
"host": "irc.libera.chat",
|
"host": "irc.libera.chat",
|
||||||
@ -11,7 +12,8 @@ module.exports = {
|
|||||||
"main": "pandorabox-test"
|
"main": "pandorabox-test"
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
"debug": true,
|
"debug": false,
|
||||||
|
"announce_channel": false,
|
||||||
"name": "Discord",
|
"name": "Discord",
|
||||||
"type": "discord",
|
"type": "discord",
|
||||||
"token": process.env.BEERCHAT_DISCORD_TEST_TOKEN,
|
"token": process.env.BEERCHAT_DISCORD_TEST_TOKEN,
|
||||||
|
@ -2,7 +2,7 @@ const app = require("../app");
|
|||||||
const events = require("../events");
|
const events = require("../events");
|
||||||
|
|
||||||
// mod -> web
|
// mod -> web
|
||||||
app.post('/reconnect', function(req, res){
|
app.post('/shutdown', function(req, res){
|
||||||
events.emit("reconnect", {});
|
events.emit("shutdown", {});
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
@ -24,7 +24,7 @@ module.exports = class {
|
|||||||
Object.keys(remote.channels).forEach(ingame_name => {
|
Object.keys(remote.channels).forEach(ingame_name => {
|
||||||
const discord_channel_name = remote.channels[ingame_name];
|
const discord_channel_name = remote.channels[ingame_name];
|
||||||
const channel = this.client.channels.cache.find(ch => ch.name === discord_channel_name);
|
const channel = this.client.channels.cache.find(ch => ch.name === discord_channel_name);
|
||||||
if (channel) {
|
if (channel && remote.announce_channel) {
|
||||||
channel.send(`beerchat_proxy connected! ingame-channel: ${ingame_name}`);
|
channel.send(`beerchat_proxy connected! ingame-channel: ${ingame_name}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -29,11 +29,13 @@ module.exports = class {
|
|||||||
this.client.on('registered', () => {
|
this.client.on('registered', () => {
|
||||||
let delay = 5000;
|
let delay = 5000;
|
||||||
Object.keys(remote.channels).forEach(ingame_name => {
|
Object.keys(remote.channels).forEach(ingame_name => {
|
||||||
setTimeout(function(){
|
setTimeout(() => {
|
||||||
const irc_name = remote.channels[ingame_name];
|
const irc_name = remote.channels[ingame_name];
|
||||||
var channel = this.client.channel("#" + irc_name);
|
var channel = this.client.channel("#" + irc_name);
|
||||||
channel.join();
|
channel.join();
|
||||||
channel.say(`beerchat_proxy connected! ingame-channel: ${ingame_name}`);
|
if (remote.announce_channel) {
|
||||||
|
channel.say(`beerchat_proxy connected! ingame-channel: ${ingame_name}`);
|
||||||
|
}
|
||||||
channels[ingame_name] = channel;
|
channels[ingame_name] = channel;
|
||||||
}, delay);
|
}, delay);
|
||||||
delay += 2000;
|
delay += 2000;
|
||||||
|
19
src/index.js
19
src/index.js
@ -8,7 +8,7 @@ enableWs(app);
|
|||||||
require("./api/rx");
|
require("./api/rx");
|
||||||
require("./api/tx");
|
require("./api/tx");
|
||||||
require("./api/ws");
|
require("./api/ws");
|
||||||
require("./api/reconnect");
|
require("./api/shutdown");
|
||||||
|
|
||||||
const cfg = require("./config");
|
const cfg = require("./config");
|
||||||
const events = require("./events");
|
const events = require("./events");
|
||||||
@ -19,19 +19,26 @@ const handlers = {
|
|||||||
discord: require("./handler/discord")
|
discord: require("./handler/discord")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const instances = [];
|
||||||
cfg.remotes.forEach(remote => {
|
cfg.remotes.forEach(remote => {
|
||||||
const Handler = handlers[remote.type];
|
const Handler = handlers[remote.type];
|
||||||
const instance = new Handler();
|
const instance = new Handler();
|
||||||
|
|
||||||
console.log(`Setting up remote: ${remote.name} with type: ${remote.type}`);
|
console.log(`Setting up remote: ${remote.name} with type: ${remote.type}`);
|
||||||
instance.init(remote, events);
|
instance.init(remote, events);
|
||||||
});
|
instances.push(instance);
|
||||||
|
|
||||||
events.on("reconnect", function(){
|
|
||||||
//TODO
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Starting message router");
|
console.log("Starting message router");
|
||||||
router(cfg, events);
|
router(cfg, events);
|
||||||
|
|
||||||
app.listen(8080, () => console.log('Listening on http://127.0.0.1:8080'));
|
const server = app.listen(8080, () => console.log('Listening on http://127.0.0.1:8080'));
|
||||||
|
|
||||||
|
events.on("shutdown", function(){
|
||||||
|
// close http server
|
||||||
|
server.close();
|
||||||
|
// close clients
|
||||||
|
instances.forEach(i => i.destroy());
|
||||||
|
// forcibly quit
|
||||||
|
process.exit(0);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user