3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-07 02:57:20 +00:00
This commit is contained in:
Tiago R 2021-09-01 14:58:24 +00:00 committed by GitHub
parent 047ab872df
commit 2907f5c079
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,4 @@
import { ChannelType, GuildTextBasedChannel, Snowflake } from "discord.js"; import { ChannelType, GuildTextBasedChannel, Snowflake, TextChannel, ThreadChannel } from "discord.js";
import * as t from "io-ts"; import * as t from "io-ts";
import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils"; import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
@ -6,7 +6,7 @@ import { automodAction } from "../helpers";
export const SetSlowmodeAction = automodAction({ export const SetSlowmodeAction = automodAction({
configType: t.type({ configType: t.type({
channels: t.array(t.string), channels: tNullable(t.array(t.string)),
duration: tNullable(tDelayString), duration: tNullable(tDelayString),
}), }),
@ -14,10 +14,13 @@ export const SetSlowmodeAction = automodAction({
duration: "10s", duration: "10s",
}, },
async apply({ pluginData, actionConfig }) { async apply({ pluginData, actionConfig, contexts }) {
const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0); const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0);
const channels = actionConfig.channels ?? new Array();
for (const channelId of 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); const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
// Only text channels and text channels within categories support slowmodes // Only text channels and text channels within categories support slowmodes