diff --git a/.gitignore b/.gitignore index 01c594f..f8f832e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ cache/ +build/ data/ appold.js migrate.js diff --git a/events/ready.js b/events/ready.js index 6b0b5b1..3d7e9fe 100644 --- a/events/ready.js +++ b/events/ready.js @@ -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( diff --git a/utils/soundplayer.js b/utils/soundplayer.js index 16829d1..c23e4dc 100644 --- a/utils/soundplayer.js +++ b/utils/soundplayer.js @@ -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."); };