simple preset for discord webhook agent for larp

This commit is contained in:
esef committed 2026-07-14 16:57:59 +03:00
1 parent 1286168f98
commit e314599d33
2 files changed
+28 -5

No files matched your search

+25 -5
View File
@@ -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: