From e314599d338b17e4dffb960a013615d3aa867162 Mon Sep 17 00:00:00 2001 From: esefxdz Date: Tue, 14 Jul 2026 16:57:59 +0300 Subject: [PATCH] simple preset for discord webhook agent for larp --- cogs/calendar.py | 30 +++++++++++++++++++++++++----- credentials_test.env | 3 +++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/cogs/calendar.py b/cogs/calendar.py index a445b70..b0ee99d 100644 --- a/cogs/calendar.py +++ b/cogs/calendar.py @@ -126,8 +126,12 @@ class BookModal(discord.ui.Modal, title="Book an Event"): ) desc = f" — {description}" if description else "" - await interaction.response.send_message( - f"Booked **{date} at {time_str} ({country})**: **{title}**{desc}", delete_after=10) + msg = f"Booked **{date} at {time_str} ({country})**: **{title}**{desc}" + await interaction.response.send_message(msg, ephemeral=True, delete_after=10) + + cog = interaction.client.get_cog("Calendar") + if cog and cog._wh: + await cog._wh.send(msg) class BookButton(discord.ui.View): @@ -149,6 +153,14 @@ class Calendar(commands.Cog): int(uid.strip()) for uid in raw.split(",") if uid.strip() } + wh_url = os.getenv("CALENDAR_WEBHOOK_AGENT", "") + self._wh: discord.Webhook | None = None + if wh_url: + try: + self._wh = discord.Webhook.from_url(wh_url, client=bot) + except Exception: + log.warning("Invalid CALENDAR_WEBHOOK_AGENT, webhook disabled") + def _check(self, user_id: int) -> bool: return user_id in self._allowed @@ -157,7 +169,10 @@ class Calendar(commands.Cog): """Send a button that opens the booking form.""" if not self._check(ctx.author.id): return await ctx.reply("You are not a maomao member.", delete_after=5) - await ctx.reply("Click below to book an event:", view=BookButton()) + if self._wh: + await self._wh.send("Click below to book an event:", view=BookButton()) + else: + await ctx.reply("Click below to book an event:", view=BookButton()) @commands.command(name="unbook") async def unbook_cmd(self, ctx: commands.Context, date: str = "", *, title: str = "") -> None: @@ -188,9 +203,14 @@ class Calendar(commands.Cog): deleted = True if deleted: - await ctx.reply(f"Removed **{title}** from {date}.") + msg = f"Removed **{title}** from {date}." else: - await ctx.reply(f"No event **{title}** found on {date}.") + msg = f"No event **{title}** found on {date}." + + if self._wh: + await self._wh.send(msg) + else: + await ctx.reply(msg) async def setup(bot: commands.Bot) -> None: diff --git a/credentials_test.env b/credentials_test.env index 74aced0..9466dc4 100644 --- a/credentials_test.env +++ b/credentials_test.env @@ -31,3 +31,6 @@ CALENDAR_USERS="id1,id2,id3" #mis ids member speicific stuff MELLO="" FEROX="" + +#calendar special webhook +CALENDAR_WEBHOOK_AGENT=webhook agent loll \ No newline at end of file