automod.reply: allow embeds, add auto_delete option

This commit is contained in:
Dragory 2020-05-22 23:38:11 +03:00
parent 1cff4fb801
commit 53a9c58dd4
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
4 changed files with 55 additions and 30 deletions

View file

@ -204,6 +204,8 @@ export const tStrictMessageContent = t.type({
embed: tNullable(tEmbed),
});
export const tMessageContent = t.union([t.string, tStrictMessageContent]);
export function dropPropertiesByName(obj, propName) {
if (obj.hasOwnProperty(propName)) delete obj[propName];
for (const value of Object.values(obj)) {
@ -1126,3 +1128,27 @@ export function memoize<T>(fn: (...args: any[]) => T, key?, time?): T {
return value;
}
type RecursiveRenderFn = (str: string) => string | Promise<string>;
export async function renderRecursively(value, fn: RecursiveRenderFn) {
if (Array.isArray(value)) {
const result = [];
for (const item of value) {
result.push(await renderRecursively(item, fn));
}
return result;
} else if (value === null) {
return null;
} else if (typeof value === "object") {
const result = {};
for (const [prop, _value] of Object.entries(value)) {
result[prop] = await renderRecursively(_value, fn);
}
return result;
} else if (typeof value === "string") {
return fn(value);
}
return value;
}