Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked automod "set_slowmode" action #441

Merged
merged 3 commits into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions backend/src/plugins/Automod/actions/setSlowmode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@ import { automodAction } from "../helpers";

export const SetSlowmodeAction = automodAction({
configType: t.type({
channels: t.array(t.string),
channels: tNullable(t.array(t.string)),
duration: tNullable(tDelayString),
}),

defaultConfig: {
duration: "10s",
},

async apply({ pluginData, actionConfig }) {
async apply({ pluginData, actionConfig, contexts }) {
const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0);

for (const channelId of actionConfig.channels) {
const channels: Snowflake[] = actionConfig.channels ?? [];
if (channels.length === 0) {
channels.push(...contexts.filter((c) => c.message?.channel_id).map((c) => c.message!.channel_id));
}
for (const channelId of channels) {
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);

// Only text channels and text channels within categories support slowmodes
if (!channel || (!channel.isTextBased() && channel.type !== ChannelType.GuildCategory)) {

if (!channel?.isTextBased() && channel?.type !== ChannelType.GuildCategory) {
continue;
}

Expand Down
Loading