3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-23 09:35:02 +00:00
This commit is contained in:
metal 2021-09-08 10:07:12 +00:00 committed by GitHub
parent 8dfa9aec2a
commit e1499f64fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 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";
@ -34,6 +35,7 @@ export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
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,
});

View file

@ -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();
}
},
});