Attempted better join/leave msgs

This commit is contained in:
Lamp 2018-05-31 13:50:42 -07:00 committed by GitHub
parent 7d3ecf716f
commit 4a079da5c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 27 deletions

View File

@ -92,35 +92,45 @@ global.createMPPbridge = function (room, DiscordChannelID, site = 'MPP', webhook
console.log(`[${site}] [${room}] ${status}`);
});*/
let lastCh = room;
gClient.on('ch', msg => {
if (lastCh && msg.ch._id !== lastCh) {
dSend(`**Channel changed from \`${lastCh}\` to \`${msg.ch._id}\`**`);
console.log(`[${site}][${room}] Channel changed from ${lastCh} to ${msg.ch._id}`);
lastCh = msg.ch._id;
let lastCh = {_id:room};
gClient.on('ch', async msg => {
// on room change
if (msg.ch._id !== lastCh._id) {
dSend(`**Channel changed from \`${lastCh._id}\` to \`${msg.ch._id}\`**`);
console.log(`[${site}][${room}] Channel changed from ${lastCh._id} to ${msg.ch._id}`);
}
(async function(){
// catch dropped crown
if (msg.ch.crown && !msg.ch.crown.hasOwnProperty('participantId')) {
gClient.sendArray([{m:'chown', id: gClient.getOwnParticipant().id}]); // if possible
var avail_time = msg.ch.crown.time + 15000 - gClient.serverTimeOffset;
var ms = avail_time - Date.now();
setTimeout(()=> gClient.sendArray([{m:'chown', id: gClient.getOwnParticipant().id}]) , ms);
// join/leave messages
if (!msg.ch.p) {
for (let lp of lastCh.ppl) {
// thoncc
}
// transfer crown to owner
if (msg.ppl && msg.ch.crown && msg.ch.crown.participantId == gClient.getOwnParticipant().id) {
var res = await dbClient.query("SELECT owner_mpp__id FROM bridges WHERE mpp_room = $1 AND site = $2;", [room, site]);
if (res.rows.length == 0) return;
var owner = res.rows[0].owner_mpp__id;
if (!owner) return;
msg.ppl.some(part => {
if (part._id == owner) {
gClient.sendArray([{m:'chown', id: part.id}]);
return true;
} else return false;
});
}
})();
}
// catch dropped crown
if (msg.ch.crown && !msg.ch.crown.hasOwnProperty('participantId')) {
gClient.sendArray([{m:'chown', id: gClient.getOwnParticipant().id}]); // if possible
var avail_time = msg.ch.crown.time + 15000 - gClient.serverTimeOffset;
var ms = avail_time - Date.now();
setTimeout(()=> gClient.sendArray([{m:'chown', id: gClient.getOwnParticipant().id}]) , ms);
}
// transfer crown to owner
if (msg.ppl && msg.ch.crown && msg.ch.crown.participantId == gClient.getOwnParticipant().id) {
var res = await dbClient.query("SELECT owner_mpp__id FROM bridges WHERE mpp_room = $1 AND site = $2;", [room, site]);
if (res.rows.length == 0) return;
var owner = res.rows[0].owner_mpp__id;
if (!owner) return;
msg.ppl.some(part => {
if (part._id == owner) {
gClient.sendArray([{m:'chown', id: part.id}]);
return true;
} else return false;
});
}
lastCh = msg.ch;
});
// MPP to Discord