Fix crash when the auto-response cannot be sent. Add pingOnBotMention option for controlling whether the staff get pinged for bot mentions.

master
Dragory 2018-05-03 20:26:12 +03:00
parent cd96c70f1c
commit 1d2f3dd4d8
3 changed files with 15 additions and 3 deletions

View File

@ -48,6 +48,7 @@ const defaultConfig = {
"newThreadCategoryId": null,
"mentionRole": "here",
"pingOnBotMention": true,
"inboxServerPermission": null,
"alwaysReply": false,

View File

@ -85,6 +85,7 @@ async function createNewThreadForUser(user, quiet = false) {
});
const newThread = await findById(newThreadId);
let responseMessageError = null;
if (! quiet) {
// Ping moderators of the new thread
@ -97,7 +98,11 @@ async function createNewThreadForUser(user, quiet = false) {
// Send auto-reply to the user
if (config.responseMessage) {
newThread.postToUser(config.responseMessage);
try {
await newThread.postToUser(config.responseMessage);
} catch (err) {
responseMessageError = err;
}
}
}
@ -145,6 +150,11 @@ async function createNewThreadForUser(user, quiet = false) {
await newThread.postSystemMessage(infoHeader);
// If there were errors sending a response to the user, note that
if (responseMessageError) {
await newThread.postSystemMessage(`**NOTE:** Could not send auto-response to the user. The error given was: \`${responseMessageError.message}\``);
}
// Return the thread
return newThread;
}

View File

@ -155,11 +155,12 @@ bot.on('messageCreate', async msg => {
let content;
const mainGuilds = utils.getMainGuilds();
const staffMention = (config.pingOnBotMention ? utils.getInboxMention() : '');
if (mainGuilds.length === 1) {
content = `${utils.getInboxMention()}Bot mentioned in ${msg.channel.mention} by **${msg.author.username}#${msg.author.discriminator}**: "${msg.cleanContent}"`;
content = `${staffMention}Bot mentioned in ${msg.channel.mention} by **${msg.author.username}#${msg.author.discriminator}**: "${msg.cleanContent}"`;
} else {
content = `${utils.getInboxMention()}Bot mentioned in ${msg.channel.mention} (${msg.channel.guild.name}) by **${msg.author.username}#${msg.author.discriminator}**: "${msg.cleanContent}"`;
content = `${staffMention}Bot mentioned in ${msg.channel.mention} (${msg.channel.guild.name}) by **${msg.author.username}#${msg.author.discriminator}**: "${msg.cleanContent}"`;
}
bot.createMessage(utils.getLogChannel(bot).id, {