Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[admin] Add button showing info about the last catches of a user #517

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion ballsdex/packages/admin/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ async def user(
catch_date__gte=datetime.datetime.now() - datetime.timedelta(days=days),
player=player,
)
class recentlyCaughtButton(discord.ui.View):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class recentlyCaughtButton(discord.ui.View):
class recentlyCaughtButton(discord.ui.View):
class RecentlyCaughtButton(discord.ui.View):

classes should be named using camelcase, just the standard used across python

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recentlyCaughtButton is already correct camelcase, which allows the first letter of the name to be either case. I believe you are describing PascalCase, which requires the first letter of each word to be only capital. I will change it accordingly.

@discord.ui.button(label='Recent Catches', style = discord.ButtonStyle.primary)
async def on_button_click(self, interaction: discord.Interaction, button: discord.ui.Button) -> None:
await interaction.response.defer(ephemeral=True, thinking=True)
embed = discord.Embed(
title=f"Catch times for {user.id} - last 30 catches",
)
recently_caught_balls = await BallInstance.filter(
player=player,
).order_by("-catch_date").limit(30)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for the edge case, should handle if recently_caught_balls is NOne and just say the user has no caught balls

ballInfo = ""
for ball in recently_caught_balls:
catch_time = ball.catch_date - ball.spawned_time
ballInfo = f"{ballInfo}{ball.description(short=True)} - {catch_time} - {ball.server_id}\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ballInfo = f"{ballInfo}{ball.description(short=True)} - {catch_time} - {ball.server_id}\n"
ballInfo += f"{ball.description(short=True)} - {catch_time} - {ball.server_id}\n"

Instead of overwriting ballInfo each time, you can append to it

embed.add_field(
name="",
value=ballInfo,
inline=False
)
await interaction.followup.send(embed=embed, ephemeral=True)
Comment on lines +132 to +151
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class should be defined outside of the function and outside of the other class

embed = discord.Embed(
title=f"{user} ({user.id})",
url=url,
Expand Down Expand Up @@ -165,4 +185,4 @@ async def user(
value=len(set([x.server_id for x in total_user_balls])),
)
embed.set_thumbnail(url=user.display_avatar) # type: ignore
await interaction.followup.send(embed=embed, ephemeral=True)
await interaction.followup.send(embed=embed,view=recentlyCaughtButton(), ephemeral=True)
Loading