Attempt workaround for Twitter errors crashing the bot, fixed lavalink memory leak
This commit is contained in:
parent
8e5c0aa2ac
commit
0760136ded
|
@ -1,4 +1,5 @@
|
||||||
cache/
|
cache/
|
||||||
|
build/
|
||||||
data/
|
data/
|
||||||
appold.js
|
appold.js
|
||||||
migrate.js
|
migrate.js
|
||||||
|
|
|
@ -158,40 +158,44 @@ module.exports = async () => {
|
||||||
tweet();
|
tweet();
|
||||||
setInterval(tweet, 1800000);
|
setInterval(tweet, 1800000);
|
||||||
twitter.active = true;
|
twitter.active = true;
|
||||||
const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
|
try {
|
||||||
stream.on("data", async (tweet) => {
|
const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
|
||||||
if (
|
stream.on("data", async (tweet) => {
|
||||||
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 (
|
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("@DownloaderBot") ||
|
||||||
tweet.text.includes("@GetVideoBot") ||
|
tweet.text.includes("@GetVideoBot") ||
|
||||||
tweet.text.includes("@DownloaderB0t") ||
|
tweet.text.includes("@DownloaderB0t") ||
|
||||||
tweet.text.includes("@thisvid_")
|
tweet.text.includes("@thisvid_")
|
||||||
) {
|
) {
|
||||||
tweetContent = await misc.getTweet(tweet, true, true);
|
tweetContent = await misc.getTweet(tweet, true, true);
|
||||||
} else {
|
} else {
|
||||||
tweetContent = await misc.getTweet(tweets, true).replace(/{{user}}/gm, `@${tweet.user.screen_name}`);
|
tweetContent = await misc.getTweet(tweets, true).replace(/{{user}}/gm, `@${tweet.user.screen_name}`);
|
||||||
}
|
}
|
||||||
const payload = {
|
const payload = {
|
||||||
status: `@${tweet.user.screen_name} ${tweetContent}`,
|
status: `@${tweet.user.screen_name} ${tweetContent}`,
|
||||||
in_reply_to_status_id: tweet.id_str,
|
in_reply_to_status_id: tweet.id_str,
|
||||||
};
|
};
|
||||||
const info = await twitter.client.statuses.update(payload);
|
const info = await twitter.client.statuses.update(payload);
|
||||||
logger.log(`Reply with id ${info.id_str} has been posted.`);
|
logger.log(`Reply with id ${info.id_str} has been posted.`);
|
||||||
// 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…
Reference in New Issue