From 2f98550ee34eb9bbf923f955cddba16b632bb318 Mon Sep 17 00:00:00 2001 From: Oliver Cordingley Date: Tue, 19 Jan 2021 14:40:01 +0000 Subject: [PATCH 1/9] added to-time package --- package-lock.json | 13 +++++++++++++ package.json | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index e05fa6c..569dd66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -319,6 +319,11 @@ } } }, + "bignumber.js": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-2.4.0.tgz", + "integrity": "sha1-g4qZLan51zfg9LLbC+YrsJ3Qxeg=" + }, "binary-extensions": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz", @@ -2521,6 +2526,14 @@ "is-number": "^7.0.0" } }, + "to-time": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/to-time/-/to-time-1.0.2.tgz", + "integrity": "sha1-T4FFoH2F9jVqYuHOoKep5mYXduM=", + "requires": { + "bignumber.js": "^2.4.0" + } + }, "toposort-class": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz", diff --git a/package.json b/package.json index 7fd66b1..647b2aa 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "n-readlines": "^1.0.1", "node-fetch": "^2.6.1", "sequelize": "^6.3.5", - "terminal-link": "^2.1.1" + "terminal-link": "^2.1.1", + "to-time": "^1.0.2" }, "optionalDependencies": { "sqlite3": "^5.0.0" From 33b300f2b37d84045f3dc27a80fa58acc6608087 Mon Sep 17 00:00:00 2001 From: Oliver Cordingley Date: Tue, 19 Jan 2021 17:20:49 +0000 Subject: [PATCH 2/9] closeall logs use already-defined plural method --- src/commands/closeall.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commands/closeall.js b/src/commands/closeall.js index f6fe8b8..cf27633 100644 --- a/src/commands/closeall.js +++ b/src/commands/closeall.js @@ -12,6 +12,7 @@ const fs = require('fs'); const { join } = require('path'); const config = require(join(__dirname, '../../user/', require('../').config)); const archive = require('../modules/archive'); +const { plural } = require('../modules/utils'); // A slight modification to the 'close' command to allow multiple tickets to be closed at once @@ -207,7 +208,7 @@ module.exports = { let embed = new MessageEmbed() .setColor(config.colour) .setAuthor(message.author.username, message.author.displayAvatarURL()) - .setTitle(`${tickets.count} ticket${tickets.count > 1 ? 's' : ''} closed (${config.prefix}closeall)`) + .setTitle(`${tickets.count} ${plural('ticket', tickets.count)} closed (${config.prefix}closeall)`) .addField('Closed by', message.author, true) .setFooter(guild.name, guild.iconURL()) .setTimestamp(); From a0a15c45517ce379b19a4a9ee979b0c0b045db5e Mon Sep 17 00:00:00 2001 From: Oliver Cordingley Date: Sat, 23 Jan 2021 17:45:35 +0000 Subject: [PATCH 3/9] closes all tickets before a specified date --- package-lock.json | 8 +++---- package.json | 2 +- src/commands/closeall.js | 51 +++++++++++++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 569dd66..c69a0c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2526,10 +2526,10 @@ "is-number": "^7.0.0" } }, - "to-time": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/to-time/-/to-time-1.0.2.tgz", - "integrity": "sha1-T4FFoH2F9jVqYuHOoKep5mYXduM=", + "to-time-monthsfork": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/to-time-monthsfork/-/to-time-monthsfork-1.1.3.tgz", + "integrity": "sha512-SykQ/IAyihZJVtQUjB04ThztVYdQBFx9birBLyCm6i62bZJx8GiuDVis/l9VBPWWsz5NuT5gr7HCrrAb/2OIEg==", "requires": { "bignumber.js": "^2.4.0" } diff --git a/package.json b/package.json index 647b2aa..8565a97 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "node-fetch": "^2.6.1", "sequelize": "^6.3.5", "terminal-link": "^2.1.1", - "to-time": "^1.0.2" + "to-time-monthsfork": "^1.1.3" }, "optionalDependencies": { "sqlite3": "^5.0.0" diff --git a/src/commands/closeall.js b/src/commands/closeall.js index cf27633..8eee123 100644 --- a/src/commands/closeall.js +++ b/src/commands/closeall.js @@ -13,15 +13,18 @@ const { join } = require('path'); const config = require(join(__dirname, '../../user/', require('../').config)); const archive = require('../modules/archive'); const { plural } = require('../modules/utils'); +const { Op } = require('sequelize'); +const toTime = require('to-time-monthsfork'); +const { time } = require('@eartharoid/dtf'); // A slight modification to the 'close' command to allow multiple tickets to be closed at once module.exports = { name: 'closeall', - description: 'Closes all currently open tickets.', - usage: '', + description: 'Closes all currently open tickets older than a specified time length', + usage: '', aliases: ['ca'], - example: 'closeall', + example: 'closeall 1y 2m', args: false, disabled: !config.commands.closeall.enabled, async execute(client, message, args, { @@ -42,11 +45,43 @@ module.exports = { .setFooter(guild.name, guild.iconURL()) ); - let tickets = await Ticket.findAndCountAll({ - where: { - open: true, - }, - }); + let tickets; + + if (args.length > 0) { + let time, maxDate; + let timestamp = args.join(' '); + + try { + time = toTime(timestamp).milliseconds(); + maxDate = new Date(Date.now() - time); + } catch (error) { + return message.channel.send( + new MessageEmbed() + .setColor(config.err_colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle('❌ **Invalid Timestamp**') + .setDescription(`The timestamp that you specified, \`${timestamp}\`, was invalid.`) + .addField('Usage', `\`${config.prefix}${this.name}${' ' + this.usage}\`\n`) + .addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`) + .setFooter(guild.name, guild.iconURL()) + ) + } + + tickets = await Ticket.findAndCountAll({ + where: { + open: true, + updatedAt: { + [Op.lte]: maxDate, + } + }, + }); + } else { + tickets = await Ticket.findAndCountAll({ + where: { + open: true, + }, + }); + } if (tickets.count === 0) return message.channel.send( From 0952d7fc37bb90f86f6b89dd66094769fd2c8738 Mon Sep 17 00:00:00 2001 From: Oliver Cordingley Date: Sat, 23 Jan 2021 17:47:38 +0000 Subject: [PATCH 4/9] linted + removed uneeded pkg require placed by VSCode --- src/commands/closeall.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commands/closeall.js b/src/commands/closeall.js index 8eee123..d2a7e83 100644 --- a/src/commands/closeall.js +++ b/src/commands/closeall.js @@ -15,7 +15,6 @@ const archive = require('../modules/archive'); const { plural } = require('../modules/utils'); const { Op } = require('sequelize'); const toTime = require('to-time-monthsfork'); -const { time } = require('@eartharoid/dtf'); // A slight modification to the 'close' command to allow multiple tickets to be closed at once @@ -64,7 +63,7 @@ module.exports = { .addField('Usage', `\`${config.prefix}${this.name}${' ' + this.usage}\`\n`) .addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`) .setFooter(guild.name, guild.iconURL()) - ) + ); } tickets = await Ticket.findAndCountAll({ From 76572c5d182f27f2cd22eff650b46a71fe39979c Mon Sep 17 00:00:00 2001 From: Oliver Cordingley Date: Sat, 23 Jan 2021 18:20:31 +0000 Subject: [PATCH 5/9] Update ticket's updatedAt property in msg event This allows for messages to be closeall'd by the last message rather than creation date --- src/events/message.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/events/message.js b/src/events/message.js index f5aea2a..58bc428 100644 --- a/src/events/message.js +++ b/src/events/message.js @@ -30,7 +30,12 @@ Type \`${config.prefix}new\` on the server to create a new ticket.`); */ let ticket = await Ticket.findOne({ where: { channel: message.channel.id } }); - if (ticket) archive.add(message); // add message to archive + if (ticket) { + archive.add(message); // add message to archive + // Update the ticket updated at so closeall can get most recent + ticket.changed('updatedAt', true); + ticket.save(); + } if (message.author.bot || message.author.id === client.user.id) return; // goodbye bots From 86578331f7cc462114b185fd7630822a45385d0d Mon Sep 17 00:00:00 2001 From: Oliver Cordingley Date: Sun, 24 Jan 2021 22:15:50 +0000 Subject: [PATCH 6/9] Update closeall.js --- src/commands/closeall.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/closeall.js b/src/commands/closeall.js index d2a7e83..d6bff2f 100644 --- a/src/commands/closeall.js +++ b/src/commands/closeall.js @@ -21,9 +21,9 @@ const toTime = require('to-time-monthsfork'); module.exports = { name: 'closeall', description: 'Closes all currently open tickets older than a specified time length', - usage: '', + usage: '[time]', aliases: ['ca'], - example: 'closeall 1y 2m', + example: 'closeall 1y 2mo', args: false, disabled: !config.commands.closeall.enabled, async execute(client, message, args, { @@ -257,4 +257,4 @@ module.exports = { } }, -}; \ No newline at end of file +}; From bfc9080fa77b470c7ee17e786ffcb643bc028782 Mon Sep 17 00:00:00 2001 From: Oliver Cordingley Date: Sun, 24 Jan 2021 22:17:55 +0000 Subject: [PATCH 7/9] Update closeall.js --- src/commands/closeall.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/closeall.js b/src/commands/closeall.js index d6bff2f..25f4caf 100644 --- a/src/commands/closeall.js +++ b/src/commands/closeall.js @@ -23,7 +23,7 @@ module.exports = { description: 'Closes all currently open tickets older than a specified time length', usage: '[time]', aliases: ['ca'], - example: 'closeall 1y 2mo', + example: 'closeall 1mo 1w', args: false, disabled: !config.commands.closeall.enabled, async execute(client, message, args, { From a51de408d5a89837207aacc81200ed3c18b6480a Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 25 Jan 2021 19:53:46 +0000 Subject: [PATCH 8/9] Fix package.json --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index beb56e8..2c258ef 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,7 @@ "node-fetch": "^2.6.1", "sequelize": "^6.4.0", "terminal-link": "^2.1.1", - "to-time-monthsfork": "^1.1.3" - "sequelize": "^6.4.0", + "to-time-monthsfork": "^1.1.3", "terminal-link": "^2.1.1" }, "optionalDependencies": { From 296b0e51fa35cb13b97bd2affe07660dc67ec411 Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 25 Jan 2021 19:55:20 +0000 Subject: [PATCH 9/9] Update package.json --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 2c258ef..180887d 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,7 @@ "node-fetch": "^2.6.1", "sequelize": "^6.4.0", "terminal-link": "^2.1.1", - "to-time-monthsfork": "^1.1.3", - "terminal-link": "^2.1.1" + "to-time-monthsfork": "^1.1.3" }, "optionalDependencies": { "sqlite3": "^5.0.0"