Skip to content

Commit 874bc06

Browse files
feat: add main language color to repo embed
today i learned that even github doesn't get their own colours right
1 parent a18a7df commit 874bc06

File tree

6 files changed

+8838
-3
lines changed

6 files changed

+8838
-3
lines changed

bot/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies = [
1818
"pfzy>=0.3.4",
1919
"more-itertools>=10.5.0",
2020
"fluent-runtime>=0.4.0",
21+
"pyyaml>=6.0.2",
2122
]
2223

2324
[tool.rye]

bot/src/ghutils/cogs/app_commands/github.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ async def repo(
154154
title=repo.full_name,
155155
description=repo.description,
156156
url=repo.html_url,
157+
color=self.bot.get_language_color(repo.language or ""),
157158
).set_image(
158159
url=image_url,
159160
)

bot/src/ghutils/core/bot.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from contextlib import asynccontextmanager
33
from dataclasses import dataclass
44
from datetime import datetime
5+
from typing import Any
56

6-
from discord import CustomActivity, Intents, Interaction
7+
import yaml
8+
from discord import Color, CustomActivity, Intents, Interaction
79
from discord.app_commands import AppCommandContext, AppInstallationType
810
from discord.ext import commands
911
from discord.ext.commands import Bot, Context, NoEntryPointError
@@ -13,6 +15,7 @@
1315
from ghutils import cogs
1416
from ghutils.common.__version__ import VERSION
1517
from ghutils.db.models import UserGitHubTokens
18+
from ghutils.resources import load_resource
1619
from ghutils.utils.imports import iter_modules
1720

1821
from .env import GHUtilsEnv
@@ -46,6 +49,7 @@ def __post_init__(self):
4649
)
4750
self.engine = create_engine(self.env.db_url)
4851
self.start_time = datetime.now()
52+
self.language_colors = self._load_language_colors()
4953

5054
@classmethod
5155
def of(cls, interaction: Interaction):
@@ -117,3 +121,20 @@ async def github_app(self, user_id: int | Interaction):
117121

118122
def _get_default_installation_app(self):
119123
return GitHub(self.env.gh.get_default_installation_auth())
124+
125+
def _load_language_colors(self) -> dict[str, Color]:
126+
langs: dict[str, dict[str, Any]] = yaml.load(
127+
load_resource("languages.yml"), Loader=yaml.CLoader
128+
)
129+
130+
return {
131+
language: Color.from_str(info["color"])
132+
for language, info in langs.items()
133+
if "color" in info
134+
}
135+
136+
# i'm not allowed to add the u to colour smh
137+
def get_language_color(self, language: str) -> Color:
138+
gh_default: Color = Color.from_str("#1B1F24")
139+
140+
return self.language_colors.get(language, gh_default)

0 commit comments

Comments
 (0)