From 5bbe5ef3030dfa1a384cdf25a4ad5f58b14accb1 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sat, 2 May 2020 19:03:11 +0200 Subject: [PATCH] Give ID to the dm message so people can reference it in feedback Signed-off-by: loicbersier --- commands/owner/dm.js | 30 ++++++++++++++++++++++++------ commands/utility/feedback.js | 28 ++++++++++++++++++++-------- json/feedbackID.json | 1 + 3 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 json/feedbackID.json diff --git a/commands/owner/dm.js b/commands/owner/dm.js index 5e1cb49..525bac6 100644 --- a/commands/owner/dm.js +++ b/commands/owner/dm.js @@ -1,6 +1,8 @@ const { Command } = require('discord-akairo'); +const { prefix } = require('../../config.json'); +const feedbackID = require('../../json/feedbackID.json'); -class EvalCommand extends Command { +class dmCommand extends Command { constructor() { super('dm', { aliases: ['dm', 'pm'], @@ -26,12 +28,28 @@ class EvalCommand extends Command { } async exec(message, args) { + function uuidv4() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); + } + + const uuid = uuidv4(); + feedbackID[uuid] = args.text; + let user = args.user; let text = args.text; + const Embed = this.client.util.embed() + .setTitle('You received a message from the developer!') + .setDescription(text) + .setFooter(`If you wish to respond use the following command: ${prefix[0]}feedback --reply ${uuid} `) + .setTimestamp(); + let Attachment = (message.attachments).array(); if (Attachment[0]) { - this.client.users.resolve(user.id).send(`**Message from the dev:**\n${text}\n**If you wish to respond use the feedback command**`, {files: [Attachment[0].url]}) + this.client.users.resolve(user.id).send(Embed, {files: [Attachment[0].url]}) .then(() => { return message.channel.send(`DM sent to ${user.username}`); }) @@ -40,16 +58,16 @@ class EvalCommand extends Command { }); } else { - this.client.users.resolve(user.id).send(`**Message from the dev:**\n${text}\n**If you wish to respond use the feedback command**`) + this.client.users.resolve(user.id).send(Embed) .then(() => { - return message.channel.send(`DM sent to ${user.username}`); + return message.channel.send(`DM sent to ${user.tag}`); }) .catch(() => { - return message.channel.send(`Could not send a DM to ${user.username}`); + return message.channel.send(`Could not send a DM to ${user.tag}`); }); } } } -module.exports = EvalCommand; \ No newline at end of file +module.exports = dmCommand; \ No newline at end of file diff --git a/commands/utility/feedback.js b/commands/utility/feedback.js index b563d32..ae2f210 100644 --- a/commands/utility/feedback.js +++ b/commands/utility/feedback.js @@ -1,5 +1,6 @@ const { Command } = require('discord-akairo'); const { feedbackChannel } = require('../../config.json'); +const feedbackID = require('../../json/feedbackID.json'); class FeedbackCommand extends Command { constructor() { @@ -15,7 +16,12 @@ class FeedbackCommand extends Command { start: 'What do you want to say to the owner?', }, match: 'rest' - } + }, + { + id: 'reply', + match: 'option', + flag: '--reply', + }, ], description: { content: 'Send feedback to the bot owner', @@ -26,19 +32,25 @@ class FeedbackCommand extends Command { } async exec(message,args) { - // Don't let account new account use this command to prevent spam + const Embed = this.client.util.embed() + .setAuthor(`${message.author.tag} (${message.author.id})`, message.author.displayAvatarURL()) + .setTimestamp(); + + if (message.guild) Embed.addField('Guild', `${message.guild.name} (${message.guild.id})`, true); + + Embed.addField('Feedback', args.text); + + if (feedbackID[args.reply]) { + Embed.addField('Responding to', feedbackID[args.reply]); + } + + // Don't let new account use this command to prevent spam, if they have an UUID its fine to skip it let date = new Date(); if (message.author.createdAt > date.setDate(date.getDate() - 7)) { return message.channel.send('Your account is too new to be able to use this command!'); } const channel = this.client.channels.resolve(feedbackChannel); - - const Embed = this.client.util.embed() - .setAuthor(`${message.author.username} (${message.author.id})`, message.author.displayAvatarURL()); - if (message.guild) Embed.addField('Guild', `${message.guild.name} (${message.guild.id})`, true); - Embed.addField('Feedback', args.text) - .setTimestamp(); channel.send({embed: Embed}); message.channel.send('Your feedback has been sent!'); diff --git a/json/feedbackID.json b/json/feedbackID.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/json/feedbackID.json @@ -0,0 +1 @@ +{} \ No newline at end of file