Revert "Attempted better join/leave msgs"

This reverts commit 4a079da5c6.
This commit is contained in:
ledlamp 2018-05-31 13:55:32 -07:00
parent 4a079da5c6
commit 5ec1bff6e9
1 changed files with 27 additions and 37 deletions

View File

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