Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backend/src/data/GuildSavedMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
}));
}

if (msg.poll) {
data.poll = {
question: msg.poll.question,
answers: msg.poll.answers.map((answer) => ({
id: answer.id,
text: answer.text,
})),
};
}

return data;
}

Expand Down
11 changes: 10 additions & 1 deletion backend/src/data/entities/SavedMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EmbedType, Snowflake, StickerFormatType, StickerType } from "discord.js";
import { EmbedType, Snowflake, StickerFormatType, StickerType, PollQuestionMedia } from "discord.js";
import { Column, Entity, PrimaryColumn } from "typeorm";

export interface ISavedMessageAttachmentData {
Expand Down Expand Up @@ -65,6 +65,14 @@ export interface ISavedMessageStickerData {
type: StickerType | null;
}

export interface ISavedMessagePollData {
question: PollQuestionMedia;
answers: {
id: number;
text: string | null;
}[];
}

export interface ISavedMessageData {
attachments?: ISavedMessageAttachmentData[];
author: {
Expand All @@ -74,6 +82,7 @@ export interface ISavedMessageData {
content: string;
embeds?: ISavedMessageEmbedData[];
stickers?: ISavedMessageStickerData[];
poll?: ISavedMessagePollData;
timestamp: number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ export function getTextMatchPartialSummary(
return `visible name: ${visibleName}`;
} else if (type === "customstatus") {
return `custom status: ${context.member!.presence?.activities.find((a) => a.type === ActivityType.Custom)?.name}`;
} else if (type === "poll") {
const message = context.message!;
const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake);
const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;

return `poll in ${channelMention}:\n${messageSummary(message)}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ type TextTriggerWithMultipleMatchTypes = {
match_usernames: boolean;
match_nicknames: boolean;
match_custom_status: boolean;
match_polls: boolean;
};

export type MatchableTextType = "message" | "embed" | "visiblename" | "username" | "nickname" | "customstatus";
export type MatchableTextType = "message" | "embed" | "visiblename" | "username" | "nickname" | "customstatus" | "poll";

type YieldedContent = [MatchableTextType, string];

Expand Down Expand Up @@ -59,4 +60,8 @@ export async function* matchMultipleTextTypesOnMessage(
break;
}
}

if (trigger.match_polls && msg.data.poll) {
yield ["poll", JSON.stringify(msg.data.poll)];
}
}
1 change: 1 addition & 0 deletions backend/src/plugins/Automod/triggers/matchInvites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const configSchema = z.strictObject({
match_usernames: z.boolean().default(false),
match_nicknames: z.boolean().default(false),
match_custom_status: z.boolean().default(false),
match_polls: z.boolean().default(false),
});

export const MatchInvitesTrigger = automodTrigger<MatchResultType>()({
Expand Down
1 change: 1 addition & 0 deletions backend/src/plugins/Automod/triggers/matchLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const configSchema = z.strictObject({
match_usernames: z.boolean().default(false),
match_nicknames: z.boolean().default(false),
match_custom_status: z.boolean().default(false),
match_polls: z.boolean().default(false),
});

export const MatchLinksTrigger = automodTrigger<MatchResultType>()({
Expand Down
1 change: 1 addition & 0 deletions backend/src/plugins/Automod/triggers/matchRegex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const configSchema = z.strictObject({
match_usernames: z.boolean().default(false),
match_nicknames: z.boolean().default(false),
match_custom_status: z.boolean().default(false),
match_polls: z.boolean().default(false),
});

const regexCache = new WeakMap<any, RegExp[]>();
Expand Down
1 change: 1 addition & 0 deletions backend/src/plugins/Automod/triggers/matchWords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const configSchema = z.strictObject({
match_usernames: z.boolean().default(false),
match_nicknames: z.boolean().default(false),
match_custom_status: z.boolean().default(false),
match_polls: z.boolean().default(false),
});

export const MatchWordsTrigger = automodTrigger<MatchResultType>()({
Expand Down
11 changes: 11 additions & 0 deletions backend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,17 @@ export function messageSummary(msg: SavedMessage) {
"\n";
}

if (msg.data.poll) {
const { poll } = msg.data;
result +=
"Poll: ```" +
escapeCodeBlock(
`Question: ${poll.question.text}
Answers: ${poll.answers.map((answer) => `${answer.text}`).join(" | ")}`
) +
"```";
}

return result;
}

Expand Down
Loading