simple preset for discord webhook agent for larp
This commit is contained in:
1 parent
1286168f98
commit
e314599d33
2 files changed
+27
-4
No files matched your search
+24
-4
@@ -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,6 +169,9 @@ 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)
|
||||
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")
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user