mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-20 16:25: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:
parent
47adfb07eb
commit
843c23f33b
1 changed files with 23 additions and 2 deletions
|
@ -20,6 +20,8 @@ export const ReplyAction = automodAction({
|
||||||
t.type({
|
t.type({
|
||||||
text: tMessageContent,
|
text: tMessageContent,
|
||||||
auto_delete: tNullable(t.union([tDelayString, t.number])),
|
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);
|
: await renderRecursively(actionConfig.text, renderReplyText);
|
||||||
|
|
||||||
if (formatted) {
|
if (formatted) {
|
||||||
const channel = pluginData.guild.channels.get(channelId) as TextChannel;
|
let replyMsg;
|
||||||
const replyMsg = await channel.createMessage(formatted);
|
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) {
|
if (typeof actionConfig === "object" && actionConfig.auto_delete) {
|
||||||
const delay = convertDelayStringToMS(String(actionConfig.auto_delete))!;
|
const delay = convertDelayStringToMS(String(actionConfig.auto_delete))!;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue