Add private option to /book
This commit is contained in:
parent
d6d61e7cc9
commit
a2f179ae35
1 changed files with 22 additions and 13 deletions
|
@ -15,17 +15,19 @@ from lib.ocr import get_room_data, NoMatchException
|
|||
plugin = lightbulb.Plugin("LibCal")
|
||||
config = load_config()
|
||||
|
||||
|
||||
def add_rooms_to_embed(room_list: list[Room], embed: hikari.Embed):
|
||||
for room in room_list:
|
||||
embed.add_field(room.get_time_str(), room.number)
|
||||
|
||||
|
||||
class BookingConfirmationView(miru.View):
|
||||
def __init__(self, *, timeout: Optional[float] = 120, autodefer: bool = True, room_list: list[Room] = [], image: Resource | None = None) -> None:
|
||||
def __init__(self, *, timeout: Optional[float] = 120, autodefer: bool = True,
|
||||
room_list: list[Room] = [], image: Resource | None = None, private: bool = False
|
||||
) -> None:
|
||||
self.room_list = room_list
|
||||
if image is not None:
|
||||
self.image = image
|
||||
else:
|
||||
self.image = None
|
||||
self.private = private
|
||||
super().__init__(timeout=timeout, autodefer=autodefer)
|
||||
|
||||
@miru.button(label="Yes", style=hikari.ButtonStyle.SUCCESS)
|
||||
|
@ -38,7 +40,9 @@ class BookingConfirmationView(miru.View):
|
|||
await ctx.edit_response(embed=embed, components=[])
|
||||
|
||||
thread_embed = hikari.Embed(title="Rooms were booked!")
|
||||
thread_embed.set_author(name=ctx.user.username, icon=ctx.user.avatar_url)
|
||||
thread_embed.set_author(
|
||||
name=ctx.user.username, icon=ctx.user.avatar_url)
|
||||
if not self.private:
|
||||
thread_embed.set_image(self.image)
|
||||
add_rooms_to_embed(self.room_list, thread_embed)
|
||||
await ctx.app.rest.create_message(config.discord_study_room_thread, embed=thread_embed)
|
||||
|
@ -47,11 +51,15 @@ class BookingConfirmationView(miru.View):
|
|||
@miru.button(label="No", style=hikari.ButtonStyle.DANGER)
|
||||
async def cancel_button(self, button: miru.Button, ctx: miru.Context) -> None:
|
||||
embed = hikari.Embed(title="Aborted!")
|
||||
add_rooms_to_embed(self.room_list, embed)
|
||||
embed.set_image(self.image)
|
||||
await ctx.edit_response(embed=embed, components=[])
|
||||
self.stop()
|
||||
|
||||
|
||||
@plugin.command
|
||||
@lightbulb.option("img", "image to check for events", type=hikari.Attachment, required=True)
|
||||
@lightbulb.option("private", "if private, the bot will not share confirmation e-mails.", type=bool, default=False)
|
||||
@lightbulb.command("book", "add room bookings to Google Calendar", ephemeral=True)
|
||||
@lightbulb.implements(lightbulb.SlashCommand)
|
||||
async def book(ctx: lightbulb.Context) -> None:
|
||||
|
@ -70,7 +78,8 @@ async def book(ctx: lightbulb.Context) -> None:
|
|||
async def book_error_handler(event: lightbulb.CommandErrorEvent):
|
||||
print("ERROR TYPE:", type(event.exception))
|
||||
if isinstance(event.exception.__cause__, NoMatchException):
|
||||
embed = hikari.Embed(title="Huh, I can't read that", description="Could you try another picture?")
|
||||
embed = hikari.Embed(title="Huh, I can't read that",
|
||||
description="Could you try another picture?")
|
||||
await event.context.respond(embed=embed)
|
||||
else:
|
||||
embed = hikari.Embed(
|
||||
|
|
Loading…
Reference in a new issue