3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Add missing logtypes, add change visualization

This commit is contained in:
Dark 2021-07-01 04:40:39 +02:00
parent 144c9c43e0
commit 968889e529
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
8 changed files with 80 additions and 10 deletions

View file

@ -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>;