|
3 | 3 | import dataclasses |
4 | 4 | import datetime |
5 | 5 | import enum |
| 6 | +import re |
6 | 7 | from abc import abstractmethod |
7 | 8 | from typing import Generic, Literal, NamedTuple, TypeVar, overload |
8 | 9 |
|
@@ -84,13 +85,19 @@ def titlize_issue(issue: githubkit.rest.Issue) -> str: |
84 | 85 |
|
85 | 86 |
|
86 | 87 | def is_mannequin_user( |
87 | | - user: githubkit.rest.SimpleUser | githubkit.rest.DiscussionPropUser | graphql_models.DiscussionCommentUser, |
| 88 | + user: githubkit.rest.SimpleUser |
| 89 | + | githubkit.rest.PublicUser |
| 90 | + | githubkit.rest.DiscussionPropUser |
| 91 | + | graphql_models.DiscussionCommentUser, |
88 | 92 | ) -> bool: |
89 | 93 | return bool(user.type and user.type.casefold() == "mannequin") |
90 | 94 |
|
91 | 95 |
|
92 | 96 | def get_user_display_name( |
93 | | - user: githubkit.rest.SimpleUser | githubkit.rest.DiscussionPropUser | graphql_models.DiscussionCommentUser, |
| 97 | + user: githubkit.rest.SimpleUser |
| 98 | + | githubkit.rest.PublicUser |
| 99 | + | githubkit.rest.DiscussionPropUser |
| 100 | + | graphql_models.DiscussionCommentUser, |
94 | 101 | *, |
95 | 102 | include_login_alias: bool = False, |
96 | 103 | include_html_url: bool = False, |
@@ -213,12 +220,50 @@ def render_tiny( |
213 | 220 |
|
214 | 221 | def render_ogp(self, obj: githubkit.rest.PublicUser, *, context: ghretos.User) -> disnake.Embed: |
215 | 222 | embed = disnake.Embed( |
216 | | - title=obj.name or obj.login, |
| 223 | + title=f"`{obj.login}`'s GitHub profile info", |
| 224 | + description=f"```{obj.bio}```\n" if obj.bio else "", |
| 225 | + colour=disnake.Colour.blurple(), |
217 | 226 | url=obj.html_url, |
218 | | - description=obj.bio, |
219 | | - color=disnake.Color(0), |
| 227 | + timestamp=obj.created_at, |
220 | 228 | ) |
221 | 229 | embed.set_thumbnail(url=obj.avatar_url) |
| 230 | + embed.set_footer(text="Account created at") |
| 231 | + |
| 232 | + if obj.type == "User": |
| 233 | + embed.add_field( |
| 234 | + name="Followers", |
| 235 | + value=f"[{obj.followers}]({obj.html_url}?tab=followers)", |
| 236 | + inline=True, |
| 237 | + ) |
| 238 | + embed.add_field( |
| 239 | + name="Following", |
| 240 | + value=f"[{obj.following}]({obj.html_url}?tab=following)", |
| 241 | + inline=True, |
| 242 | + ) |
| 243 | + elif obj.type == "Organization": |
| 244 | + embed.add_field( |
| 245 | + name="Followers", |
| 246 | + value=f"[{obj.followers}](https://github.com/orgs/{obj.login}/followerss)", |
| 247 | + inline=True, |
| 248 | + ) |
| 249 | + |
| 250 | + embed.add_field( |
| 251 | + name="Public repos", |
| 252 | + value=f"[{obj.public_repos}]({obj.html_url}?tab=repositories)", |
| 253 | + ) |
| 254 | + |
| 255 | + if obj.type == "User": |
| 256 | + embed.add_field( |
| 257 | + name="Gists", |
| 258 | + value=f"[{obj.public_gists}]({obj.html_url}/gists)", |
| 259 | + ) |
| 260 | + |
| 261 | + if obj.blog: |
| 262 | + blog = obj.blog |
| 263 | + if not re.match(r"^https?:\/\/", blog): |
| 264 | + blog = f"https://{blog}" |
| 265 | + embed.add_field(name="Website", value=blog) |
| 266 | + |
222 | 267 | return embed |
223 | 268 |
|
224 | 269 | def render_ogp_cv2(self, obj: githubkit.rest.PublicUser, *, context: ghretos.User) -> disnake.ui.Container: |
@@ -272,6 +317,53 @@ def render_tiny( |
272 | 317 | ) -> str: |
273 | 318 | return f"📦 [{obj.name}](<{obj.html_url}>)" |
274 | 319 |
|
| 320 | + def render_ogp( |
| 321 | + self, |
| 322 | + obj: githubkit.rest.Repository | githubkit.rest.FullRepository | githubkit.rest.RepoSearchResultItem, |
| 323 | + *, |
| 324 | + context: ghretos.Repo, |
| 325 | + ) -> disnake.Embed: |
| 326 | + html_url = obj.html_url |
| 327 | + description = obj.description or "" |
| 328 | + embed = disnake.Embed( |
| 329 | + title=obj.name, |
| 330 | + colour=disnake.Colour.blurple(), |
| 331 | + url=html_url, |
| 332 | + ) |
| 333 | + |
| 334 | + # If it's a fork, then it will have a parent key |
| 335 | + if isinstance(obj, githubkit.rest.FullRepository) and obj.parent: |
| 336 | + parent = obj.parent |
| 337 | + description += f"\n\nForked from [{parent.full_name}]({parent.html_url})" |
| 338 | + |
| 339 | + if repo_owner := obj.owner: |
| 340 | + embed.set_author( |
| 341 | + name=repo_owner.login, |
| 342 | + url=repo_owner.html_url, |
| 343 | + icon_url=repo_owner.avatar_url, |
| 344 | + ) |
| 345 | + |
| 346 | + repo_created_at = obj.created_at and obj.created_at.strftime("%d/%m/%Y") |
| 347 | + last_pushed = obj.pushed_at and obj.pushed_at.strftime("%d/%m/%Y at %H:%M") |
| 348 | + |
| 349 | + embed.set_footer( |
| 350 | + text=( |
| 351 | + f"{obj.forks_count} ⑂ " |
| 352 | + f"• {obj.stargazers_count} ⭐ " |
| 353 | + f"• Created At {repo_created_at} " |
| 354 | + f"• Last Commit {last_pushed}" |
| 355 | + ) |
| 356 | + ) |
| 357 | + |
| 358 | + # mirrors have a mirror_url key. See google/skia as an example. |
| 359 | + if obj.mirror_url: |
| 360 | + mirror_url = obj.mirror_url |
| 361 | + description += f"\n\nMirrored from <{mirror_url}>." |
| 362 | + |
| 363 | + embed.description = description |
| 364 | + |
| 365 | + return embed |
| 366 | + |
275 | 367 | def render_ogp_cv2( |
276 | 368 | self, |
277 | 369 | obj: githubkit.rest.Repository | githubkit.rest.FullRepository | githubkit.rest.RepoSearchResultItem, |
@@ -609,6 +701,9 @@ def render_ogp( |
609 | 701 | ghretos.PullRequestComment: IssueCommentRenderer, |
610 | 702 | ghretos.PullRequestReviewComment: IssueCommentRenderer, |
611 | 703 | ghretos.DiscussionComment: IssueCommentRenderer, |
| 704 | + # Non-autolinked |
| 705 | + ghretos.User: UserRenderer, |
| 706 | + ghretos.Repo: RepoRenderer, |
612 | 707 | } |
613 | 708 |
|
614 | 709 | # GitHub supports url redirects on the frontend side for certain resources. |
|
0 commit comments