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")
|
plugin = lightbulb.Plugin("LibCal")
|
||||||
config = load_config()
|
config = load_config()
|
||||||
|
|
||||||
|
|
||||||
def add_rooms_to_embed(room_list: list[Room], embed: hikari.Embed):
|
def add_rooms_to_embed(room_list: list[Room], embed: hikari.Embed):
|
||||||
for room in room_list:
|
for room in room_list:
|
||||||
embed.add_field(room.get_time_str(), room.number)
|
embed.add_field(room.get_time_str(), room.number)
|
||||||
|
|
||||||
|
|
||||||
class BookingConfirmationView(miru.View):
|
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
|
self.room_list = room_list
|
||||||
if image is not None:
|
|
||||||
self.image = image
|
self.image = image
|
||||||
else:
|
self.private = private
|
||||||
self.image = None
|
|
||||||
super().__init__(timeout=timeout, autodefer=autodefer)
|
super().__init__(timeout=timeout, autodefer=autodefer)
|
||||||
|
|
||||||
@miru.button(label="Yes", style=hikari.ButtonStyle.SUCCESS)
|
@miru.button(label="Yes", style=hikari.ButtonStyle.SUCCESS)
|
||||||
|
@ -38,7 +40,9 @@ class BookingConfirmationView(miru.View):
|
||||||
await ctx.edit_response(embed=embed, components=[])
|
await ctx.edit_response(embed=embed, components=[])
|
||||||
|
|
||||||
thread_embed = hikari.Embed(title="Rooms were booked!")
|
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)
|
thread_embed.set_image(self.image)
|
||||||
add_rooms_to_embed(self.room_list, 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)
|
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)
|
@miru.button(label="No", style=hikari.ButtonStyle.DANGER)
|
||||||
async def cancel_button(self, button: miru.Button, ctx: miru.Context) -> None:
|
async def cancel_button(self, button: miru.Button, ctx: miru.Context) -> None:
|
||||||
embed = hikari.Embed(title="Aborted!")
|
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=[])
|
await ctx.edit_response(embed=embed, components=[])
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
|
||||||
@plugin.command
|
@plugin.command
|
||||||
@lightbulb.option("img", "image to check for events", type=hikari.Attachment, required=True)
|
@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.command("book", "add room bookings to Google Calendar", ephemeral=True)
|
||||||
@lightbulb.implements(lightbulb.SlashCommand)
|
@lightbulb.implements(lightbulb.SlashCommand)
|
||||||
async def book(ctx: lightbulb.Context) -> None:
|
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):
|
async def book_error_handler(event: lightbulb.CommandErrorEvent):
|
||||||
print("ERROR TYPE:", type(event.exception))
|
print("ERROR TYPE:", type(event.exception))
|
||||||
if isinstance(event.exception.__cause__, NoMatchException):
|
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)
|
await event.context.respond(embed=embed)
|
||||||
else:
|
else:
|
||||||
embed = hikari.Embed(
|
embed = hikari.Embed(
|
||||||
|
|
Loading…
Reference in a new issue