diff --git a/src/data/Thread.js b/src/data/Thread.js index 334609a..dba4663 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -32,7 +32,7 @@ class Thread { * @param {String} text * @param {Eris~MessageFile[]} replyAttachments * @param {Boolean} isAnonymous - * @returns {Promise} + * @returns {Promise} Whether we were able to send the reply */ async replyToUser(moderator, text, replyAttachments = [], isAnonymous = false) { // Username to reply with @@ -75,8 +75,16 @@ class Thread { try { dmMessage = await this.postToUser(dmContent, files); } catch (e) { + await this.addThreadMessageToDB({ + message_type: THREAD_MESSAGE_TYPE.COMMAND, + user_id: moderator.id, + user_name: logModUsername, + body: logContent + }); + await this.postSystemMessage(`Error while replying to user: ${e.message}`); - return; + + return false; } // Send the reply to the modmail thread @@ -96,6 +104,8 @@ class Thread { await this.cancelScheduledClose(); await this.postSystemMessage(`Cancelling scheduled closing of this thread due to new reply`); } + + return true; } /** diff --git a/src/main.js b/src/main.js index 37e698d..7c767cb 100644 --- a/src/main.js +++ b/src/main.js @@ -52,8 +52,9 @@ bot.on('messageCreate', async msg => { if (! utils.isStaff(msg.member)) return; // Only staff are allowed to reply if (msg.attachments.length) await attachments.saveAttachmentsInMessage(msg); - await thread.replyToUser(msg.member, msg.content.trim(), msg.attachments, config.alwaysReplyAnon || false); - msg.delete(); + + const replied = await thread.replyToUser(msg.member, msg.content.trim(), msg.attachments, config.alwaysReplyAnon || false); + if (replied) msg.delete(); } else { // Otherwise just save the messages as "chat" in the logs thread.saveChatMessage(msg); diff --git a/src/modules/reply.js b/src/modules/reply.js index 49d56a1..ac6931a 100644 --- a/src/modules/reply.js +++ b/src/modules/reply.js @@ -11,8 +11,9 @@ module.exports = bot => { const text = args.join(' ').trim(); if (msg.attachments.length) await attachments.saveAttachmentsInMessage(msg); - await thread.replyToUser(msg.member, text, msg.attachments, false); - msg.delete(); + + const replied = await thread.replyToUser(msg.member, text, msg.attachments, false); + if (replied) msg.delete(); }); bot.registerCommandAlias('r', 'reply'); @@ -23,8 +24,9 @@ module.exports = bot => { const text = args.join(' ').trim(); if (msg.attachments.length) await attachments.saveAttachmentsInMessage(msg); - await thread.replyToUser(msg.member, text, msg.attachments, true); - msg.delete(); + + const replied = await thread.replyToUser(msg.member, text, msg.attachments, true); + if (replied) msg.delete(); }); bot.registerCommandAlias('ar', 'anonreply'); diff --git a/src/modules/snippets.js b/src/modules/snippets.js index 5fcec44..a084871 100644 --- a/src/modules/snippets.js +++ b/src/modules/snippets.js @@ -47,8 +47,8 @@ module.exports = bot => { const snippet = await snippets.get(trigger); if (! snippet) return; - await thread.replyToUser(msg.member, snippet.body, [], isAnonymous); - msg.delete(); + const replied = await thread.replyToUser(msg.member, snippet.body, [], isAnonymous); + if (replied) msg.delete(); }); // Show or add a snippet