51 lines
2 KiB
TypeScript
51 lines
2 KiB
TypeScript
import { ApplicationCommandType, ChatInputCommandInteraction, ApplicationCommandOption, ApplicationCommandOptionType, APIEmbedField } from "discord.js";
|
|
|
|
import Command from "../command";
|
|
import { config } from "../index";
|
|
|
|
export default class MyLimit extends Command implements Command {
|
|
name = "check-limit";
|
|
description = "Checks your limit and usage";
|
|
type = ApplicationCommandType.ChatInput;
|
|
options: ApplicationCommandOption[] = [
|
|
{
|
|
name: "recovery-for",
|
|
description: "Calculate the limit recovery time for given message count (default 1)",
|
|
type: ApplicationCommandOptionType.Integer,
|
|
required: false,
|
|
},
|
|
{
|
|
name: "ephemeral",
|
|
description: "if true, only you can see the response (default true)",
|
|
type: ApplicationCommandOptionType.Boolean,
|
|
}
|
|
];
|
|
|
|
async execute(interaction: ChatInputCommandInteraction) {
|
|
let recoveryFor = interaction.options.getInteger("recovery-for", false) ?? 1;
|
|
const ephemeral = interaction.options.getBoolean("ephemeral", false) ?? true;
|
|
|
|
if (recoveryFor <= 0) recoveryFor = 1;
|
|
|
|
const userQuotaRecovery = await config.quota.getUserQuotaRecovery(interaction.user, interaction, recoveryFor);
|
|
|
|
const fields: APIEmbedField[] = [];
|
|
|
|
fields.push({ name: "Quota", inline: true, value: `${userQuotaRecovery.quota} ${userQuotaRecovery.unitName}`.trim() });
|
|
fields.push({ name: "Usage", inline: true, value: `${userQuotaRecovery.used} ${userQuotaRecovery.unitName}`.trim() });
|
|
|
|
if (userQuotaRecovery.recoveryTimestamp !== undefined) fields.push({
|
|
name: `Recovery for ${recoveryFor} ${userQuotaRecovery.unitName}`.trim(),
|
|
value: userQuotaRecovery.recoveryTimestamp === Infinity ? "never" :
|
|
`<t:${Math.ceil(userQuotaRecovery.recoveryTimestamp/1000)}:R>`
|
|
});
|
|
|
|
await interaction.reply({
|
|
embeds: [{
|
|
author: { name: interaction.user.username, icon_url: interaction.user.displayAvatarURL({ size: 128 }) },
|
|
fields: fields,
|
|
}],
|
|
ephemeral: ephemeral,
|
|
});
|
|
}
|
|
}
|