3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-25 02:25:01 +00:00
This commit is contained in:
metal 2022-07-16 00:19:13 -07:00 committed by GitHub
commit 15677c848f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View file

@ -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";
@ -36,6 +37,7 @@ export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
set_slowmode: SetSlowmodeAction,
start_thread: StartThreadAction,
archive_thread: ArchiveThreadAction,
crosspost_message: CrosspostMessageAction,
};
export const AvailableActions = t.type({
@ -56,4 +58,5 @@ export const AvailableActions = t.type({
set_slowmode: SetSlowmodeAction.configType,
start_thread: StartThreadAction.configType,
archive_thread: ArchiveThreadAction.configType,
crosspost_message: CrosspostMessageAction.configType,
});

View file

@ -0,0 +1,26 @@
import * as t from "io-ts";
import { ChannelTypeStrings } from "../../../types";
import { noop } from "../../../utils";
import { automodAction } from "../helpers";
export const CrosspostMessageAction = automodAction({
configType: t.type({}),
defaultConfig: {},
async apply({ pluginData, contexts }) {
const messages = contexts
.filter(c => c.message?.id)
.map(c => {
const channel = pluginData.guild.channels.cache.get(c.message!.channel_id);
if (channel?.type === ChannelTypeStrings.NEWS && channel.isText()) {
// .isText() to fix the typings
return channel.messages.fetch(c.message!.id);
}
return null;
});
for await (const msg of messages) {
if (msg?.crosspostable) await msg?.crosspost().catch(noop);
}
},
});