Add 'silent' option to !close when closeMessage is specified

master
Dragory 2019-02-23 23:32:18 +02:00
parent f4a295c00e
commit 5e1a1e7e15
2 changed files with 19 additions and 15 deletions

View File

@ -326,8 +326,8 @@ class Thread {
/**
* @returns {Promise<void>}
*/
async close(silent = false) {
if (! silent) {
async close(noSystemMessage = false) {
if (! noSystemMessage) {
console.log(`Closing thread ${this.id}`);
await this.postSystemMessage('Closing thread...');
}

View File

@ -41,6 +41,8 @@ module.exports = bot => {
bot.registerCommand('close', async (msg, args) => {
let thread, closedBy;
let sendCloseMessage = !! config.closeMessage;
if (msg.channel instanceof Eris.PrivateChannel) {
// User is closing the thread by themselves (if enabled)
if (! config.allowUserClose) return;
@ -67,7 +69,7 @@ module.exports = bot => {
// Timed close
if (args.length) {
if (args[0].startsWith('c')) {
if (args.includes('cancel') || args.includes('c')) {
// Cancel timed close
if (thread.scheduled_close_at) {
await thread.cancelScheduledClose();
@ -75,8 +77,9 @@ module.exports = bot => {
}
return;
}
} else if (args.includes('silent') || args.includes('s')) {
sendCloseMessage = false;
} else {
// Set a timed close
const delay = utils.convertDelayStringToMS(args.join(' '));
if (delay === 0 || delay === null) {
@ -90,13 +93,14 @@ module.exports = bot => {
return;
}
}
// Regular close
await thread.close();
closedBy = msg.author.username;
}
if (config.closeMessage) {
if (sendCloseMessage) {
await thread.postToUser(config.closeMessage).catch(() => {});
}