Skip to content

Commit 7b12f2d

Browse files
committed
feat: support polls
1 parent 3ef8924 commit 7b12f2d

9 files changed

Lines changed: 47 additions & 2 deletions

File tree

backend/src/data/GuildSavedMessages.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
119119
}));
120120
}
121121

122+
if (msg.poll) {
123+
data.poll = {
124+
question: msg.poll.question,
125+
answers: msg.poll.answers.map((answer) => ({
126+
id: answer.id,
127+
text: answer.text,
128+
})),
129+
};
130+
}
131+
122132
return data;
123133
}
124134

backend/src/data/entities/SavedMessage.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EmbedType, Snowflake, StickerFormatType, StickerType } from "discord.js";
1+
import { EmbedType, Snowflake, StickerFormatType, StickerType, PollQuestionMedia } from "discord.js";
22
import { Column, Entity, PrimaryColumn } from "typeorm";
33

44
export interface ISavedMessageAttachmentData {
@@ -65,6 +65,14 @@ export interface ISavedMessageStickerData {
6565
type: StickerType | null;
6666
}
6767

68+
export interface ISavedMessagePollData {
69+
question: PollQuestionMedia;
70+
answers: {
71+
id: number;
72+
text: string | null;
73+
}[];
74+
}
75+
6876
export interface ISavedMessageData {
6977
attachments?: ISavedMessageAttachmentData[];
7078
author: {
@@ -74,6 +82,7 @@ export interface ISavedMessageData {
7482
content: string;
7583
embeds?: ISavedMessageEmbedData[];
7684
stickers?: ISavedMessageStickerData[];
85+
poll?: ISavedMessagePollData;
7786
timestamp: number;
7887
}
7988

backend/src/plugins/Automod/functions/getTextMatchPartialSummary.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ export function getTextMatchPartialSummary(
3030
return `visible name: ${visibleName}`;
3131
} else if (type === "customstatus") {
3232
return `custom status: ${context.member!.presence?.activities.find((a) => a.type === ActivityType.Custom)?.name}`;
33+
} else if (type === "poll") {
34+
const message = context.message!;
35+
const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake);
36+
const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
37+
38+
return `poll in ${channelMention}:\n${messageSummary(message)}`;
3339
}
3440
}

backend/src/plugins/Automod/functions/matchMultipleTextTypesOnMessage.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ type TextTriggerWithMultipleMatchTypes = {
1212
match_usernames: boolean;
1313
match_nicknames: boolean;
1414
match_custom_status: boolean;
15+
match_polls: boolean;
1516
};
1617

17-
export type MatchableTextType = "message" | "embed" | "visiblename" | "username" | "nickname" | "customstatus";
18+
export type MatchableTextType = "message" | "embed" | "visiblename" | "username" | "nickname" | "customstatus" | "poll";
1819

1920
type YieldedContent = [MatchableTextType, string];
2021

@@ -59,4 +60,8 @@ export async function* matchMultipleTextTypesOnMessage(
5960
break;
6061
}
6162
}
63+
64+
if (trigger.match_polls && msg.data.poll) {
65+
yield ["poll", JSON.stringify(msg.data.poll)];
66+
}
6267
}

backend/src/plugins/Automod/triggers/matchInvites.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const configSchema = z.strictObject({
2424
match_usernames: z.boolean().default(false),
2525
match_nicknames: z.boolean().default(false),
2626
match_custom_status: z.boolean().default(false),
27+
match_polls: z.boolean().default(false),
2728
});
2829

2930
export const MatchInvitesTrigger = automodTrigger<MatchResultType>()({

backend/src/plugins/Automod/triggers/matchLinks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const configSchema = z.strictObject({
4747
match_usernames: z.boolean().default(false),
4848
match_nicknames: z.boolean().default(false),
4949
match_custom_status: z.boolean().default(false),
50+
match_polls: z.boolean().default(false),
5051
});
5152

5253
export const MatchLinksTrigger = automodTrigger<MatchResultType>()({

backend/src/plugins/Automod/triggers/matchRegex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const configSchema = z.strictObject({
2424
match_usernames: z.boolean().default(false),
2525
match_nicknames: z.boolean().default(false),
2626
match_custom_status: z.boolean().default(false),
27+
match_polls: z.boolean().default(false),
2728
});
2829

2930
const regexCache = new WeakMap<any, RegExp[]>();

backend/src/plugins/Automod/triggers/matchWords.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const configSchema = z.strictObject({
2828
match_usernames: z.boolean().default(false),
2929
match_nicknames: z.boolean().default(false),
3030
match_custom_status: z.boolean().default(false),
31+
match_polls: z.boolean().default(false),
3132
});
3233

3334
export const MatchWordsTrigger = automodTrigger<MatchResultType>()({

backend/src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,17 @@ export function messageSummary(msg: SavedMessage) {
13371337
"\n";
13381338
}
13391339

1340+
if (msg.data.poll) {
1341+
const { poll } = msg.data;
1342+
result +=
1343+
"Poll: ```" +
1344+
escapeCodeBlock(
1345+
`Question: ${poll.question.text}
1346+
Answers: ${poll.answers.map((answer) => `${answer.text}`).join(" | ")}`
1347+
) +
1348+
"```";
1349+
}
1350+
13401351
return result;
13411352
}
13421353

0 commit comments

Comments
 (0)