mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 10:25:01 +00:00
fix(automod): start_thread action thread options
This commit is contained in:
parent
6636092410
commit
07d33a2dc5
1 changed files with 37 additions and 14 deletions
|
@ -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,
|
startMessage:
|
||||||
// @ts-expect-error FIXME
|
!actionConfig.private && guild.features.includes(GuildFeature.PrivateThreads)
|
||||||
type: actionConfig.private ? ChannelType.PrivateThread : ChannelType.PublicThread,
|
? threadContext.message!.id
|
||||||
startMessage:
|
: undefined,
|
||||||
!actionConfig.private && guild.features.includes(GuildFeature.PrivateThreads)
|
};
|
||||||
? threadContext.message!.id
|
|
||||||
: undefined,
|
let thread: ThreadChannel | undefined;
|
||||||
})
|
if (channel.type === ChannelType.GuildNews) {
|
||||||
.catch(noop);
|
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,
|
||||||
|
startMessage:
|
||||||
|
!actionConfig.private && guild.features.includes(GuildFeature.PrivateThreads)
|
||||||
|
? threadContext.message!.id
|
||||||
|
: undefined,
|
||||||
|
})
|
||||||
|
.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) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue