forked from Galactic/modmail
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
const Command = require('../Command');
|
|
|
|
class Modmail extends Command {
|
|
|
|
constructor (client) {
|
|
super(client, {
|
|
name: 'modmail',
|
|
aliases: [ 'mm' ],
|
|
showUsage: true,
|
|
usage: `<user> <content>`
|
|
});
|
|
}
|
|
|
|
async execute (message, { args }) {
|
|
// eslint-disable-next-line prefer-const
|
|
let [ first, second ] = args.map((a) => a);
|
|
// 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;
|
|
} else if (second?.toLowerCase() === 'anon') {
|
|
anon = true;
|
|
content = content.replace(second, '');
|
|
}
|
|
|
|
const user = await this.client.resolveUser(first, true);
|
|
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, '').trim();
|
|
|
|
if (!content.length) return {
|
|
error: true,
|
|
msg: `Cannot send empty message`
|
|
};
|
|
|
|
return this.client.modmail.sendModmail({ message, content, anon, target: user });
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Modmail; |