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,40 +158,44 @@ module.exports = async () => {
tweet();
setInterval(tweet, 1800000);
twitter.active = true;
const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
stream.on("data", async (tweet) => {
if (
tweet.user.screen_name !== "esmBot_" &&
!blocks.ids.includes(tweet.user.id_str)
) {
const tweets = (
await database.tweets
.find({
enabled: true,
})
.exec()
)[0];
let tweetContent;
try {
const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
stream.on("data", async (tweet) => {
if (
tweet.text.includes("@this_vid") ||
tweet.user.screen_name !== "esmBot_" &&
!blocks.ids.includes(tweet.user.id_str)
) {
const tweets = (
await database.tweets
.find({
enabled: true,
})
.exec()
)[0];
let tweetContent;
if (
tweet.text.includes("@this_vid") ||
tweet.text.includes("@DownloaderBot") ||
tweet.text.includes("@GetVideoBot") ||
tweet.text.includes("@DownloaderB0t") ||
tweet.text.includes("@thisvid_")
) {
tweetContent = await misc.getTweet(tweet, true, true);
} else {
tweetContent = await misc.getTweet(tweets, true).replace(/{{user}}/gm, `@${tweet.user.screen_name}`);
}
const payload = {
status: `@${tweet.user.screen_name} ${tweetContent}`,
in_reply_to_status_id: tweet.id_str,
};
const info = await twitter.client.statuses.update(payload);
logger.log(`Reply with id ${info.id_str} has been posted.`);
) {
tweetContent = await misc.getTweet(tweet, true, true);
} else {
tweetContent = await misc.getTweet(tweets, true).replace(/{{user}}/gm, `@${tweet.user.screen_name}`);
}
const payload = {
status: `@${tweet.user.screen_name} ${tweetContent}`,
in_reply_to_status_id: tweet.id_str,
};
const info = await twitter.client.statuses.update(payload);
logger.log(`Reply with id ${info.id_str} has been posted.`);
// 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.");
};