3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-23 09:35:02 +00:00

Update backend/src/plugins/Automod/actions/crosspostMessage.ts

Co-authored-by: Almeida <almeidx@pm.me>
This commit is contained in:
metal 2021-09-08 11:39:54 +01:00 committed by GitHub
parent 8c3d232eb9
commit 5b73253962
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,22 +9,19 @@ export const CrosspostMessageAction = automodAction({
defaultConfig: {}, defaultConfig: {},
async apply({ pluginData, contexts, actionConfig }) { async apply({ pluginData, contexts, actionConfig }) {
const messages = await Promise.all( const messages = contexts
contexts .filter(c => c.message?.id)
.filter(c => c.message?.id) .map(c => {
.map(async c => { const channel = pluginData.guild.channels.cache.get(c.message!.channel_id);
const channel = pluginData.guild.channels.cache.get(c.message!.channel_id); if (channel?.type === ChannelTypeStrings.NEWS && channel.isText()) {
if (channel?.type === ChannelTypeStrings.NEWS && channel.isText()) { // .isText() to fix the typings
// .isText() to fix the typings return channel.messages.fetch(c.message!.id);
const msg = await channel.messages.fetch(c.message!.id); }
return msg && msg.crosspostable ? msg : null; return null;
} });
return null;
}),
);
for (const msg of messages) { for await (const msg of messages) {
await msg?.crosspost().catch(noop); if (msg?.crosspostable) await msg?.crosspost().catch(noop);
} }
}, },
}); });