From e1499f64fc123f43c5df9ba0bb0608180ee8567e Mon Sep 17 00:00:00 2001 From: metal Date: Wed, 8 Sep 2021 10:07:12 +0000 Subject: [PATCH] initial --- .../Automod/actions/availableActions.ts | 3 ++ .../Automod/actions/crosspostMessage.ts | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 backend/src/plugins/Automod/actions/crosspostMessage.ts diff --git a/backend/src/plugins/Automod/actions/availableActions.ts b/backend/src/plugins/Automod/actions/availableActions.ts index 76b2a60e..8b8b75d3 100644 --- a/backend/src/plugins/Automod/actions/availableActions.ts +++ b/backend/src/plugins/Automod/actions/availableActions.ts @@ -7,6 +7,7 @@ import { ArchiveThreadAction } from "./archiveThread"; import { BanAction } from "./ban"; import { ChangeNicknameAction } from "./changeNickname"; import { CleanAction } from "./clean"; +import { CrosspostMessageAction } from "./crosspostMessage"; import { KickAction } from "./kick"; import { LogAction } from "./log"; import { MuteAction } from "./mute"; @@ -34,6 +35,7 @@ export const availableActions: Record> = { set_counter: SetCounterAction, set_slowmode: SetSlowmodeAction, archive_thread: ArchiveThreadAction, + crosspost_message: CrosspostMessageAction, }; export const AvailableActions = t.type({ @@ -53,4 +55,5 @@ export const AvailableActions = t.type({ set_counter: SetCounterAction.configType, set_slowmode: SetSlowmodeAction.configType, archive_thread: ArchiveThreadAction.configType, + crosspost_message: CrosspostMessageAction.configType, }); diff --git a/backend/src/plugins/Automod/actions/crosspostMessage.ts b/backend/src/plugins/Automod/actions/crosspostMessage.ts new file mode 100644 index 00000000..0c1e306f --- /dev/null +++ b/backend/src/plugins/Automod/actions/crosspostMessage.ts @@ -0,0 +1,29 @@ +import { Message } from "discord.js"; +import * as t from "io-ts"; +import { ChannelTypeStrings } from "src/types"; +import { automodAction } from "../helpers"; + +export const CrosspostMessageAction = automodAction({ + configType: t.type({}), + defaultConfig: {}, + + async apply({ pluginData, contexts, actionConfig }) { + const messages = await Promise.all( + contexts + .filter(c => c.message?.id) + .map(async c => { + const channel = pluginData.guild.channels.cache.get(c.message!.channel_id); + if (channel?.type === ChannelTypeStrings.NEWS && channel.isText()) { + // .isText() to fix the typings + const msg = await channel.messages.fetch(c.message!.id); + return msg && msg.crosspostable ? msg : null; + } + return null; + }), + ); + + for (const msg of messages) { + await msg?.crosspost(); + } + }, +});