modtimers command

This commit is contained in:
Erik 2022-05-09 18:03:13 +03:00
parent 71fed41529
commit 6aaa2f4658
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 73 additions and 1 deletions

View File

@ -121,3 +121,20 @@ No grantable roles.
{emoji_success} **Grantable roles** {emoji_success} **Grantable roles**
**{roles}** **{roles}**
// Modtimers
[COMMAND_MODTIMERS_HELP]
List currently active timed infractions, e.g. mutes & bans.
[COMMAND_MODTIMERS_TITLE]
Currently active timed infractions
[COMMAND_MODTIMERS_DESC]
**User:** {target}
**Moderator:** {moderator}
**Issued:** <t:{issued}:f>, <t:{issued}:R>
**Ends:** <t:{ends}:f>, <t:{ends}:R>
**Reason:** {reason}
[COMMAND_MODTIMERS_NONE]
No active timed infractions.

View File

@ -0,0 +1,55 @@
const { SlashCommand } = require("../../../interfaces");
class ModtimersCommand extends SlashCommand {
constructor(client) {
super(client, {
name: 'modtimers',
description: 'List active timed infractions',
module: 'moderation',
memberPermissions: ['MANAGE_MESSAGES'],
guildOnly: true
});
}
async execute(invoker) {
const { guild } = invoker;
const { moderation } = this.client;
const callbacks = moderation.callbacks.filter((cb) => cb.infraction.guild === guild.id);
if(!callbacks.size) return { emoji: 'failure', index: 'COMMAND_MODTIMERS_NONE' };
const fields = [];
for (const { infraction } of callbacks.values()) {
const user = await guild.resolveUser(infraction.target);
const moderator = await guild.resolveUser(infraction.executor);
fields.push({
name: `Case ${infraction.case}`,
value: guild.format('COMMAND_MODTIMERS_DESC', {
target: `${user.tag} (${user.id})`,
moderator: `${moderator.tag} (${moderator.id})`,
issued: Math.floor(infraction.timestamp / 1000),
ends: Math.floor((infraction.timestamp + infraction.duration) / 1000),
reason: infraction.reason
})
});
if (fields.length === 25) {
break;
}
}
const embed = {
title: guild.format('COMMAND_MODTIMERS_TITLE'),
fields,
footer: {
text: `${callbacks.size} infraction${callbacks.size > 1 ? 's' : ''}`
}
};
return { embed };
}
}
module.exports = ModtimersCommand;