2018-12-30 03:35:25 +01:00
|
|
|
const { Command } = require('discord-akairo');
|
2020-05-02 19:03:11 +02:00
|
|
|
const { prefix } = require('../../config.json');
|
|
|
|
const feedbackID = require('../../json/feedbackID.json');
|
2018-12-30 03:35:25 +01:00
|
|
|
|
2020-05-02 19:03:11 +02:00
|
|
|
class dmCommand extends Command {
|
2019-01-02 08:09:45 +01:00
|
|
|
constructor() {
|
|
|
|
super('dm', {
|
|
|
|
aliases: ['dm', 'pm'],
|
|
|
|
category: 'owner',
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
id: 'user',
|
2020-05-02 19:21:53 +02:00
|
|
|
type: 'string'
|
2019-01-02 08:09:45 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'text',
|
2019-01-10 20:45:29 +01:00
|
|
|
type: 'string',
|
2020-05-02 19:21:53 +02:00
|
|
|
prompt: {
|
|
|
|
start: 'What do you want to send to that user?',
|
|
|
|
},
|
2019-01-10 20:45:29 +01:00
|
|
|
match: 'rest'
|
2019-01-02 08:09:45 +01:00
|
|
|
}
|
|
|
|
],
|
|
|
|
ownerOnly: 'true',
|
|
|
|
description: {
|
2018-12-30 03:35:25 +01:00
|
|
|
content: 'DM users',
|
|
|
|
usage: '[user id] [message]',
|
|
|
|
examples: ['267065637183029248 hello i recived your feedback and...']
|
|
|
|
}
|
2019-01-02 08:09:45 +01:00
|
|
|
});
|
|
|
|
}
|
2018-12-30 03:35:25 +01:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
async exec(message, args) {
|
2020-05-02 19:03:11 +02:00
|
|
|
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;
|
|
|
|
|
2020-05-02 19:21:53 +02:00
|
|
|
let user = this.client.users.resolve(args.user);
|
|
|
|
if (!user) return message.channel.send('Not a valid ID');
|
2019-01-02 08:09:45 +01:00
|
|
|
let text = args.text;
|
2018-12-30 03:39:59 +01:00
|
|
|
|
2020-05-02 19:03:11 +02:00
|
|
|
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} <message>`)
|
|
|
|
.setTimestamp();
|
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
let Attachment = (message.attachments).array();
|
|
|
|
if (Attachment[0]) {
|
2020-05-02 19:21:53 +02:00
|
|
|
this.client.users.resolve(user).send(Embed, {files: [Attachment[0].url]})
|
2019-04-15 22:23:26 +02:00
|
|
|
.then(() => {
|
|
|
|
return message.channel.send(`DM sent to ${user.username}`);
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
return message.channel.send(`Could not send a DM to ${user.username}`);
|
|
|
|
});
|
2019-01-02 08:09:45 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-05-02 19:21:53 +02:00
|
|
|
this.client.users.resolve(user).send(Embed)
|
2019-04-15 22:23:26 +02:00
|
|
|
.then(() => {
|
2020-05-02 19:03:11 +02:00
|
|
|
return message.channel.send(`DM sent to ${user.tag}`);
|
2019-04-15 22:23:26 +02:00
|
|
|
})
|
|
|
|
.catch(() => {
|
2020-05-02 19:03:11 +02:00
|
|
|
return message.channel.send(`Could not send a DM to ${user.tag}`);
|
2019-04-15 22:23:26 +02:00
|
|
|
});
|
2019-01-02 08:09:45 +01:00
|
|
|
}
|
2018-12-30 03:35:25 +01:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
}
|
2018-12-30 03:35:25 +01:00
|
|
|
}
|
|
|
|
|
2020-05-02 19:03:11 +02:00
|
|
|
module.exports = dmCommand;
|