Created
February 16, 2021 22:08
-
-
Save H7-25/f19e194caefe9de473d4c23fbc690ba3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.init = async function init(hooks, app) { | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
hooks.on('client_disconnected', async (event) => { | |
const con = event.client; | |
const user = await app.db.factories.User.query().where('id', con.state.authUserId).first(); | |
const networks = await con.userDb.getUserNetworks(con.state.authUserId); | |
networks.forEach((net) => { | |
if (app.cons.findAllUsersClients(user.id).length === 1) { | |
let upstream = null; | |
upstream = con.conDict.findUsersOutgoingConnection(con.state.authUserId, net.id); | |
// wait 10 minutes before close bouncer connection to IRC | |
await sleep(600000); | |
// check if meanwhile any client has connected to the bouncer | |
if (app.cons.findAllUsersClients(user.id).length === 0) { | |
if (upstream && upstream.state.connected) { | |
let quitMessage = 'Bye Bye'; | |
upstream.writeLine('QUIT', quitMessage); | |
upstream.close(); | |
} | |
} else { | |
return; | |
} | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment