DM listed users when deadman is armed
This commit is contained in:
@@ -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).
|
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
@@ -194,13 +194,37 @@ class Deadman(commands.Cog):
|
|||||||
self._triggered = False
|
self._triggered = False
|
||||||
|
|
||||||
expires_str = expires_at.strftime("%Y-%m-%d %H:%M UTC")
|
expires_str = expires_at.strftime("%Y-%m-%d %H:%M UTC")
|
||||||
await ctx.send(
|
notified = 0
|
||||||
f"Deadman switch ARMED.\n"
|
failed = []
|
||||||
f"Expires: **{expires_str}** (in {duration_td})\n"
|
for user in users:
|
||||||
f"Users notified: {', '.join(u.mention for u in users)}\n"
|
try:
|
||||||
+ (f"Alert channel: {trigger_channel.mention}\n" if trigger_channel else "\n")
|
await user.send(
|
||||||
+ "Run `[p]deadman disable` before that time to cancel."
|
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")
|
@deadman.command(name="disable")
|
||||||
async def deadman_disable(self, ctx):
|
async def deadman_disable(self, ctx):
|
||||||
|
|||||||
Reference in New Issue
Block a user