-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathaddReactions.ts
More file actions
37 lines (30 loc) · 1.16 KB
/
addReactions.ts
File metadata and controls
37 lines (30 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Snowflake } from "discord.js";
import { z } from "zod";
import { noop } from "../../../utils.js";
import { automodAction } from "../helpers.js";
const configSchema = z.array(z.string())
export const AddReactionsAction = automodAction({
configSchema,
async apply({ pluginData, contexts, actionConfig }) {
const messageIdsByChannel = new Map<string, Set<string>>();
for (const context of contexts) {
if (context.message) {
if (!messageIdsByChannel.has(context.message.channel_id)) {
messageIdsByChannel.set(context.message.channel_id, new Set<string>());
}
messageIdsByChannel.get(context.message.channel_id)!.add(context.message.id);
}
}
for (const [channelId, messageIds] of messageIdsByChannel.entries()) {
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake)
if (!channel?.isTextBased?.()) continue;
for (const messageId of messageIds) {
const msg = await channel.messages.fetch(messageId).catch(noop);
if (!msg) continue;
for (const emoji of actionConfig) {
await msg.react(emoji).catch(noop);
}
}
}
},
});