From 158db3c07061896147a9e1b5e61b398d9b2eacb6 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 16 Jun 2019 22:37:05 +0300 Subject: [PATCH] Fix replies without text that include attachments --- src/modules/reply.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/modules/reply.js b/src/modules/reply.js index 545fec3..1e1d5ea 100644 --- a/src/modules/reply.js +++ b/src/modules/reply.js @@ -1,10 +1,16 @@ const attachments = require("../data/attachments"); +const utils = require('../utils'); 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 - commands.addInboxThreadCommand('reply', '', async (msg, args, thread) => { - const replied = await thread.replyToUser(msg.member, args.text, msg.attachments, false); + commands.addInboxThreadCommand('reply', '[text$]', async (msg, args, thread) => { + if (! args.text && msg.attachments.length === 0) { + utils.postError(msg.channel, 'Text or attachment required'); + return; + } + + const replied = await thread.replyToUser(msg.member, args.text || '', msg.attachments, false); if (replied) msg.delete(); }, { aliases: ['r'] @@ -12,8 +18,13 @@ module.exports = (bot, knex, config, commands) => { // Anonymous replies only show the role, not the username - commands.addInboxThreadCommand('anonreply', '', async (msg, args, thread) => { - const replied = await thread.replyToUser(msg.member, args.text, msg.attachments, true); + commands.addInboxThreadCommand('anonreply', '[text$]', async (msg, args, thread) => { + if (! args.text && msg.attachments.length === 0) { + utils.postError(msg.channel, 'Text or attachment required'); + return; + } + + const replied = await thread.replyToUser(msg.member, args.text || '', msg.attachments, true); if (replied) msg.delete(); }, { aliases: ['ar']