From e84e7d67139498b7f9c02149998839e3740e7246 Mon Sep 17 00:00:00 2001 From: Arthur Neuman Date: Mon, 2 Nov 2020 22:02:43 -0500 Subject: [PATCH] Add framework for quoting --- src/data/listeners/onMessage.js | 2 ++ src/data/util/routines.js | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/data/listeners/onMessage.js b/src/data/listeners/onMessage.js index 1cee452..6957a05 100644 --- a/src/data/listeners/onMessage.js +++ b/src/data/listeners/onMessage.js @@ -12,6 +12,8 @@ const { * @param {Number} [level=0] The permission level of the author */ async function onMessage (client, db, msg, res, level = 0) { + // await routines.checkJumpLink(msg) + if (res && res.command) console.log(`[COMMAND] ${msg.timestamp} - **${msg.author.username}** > *${res.command.name || 'AWAIT'}*`) else if ((msg.content || msg.attachments.length) && !msg.type && await routines.isTransmissionChannel(db, msg.channel)) { return routines.compileMessage(db, msg, level) diff --git a/src/data/util/routines.js b/src/data/util/routines.js index de6e239..220359f 100644 --- a/src/data/util/routines.js +++ b/src/data/util/routines.js @@ -5,6 +5,8 @@ const { const alerts = require('./alerts/') +const jumpLinkRegex = /https:\/\/discord(?:app)?\.com\/channels\/(\d+)\/(\d+)\/(\d+)\/?/ + /** * Abbreviate a name * @param {String} name The name to abbreviate @@ -75,6 +77,42 @@ async function buildPanel (client, db, room, guild) { } } +function checkJumpLink (msg) { + const match = msg.content.match(jumpLinkRegex) + + if (match !== null) { + const [ + full, + guild, + channel, + message + ] = match + + if (guild === msg.channel.guild.id) { + const target = msg.channel.guild.channels.get(channel).messages.get(message) + + if (target) { + msg.channel.createMessage({ + embed: { + author: { + name: target.author.username, + url: full, /* Switch to Message.jumpLink when released */ + icon_url: target.author.avatarURL + }, + description: target.content, + color: 0x00B0F4, + footer: { + icon_url: target.channel.guild.iconURL, + text: '#' + target.channel.name + }, + timestamp: new Date(target.timestamp) + } + }) + } + } + } +} + /** * Compile Discord messages into content suitable for transmitting * @async @@ -277,6 +315,7 @@ async function transmit (client, db, { room, msg, exclude = '' }) { module.exports = { abbreviate, buildPanel, + checkJumpLink, compileMessage, createRoom, deleteRoom,