Fix minor bugs in LTX

This commit is contained in:
Zeva Rose 2022-10-17 01:28:35 +00:00
parent cc5456457b
commit eb4364ce03

View file

@ -27,17 +27,20 @@ class EventCog(Extension):
async def is_dipshit(self, ctx: InteractionContext) -> bool: async def is_dipshit(self, ctx: InteractionContext) -> bool:
"""Checks if author is bot owner.""" """Checks if author is bot owner."""
return dipshit_id in ctx.author._role_ids guild = await self.bot.fetch_guild(520021794380447745)
member = await guild.fetch_member(ctx.author.id)
return member and dipshit_id in member._role_ids
ltx = SlashCommand(name="ltx", description="LTX Meetup management", scopes=[520021794380447745]) ltx = SlashCommand(name="ltx", description="LTX Meetup management")
@ltx.subcommand(sub_cmd_name="register", sub_cmd_description="Register for LTX") @ltx.subcommand(sub_cmd_name="register", sub_cmd_description="Register for LTX")
@slash_option(name="going", description="Are you going?", opt_type=OptionTypes.BOOLEAN) @slash_option(name="going", description="Are you going?", opt_type=OptionTypes.BOOLEAN)
async def _ltx_register(self, ctx: InteractionContext, going: bool) -> None: async def _ltx_register(self, ctx: InteractionContext, going: bool) -> None:
event = await Event.find_one(q(user=ctx.author.id, event="ltx")) event = await Event.find_one(q(user=ctx.author.id, event_name="ltx"))
if not event: if not event:
event = Event(user=ctx.author.id, going=going) event = Event(user=ctx.author.id, going=going, event_name="ltx")
event.going = going event.going = going
await event.commit()
msg = "going" if going else "not going" msg = "going" if going else "not going"
await ctx.send(f"Registration updated! You are now {msg}", ephemeral=True) await ctx.send(f"Registration updated! You are now {msg}", ephemeral=True)
@ -45,15 +48,15 @@ class EventCog(Extension):
@slash_option( @slash_option(
name="user", description="User to show", opt_type=OptionTypes.USER, required=False name="user", description="User to show", opt_type=OptionTypes.USER, required=False
) )
async def _ltx_show(self, ctx: InteractionContext, user: Member) -> None: async def _ltx_show(self, ctx: InteractionContext, user: Member = None) -> None:
user = user or ctx.author user = user or ctx.author
event = await Event.find_one(q(user=user.id, event="ltx")) event = await Event.find_one(q(user=user.id, event_name="ltx"))
if not event: if not event:
await ctx.send("That user hasn't registered", ephemeral=False) await ctx.send("That user hasn't registered", ephemeral=True)
return return
if not event.going: if not event.going:
await ctx.send("That user isn't going", ephemeral=False) await ctx.send("That user isn't going", ephemeral=True)
return return
fields = [] fields = []
@ -112,9 +115,9 @@ class EventCog(Extension):
to_airport: str, to_airport: str,
flight: str, flight: str,
) -> None: ) -> None:
event = await Event.find_one(q(user=ctx.author.id, event="ltx")) event = await Event.find_one(q(user=ctx.author.id, event_name="ltx"))
if not event: if not event:
event = Event(user=ctx.author.id, event="ltx", going=True) event = Event(user=ctx.author.id, event_name="ltx", going=True)
base_settings = { base_settings = {
"PREFER_DATES_FROM": "future", "PREFER_DATES_FROM": "future",
@ -156,6 +159,8 @@ class EventCog(Extension):
event.before_departure_time = departure event.before_departure_time = departure
event.before_flight = f"{from_airport} -> {to_airport} {flight}" event.before_flight = f"{from_airport} -> {to_airport} {flight}"
await event.commit()
dts = int(departure.timestamp()) dts = int(departure.timestamp())
ats = int(arrival.timestamp()) ats = int(arrival.timestamp())
@ -166,7 +171,7 @@ class EventCog(Extension):
embed = build_embed( embed = build_embed(
title="Your Pre-LTX Flight Information", title="Your Pre-LTX Flight Information",
description=f"🛫 {from_airport} -> {to_airport} 🛬", description=f"🛫 {from_airport} -> {to_airport} {flight} 🛬",
fields=fields, fields=fields,
) )
embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.display_avatar.url) embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.display_avatar.url)
@ -201,9 +206,9 @@ class EventCog(Extension):
to_airport: str, to_airport: str,
flight: str, flight: str,
) -> None: ) -> None:
event = await Event.find_one(q(user=ctx.author.id, event="ltx")) event = await Event.find_one(q(user=ctx.author.id, event_name="ltx"))
if not event: if not event:
event = Event(user=ctx.author.id, event="ltx", going=True) event = Event(user=ctx.author.id, event_name="ltx", going=True)
base_settings = { base_settings = {
"PREFER_DATES_FROM": "future", "PREFER_DATES_FROM": "future",
@ -245,6 +250,8 @@ class EventCog(Extension):
event.after_departure_time = departure event.after_departure_time = departure
event.after_flight = f"{from_airport} -> {to_airport} {flight}" event.after_flight = f"{from_airport} -> {to_airport} {flight}"
await event.commit()
dts = int(departure.timestamp()) dts = int(departure.timestamp())
ats = int(arrival.timestamp()) ats = int(arrival.timestamp())
@ -255,9 +262,12 @@ class EventCog(Extension):
embed = build_embed( embed = build_embed(
title="Your Post-LTX Flight Information", title="Your Post-LTX Flight Information",
description=f"🛫 {from_airport} -> {to_airport} 🛬", description=f"🛫 {from_airport} -> {to_airport} {flight} 🛬",
fields=fields, fields=fields,
) )
embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.display_avatar.url) embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.display_avatar.url)
await ctx.send(embeds=embed) await ctx.send(embeds=embed)
def setup(client):
EventCog(client)