Attempt workaround for Twitter errors crashing the bot, fixed lavalink memory leak
This commit is contained in:
		
							parent
							
								
									8e5c0aa2ac
								
							
						
					
					
						commit
						0760136ded
					
				
					 3 changed files with 39 additions and 29 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
cache/
 | 
					cache/
 | 
				
			||||||
 | 
					build/
 | 
				
			||||||
data/
 | 
					data/
 | 
				
			||||||
appold.js
 | 
					appold.js
 | 
				
			||||||
migrate.js
 | 
					migrate.js
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -158,6 +158,7 @@ module.exports = async () => {
 | 
				
			||||||
    tweet();
 | 
					    tweet();
 | 
				
			||||||
    setInterval(tweet, 1800000);
 | 
					    setInterval(tweet, 1800000);
 | 
				
			||||||
    twitter.active = true;
 | 
					    twitter.active = true;
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
      const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
 | 
					      const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
 | 
				
			||||||
      stream.on("data", async (tweet) => {
 | 
					      stream.on("data", async (tweet) => {
 | 
				
			||||||
        if (
 | 
					        if (
 | 
				
			||||||
| 
						 | 
					@ -192,6 +193,9 @@ module.exports = async () => {
 | 
				
			||||||
        // with status code ${info.resp.statusCode} ${info.resp.statusMessage}
 | 
					        // with status code ${info.resp.statusCode} ${info.resp.statusMessage}
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
 | 
					    } catch (e) {
 | 
				
			||||||
 | 
					      logger.error(`The Twitter streaming API ran into an error: ${e}`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  logger.log(
 | 
					  logger.log(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -99,6 +99,7 @@ exports.nextSong = async (message, connection, track, info, music, voiceChannel)
 | 
				
			||||||
  connection.on("error", (error) => {
 | 
					  connection.on("error", (error) => {
 | 
				
			||||||
    playingMessage.delete();
 | 
					    playingMessage.delete();
 | 
				
			||||||
    this.manager.leave(voiceChannel.guild.id);
 | 
					    this.manager.leave(voiceChannel.guild.id);
 | 
				
			||||||
 | 
					    connection.destroy();
 | 
				
			||||||
    this.players.delete(voiceChannel.guild.id);
 | 
					    this.players.delete(voiceChannel.guild.id);
 | 
				
			||||||
    queues.delete(voiceChannel.guild.id);
 | 
					    queues.delete(voiceChannel.guild.id);
 | 
				
			||||||
    throw error;
 | 
					    throw error;
 | 
				
			||||||
| 
						 | 
					@ -111,6 +112,7 @@ exports.nextSong = async (message, connection, track, info, music, voiceChannel)
 | 
				
			||||||
    await playingMessage.delete();
 | 
					    await playingMessage.delete();
 | 
				
			||||||
    if (newQueue.length === 0) {
 | 
					    if (newQueue.length === 0) {
 | 
				
			||||||
      this.manager.leave(voiceChannel.guild.id);
 | 
					      this.manager.leave(voiceChannel.guild.id);
 | 
				
			||||||
 | 
					      connection.destroy();
 | 
				
			||||||
      this.players.delete(voiceChannel.guild.id);
 | 
					      this.players.delete(voiceChannel.guild.id);
 | 
				
			||||||
      queues.delete(voiceChannel.guild.id);
 | 
					      queues.delete(voiceChannel.guild.id);
 | 
				
			||||||
      if (music) await client.createMessage(message.channel.id, "🔊 The current voice channel session has ended.");
 | 
					      if (music) await client.createMessage(message.channel.id, "🔊 The current voice channel session has ended.");
 | 
				
			||||||
| 
						 | 
					@ -125,8 +127,11 @@ exports.stop = async (message) => {
 | 
				
			||||||
  if (!message.member.voiceState.channelID) return client.createMessage(message.channel.id, `${message.author.mention}, you need to be in a voice channel first!`);
 | 
					  if (!message.member.voiceState.channelID) return client.createMessage(message.channel.id, `${message.author.mention}, you need to be in a voice channel first!`);
 | 
				
			||||||
  if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return client.createMessage(message.channel.id, `${message.author.mention}, I'm not in a voice channel!`);
 | 
					  if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return client.createMessage(message.channel.id, `${message.author.mention}, I'm not in a voice channel!`);
 | 
				
			||||||
  if (this.players.get(message.channel.guild.id).host !== message.author.id) return client.createMessage(message.channel.id, `${message.author.mention}, only the current voice session host can stop the music!`);
 | 
					  if (this.players.get(message.channel.guild.id).host !== message.author.id) return client.createMessage(message.channel.id, `${message.author.mention}, only the current voice session host can stop the music!`);
 | 
				
			||||||
  this.players.delete(message.channel.guild.id);
 | 
					 | 
				
			||||||
  this.manager.leave(message.channel.guild.id);
 | 
					  this.manager.leave(message.channel.guild.id);
 | 
				
			||||||
 | 
					  const connection = this.players.get(message.channel.guild.id).player;
 | 
				
			||||||
 | 
					  connection.destroy();
 | 
				
			||||||
 | 
					  this.players.delete(message.channel.guild.id);
 | 
				
			||||||
 | 
					  queues.delete(message.channel.guild.id);
 | 
				
			||||||
  await client.createMessage(message.channel.id, "🔊 The current voice channel session has ended.");
 | 
					  await client.createMessage(message.channel.id, "🔊 The current voice channel session has ended.");
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue