mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-06 02:27:19 +00:00
feat: support polls
This commit is contained in:
parent
3ef89246ba
commit
7b12f2d6c8
9 changed files with 47 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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: {
|
||||
|
@ -74,6 +82,7 @@ export interface ISavedMessageData {
|
|||
content: string;
|
||||
embeds?: ISavedMessageEmbedData[];
|
||||
stickers?: ISavedMessageStickerData[];
|
||||
poll?: ISavedMessagePollData;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)}`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
||||
|
@ -59,4 +60,8 @@ export async function* matchMultipleTextTypesOnMessage(
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (trigger.match_polls && msg.data.poll) {
|
||||
yield ["poll", JSON.stringify(msg.data.poll)];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>()({
|
||||
|
|
|
@ -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>()({
|
||||
|
|
|
@ -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[]>();
|
||||
|
|
|
@ -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>()({
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue