From 2b3ff7a396601fbb561a0940ef56fd0d853e99cd Mon Sep 17 00:00:00 2001 From: dtinth on MBP M1 Date: Fri, 2 Jun 2023 19:50:44 +0700 Subject: [PATCH] baidang --- pnpm-lock.yaml | 6 +++++- prisma/schema.prisma | 10 +++++++++ src/Bot.ts | 1 + src/features/index.ts | 2 ++ src/features/redFlagLogger/index.ts | 33 +++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/features/redFlagLogger/index.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c5167a0b..60515801 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,8 @@ -lockfileVersion: '6.0' +lockfileVersion: '6.1' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false dependencies: '@(-.-)/env': diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 049c298f..d8578bdb 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -111,3 +111,13 @@ model TempRole { @@unique([userId, roleId]) } + +model RedFlag { + id String @id @default(uuid()) + actorId String + flaggedUserId String + flaggedChannelId String + flaggedMessageId String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} diff --git a/src/Bot.ts b/src/Bot.ts index 91caa681..cb984fdf 100644 --- a/src/Bot.ts +++ b/src/Bot.ts @@ -27,6 +27,7 @@ export class Bot { IntentsBitField.Flags.GuildMembers, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.MessageContent, + IntentsBitField.Flags.GuildMessageReactions, ], }) private readonly runtimeConfiguration = new RuntimeConfiguration() diff --git a/src/features/index.ts b/src/features/index.ts index b89a060b..53d0cc65 100644 --- a/src/features/index.ts +++ b/src/features/index.ts @@ -8,6 +8,7 @@ import nominations from './nominations' import ping from './ping' import preventEmojiSpam from './preventEmojiSpam' import profileInspector from './profileInspector' +import redFlagLogger from './redFlagLogger' import runtimeConfig from './runtimeConfig' import slowmode from './slowmode' import stickyMessage from './stickyMessage' @@ -24,6 +25,7 @@ export default [ ping, preventEmojiSpam, profileInspector, + redFlagLogger, runtimeConfig, slowmode, stickyMessage, diff --git a/src/features/redFlagLogger/index.ts b/src/features/redFlagLogger/index.ts new file mode 100644 index 00000000..94bc6006 --- /dev/null +++ b/src/features/redFlagLogger/index.ts @@ -0,0 +1,33 @@ +import { Events } from 'discord.js' + +import { prisma } from '@/prisma' +import { definePlugin } from '@/types/definePlugin' + +export default definePlugin({ + name: 'redFlagLogger', + setup: (pluginContext) => { + pluginContext.addEventHandler({ + eventName: Events.MessageReactionAdd, + once: false, + execute: async (botContext, reaction, user) => { + const redFlagEmojiIdentifier = '%F0%9F%9F%A5' // 🟥 + if (reaction.emoji.identifier !== redFlagEmojiIdentifier) return + const author = reaction.message.author + if (!author) return + const channel = reaction.message.channel + if (!channel) return + botContext.log.info( + `actor=${user.id} message=${reaction.message.id} messageAuthor=${author.id}`, + ) + await prisma.redFlag.create({ + data: { + actorId: user.id, + flaggedChannelId: reaction.message.channel.id, + flaggedMessageId: reaction.message.id, + flaggedUserId: author.id, + }, + }) + }, + }) + }, +})