-
Notifications
You must be signed in to change notification settings - Fork 167
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -129,6 +129,26 @@ async def user( | |||||
catch_date__gte=datetime.datetime.now() - datetime.timedelta(days=days), | ||||||
player=player, | ||||||
) | ||||||
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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||||||
|
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
classes should be named using camelcase, just the standard used across python
There was a problem hiding this comment.
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.