Add private option to /book

This commit is contained in:
Riley Housden 2022-08-20 00:21:26 -04:00
parent d6d61e7cc9
commit a2f179ae35
Signed by: InValidFire
GPG key ID: 0D6208F6DF56B4D8

View file

@ -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.image = image
self.private = private
super().__init__(timeout=timeout, autodefer=autodefer)
@miru.button(label="Yes", style=hikari.ButtonStyle.SUCCESS)
@ -33,25 +35,31 @@ class BookingConfirmationView(miru.View):
gcal = GoogleCalendarAPI()
for room in self.room_list:
await gcal.create_event(room.number, room.start_time, room.end_time)
embed = hikari.Embed(title="Rooms Booked!")
add_rooms_to_embed(self.room_list, embed)
await ctx.edit_response(embed=embed, components=[])
embed = hikari.Embed(title="Rooms Booked!")
add_rooms_to_embed(self.room_list, embed)
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 = hikari.Embed(title="Rooms were booked!")
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)
add_rooms_to_embed(self.room_list, thread_embed)
await ctx.app.rest.create_message(config.discord_study_room_thread, embed=thread_embed)
self.stop()
@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(