ramirez/src/modules/reply.js

74 lines
2.5 KiB
JavaScript
Raw Normal View History

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");
module.exports = ({ bot, knex, config, commands }) => {
// 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) => {
if (! args.text && msg.attachments.length === 0) {
2020-08-12 17:08:37 -04:00
utils.postError(msg.channel, "Text or attachment required");
return;
}
2020-08-12 17:08:37 -04:00
const replied = await thread.replyToUser(msg.member, args.text || "", msg.attachments, false);
if (replied) msg.delete();
}, {
2020-08-12 17:08:37 -04:00
aliases: ["r"]
});
// 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) => {
if (! args.text && msg.attachments.length === 0) {
2020-08-12 17:08:37 -04:00
utils.postError(msg.channel, "Text or attachment required");
return;
}
2020-08-12 17:08:37 -04:00
const replied = await thread.replyToUser(msg.member, args.text || "", msg.attachments, true);
if (replied) msg.delete();
}, {
2020-08-12 17:08:37 -04:00
aliases: ["ar"]
});
if (config.allowStaffEdit) {
2020-08-12 17:08:37 -04:00
commands.addInboxThreadCommand("edit", "<messageNumber:number> <text:string$>", async (msg, args, thread) => {
const threadMessage = await thread.findThreadMessageByMessageNumber(args.messageNumber);
if (! threadMessage) {
2020-08-12 17:08:37 -04:00
utils.postError(msg.channel, "Unknown message number");
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");
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-08-12 17:08:37 -04:00
aliases: ["e"]
});
}
if (config.allowStaffDelete) {
2020-08-12 17:08:37 -04:00
commands.addInboxThreadCommand("delete", "<messageNumber:number>", async (msg, args, thread) => {
const threadMessage = await thread.findThreadMessageByMessageNumber(args.messageNumber);
if (! threadMessage) {
2020-08-12 17:08:37 -04:00
utils.postError(msg.channel, "Unknown message number");
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");
return;
}
await thread.deleteStaffReply(msg.member, threadMessage);
msg.delete().catch(utils.noop);
}, {
2020-08-12 17:08:37 -04:00
aliases: ["d"]
});
}
};