DM listed users when deadman is armed

This commit is contained in:
2026-09-07 15:49:17 -05:00
parent 9cc3b1ecc1
commit e0ff129b6b
2 changed files with 32 additions and 8 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ A member of the Scrapyard Cogworks package. A deadman switch that alerts listed
Supported units: `s`, `m`, `h`, `d`, `w` (and their full names).
When the switch is armed, the bot stores the expiry time and alerts users by DM. If an optional channel is provided, it also posts the alert there. If `[p]deadman disable` is not run before expiry, the listed users are DM'd and pinged that "the deadman switch has been TRIGGERED".
When the switch is armed, each listed user is DM'd to confirm they were added. If an optional channel is provided, the trigger alert is also posted there. If `[p]deadman disable` is not run before expiry, the listed users are DM'd and pinged that "the deadman switch has been TRIGGERED".
---
+30 -6
View File
@@ -194,13 +194,37 @@ class Deadman(commands.Cog):
self._triggered = False
expires_str = expires_at.strftime("%Y-%m-%d %H:%M UTC")
await ctx.send(
f"Deadman switch ARMED.\n"
f"Expires: **{expires_str}** (in {duration_td})\n"
f"Users notified: {', '.join(u.mention for u in users)}\n"
+ (f"Alert channel: {trigger_channel.mention}\n" if trigger_channel else "\n")
+ "Run `[p]deadman disable` before that time to cancel."
notified = 0
failed = []
for user in users:
try:
await user.send(
f"**Deadman switch armed**\n"
f"You have been added to a deadman switch.\n"
f"It expires at **{expires_str}**.\n"
f"If it is not disabled before then, you will receive a TRIGGERED alert.\n"
f"Contact the bot owner if this is a mistake."
)
notified += 1
except discord.Forbidden:
failed.append(user)
except Exception:
failed.append(user)
status_parts = [
f"Deadman switch ARMED.",
f"Expires: **{expires_str}** (in {duration_td})",
f"Users notified: {', '.join(u.mention for u in users)}",
]
if trigger_channel:
status_parts.append(f"Alert channel: {trigger_channel.mention}")
status_parts.append(f"DM'd {notified} of {len(users)} user(s).")
if failed:
status_parts.append(
"Could not DM: " + ", ".join(u.mention for u in failed)
)
status_parts.append("Run `[p]deadman disable` before that time to cancel.")
await ctx.send("\n".join(status_parts))
@deadman.command(name="disable")
async def deadman_disable(self, ctx):