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

Conversation

i2viyh
Copy link

@i2viyh i2viyh commented Jan 22, 2025

Added a button to the embed created by the command 'admin info user', which shows information on the last (up to 30) catches by the user viewed. This includes the ball ID, name, catch time and ID of the server caught in.
Resolves #509

Comment on lines +132 to +151
class recentlyCaughtButton(discord.ui.View):
@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)
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"
embed.add_field(
name="",
value=ballInfo,
inline=False
)
await interaction.followup.send(embed=embed, ephemeral=True)
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

@@ -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.

)
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

flaree
flaree previously approved these changes Jan 23, 2025
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

@flaree flaree dismissed their stale review January 23, 2025 23:38

missclick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[admin] recently caught button on info iser
2 participants