3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25: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);
}
}
}
}