Thread fixes

This commit is contained in:
Dragory 2021-08-18 20:47:24 +03:00
parent d109a58cb7
commit 0e7cf9715f
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
5 changed files with 18 additions and 11 deletions

View file

@ -1,4 +1,4 @@
import { MessageOptions, Permissions, Snowflake, TextChannel, User } from "discord.js";
import { MessageOptions, Permissions, Snowflake, TextChannel, ThreadChannel, User } from "discord.js";
import * as t from "io-ts";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { LogType } from "../../../data/LogType";
@ -32,7 +32,10 @@ export const ReplyAction = automodAction({
async apply({ pluginData, contexts, actionConfig, ruleName }) {
const contextsWithTextChannels = contexts
.filter(c => c.message?.channel_id)
.filter(c => pluginData.guild.channels.cache.get(c.message!.channel_id as Snowflake) instanceof TextChannel);
.filter(c => {
const channel = pluginData.guild.channels.cache.get(c.message!.channel_id as Snowflake);
return channel instanceof TextChannel || channel instanceof ThreadChannel;
});
const contextsByChannelId = contextsWithTextChannels.reduce((map: Map<string, AutomodContext[]>, context) => {
if (!map.has(context.message!.channel_id)) {
@ -59,6 +62,7 @@ export const ReplyAction = automodAction({
? await renderReplyText(actionConfig)
: ((await renderRecursively(actionConfig.text, renderReplyText)) as MessageOptions);
console.log("formatted:", formatted);
if (formatted) {
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake) as TextChannel;
@ -89,6 +93,7 @@ export const ReplyAction = automodAction({
}
const messageContent: MessageOptions = typeof formatted === "string" ? { content: formatted } : formatted;
console.log(`sending reply message to ${channel.id}`);
const replyMsg = await channel.send({
...messageContent,
allowedMentions: {