3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 04:45:02 +00:00
zeppelin/backend/src/plugins/Slowmode/commands/SlowmodeListCmd.ts
2025-01-03 15:15:45 +01:00

46 lines
1.5 KiB
TypeScript

import { GuildChannel, TextChannel } from "discord.js";
import { createChunkedMessage } from "knub/helpers";
import { humanizeDuration } from "../../../humanizeDuration.js";
import { errorMessage } from "../../../utils.js";
import { slowmodeCmd } from "../types.js";
export const SlowmodeListCmd = slowmodeCmd({
trigger: ["slowmode list", "slowmode l", "slowmodes"],
permission: "can_manage",
async run({ message: msg, pluginData }) {
const channels = pluginData.guild.channels;
const slowmodes: Array<{ channel: GuildChannel; seconds: number; native: boolean }> = [];
for (const channel of channels.cache.values()) {
if (!(channel instanceof TextChannel)) continue;
// Bot slowmode
const botSlowmode = await pluginData.state.slowmodes.getChannelSlowmode(channel.id);
if (botSlowmode) {
slowmodes.push({ channel, seconds: botSlowmode.slowmode_seconds, native: false });
continue;
}
// Native slowmode
if (channel.rateLimitPerUser) {
slowmodes.push({ channel, seconds: channel.rateLimitPerUser, native: true });
continue;
}
}
if (slowmodes.length) {
const lines = slowmodes.map((slowmode) => {
const humanized = humanizeDuration(slowmode.seconds * 1000);
const type = slowmode.native ? "native slowmode" : "bot slowmode";
return `<#${slowmode.channel.id}> **${humanized}** ${type}`;
});
createChunkedMessage(msg.channel, lines.join("\n"));
} else {
msg.channel.send(errorMessage("No active slowmodes!"));
}
},
});