()
| 32 | } |
| 33 | |
| 34 | async run() { |
| 35 | this.success = false; |
| 36 | |
| 37 | if (!this.permissions.has("ATTACH_FILES")) return this.getString("permissions.noAttachFiles"); |
| 38 | |
| 39 | const timestamp = |
| 40 | this.type === "application" && this.interaction |
| 41 | ? CommandInteraction.getCreatedAt(this.interaction.id) |
| 42 | : (this.message?.createdAt ?? new Date()); |
| 43 | // check if this command has already been run in this channel with the same arguments, and we are awaiting its result |
| 44 | // if so, don't re-run it |
| 45 | const running = runningCommands.get(this.author?.id); |
| 46 | if (running && running.getTime() - timestamp.getTime() < 5000) { |
| 47 | return this.getString("image.slowDown"); |
| 48 | } |
| 49 | // before awaiting the command result, add this command to the set of running commands |
| 50 | runningCommands.set(this.author.id, timestamp); |
| 51 | |
| 52 | const staticProps = this.constructor as typeof MediaCommand; |
| 53 | |
| 54 | const ephemeral = this.getOptionBoolean("ephemeral"); |
| 55 | const spoiler = this.getOptionBoolean("spoiler"); |
| 56 | let mediaParams: MediaParams; |
| 57 | |
| 58 | if (staticProps.requiresImage) { |
| 59 | try { |
| 60 | let selection: MediaMeta | undefined; |
| 61 | if (!this.getOptionAttachment("image") && !this.getOptionString("link")) { |
| 62 | selection = selectedImages.get(this.author.id); |
| 63 | } |
| 64 | const media = selection |
| 65 | ? [selection] |
| 66 | : await mediaDetect(this.client, this.permissions, this.message, this.interaction).catch((e) => { |
| 67 | if (e.name === "AbortError") { |
| 68 | runningCommands.delete(this.author.id); |
| 69 | return this.getString("image.timeout"); |
| 70 | } |
| 71 | throw e; |
| 72 | }); |
| 73 | if (media.length === 0) { |
| 74 | runningCommands.delete(this.author.id); |
| 75 | return `${this.getString(`commands.noImage.${this.cmdName}`, { returnNull: true }) || this.getString("image.noImage", { returnNull: true }) || staticProps.noImage} ${this.getString("image.tip", { params: { name: this.client.user.globalName ?? this.client.user.username } })}`; |
| 76 | } |
| 77 | if (typeof media === "string") return media; |
| 78 | selectedImages.delete(this.author.id); |
| 79 | mediaParams = { |
| 80 | cmd: staticProps.command, |
| 81 | params: {}, |
| 82 | id: (this.interaction ?? this.message)?.id ?? Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(), |
| 83 | inputs: media, |
| 84 | ephemeral, |
| 85 | spoiler, |
| 86 | token: this.interaction?.token, |
| 87 | }; |
| 88 | } catch (e) { |
| 89 | runningCommands.delete(this.author.id); |
| 90 | throw e; |
| 91 | } |
nothing calls this directly
no test coverage detected