Skip to content

Commit

Permalink
Merge pull request #123 from BluLightShow/develop
Browse files Browse the repository at this point in the history
hotfix: tag cmds, feat: codeblock copy chars
  • Loading branch information
max-bromberg authored Nov 13, 2021
2 parents 500dc0b + f6640aa commit aa7942f
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 5 deletions.
71 changes: 67 additions & 4 deletions src/commands/tag.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { Command } from 'discord-akairo'
import fs from 'fs'
import { MessageEmbed } from 'discord.js'
import {
ButtonInteraction,
Interaction,
Message,
MessageActionRow,
MessageButton,
MessageEmbed,
MessageOptions,
SelectMenuInteraction
} from 'discord.js'
import { embed, config } from '../bot'

let files = fs.readdirSync('./src/tags')
Expand Down Expand Up @@ -31,7 +40,7 @@ export default class TagCommand extends Command {
}

exec(message: any, args: any) {
// var usedAlias = message.util.parsed.alias -- This should work but it's not so I'm writing a workaround
// var usedAlias = message.util.parsed.alias // This should work but it's not so I'm writing a workaround
var usedAlias = message.content.replace(config.prefix, '').split(' ')[0]
if (usedAlias === ('tag' || 'qr' || 'res')) {
if (!args.tagAlias) {
Expand Down Expand Up @@ -61,7 +70,35 @@ export default class TagCommand extends Command {
tagEmbed.addField(field.name, field.value, false)
})

return message.channel.send({ embeds: [tagEmbed], content: tagFile.content ? tagFile.content : '' })
var messageObject: MessageOptions = {
embeds: [tagEmbed]
}
if (tagFile.actionRow) {
messageObject = {
...messageObject,
components: [{ ...tagFile.actionRow, type: 'ACTION_ROW' }]
}
}
var messageTiedToId: String
message.channel
.send(messageObject)
.then((msg: Message) => (messageTiedToId = msg.id))

message.channel
.createMessageComponentCollector({
componentType: 'BUTTON',
time: 300_000,
filter: (interaction: ButtonInteraction) => {
return interaction.message.id === messageTiedToId
}
})
.on('collect', (interaction: ButtonInteraction) => {
if (tagFile.buttonReplies[interaction.customId]) {
interaction.reply(
tagFile.buttonReplies[interaction.customId]
)
}
})
}
}
})
Expand All @@ -80,7 +117,33 @@ export default class TagCommand extends Command {
tagEmbed.addField(field.name, field.value, false)
})

return message.channel.send({ embeds: [tagEmbed], content: tagFile.content ? tagFile.content : '' })
var messageObject: MessageOptions = {
embeds: [tagEmbed]
}
if (tagFile.actionRow) {
messageObject = {
...messageObject,
components: [{ ...tagFile.actionRow, type: 'ACTION_ROW' }]
}
}
var messageTiedToId: String
message.channel
.send(messageObject)
.then((msg: Message) => (messageTiedToId = msg.id))

message.channel
.createMessageComponentCollector({
componentType: 'BUTTON',
time: 300_000,
filter: (interaction: ButtonInteraction) => {
return interaction.message.id === messageTiedToId
}
})
.on('collect', (interaction: ButtonInteraction) => {
if (tagFile.buttonReplies[interaction.customId]) {
interaction.reply(tagFile.buttonReplies[interaction.customId])
}
})
}
}
})
Expand Down
25 changes: 24 additions & 1 deletion src/tags/codeblock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@
"value": "If using new lines, a file extension can be placed directly after the first 3 backticks to highlight in that language. An example is shown below, highlighting code in arduino. The backtick key is typically found to the left of the 1 key."
}
],
"content": "",
"actionRow": {
"components": [
{
"type": "BUTTON",
"label": "Copy Characters",
"customId": "copy",
"style": "SECONDARY",
"emoji": "💾"
}
]
},
"buttonReplies": {
"copy": {
"ephemeral": true,
"embeds": [
{
"title": "Please copy the 3 characters above and place them before & after your code message",
"description": "For mobile hold this message and tap \"Copy Text\"",
"color": "2f3136"
}
],
"content": "```"
}
},
"image": "https://this-u.lol/09kbow.png"
}

0 comments on commit aa7942f

Please sign in to comment.