mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-02 00:31:27 +03:00
closes all tickets before a specified date
This commit is contained in:
@@ -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: '<timestamp>',
|
||||
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(
|
||||
|
Reference in New Issue
Block a user