mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-21 00:35:02 +00:00
Add automod action for setting slowmode
This commit is contained in:
parent
fdaf386193
commit
db3d1d7c3b
2 changed files with 45 additions and 0 deletions
|
@ -14,6 +14,7 @@ import { SetAntiraidLevelAction } from "./setAntiraidLevel";
|
||||||
import { ReplyAction } from "./reply";
|
import { ReplyAction } from "./reply";
|
||||||
import { AddToCounterAction } from "./addToCounter";
|
import { AddToCounterAction } from "./addToCounter";
|
||||||
import { SetCounterAction } from "./setCounter";
|
import { SetCounterAction } from "./setCounter";
|
||||||
|
import { SetSlowmodeAction } from "./setSlowmode";
|
||||||
|
|
||||||
export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
|
export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
|
||||||
clean: CleanAction,
|
clean: CleanAction,
|
||||||
|
@ -30,6 +31,7 @@ export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
|
||||||
reply: ReplyAction,
|
reply: ReplyAction,
|
||||||
add_to_counter: AddToCounterAction,
|
add_to_counter: AddToCounterAction,
|
||||||
set_counter: SetCounterAction,
|
set_counter: SetCounterAction,
|
||||||
|
set_slowmode: SetSlowmodeAction,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AvailableActions = t.type({
|
export const AvailableActions = t.type({
|
||||||
|
@ -47,4 +49,5 @@ export const AvailableActions = t.type({
|
||||||
reply: ReplyAction.configType,
|
reply: ReplyAction.configType,
|
||||||
add_to_counter: AddToCounterAction.configType,
|
add_to_counter: AddToCounterAction.configType,
|
||||||
set_counter: SetCounterAction.configType,
|
set_counter: SetCounterAction.configType,
|
||||||
|
set_slowmode: SetSlowmodeAction.configType,
|
||||||
});
|
});
|
||||||
|
|
42
backend/src/plugins/Automod/actions/setSlowmode.ts
Normal file
42
backend/src/plugins/Automod/actions/setSlowmode.ts
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import * as t from "io-ts";
|
||||||
|
import { automodAction } from "../helpers";
|
||||||
|
import { convertDelayStringToMS, isDiscordRESTError, tDelayString, tNullable } from "../../../utils";
|
||||||
|
import { LogType } from "../../../data/LogType";
|
||||||
|
|
||||||
|
export const SetSlowmodeAction = automodAction({
|
||||||
|
configType: t.type({
|
||||||
|
channels: t.array(t.string),
|
||||||
|
duration: tNullable(tDelayString),
|
||||||
|
}),
|
||||||
|
|
||||||
|
defaultConfig: {
|
||||||
|
duration: "10s",
|
||||||
|
},
|
||||||
|
|
||||||
|
async apply({ pluginData, actionConfig }) {
|
||||||
|
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0;
|
||||||
|
|
||||||
|
for (const channelId of actionConfig.channels) {
|
||||||
|
const channel = pluginData.guild.channels.get(channelId);
|
||||||
|
// 2 = Guild Voice, 5 = Guild News - Both dont allow slowmode
|
||||||
|
if (!channel || channel.type === 2 || channel.type === 5) continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await channel.edit({
|
||||||
|
rateLimitPerUser: duration / 1000, // ms -> seconds
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
let errorMessage = e;
|
||||||
|
|
||||||
|
// Check for invalid form body -> indicates duration was too large
|
||||||
|
if (isDiscordRESTError(e) && e.code === 50035) {
|
||||||
|
errorMessage = `Duration is greater than maximum native slowmode duration`;
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Unable to set slowmode for channel ${channel.id} to ${duration / 1000} seconds: ${errorMessage}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue