3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-20 08:15:03 +00:00

Allow the automod action "reply" to reply in DMs

Also allows the sending of a second message in the server channel to, i.e. let them know they received a DM.
If the DM fails, falls back to in-server reply.
DM messages are not affected by auto_delete, all other "new" messages are.
This commit is contained in:
Dark 2021-02-15 01:47:14 +01:00
parent 47adfb07eb
commit 843c23f33b
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8

View file

@ -20,6 +20,8 @@ export const ReplyAction = automodAction({
t.type({
text: tMessageContent,
auto_delete: tNullable(t.union([tDelayString, t.number])),
as_dm: tNullable(t.boolean),
channel_text_on_dm: tNullable(tMessageContent),
}),
]),
@ -53,8 +55,27 @@ export const ReplyAction = automodAction({
: await renderRecursively(actionConfig.text, renderReplyText);
if (formatted) {
const channel = pluginData.guild.channels.get(channelId) as TextChannel;
const replyMsg = await channel.createMessage(formatted);
let replyMsg;
const serverChannel = pluginData.guild.channels.get(channelId) as TextChannel;
if (typeof actionConfig !== "string" && actionConfig.as_dm) {
let fallback = false;
try {
const dmChannel = await user!.getDMChannel();
await dmChannel.createMessage(formatted); // Don't store in replyMsg as to not delete a DM
} catch (e) {
// Fallback to in-server reply
replyMsg = await serverChannel.createMessage(formatted);
fallback = true;
}
if (actionConfig.channel_text_on_dm && !fallback) {
const channelFormatted = await renderReplyText(actionConfig.channel_text_on_dm);
replyMsg = await serverChannel.createMessage(channelFormatted);
}
} else {
replyMsg = await serverChannel.createMessage(formatted);
}
if (typeof actionConfig === "object" && actionConfig.auto_delete) {
const delay = convertDelayStringToMS(String(actionConfig.auto_delete))!;