const { Command } = require('../../../../interfaces/'); const { Util, Constants } = require('../../../../../util/'); const pageSize = 10; class ModerationTimersCommand extends Command { constructor(client) { super(client, { name: 'moderationTimers', module: 'moderation', usage: "[page]", aliases: [ 'moderationTimer', 'modTimer', 'modTimers' ], memberPermissions: ['MANAGE_MESSAGES'], guildOnly: true, throttling: { usages: 2, duration: 5 }, archivable: false }); this.client = client; } async execute(message, { params }) { const callbacks = this.client.moderationManager.callbacks.filter((c) => { return c.infraction.guild === message.guild.id; }).sort((a, b) => b.infraction.timestamp - a.infraction.timestamp).array(); let currentPage = 1; if(params.length > 0) { const number = parseInt(params[0]); if(!Number.isNaN(number) && number > 1) { currentPage = number; } } const { items, page, maxPage } = Util.paginate(callbacks, currentPage, pageSize); const embed = { author: { name: "Moderation Timers", icon_url: message.guild.iconURL() //eslint-disable-line camelcase }, description: '', footer: { text: `• Page ${page}/${maxPage} | ${callbacks.length} Result${callbacks.length === 1 ? '' : 's'}` } }; for(const { infraction } of items) { const target = await this.client.moderationManager._fetchTarget(message.guild, infraction.target, infraction.targetType, true); const when = Util.duration((infraction.callback - new Date())/1000); embed.description += ` \`[case-${infraction.case}]\` **${Constants.InfractionOpposites[infraction.type]}** ${target?.mention || ``} in *${when}*\n`; } return message.respond('Fetched the latest moderation timers.', { embed, emoji: 'success' }); } } module.exports = ModerationTimersCommand;