2018-03-13 01:45:31 -04:00
|
|
|
const attachments = require("../data/attachments");
|
2020-08-12 17:08:37 -04:00
|
|
|
const utils = require("../utils");
|
|
|
|
const config = require("../cfg");
|
|
|
|
const Thread = require("../data/Thread");
|
2018-03-13 01:45:31 -04:00
|
|
|
|
2019-08-13 13:34:46 -04:00
|
|
|
module.exports = ({ bot, knex, config, commands }) => {
|
2018-03-13 01:45:31 -04:00
|
|
|
// Mods can reply to modmail threads using !r or !reply
|
|
|
|
// These messages get relayed back to the DM thread between the bot and the user
|
2020-08-12 17:08:37 -04:00
|
|
|
commands.addInboxThreadCommand("reply", "[text$]", async (msg, args, thread) => {
|
2019-06-16 15:37:05 -04:00
|
|
|
if (! args.text && msg.attachments.length === 0) {
|
2020-08-12 17:08:37 -04:00
|
|
|
utils.postError(msg.channel, "Text or attachment required");
|
2019-06-16 15:37:05 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-12 17:08:37 -04:00
|
|
|
const replied = await thread.replyToUser(msg.member, args.text || "", msg.attachments, false);
|
2019-02-23 15:55:26 -05:00
|
|
|
if (replied) msg.delete();
|
2019-06-16 15:27:30 -04:00
|
|
|
}, {
|
2020-08-12 17:08:37 -04:00
|
|
|
aliases: ["r"]
|
2018-03-13 01:45:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Anonymous replies only show the role, not the username
|
2020-08-12 17:08:37 -04:00
|
|
|
commands.addInboxThreadCommand("anonreply", "[text$]", async (msg, args, thread) => {
|
2019-06-16 15:37:05 -04:00
|
|
|
if (! args.text && msg.attachments.length === 0) {
|
2020-08-12 17:08:37 -04:00
|
|
|
utils.postError(msg.channel, "Text or attachment required");
|
2019-06-16 15:37:05 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-12 17:08:37 -04:00
|
|
|
const replied = await thread.replyToUser(msg.member, args.text || "", msg.attachments, true);
|
2019-02-23 15:55:26 -05:00
|
|
|
if (replied) msg.delete();
|
2019-06-16 15:27:30 -04:00
|
|
|
}, {
|
2020-08-12 17:08:37 -04:00
|
|
|
aliases: ["ar"]
|
2018-03-13 01:45:31 -04:00
|
|
|
});
|
2020-07-19 07:20:45 -04:00
|
|
|
|
|
|
|
if (config.allowStaffEdit) {
|
2020-08-12 17:08:37 -04:00
|
|
|
commands.addInboxThreadCommand("edit", "<messageNumber:number> <text:string$>", async (msg, args, thread) => {
|
2020-07-19 07:20:45 -04:00
|
|
|
const threadMessage = await thread.findThreadMessageByMessageNumber(args.messageNumber);
|
|
|
|
if (! threadMessage) {
|
2020-08-12 17:08:37 -04:00
|
|
|
utils.postError(msg.channel, "Unknown message number");
|
2020-07-19 07:20:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (threadMessage.user_id !== msg.author.id) {
|
2020-08-12 17:08:37 -04:00
|
|
|
utils.postError(msg.channel, "You can only edit your own replies");
|
2020-07-19 07:20:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-21 14:29:20 -04:00
|
|
|
const edited = await thread.editStaffReply(msg.member, threadMessage, args.text);
|
|
|
|
if (edited) msg.delete().catch(utils.noop);
|
2020-07-19 07:20:45 -04:00
|
|
|
}, {
|
2020-08-12 17:08:37 -04:00
|
|
|
aliases: ["e"]
|
2020-07-19 07:20:45 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.allowStaffDelete) {
|
2020-08-12 17:08:37 -04:00
|
|
|
commands.addInboxThreadCommand("delete", "<messageNumber:number>", async (msg, args, thread) => {
|
2020-07-19 07:20:45 -04:00
|
|
|
const threadMessage = await thread.findThreadMessageByMessageNumber(args.messageNumber);
|
|
|
|
if (! threadMessage) {
|
2020-08-12 17:08:37 -04:00
|
|
|
utils.postError(msg.channel, "Unknown message number");
|
2020-07-19 07:20:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (threadMessage.user_id !== msg.author.id) {
|
2020-08-12 17:08:37 -04:00
|
|
|
utils.postError(msg.channel, "You can only delete your own replies");
|
2020-07-19 07:20:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await thread.deleteStaffReply(msg.member, threadMessage);
|
2020-08-16 19:02:19 -04:00
|
|
|
msg.delete().catch(utils.noop);
|
2020-07-19 07:20:45 -04:00
|
|
|
}, {
|
2020-08-12 17:08:37 -04:00
|
|
|
aliases: ["d"]
|
2020-07-19 07:20:45 -04:00
|
|
|
});
|
|
|
|
}
|
2018-03-13 01:45:31 -04:00
|
|
|
};
|