3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-25 18:25:03 +00:00

fix(automod): start_thread action thread options

This commit is contained in:
Dragory 2023-04-01 13:54:06 +03:00
parent 6636092410
commit 07d33a2dc5
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -1,4 +1,10 @@
import { ChannelType, GuildFeature, ThreadAutoArchiveDuration } from "discord.js"; import {
ChannelType,
GuildFeature,
GuildTextThreadCreateOptions,
ThreadAutoArchiveDuration,
ThreadChannel,
} from "discord.js";
import * as t from "io-ts"; import * as t from "io-ts";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter"; import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { convertDelayStringToMS, MINUTES, noop, tDelayString, tNullable } from "../../../utils"; import { convertDelayStringToMS, MINUTES, noop, tDelayString, tNullable } from "../../../utils";
@ -51,7 +57,7 @@ export const StartThreadAction = automodAction({
for (const threadContext of threads) { for (const threadContext of threads) {
const channel = pluginData.guild.channels.cache.get(threadContext.message!.channel_id); const channel = pluginData.guild.channels.cache.get(threadContext.message!.channel_id);
if (!channel || !("threads" in channel)) continue; if (!channel || !("threads" in channel) || channel.type === ChannelType.GuildForum) continue;
const renderThreadName = async (str: string) => const renderThreadName = async (str: string) =>
renderTemplate( renderTemplate(
@ -62,18 +68,35 @@ export const StartThreadAction = automodAction({
}), }),
); );
const threadName = await renderThreadName(actionConfig.name ?? "{user.tag}s thread"); const threadName = await renderThreadName(actionConfig.name ?? "{user.tag}s thread");
const thread = await channel.threads const threadOptions: GuildTextThreadCreateOptions<unknown> = {
.create({
name: threadName, name: threadName,
autoArchiveDuration: autoArchive, autoArchiveDuration: autoArchive,
// @ts-expect-error FIXME startMessage:
!actionConfig.private && guild.features.includes(GuildFeature.PrivateThreads)
? threadContext.message!.id
: undefined,
};
let thread: ThreadChannel | undefined;
if (channel.type === ChannelType.GuildNews) {
thread = await channel.threads
.create({
...threadOptions,
type: ChannelType.AnnouncementThread,
})
.catch(() => undefined);
} else {
thread = await channel.threads
.create({
...threadOptions,
type: actionConfig.private ? ChannelType.PrivateThread : ChannelType.PublicThread, type: actionConfig.private ? ChannelType.PrivateThread : ChannelType.PublicThread,
startMessage: startMessage:
!actionConfig.private && guild.features.includes(GuildFeature.PrivateThreads) !actionConfig.private && guild.features.includes(GuildFeature.PrivateThreads)
? threadContext.message!.id ? threadContext.message!.id
: undefined, : undefined,
}) })
.catch(noop); .catch(() => undefined);
}
if (actionConfig.slowmode && thread) { if (actionConfig.slowmode && thread) {
const dur = Math.ceil(Math.max(convertDelayStringToMS(actionConfig.slowmode) ?? 0, 0) / 1000); const dur = Math.ceil(Math.max(convertDelayStringToMS(actionConfig.slowmode) ?? 0, 0) / 1000);
if (dur > 0) { if (dur > 0) {