Skip to content

Commit

Permalink
Add framework for quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
exoRift committed Nov 3, 2020
1 parent b0b08e0 commit e84e7d6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/data/listeners/onMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions src/data/util/routines.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -277,6 +315,7 @@ async function transmit (client, db, { room, msg, exclude = '' }) {
module.exports = {
abbreviate,
buildPanel,
checkJumpLink,
compileMessage,
createRoom,
deleteRoom,
Expand Down

0 comments on commit e84e7d6

Please sign in to comment.