From e4e633beff1c1a791bfefa24e2705be03f01ae2f Mon Sep 17 00:00:00 2001 From: Essem Date: Fri, 6 Aug 2021 12:03:44 -0500 Subject: [PATCH] Allow owner to use music commands in production, make cache request to 8MB images --- commands/music/loop.js | 2 +- commands/music/nowplaying.js | 2 +- commands/music/pause.js | 2 +- commands/music/play.js | 2 +- commands/music/queue.js | 2 +- commands/music/skip.js | 2 +- commands/music/stop.js | 2 +- events/messageCreate.js | 11 +++++++++-- 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/commands/music/loop.js b/commands/music/loop.js index 2a154e7..451cdd2 100644 --- a/commands/music/loop.js +++ b/commands/music/loop.js @@ -3,7 +3,7 @@ const MusicCommand = require("../../classes/musicCommand.js"); class LoopCommand extends MusicCommand { async run() { - if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; + if (process.env.NODE_ENV === "production" && this.message.author.id !== process.env.OWNER) return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; if (!this.message.channel.guild) return "This command only works in servers!"; if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!"; diff --git a/commands/music/nowplaying.js b/commands/music/nowplaying.js index 613c454..ba4408e 100644 --- a/commands/music/nowplaying.js +++ b/commands/music/nowplaying.js @@ -6,7 +6,7 @@ const MusicCommand = require("../../classes/musicCommand.js"); class NowPlayingCommand extends MusicCommand { async run() { - if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; + if (process.env.NODE_ENV === "production" && this.message.author.id !== process.env.OWNER) return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; if (!this.message.channel.guild) return "This command only works in servers!"; if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!"; diff --git a/commands/music/pause.js b/commands/music/pause.js index f4eb373..5e4e080 100644 --- a/commands/music/pause.js +++ b/commands/music/pause.js @@ -2,7 +2,7 @@ const MusicCommand = require("../../classes/musicCommand.js"); class PauseCommand extends MusicCommand { async run() { - if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; + if (process.env.NODE_ENV === "production" && this.message.author.id !== process.env.OWNER) return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; if (!this.message.channel.guild) return "This command only works in servers!"; if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!"; diff --git a/commands/music/play.js b/commands/music/play.js index d6aa2f0..715e3f1 100644 --- a/commands/music/play.js +++ b/commands/music/play.js @@ -5,7 +5,7 @@ const searchRegex = /^ytsearch:/; class PlayCommand extends MusicCommand { async run() { - if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; + if (process.env.NODE_ENV === "production" && this.message.author.id !== process.env.OWNER) return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; if (!this.args[0]) return "You need to provide what you want to play!"; const query = this.args.join(" ").trim(); diff --git a/commands/music/queue.js b/commands/music/queue.js index cdea4d7..63b380f 100644 --- a/commands/music/queue.js +++ b/commands/music/queue.js @@ -8,7 +8,7 @@ const MusicCommand = require("../../classes/musicCommand.js"); class QueueCommand extends MusicCommand { async run() { - if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; + if (process.env.NODE_ENV === "production" && this.message.author.id !== process.env.OWNER) return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; if (!this.message.channel.guild) return "This command only works in servers!"; if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!"; diff --git a/commands/music/skip.js b/commands/music/skip.js index 2f95bba..a7a5859 100644 --- a/commands/music/skip.js +++ b/commands/music/skip.js @@ -3,7 +3,7 @@ const MusicCommand = require("../../classes/musicCommand.js"); class SkipCommand extends MusicCommand { async run() { - if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; + if (process.env.NODE_ENV === "production" && this.message.author.id !== process.env.OWNER) return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; if (!this.message.channel.guild) return "This command only works in servers!"; if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!"; diff --git a/commands/music/stop.js b/commands/music/stop.js index bbacdf0..898e816 100644 --- a/commands/music/stop.js +++ b/commands/music/stop.js @@ -3,7 +3,7 @@ const MusicCommand = require("../../classes/musicCommand.js"); class StopCommand extends MusicCommand { async run() { - if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; + if (process.env.NODE_ENV === "production" && this.message.author.id !== process.env.OWNER) return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!"; if (!this.message.channel.guild) return "This command only works in servers!"; if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!"; diff --git a/events/messageCreate.js b/events/messageCreate.js index ae4e417..c81a001 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -1,4 +1,5 @@ const fs = require("fs"); +const fetch = require("node-fetch"); const database = require("../utils/database.js"); const logger = require("../utils/logger.js"); const collections = require("../utils/collections.js"); @@ -104,13 +105,19 @@ module.exports = async (client, cluster, worker, ipc, message) => { if (result.file.length > 8388119 && process.env.TEMPDIR !== "") { const filename = `${Math.random().toString(36).substring(2, 15)}.${result.name.split(".")[1]}`; await fs.promises.writeFile(`${process.env.TEMPDIR}/${filename}`, result.file); + const imageURL = `${process.env.TMP_DOMAIN == "" ? "https://tmp.projectlounge.pw" : process.env.TMP_DOMAIN}/${filename}`; + try { + await fetch(imageURL); + } catch { + // this is here to make sure the image is properly cached by discord + } await client.createMessage(message.channel.id, Object.assign({ embed: { color: 16711680, title: "Here's your image!", - url: `${process.env.TMP_DOMAIN == "" ? "https://tmp.projectlounge.pw" : process.env.TMP_DOMAIN}/${filename}`, + url: imageURL, image: { - url: `${process.env.TMP_DOMAIN == "" ? "https://tmp.projectlounge.pw" : process.env.TMP_DOMAIN}/${filename}` + url: imageURL }, footer: { text: "The result image was more than 8MB in size, so it was uploaded to an external site instead."