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

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

@ -13,6 +13,7 @@ import {
messageSummary,
MINUTES,
noop,
renderRecursively,
SECONDS,
stripObjectToScalars,
tDeepPartial,
@ -1297,12 +1298,24 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema, ICustomOverride
const channel = this.guild.channels.get(channelId);
if (channel && channel instanceof TextChannel) {
const user = await this.resolveUser(matchResult.userId);
const formatted = await renderTemplate(rule.actions.reply, {
user: stripObjectToScalars(user),
});
const renderReplyText = async str =>
renderTemplate(str, {
user: stripObjectToScalars(user),
});
const formatted =
typeof rule.actions.reply === "string"
? await renderReplyText(rule.actions.reply)
: await renderRecursively(rule.actions.reply.text, renderReplyText);
if (formatted) {
await channel.createMessage(formatted);
const replyMsg = await channel.createMessage(formatted);
actionsTaken.push("reply");
if (typeof rule.actions.reply === "object" && rule.actions.reply.auto_delete != null) {
const delay = convertDelayStringToMS(String(rule.actions.reply.auto_delete));
setTimeout(() => replyMsg.delete().catch(noop), delay);
console.log("deleting in", delay);
}
}
}
}

View file

@ -1,6 +1,6 @@
import * as t from "io-ts";
import { TSafeRegex } from "../../validatorUtils";
import { tDelayString, tNullable } from "../../utils";
import { tDelayString, tMessageContent, tNullable } from "../../utils";
export enum RecentActionType {
Message = 1,
@ -286,7 +286,13 @@ export const RemoveRolesAction = t.array(t.string);
export const SetAntiraidLevelAction = t.string;
export const ReplyAction = t.string;
export const ReplyAction = t.union([
t.string,
t.type({
text: tMessageContent,
auto_delete: tNullable(t.union([t.string, t.number])),
}),
]);
/**
* RULES