Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"editor.rulers": [88],
},
"ruff.organizeImports": true,
"ruff.lint.args": [
"--extend-ignore=I",
],
"ruff.lint.ignore": ["I"],
"python.languageServer": "Pylance",
"python.analysis.diagnosticMode": "workspace",
"python.testing.unittestEnabled": false,
Expand Down
75 changes: 52 additions & 23 deletions bot/src/ghutils/cogs/app_commands/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,6 @@ async def user(
user: UserOption,
visibility: MessageVisibility = "private",
):
# Use GraphQL to get # of repos starred by user...?
async with self.bot.github_app(interaction) as (github, _):
result = await github.async_graphql(
"""
query($username: String!) {
user(login: $username) {
starredRepositories {
totalCount
}
}
}
""",
{
"username": user.login,
},
)
num_stars: int = result["user"]["starredRepositories"]["totalCount"]

# Pylette ints are actually int64s, thanks NumPy
user_rgb = [
int(val)
Expand All @@ -194,6 +176,7 @@ async def user(
.rgb
]

# Start creating the embed first (see GraphQL queries)
embed = (
Embed(
description=user.bio,
Expand All @@ -202,19 +185,65 @@ async def user(
)
.set_thumbnail(url=user.avatar_url)
.add_field(name="Repositories", value=user.public_repos, inline=True)
.add_field(name="Stars", value=num_stars, inline=True)
)

# In case user doesn't have a display name
footer_text: str = f"{user.type} • {user.followers} followers"

async with self.bot.github_app(interaction) as (github, state):
match user.type:
# Users only: get # of repos starred and # following
case "User":
result = await github.async_graphql(
"""
query($username: String!) {
user(login: $username) {
starredRepositories {
totalCount
}
}
}
""",
{
"username": user.login,
},
)
num_stars: int = result["user"]["starredRepositories"]["totalCount"]
embed.add_field(name="Stars", value=num_stars, inline=True)
footer_text += f" • {user.following} following"

# Organizations only: add # of people in org (only works if logged in)
case "Organization":
if state == LoginState.LOGGED_IN:
result = await github.async_graphql(
"""
query ($name: String!) {
organization(login: $name) {
membersWithRole {
totalCount
}
}
}
""",
{
"name": user.login,
},
)
num_members: int = result["organization"]["membersWithRole"][
"totalCount"
]
embed.add_field(name="People", value=num_members, inline=True)

case _:
logger.warning(f"Unhandled user type: {user.type}")

# In case there's no display name
if user.name is None:
embed.title = user.login
else:
embed.title = user.name
embed.set_author(name=user.login)

embed.set_footer(
text=f"{user.followers} followers • {user.following} following"
)
embed.set_footer(text=footer_text)

await respond_with_visibility(interaction, visibility, embed=embed)

Expand Down