Users register their birthday via /birthday MM-DD; the daily gate (recipe 3) announces the day's birthdays with the first message after midnight UTC. The mentions render but do not ping (anti-mass-ping guard).
from datetime import datetime, timezone
@plugin.on_slash_command("birthday")
def set_bday(ctx: Context, event: dict):
opts = {o["name"]: o["value"] for o in event.get("options", [])}
ctx.kv.set(f"bday:{event['user_id']}", opts.get("date"))
ctx.interaction.respond(content=f"Saved {opts.get('date')}.")
@plugin.on_event("message_create")
def announce(ctx: Context, event: dict):
today = datetime.now(timezone.utc).strftime("%m-%d")
stamp = datetime.now(timezone.utc).strftime("%Y-%m-%d")
if not ctx.ephemeral.dedup(f"bday_check:{stamp}", ttl_seconds=86400):
return # already checked today
channel_id = ctx.kv.get("birthday_channel_id")
if not channel_id:
return
bdays = ctx.kv.list_values(prefix="bday:") or {} # {key: "MM-DD"}
user_ids = [k.split(":")[1] for k, d in bdays.items() if d == today]
if not user_ids:
return
mentions = " ".join(f"<@{uid}>" for uid in user_ids)
ctx.discord.send_message(channel_id=str(channel_id),
content=f"🎂 Happy birthday {mentions}!")