bugfix for empty messages
This commit is contained in:
parent
88fdf4e7b9
commit
c325bf5ab4
@ -1,53 +1,51 @@
|
|||||||
const Command = require('../Command');
|
const Command = require('../Command');
|
||||||
|
|
||||||
class Modmail extends Command {
|
class Modmail extends Command {
|
||||||
|
|
||||||
constructor (client) {
|
constructor (client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'modmail',
|
name: 'modmail',
|
||||||
aliases: [ 'mm' ],
|
aliases: [ 'mm' ],
|
||||||
showUsage: true,
|
showUsage: true,
|
||||||
usage: `<user> <content>`
|
usage: `<user> <content>`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute (message, { args }) {
|
async execute (message, { args }) {
|
||||||
|
// eslint-disable-next-line prefer-const
|
||||||
// eslint-disable-next-line prefer-const
|
let [ first, second ] = args.map((a) => a);
|
||||||
let [ first, second ] = args.map((a) => a);
|
// eslint-disable-next-line prefer-const
|
||||||
// eslint-disable-next-line prefer-const
|
let { content, _caller } = message,
|
||||||
let { content, _caller } = message,
|
anon = false;
|
||||||
anon = false;
|
content = content.replace(`${this.client.prefix}${_caller}`, '');
|
||||||
content = content.replace(`${this.client.prefix}${_caller}`, '');
|
if (first.toLowerCase() === 'anon') {
|
||||||
if (first.toLowerCase() === 'anon') {
|
anon = true;
|
||||||
anon = true;
|
content = content.replace(first, '');
|
||||||
content = content.replace(first, '');
|
first = second;
|
||||||
first = second;
|
} else if (second?.toLowerCase() === 'anon') {
|
||||||
} else if (second?.toLowerCase() === 'anon') {
|
anon = true;
|
||||||
anon = true;
|
content = content.replace(second, '');
|
||||||
content = content.replace(second, '');
|
}
|
||||||
}
|
|
||||||
|
const user = await this.client.resolveUser(first, true);
|
||||||
const user = await this.client.resolveUser(first, true);
|
if (!user) return {
|
||||||
if (!user) return {
|
error: true,
|
||||||
error: true,
|
msg: 'Failed to resolve user'
|
||||||
msg: 'Failed to resolve user'
|
};
|
||||||
};
|
else if (user.bot) return {
|
||||||
else if (user.bot) return {
|
error: true,
|
||||||
error: true,
|
msg: 'Cannot send modmail to a bot.'
|
||||||
msg: 'Cannot send modmail to a bot.'
|
};
|
||||||
};
|
content = content.replace(first, '').trim();
|
||||||
content = content.replace(first, '');
|
|
||||||
|
if (!content.length) return {
|
||||||
if (!content.length) return {
|
error: true,
|
||||||
error: true,
|
msg: `Cannot send empty message`
|
||||||
msg: `Cannot send empty message`
|
};
|
||||||
};
|
|
||||||
|
return this.client.modmail.sendModmail({ message, content, anon, target: user });
|
||||||
return this.client.modmail.sendModmail({ message, content: content.trim(), anon, target: user });
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Modmail;
|
module.exports = Modmail;
|
Loading…
Reference in New Issue
Block a user