Skip to content

Commit

Permalink
feat(gaw): add participants list embed color
Browse files Browse the repository at this point in the history
  • Loading branch information
ZRunner committed Oct 22, 2023
1 parent aefd42e commit 45a2118
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/modules/giveaways/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ async def gw_list_participants(self, interaction: COInteraction, giveaway: str):
if not participants:
await interaction.followup.send("No participants!")
return
view = ParticipantsPaginator(self.bot, interaction.user, gaw, participants)
view = ParticipantsPaginator(self.bot, self.embed_color, interaction.user, gaw, participants)
await view.send_init(interaction)

@gw_list_participants.autocomplete("giveaway")
Expand Down
14 changes: 9 additions & 5 deletions src/modules/giveaways/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def __init__(self, bot: CObot, data: GiveawayToSendData, button_label: str):

class ParticipantsPaginator(Paginator):
"Allows users to see the participants of a giveaway"
def __init__(self, client: CObot, user: Union[User, Member], gaw: GiveawayData, participants: list[int]):
def __init__(self, client: CObot, embed_color: int, user: Union[User, Member], gaw: GiveawayData, participants: list[int]):
super().__init__(client, user)
self.embed_color = embed_color
self.title = f"Participants of {gaw['name']}"
self.participants = participants
self.page_count = ceil(len(participants) / 20)
Expand All @@ -45,13 +46,16 @@ async def get_page_content(self, interaction, page):
f"<@{user_id}> ({user_id})"
for user_id in self.participants[lower_index:upper_index]
]
if participants_count <= 20:
desc_header = f"### {participants_count} participants\n\n"
if participants_count == 1:
desc_header = "### 1 participant"
elif participants_count <= 20:
desc_header = f"### {participants_count} participants"
else:
desc_header = f"### Participants {lower_index+1}-{upper_index} out of {participants_count}\n\n"
desc_header = f"### Participants {lower_index+1}-{upper_index} out of {participants_count}"
embed = Embed(
title=self.title,
description=desc_header + "\n".join(page_participants),
description=desc_header + "\n\n" + "\n".join(page_participants),
color=self.embed_color
)
embed.set_footer(text=f"Page {page}/{self.page_count}")
return {"embed": embed}

0 comments on commit 45a2118

Please sign in to comment.