mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Add missing logtypes, add change visualization
This commit is contained in:
parent
144c9c43e0
commit
968889e529
8 changed files with 80 additions and 10 deletions
|
@ -24,15 +24,15 @@
|
|||
|
||||
"CHANNEL_CREATE": "🖊 Channel {channelMention(channel)} was created",
|
||||
"CHANNEL_DELETE": "🗑 Channel {channelMention(channel)} was deleted",
|
||||
"CHANNEL_EDIT": "✏ Channel {channelMention(channel)} was edited",
|
||||
"CHANNEL_UPDATE": "✏ Channel {channelMention(newChannel)} was edited. Changes:\n{differenceString}",
|
||||
|
||||
"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}`",
|
||||
"THREAD_UPDATE": "✏ Thread {channelMention(newThread)} was edited. Changes:\n{differenceString}",
|
||||
|
||||
"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",
|
||||
"ROLE_UPDATE": "🖊 Role **{newRole.name}** (`{newRole.id}`) was edited. Changes:\n{differenceString}",
|
||||
|
||||
"MESSAGE_EDIT": "✏ {userMention(user)} edited their message (`{after.id}`) in {channelMention(channel)}:\n**Before:**{messageSummary(before)}**After:**{messageSummary(after)}",
|
||||
"MESSAGE_DELETE": "🗑 Message (`{message.id}`) from {userMention(user)} deleted in {channelMention(channel)} (originally posted at **{messageDate}**):{messageSummary(message)}",
|
||||
|
@ -48,7 +48,7 @@
|
|||
|
||||
"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}`",
|
||||
"STAGE_INSTANCE_UPDATE": "📣 Stage Instance `{newStageInstance.topic}` was edited in Stage Channel <#{stageChannel.id}>. Changes:\n{differenceString}",
|
||||
|
||||
"COMMAND": "🤖 {userMention(member)} used command in {channelMention(channel)}:\n`{command}`",
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ export enum LogType {
|
|||
|
||||
CHANNEL_CREATE,
|
||||
CHANNEL_DELETE,
|
||||
CHANNEL_UPDATE,
|
||||
|
||||
THREAD_CREATE,
|
||||
THREAD_DELETE,
|
||||
|
@ -25,6 +26,7 @@ export enum LogType {
|
|||
|
||||
ROLE_CREATE,
|
||||
ROLE_DELETE,
|
||||
ROLE_UPDATE,
|
||||
|
||||
MESSAGE_EDIT,
|
||||
MESSAGE_DELETE,
|
||||
|
|
|
@ -11,10 +11,10 @@ import { disableCodeBlocks } from "../../utils";
|
|||
import { CasesPlugin } from "../Cases/CasesPlugin";
|
||||
import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { LogsChannelCreateEvt, LogsChannelDeleteEvt } from "./events/LogsChannelModifyEvts";
|
||||
import { LogsChannelCreateEvt, LogsChannelDeleteEvt, LogsChannelUpdateEvt } from "./events/LogsChannelModifyEvts";
|
||||
import { LogsGuildMemberAddEvt } from "./events/LogsGuildMemberAddEvt";
|
||||
import { LogsGuildMemberRemoveEvt } from "./events/LogsGuildMemberRemoveEvt";
|
||||
import { LogsRoleCreateEvt, LogsRoleDeleteEvt } from "./events/LogsRoleModifyEvts";
|
||||
import { LogsRoleCreateEvt, LogsRoleDeleteEvt, LogsRoleUpdateEvt } from "./events/LogsRoleModifyEvts";
|
||||
import {
|
||||
LogsStageInstanceCreateEvt,
|
||||
LogsStageInstanceDeleteEvt,
|
||||
|
@ -70,8 +70,10 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()({
|
|||
LogsGuildMemberUpdateEvt,
|
||||
LogsChannelCreateEvt,
|
||||
LogsChannelDeleteEvt,
|
||||
LogsChannelUpdateEvt,
|
||||
LogsRoleCreateEvt,
|
||||
LogsRoleDeleteEvt,
|
||||
LogsRoleUpdateEvt,
|
||||
LogsVoiceStateUpdateEvt,
|
||||
LogsStageInstanceCreateEvt,
|
||||
LogsStageInstanceDeleteEvt,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
|
||||
import { logsEvt } from "../types";
|
||||
|
||||
export const LogsChannelCreateEvt = logsEvt({
|
||||
|
@ -21,3 +21,18 @@ export const LogsChannelDeleteEvt = logsEvt({
|
|||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const LogsChannelUpdateEvt = logsEvt({
|
||||
event: "channelUpdate",
|
||||
|
||||
async listener(meta) {
|
||||
const diff = getScalarDifference(meta.args.oldChannel, meta.args.newChannel);
|
||||
const differenceString = differenceToString(diff);
|
||||
|
||||
meta.pluginData.state.guildLogs.log(LogType.CHANNEL_UPDATE, {
|
||||
oldChannel: stripObjectToScalars(meta.args.oldChannel),
|
||||
newChannel: stripObjectToScalars(meta.args.newChannel),
|
||||
differenceString,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
|
||||
import { logsEvt } from "../types";
|
||||
|
||||
export const LogsRoleCreateEvt = logsEvt({
|
||||
|
@ -21,3 +21,18 @@ export const LogsRoleDeleteEvt = logsEvt({
|
|||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const LogsRoleUpdateEvt = logsEvt({
|
||||
event: "roleUpdate",
|
||||
|
||||
async listener(meta) {
|
||||
const diff = getScalarDifference(meta.args.oldRole, meta.args.newRole);
|
||||
const differenceString = differenceToString(diff);
|
||||
|
||||
meta.pluginData.state.guildLogs.log(LogType.ROLE_UPDATE, {
|
||||
newRole: stripObjectToScalars(meta.args.newRole),
|
||||
oldRole: stripObjectToScalars(meta.args.oldRole),
|
||||
differenceString,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
|
||||
import { logsEvt } from "../types";
|
||||
|
||||
export const LogsStageInstanceCreateEvt = logsEvt({
|
||||
|
@ -37,10 +37,15 @@ export const LogsStageInstanceUpdateEvt = logsEvt({
|
|||
const stageChannel =
|
||||
meta.args.newStageInstance.channel ??
|
||||
(await meta.pluginData.guild.channels.fetch(meta.args.newStageInstance.channelID));
|
||||
|
||||
const diff = getScalarDifference(meta.args.oldStageInstance, meta.args.newStageInstance);
|
||||
const differenceString = differenceToString(diff);
|
||||
|
||||
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_UPDATE, {
|
||||
oldStageInstance: stripObjectToScalars(meta.args.oldStageInstance),
|
||||
newStageInstance: stripObjectToScalars(meta.args.newStageInstance),
|
||||
stageChannel: stripObjectToScalars(stageChannel),
|
||||
differenceString,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { stripObjectToScalars, getScalarDifference, differenceToString } from "../../../utils";
|
||||
import { logsEvt } from "../types";
|
||||
|
||||
export const LogsThreadCreateEvt = logsEvt({
|
||||
|
@ -26,9 +26,13 @@ export const LogsThreadUpdateEvt = logsEvt({
|
|||
event: "threadUpdate",
|
||||
|
||||
async listener(meta) {
|
||||
const diff = getScalarDifference(meta.args.oldThread, meta.args.newThread, ["messageCount", "archiveTimestamp"]);
|
||||
const differenceString = differenceToString(diff);
|
||||
|
||||
meta.pluginData.state.guildLogs.log(LogType.THREAD_UPDATE, {
|
||||
oldThread: stripObjectToScalars(meta.args.oldThread),
|
||||
newThread: stripObjectToScalars(meta.args.newThread),
|
||||
differenceString,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -35,6 +35,7 @@ import { SimpleCache } from "./SimpleCache";
|
|||
import { sendDM } from "./utils/sendDM";
|
||||
import { waitForButtonConfirm } from "./utils/waitForInteraction";
|
||||
import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils";
|
||||
import { isEqual } from "lodash";
|
||||
|
||||
const fsp = fs.promises;
|
||||
|
||||
|
@ -165,6 +166,32 @@ function tDeepPartialProp(prop: any) {
|
|||
}
|
||||
}
|
||||
|
||||
export function getScalarDifference<T>(
|
||||
base: T,
|
||||
object: T,
|
||||
ignoreKeys: string[] = [],
|
||||
): Map<string, { was: any; is: any }> {
|
||||
base = stripObjectToScalars(base) as T;
|
||||
object = stripObjectToScalars(object) as T;
|
||||
const diff = new Map<string, { was: any; is: any }>();
|
||||
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
if (!isEqual(value, base[key]) && !ignoreKeys.includes(key)) {
|
||||
diff.set(key, { was: base[key], is: value });
|
||||
}
|
||||
}
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
export function differenceToString(diff: Map<string, { was: any; is: any }>): string {
|
||||
let toReturn = "";
|
||||
for (const [key, difference] of diff) {
|
||||
toReturn += `${key[0].toUpperCase() + key.slice(1)}: \`${difference.was}\` ➜ \`${difference.is}\`\n`;
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/49262929/316944
|
||||
export type Not<T, E> = T & Exclude<T, E>;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue