Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Add initial last active date to userstats command
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Jul 10, 2021
1 parent 2fc683d commit 2c0f729
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
34 changes: 28 additions & 6 deletions buttercup/cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,46 @@ async def _user_stats(
# We will edit this message later with the actual content.
msg = await ctx.send(i18n["user_stats"]["getting_stats"].format(user=user))

response = self.blossom_api.get_user(user)

if response.status != BlossomStatus.ok:
volunteer_response = self.blossom_api.get_user(user)
if volunteer_response.status != BlossomStatus.ok:
await msg.edit(
content=i18n["user_stats"]["failed_getting_stats"].format(user=user)
)
return
volunteer_data = volunteer_response.data

data = response.data
# Get the date of last activity
# TODO: Make this more efficient, e.g. by ordering it by complete_time
submission_response = self.blossom_api.get(
"submission/", params={"completed_by": volunteer_data["id"], "page_size": 1, "page": 1}
)
if submission_response.status_code != 200:
await msg.edit(
content=i18n["user_stats"]["failed_getting_stats"].format(user=user)
)
return
last_page = submission_response.json()["count"]
submission_response = self.blossom_api.get(
"submission/", params={"completed_by": volunteer_data["id"], "page_size": 1, "page": last_page}
)
if submission_response.status_code != 200:
await msg.edit(
content=i18n["user_stats"]["failed_getting_stats"].format(user=user)
)
return
submission_data = submission_response.json()["results"][0]

date_joined = parse(data["date_joined"])
date_joined = parse(volunteer_data["date_joined"])
last_active = parse(submission_data["complete_time"])

description = i18n["user_stats"]["embed_description"].format(
gamma=data["gamma"],
gamma=volunteer_data["gamma"],
flair_rank="Green",
leaderboard_rank=22,
date_joined=date_joined.strftime("%B %d, %Y"),
joined_ago=get_duration_str(date_joined),
last_active=last_active.strftime("%B %d, %Y"),
last_ago=get_duration_str(last_active),
)

await msg.edit(
Expand Down
1 change: 1 addition & 0 deletions buttercup/strings/en_US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ user_stats:
**Flair Rank**: {flair_rank}
**Leaderboard**: #{leaderboard_rank}
**Date Joined**: {date_joined} ({joined_ago} ago)
**Last Active**: {last_active} ({last_ago} ago)
progress:
getting_progress: |
Getting progress for u/{user} in the last {hours} hours...
Expand Down

0 comments on commit 2c0f729

Please sign in to comment.