Attempt workaround for Twitter errors crashing the bot, fixed lavalink memory leak

This commit is contained in:
TheEssem 2020-07-07 14:28:16 -05:00
parent 8e5c0aa2ac
commit 0760136ded
3 changed files with 39 additions and 29 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
cache/
build/
data/
appold.js
migrate.js

View File

@ -158,6 +158,7 @@ module.exports = async () => {
tweet();
setInterval(tweet, 1800000);
twitter.active = true;
try {
const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
stream.on("data", async (tweet) => {
if (
@ -192,6 +193,9 @@ module.exports = async () => {
// with status code ${info.resp.statusCode} ${info.resp.statusMessage}
}
});
} catch (e) {
logger.error(`The Twitter streaming API ran into an error: ${e}`);
}
}
logger.log(

View File

@ -99,6 +99,7 @@ exports.nextSong = async (message, connection, track, info, music, voiceChannel)
connection.on("error", (error) => {
playingMessage.delete();
this.manager.leave(voiceChannel.guild.id);
connection.destroy();
this.players.delete(voiceChannel.guild.id);
queues.delete(voiceChannel.guild.id);
throw error;
@ -111,6 +112,7 @@ exports.nextSong = async (message, connection, track, info, music, voiceChannel)
await playingMessage.delete();
if (newQueue.length === 0) {
this.manager.leave(voiceChannel.guild.id);
connection.destroy();
this.players.delete(voiceChannel.guild.id);
queues.delete(voiceChannel.guild.id);
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.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!`);
this.players.delete(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.");
};