Open themaxdavitt opened 3 years ago
So I did some more testing to help clean up the debug console on the streaming role to help handle user presence now the logs are clean and no issues (for now lol)
client.on('presenceUpdate', (oldPresence, newPresence) =>{
try{
const streamRole = newPresence.guild.roles.cache.find(role => role.name === "🔴 - Currently Streaming");
//console.log(streamRole);
//The reason we use undefined here is because when a presence changes it does not require an activity (IE. going from away to online with not playing anything)
//This will throw an error saying that 'newPresence.activities[0]' is undefined causing our logs to get spammed with errors. Their might be a better way of handling this but thats what I got for now.
if(newPresence.activities.length !== 0){
//once the users presence is streaming add the role.
if(newPresence.activities[0].type === 'STREAMING'){
newPresence.guild.members.cache.get(newPresence.userID).roles.add(streamRole);
console.log("Stream Role Added");
}
//Once a user is no longer streaming and the user has the role take the role away
else if((newPresence.activities[0].type !== 'STREAMING') && newPresence.guild.members.cache.get(newPresence.userID).roles.cache.has('748586477151060119')){
console.log("Stream Role removed");
newPresence.guild.members.cache.get(newPresence.user.id).roles.remove(streamRole);
}
else{}
}
//This is to deal with people who don't show game status so we check the oldPresence since the code block above doesn't take into account blank activities
else if(newPresence.activities.length == 0 && oldPresence != undefined){
if(oldPresence.activities.length >= 1){
if(oldPresence.activities[0].type === "STREAMING"){
console.log("Stream Role removed");
newPresence.guild.members.cache.get(newPresence.user.id).roles.remove(streamRole);
}
}
}
}
catch (error){
console.log(error)
}
Twitter The way I have done a Twitter feed in the past is by using a package called twit (https://github.com/ttezel/twit#readme) from here it lets me interact with the Twitter API and gives a stream of data when an account we are pointing at does an event on Twitter we can filter this down to tweets and not retweets. Here is some code we are using currently
In the Main js file to open the stream
The code to make an embedded message on a tweet event
Livestream status For setting a users special role when they are streaming we do this in a presenceUpdate event and there is still currently some filtering issues I need to handle to not clog up the console but once that is done this should be workable
All of this can be changed and worked on to be better set for multiple servers since I didn't fully design this to scale up