mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-23 17:45:03 +00:00
initial
This commit is contained in:
parent
7f2731262d
commit
50fab9718f
1 changed files with 19 additions and 8 deletions
|
@ -1,14 +1,13 @@
|
||||||
import { Snowflake, TextChannel } from "discord.js";
|
import { Snowflake, TextChannel, ThreadChannel } from "discord.js";
|
||||||
import * as t from "io-ts";
|
import * as t from "io-ts";
|
||||||
import { ChannelTypeStrings } from "src/types";
|
import { ChannelTypeStrings } from "src/types";
|
||||||
import { LogType } from "../../../data/LogType";
|
|
||||||
import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils";
|
import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils";
|
||||||
import { automodAction } from "../helpers";
|
import { automodAction } from "../helpers";
|
||||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||||
|
|
||||||
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),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -16,18 +15,30 @@ 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
|
||||||
if (!channel || !(channel.type === ChannelTypeStrings.TEXT || ChannelTypeStrings.CATEGORY)) {
|
if (
|
||||||
|
!channel ||
|
||||||
|
!(
|
||||||
|
channel.type === ChannelTypeStrings.TEXT ||
|
||||||
|
ChannelTypeStrings.CATEGORY ||
|
||||||
|
ChannelTypeStrings.PUBLIC_THREAD ||
|
||||||
|
ChannelTypeStrings.NEWS_THREAD ||
|
||||||
|
ChannelTypeStrings.PRIVATE_THREAD
|
||||||
|
)
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const channelsToSlowmode: TextChannel[] = [];
|
const channelsToSlowmode: Array<TextChannel | ThreadChannel> = [];
|
||||||
if (channel.type === ChannelTypeStrings.CATEGORY) {
|
if (channel.type === ChannelTypeStrings.CATEGORY) {
|
||||||
// Find all text channels within the category
|
// Find all text channels within the category
|
||||||
for (const ch of pluginData.guild.channels.cache.values()) {
|
for (const ch of pluginData.guild.channels.cache.values()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue