From 144c9c43e0ca6fb827e63027dd7e613f1f1c73f4 Mon Sep 17 00:00:00 2001 From: Dark <7890309+DarkView@users.noreply.github.com> Date: Thu, 1 Jul 2021 02:21:16 +0200 Subject: [PATCH] Add logging for threads and stages --- backend/src/data/DefaultLogMessages.json | 8 ++++ backend/src/data/LogType.ts | 8 ++++ backend/src/plugins/Logs/LogsPlugin.ts | 12 +++++ .../events/LogsStageInstanceModifyEvts.ts | 46 +++++++++++++++++++ .../Logs/events/LogsThreadModifyEvts.ts | 34 ++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 backend/src/plugins/Logs/events/LogsStageInstanceModifyEvts.ts create mode 100644 backend/src/plugins/Logs/events/LogsThreadModifyEvts.ts diff --git a/backend/src/data/DefaultLogMessages.json b/backend/src/data/DefaultLogMessages.json index 0c6c010e..2f00d39c 100644 --- a/backend/src/data/DefaultLogMessages.json +++ b/backend/src/data/DefaultLogMessages.json @@ -26,6 +26,10 @@ "CHANNEL_DELETE": "🗑 Channel {channelMention(channel)} was deleted", "CHANNEL_EDIT": "✏ Channel {channelMention(channel)} was edited", + "THREAD_CREATE": "🖊 Thread {channelMention(thread)} was created in channel <#{thread.parentID}>", + "THREAD_DELETE": "🗑 Thread {channelMention(thread)} was deleted/archived from channel <#{thread.parentID}>", + "THREAD_UPDATE": "✏ Thread {channelMention(newThread)} was edited. Previous name: `{oldThread.name}`", + "ROLE_CREATE": "🖊 Role **{role.name}** (`{role.id}`) was created", "ROLE_DELETE": "🖊 Role **{role.name}** (`{role.id}`) was deleted", "ROLE_EDIT": "🖊 Role **{role.name}** (`{role.id}`) was edited", @@ -42,6 +46,10 @@ "VOICE_CHANNEL_FORCE_MOVE": "\uD83C\uDF99 ✍ {userMention(member)} was moved from **{oldChannel.name}** to **{newChannel.name}** by {userMention(mod)}", "VOICE_CHANNEL_FORCE_DISCONNECT": "\uD83C\uDF99 🚫 {userMention(member)} was forcefully disconnected from **{oldChannel.name}** by {userMention(mod)}", + "STAGE_INSTANCE_CREATE": "📣 Stage Instance `{stageInstance.topic}` was created in Stage Channel <#{stageChannel.id}>", + "STAGE_INSTANCE_DELETE": "📣 Stage Instance `{stageInstance.topic}` was deleted in Stage Channel <#{stageChannel.id}>", + "STAGE_INSTANCE_UPDATE": "📣 Stage Instance `{newStageInstance.topic}` was edited in Stage Channel <#{stageChannel.id}>. Previous topic: `{oldStageInstance.topic}`", + "COMMAND": "🤖 {userMention(member)} used command in {channelMention(channel)}:\n`{command}`", "MESSAGE_SPAM_DETECTED": "🛑 {userMention(member)} spam detected in {channelMention(channel)}: {description} (more than {limit} in {interval}s)\n{archiveUrl}", diff --git a/backend/src/data/LogType.ts b/backend/src/data/LogType.ts index bc62cd02..c01610e2 100644 --- a/backend/src/data/LogType.ts +++ b/backend/src/data/LogType.ts @@ -19,6 +19,10 @@ export enum LogType { CHANNEL_CREATE, CHANNEL_DELETE, + THREAD_CREATE, + THREAD_DELETE, + THREAD_UPDATE, + ROLE_CREATE, ROLE_DELETE, @@ -31,6 +35,10 @@ export enum LogType { VOICE_CHANNEL_LEAVE, VOICE_CHANNEL_MOVE, + STAGE_INSTANCE_CREATE, + STAGE_INSTANCE_DELETE, + STAGE_INSTANCE_UPDATE, + COMMAND, MESSAGE_SPAM_DETECTED, diff --git a/backend/src/plugins/Logs/LogsPlugin.ts b/backend/src/plugins/Logs/LogsPlugin.ts index 6de27037..8c8520be 100644 --- a/backend/src/plugins/Logs/LogsPlugin.ts +++ b/backend/src/plugins/Logs/LogsPlugin.ts @@ -15,6 +15,12 @@ import { LogsChannelCreateEvt, LogsChannelDeleteEvt } from "./events/LogsChannel import { LogsGuildMemberAddEvt } from "./events/LogsGuildMemberAddEvt"; import { LogsGuildMemberRemoveEvt } from "./events/LogsGuildMemberRemoveEvt"; import { LogsRoleCreateEvt, LogsRoleDeleteEvt } from "./events/LogsRoleModifyEvts"; +import { + LogsStageInstanceCreateEvt, + LogsStageInstanceDeleteEvt, + LogsStageInstanceUpdateEvt, +} from "./events/LogsStageInstanceModifyEvts"; +import { LogsThreadCreateEvt, LogsThreadDeleteEvt, LogsThreadUpdateEvt } from "./events/LogsThreadModifyEvts"; import { LogsGuildMemberUpdateEvt } from "./events/LogsUserUpdateEvts"; import { LogsVoiceStateUpdateEvt } from "./events/LogsVoiceChannelEvts"; import { ConfigSchema, FORMAT_NO_TIMESTAMP, LogsPluginType } from "./types"; @@ -67,6 +73,12 @@ export const LogsPlugin = zeppelinGuildPlugin()({ LogsRoleCreateEvt, LogsRoleDeleteEvt, LogsVoiceStateUpdateEvt, + LogsStageInstanceCreateEvt, + LogsStageInstanceDeleteEvt, + LogsStageInstanceUpdateEvt, + LogsThreadCreateEvt, + LogsThreadDeleteEvt, + LogsThreadUpdateEvt, ], public: { diff --git a/backend/src/plugins/Logs/events/LogsStageInstanceModifyEvts.ts b/backend/src/plugins/Logs/events/LogsStageInstanceModifyEvts.ts new file mode 100644 index 00000000..25b68a53 --- /dev/null +++ b/backend/src/plugins/Logs/events/LogsStageInstanceModifyEvts.ts @@ -0,0 +1,46 @@ +import { LogType } from "../../../data/LogType"; +import { stripObjectToScalars } from "../../../utils"; +import { logsEvt } from "../types"; + +export const LogsStageInstanceCreateEvt = logsEvt({ + event: "stageInstanceCreate", + + async listener(meta) { + const stageChannel = + meta.args.stageInstance.channel ?? + (await meta.pluginData.guild.channels.fetch(meta.args.stageInstance.channelID)); + meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_CREATE, { + stageInstance: stripObjectToScalars(meta.args.stageInstance), + stageChannel: stripObjectToScalars(stageChannel), + }); + }, +}); + +export const LogsStageInstanceDeleteEvt = logsEvt({ + event: "stageInstanceDelete", + + async listener(meta) { + const stageChannel = + meta.args.stageInstance.channel ?? + (await meta.pluginData.guild.channels.fetch(meta.args.stageInstance.channelID)); + meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_DELETE, { + stageInstance: stripObjectToScalars(meta.args.stageInstance), + stageChannel: stripObjectToScalars(stageChannel), + }); + }, +}); + +export const LogsStageInstanceUpdateEvt = logsEvt({ + event: "stageInstanceUpdate", + + async listener(meta) { + const stageChannel = + meta.args.newStageInstance.channel ?? + (await meta.pluginData.guild.channels.fetch(meta.args.newStageInstance.channelID)); + meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_UPDATE, { + oldStageInstance: stripObjectToScalars(meta.args.oldStageInstance), + newStageInstance: stripObjectToScalars(meta.args.newStageInstance), + stageChannel: stripObjectToScalars(stageChannel), + }); + }, +}); diff --git a/backend/src/plugins/Logs/events/LogsThreadModifyEvts.ts b/backend/src/plugins/Logs/events/LogsThreadModifyEvts.ts new file mode 100644 index 00000000..bb5c4b5d --- /dev/null +++ b/backend/src/plugins/Logs/events/LogsThreadModifyEvts.ts @@ -0,0 +1,34 @@ +import { LogType } from "../../../data/LogType"; +import { stripObjectToScalars } from "../../../utils"; +import { logsEvt } from "../types"; + +export const LogsThreadCreateEvt = logsEvt({ + event: "threadCreate", + + async listener(meta) { + meta.pluginData.state.guildLogs.log(LogType.THREAD_CREATE, { + thread: stripObjectToScalars(meta.args.thread), + }); + }, +}); + +export const LogsThreadDeleteEvt = logsEvt({ + event: "threadDelete", + + async listener(meta) { + meta.pluginData.state.guildLogs.log(LogType.THREAD_DELETE, { + thread: stripObjectToScalars(meta.args.thread), + }); + }, +}); + +export const LogsThreadUpdateEvt = logsEvt({ + event: "threadUpdate", + + async listener(meta) { + meta.pluginData.state.guildLogs.log(LogType.THREAD_UPDATE, { + oldThread: stripObjectToScalars(meta.args.oldThread), + newThread: stripObjectToScalars(meta.args.newThread), + }); + }, +});