Only delete the reply command if the bot was able to send the reply
parent
bb7e9169a2
commit
86bc6fd809
|
@ -32,7 +32,7 @@ class Thread {
|
||||||
* @param {String} text
|
* @param {String} text
|
||||||
* @param {Eris~MessageFile[]} replyAttachments
|
* @param {Eris~MessageFile[]} replyAttachments
|
||||||
* @param {Boolean} isAnonymous
|
* @param {Boolean} isAnonymous
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<boolean>} Whether we were able to send the reply
|
||||||
*/
|
*/
|
||||||
async replyToUser(moderator, text, replyAttachments = [], isAnonymous = false) {
|
async replyToUser(moderator, text, replyAttachments = [], isAnonymous = false) {
|
||||||
// Username to reply with
|
// Username to reply with
|
||||||
|
@ -75,8 +75,16 @@ class Thread {
|
||||||
try {
|
try {
|
||||||
dmMessage = await this.postToUser(dmContent, files);
|
dmMessage = await this.postToUser(dmContent, files);
|
||||||
} catch (e) {
|
} 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}`);
|
await this.postSystemMessage(`Error while replying to user: ${e.message}`);
|
||||||
return;
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the reply to the modmail thread
|
// Send the reply to the modmail thread
|
||||||
|
@ -96,6 +104,8 @@ class Thread {
|
||||||
await this.cancelScheduledClose();
|
await this.cancelScheduledClose();
|
||||||
await this.postSystemMessage(`Cancelling scheduled closing of this thread due to new reply`);
|
await this.postSystemMessage(`Cancelling scheduled closing of this thread due to new reply`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -52,8 +52,9 @@ bot.on('messageCreate', async msg => {
|
||||||
if (! utils.isStaff(msg.member)) return; // Only staff are allowed to reply
|
if (! utils.isStaff(msg.member)) return; // Only staff are allowed to reply
|
||||||
|
|
||||||
if (msg.attachments.length) await attachments.saveAttachmentsInMessage(msg);
|
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 {
|
} else {
|
||||||
// Otherwise just save the messages as "chat" in the logs
|
// Otherwise just save the messages as "chat" in the logs
|
||||||
thread.saveChatMessage(msg);
|
thread.saveChatMessage(msg);
|
||||||
|
|
|
@ -11,8 +11,9 @@ module.exports = bot => {
|
||||||
|
|
||||||
const text = args.join(' ').trim();
|
const text = args.join(' ').trim();
|
||||||
if (msg.attachments.length) await attachments.saveAttachmentsInMessage(msg);
|
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');
|
bot.registerCommandAlias('r', 'reply');
|
||||||
|
@ -23,8 +24,9 @@ module.exports = bot => {
|
||||||
|
|
||||||
const text = args.join(' ').trim();
|
const text = args.join(' ').trim();
|
||||||
if (msg.attachments.length) await attachments.saveAttachmentsInMessage(msg);
|
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');
|
bot.registerCommandAlias('ar', 'anonreply');
|
||||||
|
|
|
@ -47,8 +47,8 @@ module.exports = bot => {
|
||||||
const snippet = await snippets.get(trigger);
|
const snippet = await snippets.get(trigger);
|
||||||
if (! snippet) return;
|
if (! snippet) return;
|
||||||
|
|
||||||
await thread.replyToUser(msg.member, snippet.body, [], isAnonymous);
|
const replied = await thread.replyToUser(msg.member, snippet.body, [], isAnonymous);
|
||||||
msg.delete();
|
if (replied) msg.delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show or add a snippet
|
// Show or add a snippet
|
||||||
|
|
Loading…
Reference in New Issue