modmail/structure/commands/Modmail.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-06-19 15:06:20 +02:00
const Command = require('../Command');
class Modmail extends Command {
2021-10-22 09:35:04 +02:00
constructor (client) {
2021-06-19 15:06:20 +02:00
super(client, {
name: 'modmail',
2021-10-22 09:35:04 +02:00
aliases: [ 'mm' ],
2021-06-19 15:06:20 +02:00
showUsage: true,
usage: `<user> <content>`
});
}
2021-10-22 09:35:04 +02:00
async execute (message, { args }) {
2021-06-19 15:06:20 +02:00
// eslint-disable-next-line prefer-const
2021-10-22 09:35:04 +02:00
let [ first, second ] = args.map((a) => a);
2021-06-19 15:06:20 +02:00
// eslint-disable-next-line prefer-const
let { content, _caller } = message,
anon = false;
content = content.replace(`${this.client.prefix}${_caller}`, '');
if (first.toLowerCase() === 'anon') {
anon = true;
content = content.replace(first, '');
first = second;
2021-10-27 09:28:03 +02:00
} else if (second?.toLowerCase() === 'anon') {
2021-06-29 16:04:54 +02:00
anon = true;
content = content.replace(second, '');
2021-06-19 15:06:20 +02:00
}
2021-06-20 13:12:23 +02:00
const user = await this.client.resolveUser(first, true);
2021-06-19 15:06:20 +02:00
if (!user) return {
error: true,
msg: 'Failed to resolve user'
};
else if (user.bot) return {
error: true,
msg: 'Cannot send modmail to a bot.'
};
content = content.replace(first, '');
if (!content.length) return {
error: true,
msg: `Cannot send empty message`
};
return this.client.modmail.sendModmail({ message, content: content.trim(), anon, target: user });
}
}
module.exports = Modmail;