From 79b97631598d630072c5465921d764cda581b1d1 Mon Sep 17 00:00:00 2001 From: Supositware Date: Fri, 15 Mar 2019 17:08:16 +0100 Subject: [PATCH] Send image as attachment when the message is only a link --- event/listeners/messageReactionAdd.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/event/listeners/messageReactionAdd.js b/event/listeners/messageReactionAdd.js index 8504f68e..c5276a64 100644 --- a/event/listeners/messageReactionAdd.js +++ b/event/listeners/messageReactionAdd.js @@ -1,6 +1,7 @@ const { Listener } = require('discord-akairo'); const { MessageEmbed } = require('discord.js'); const reload = require('auto-reload'); +const getUrls = require('get-urls'); let messageID = require('../../json/starboard.json'); class MessageReactionAddListener extends Listener { @@ -14,6 +15,7 @@ class MessageReactionAddListener extends Listener { async exec(reaction) { let messageContent = reaction.message.content; let messageAttachments = reaction.message.attachments.map(u=> `${u.url}`); + let URL = [...getUrls(messageContent)]; let starboardChannel; let staremote; @@ -49,6 +51,11 @@ class MessageReactionAddListener extends Listener { .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL()) .setTimestamp(); + if (URL) { + return channel.send(`in: ${reaction.message.channel}\nhttps://discordapp.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id}`, {files: [URL[0]]}) + .catch(() => channel.send(`${reaction.message.author.username}, in: ${reaction.message.channel}\n${URL[0]}`)); + } + return channel.send(`in: ${reaction.message.channel}`, {files: messageAttachments, embed: starEmbed}) .catch(() => channel.send(`${reaction.message.author.username}, in: ${reaction.message.channel}`, { embed: starEmbed})); } @@ -87,6 +94,11 @@ class MessageReactionAddListener extends Listener { .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL()) .setTimestamp(); + if (URL) { + return channel.send(`in: ${reaction.message.channel}\nhttps://discordapp.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id}`, {files: [URL[0]]}) + .catch(() => channel.send(`${reaction.message.author.username}, in: ${reaction.message.channel}\n${URL[0]}`)); + } + return channel.send(`in: ${reaction.message.channel}`,{files: messageAttachments, embed: shameEmbed}) .catch(() => channel.send(`${reaction.message.author.username}, in: ${reaction.message.channel}`, { embed: shameEmbed})); }