Skip to content

Commit

Permalink
Add AutoPub support
Browse files Browse the repository at this point in the history
  • Loading branch information
trickeydan committed Oct 15, 2024
1 parent aeca29e commit c288f25
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
1 change: 0 additions & 1 deletion kmibot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ async def create_pub_event(
"pub": str(pub_id),
"discord_id": scheduled_event_id,
"table": None,
"attendees": [],
"created_by": str(created_by),
}
await self._request("POST", "v2/pub/events/", json=payload)
Expand Down
78 changes: 68 additions & 10 deletions kmibot/modules/pub/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,88 @@ async def next(self, interaction: discord.Interaction) -> None: # noqa: A003
pub_channel = interaction.guild.get_channel(self.config.pub.channel_id)
assert isinstance(pub_channel, discord.TextChannel)

await self._create_pub_event(
scheduled_event = await self._create_pub_event(
interaction.guild,
pub,
pub_time,
user=interaction.user,
)

pub_event = await self.api_client.get_pub_event_by_discord_id(scheduled_event.id)

if not pub_event:
await interaction.followup.send(
"Something went wrong when creating the event", ephemeral=True
)
return

def _get_display(attendee) -> str:
if attendee.discord_id:
return f"<@{attendee.discord_id}>"
else:
return attendee.display_name

attendee_mentions = " ,".join(_get_display(a) for a in pub_event.attendees)

pub_channel = interaction.guild.get_channel(self.config.pub.channel_id)
assert isinstance(pub_channel, discord.TextChannel)

LOGGER.info(f"Posting pub info in {pub_channel}")
formatted_pub_name = get_formatted_pub_name(pub, self.config)
message = [
"**Pub Next Week**",
f"The next pub will be <t:{int(pub_time.timestamp())}:R>",
f"It will be held at {formatted_pub_name}",
"",
"If you are coming, please mark 🔔 interest on the event!",
]

if attendee_mentions:
message += [
"",
f"The following people have opted-in via AutoPub: {attendee_mentions}",
]

await pub_channel.send(
"\n".join(
[
"**Pub Next Week**",
f"The next pub will be <t:{int(pub_time.timestamp())}:R>",
f"It will be held at {formatted_pub_name}",
"",
"If you are coming, please mark 🔔 interest on the event!",
],
),
"\n".join(message),
view=get_pub_buttons_view(pub),
)

@command(description="Get the people attending the next pub event")
async def attendees(self, interaction: discord.Interaction) -> None:
assert interaction.guild

event = self._get_next_pub_scheduled_event(interaction.guild, ignore_time=True)
if event is None:
LOGGER.info("No pub exists.")
await interaction.response.send_message(
"There doesn't appear to be a pub at this time.",
ephemeral=True,
)
return

pub_event = await self.api_client.get_pub_event_by_discord_id(event.id)
if pub_event is None:
await interaction.response.send_message(
"Unable to find the current pub event in the database.",
ephemeral=True,
)
return

count = len(pub_event.attendees)

message = [f"There are {count} people coming to the pub on {pub_event.timestamp}:"]

message += [
f"<@{attendee.discord_id}>" if attendee.discord_id else attendee.display_name
for attendee in pub_event.attendees
]

await interaction.response.send_message(
"\n".join(message),
ephemeral=True,
)

@command(description="Change the venue for a pub event") # type: ignore[arg-type]
async def change(self, interaction: discord.Interaction) -> None: # noqa: A003
LOGGER.info(f"{interaction.user} used /pub change")
Expand Down Expand Up @@ -306,6 +363,7 @@ async def help(self, interaction: discord.Interaction) -> None: # noqa: A003
"**Commands**",
"/pub next - create the next pub event, if needed",
"/pub table <table_no> - add the table number and let others know",
"/pub attendees - get the people coming to the next pub, including AutoPub attendees",
"/pub change - move the location of the pub and ping all attendees.",
],
),
Expand Down

0 comments on commit c288f25

Please sign in to comment.