Re-order some stuff in Streams.js

This commit is contained in:
Holly Stubbs 2022-02-22 09:03:18 +00:00
parent acf767c71e
commit 197dc1145e
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E

View file

@ -41,30 +41,11 @@ module.exports = class {
consoleHelper.printBancho(`BinatoStream is running! Checks running at a ${interval}ms interval`); consoleHelper.printBancho(`BinatoStream is running! Checks running at a ${interval}ms interval`);
} }
sendToStream(streamName, streamData, initUser = null) { removeStream(streamName) {
// Make sure the stream we are attempting to send to even exists try {
if (!this.doesStreamExist(streamName)) delete this.avaliableStreams[streamName];
return consoleHelper.printBancho(`Did not send to stream [${streamName}] because it does not exist!`); this.avaliableStreamKeys = Object.keys(this.avaliableStreams);
} catch (e) { consoleHelper.printError(`Was not able to remove stream [${streamName}]`) }
// Get the stream to send the data to
const currentStream = this.avaliableStreams[streamName];
// Loop through the users in this stream
for (let i = 0; i < currentStream.streamUsers.length; i++) {
// Get the user token of the user in the queue
const currentUserToken = currentStream.streamUsers[i];
// Make sure we don't send this data back to the user requesting this data to be sent
if (initUser != null && currentUserToken == initUser && (streamName[0] == "#" || streamName.includes("mp_"))) continue;
if (currentUserToken == 3) continue; // Skip if user is bot
// Get user object
const currentUser = getUserByToken(currentUserToken);
// Skip if user is nonexistant
if (currentUser == null) continue;
// Send stream data to user's own queue
currentUser.addActionToQueue(streamData);
}
} }
addUserToStream(streamName, userToken) { addUserToStream(streamName, userToken) {
@ -113,6 +94,32 @@ module.exports = class {
} catch (e) { consoleHelper.printBancho(`Can't Remove user [${userToken}] from stream ${streamName}`); } } catch (e) { consoleHelper.printBancho(`Can't Remove user [${userToken}] from stream ${streamName}`); }
} }
sendToStream(streamName, streamData, initUser = null) {
// Make sure the stream we are attempting to send to even exists
if (!this.doesStreamExist(streamName))
return consoleHelper.printBancho(`Did not send to stream [${streamName}] because it does not exist!`);
// Get the stream to send the data to
const currentStream = this.avaliableStreams[streamName];
// Loop through the users in this stream
for (let i = 0; i < currentStream.streamUsers.length; i++) {
// Get the user token of the user in the queue
const currentUserToken = currentStream.streamUsers[i];
// Make sure we don't send this data back to the user requesting this data to be sent
if (initUser != null && currentUserToken == initUser && (streamName[0] == "#" || streamName.includes("mp_"))) continue;
if (currentUserToken == 3) continue; // Skip if user is bot
// Get user object
const currentUser = getUserByToken(currentUserToken);
// Skip if user is nonexistant
if (currentUser == null) continue;
// Send stream data to user's own queue
currentUser.addActionToQueue(streamData);
}
}
doesStreamExist(streamName) { doesStreamExist(streamName) {
return this.avaliableStreamKeys.includes(streamName); return this.avaliableStreamKeys.includes(streamName);
} }
@ -126,11 +133,4 @@ module.exports = class {
if (this.avaliableStreams[streamName].streamUsers.includes(userToken)) return true; if (this.avaliableStreams[streamName].streamUsers.includes(userToken)) return true;
else return false; else return false;
} }
removeStream(streamName) {
try {
delete this.avaliableStreams[streamName];
this.avaliableStreamKeys = Object.keys(this.avaliableStreams);
} catch (e) { consoleHelper.printError(`Was not able to remove stream [${streamName}]`) }
}
} }