close: use native options for -s, add -silent/-cancel/-c options

cshd
Dragory 2021-01-07 20:42:12 +02:00
parent ff5707c40f
commit cd500f06dd
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
1 changed files with 37 additions and 32 deletions

View File

@ -92,8 +92,9 @@ module.exports = ({ bot, knex, config, commands }) => {
thread = await threads.findOpenThreadByChannelId(msg.channel.id); thread = await threads.findOpenThreadByChannelId(msg.channel.id);
if (! thread) return; if (! thread) return;
if (args.opts && args.opts.length) { const opts = args.opts || [];
if (args.opts.includes("cancel") || args.opts.includes("c")) {
if (args.cancel || opts.includes("cancel") || opts.includes("c")) {
// Cancel timed close // Cancel timed close
if (thread.scheduled_close_at) { if (thread.scheduled_close_at) {
await thread.cancelScheduledClose(); await thread.cancelScheduledClose();
@ -104,12 +105,12 @@ module.exports = ({ bot, knex, config, commands }) => {
} }
// Silent close (= no close message) // Silent close (= no close message)
if (args.opts.includes("silent") || args.opts.includes("s") || args.opts.includes("-s")) { if (args.silent || opts.includes("silent") || opts.includes("s")) {
silentClose = true; silentClose = true;
} }
// Timed close // Timed close
const delayStringArg = args.opts.find(arg => utils.delayStringRegex.test(arg)); const delayStringArg = opts.find(arg => utils.delayStringRegex.test(arg));
if (delayStringArg) { if (delayStringArg) {
const delay = utils.convertDelayStringToMS(delayStringArg); const delay = utils.convertDelayStringToMS(delayStringArg);
if (delay === 0 || delay === null) { if (delay === 0 || delay === null) {
@ -131,7 +132,6 @@ module.exports = ({ bot, knex, config, commands }) => {
return; return;
} }
}
// Regular close // Regular close
closedBy = msg.author.username; closedBy = msg.author.username;
@ -146,6 +146,11 @@ module.exports = ({ bot, knex, config, commands }) => {
await thread.close(suppressSystemMessages, silentClose); await thread.close(suppressSystemMessages, silentClose);
await sendCloseNotification(thread, `Modmail thread #${thread.thread_number} with ${thread.user_name} (${thread.user_id}) was closed by ${closedBy}`); await sendCloseNotification(thread, `Modmail thread #${thread.thread_number} with ${thread.user_name} (${thread.user_id}) was closed by ${closedBy}`);
}, {
options: [
{ name: "silent", shortcut: "s", isSwitch: true },
{ name: "cancel", shortcut: "c", isSwitch: true },
],
}); });
// Auto-close threads if their channel is deleted // Auto-close threads if their channel is deleted