From e0ff129b6b865adea0b105115638c19836ad22af Mon Sep 17 00:00:00 2001 From: Kingston-SCYD Date: Mon, 7 Sep 2026 15:49:17 -0500 Subject: [PATCH] DM listed users when deadman is armed --- README.md | 2 +- deadman/deadman.py | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fcadf67..660a3b2 100644 --- a/README.md +++ b/README.md @@ -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". --- diff --git a/deadman/deadman.py b/deadman/deadman.py index b1cd418..5acafb5 100644 --- a/deadman/deadman.py +++ b/deadman/deadman.py @@ -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):