Add Logs plugin and GuildServerLogs class to communicate with it
This commit is contained in:
parent
8234f67b0f
commit
c087654979
5 changed files with 188 additions and 3 deletions
36
src/utils.ts
36
src/utils.ts
|
@ -1,5 +1,4 @@
|
|||
import * as moment from "moment-timezone";
|
||||
import { ModActionType } from "./data/ModActionType";
|
||||
import at = require("lodash.at");
|
||||
|
||||
/**
|
||||
* Turns a "delay string" such as "1h30m" to milliseconds
|
||||
|
@ -42,3 +41,36 @@ export function errorMessage(str) {
|
|||
export function uclower(str) {
|
||||
return str[0].toLowerCase() + str.slice(1);
|
||||
}
|
||||
|
||||
export function stripObjectToScalars(obj, includedNested: string[]) {
|
||||
const result = {};
|
||||
|
||||
for (const key in obj) {
|
||||
if (
|
||||
obj[key] == null ||
|
||||
typeof obj[key] === "string" ||
|
||||
typeof obj[key] === "number" ||
|
||||
typeof obj[key] === "boolean"
|
||||
) {
|
||||
result[key] = obj[key];
|
||||
} else if (typeof obj[key] === "object") {
|
||||
const prefix = `${key}.`;
|
||||
const nestedNested = includedNested
|
||||
.filter(p => p === key || p.startsWith(prefix))
|
||||
.map(p => (p === key ? p : p.slice(prefix.length)));
|
||||
|
||||
if (nestedNested.length) {
|
||||
result[key] = stripObjectToScalars(obj[key], nestedNested);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const stringFormatRegex = /{([^{}]+?)}/g;
|
||||
export function formatTemplateString(str: string, values) {
|
||||
return str.replace(stringFormatRegex, (match, val) => {
|
||||
return (at(values, val)[0] as string) || "";
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue