|
2 | 2 | from contextlib import asynccontextmanager |
3 | 3 | from dataclasses import dataclass |
4 | 4 | from datetime import datetime |
| 5 | +from typing import Any |
5 | 6 |
|
6 | | -from discord import CustomActivity, Intents, Interaction |
| 7 | +import yaml |
| 8 | +from discord import Color, CustomActivity, Intents, Interaction |
7 | 9 | from discord.app_commands import AppCommandContext, AppInstallationType |
8 | 10 | from discord.ext import commands |
9 | 11 | from discord.ext.commands import Bot, Context, NoEntryPointError |
|
13 | 15 | from ghutils import cogs |
14 | 16 | from ghutils.common.__version__ import VERSION |
15 | 17 | from ghutils.db.models import UserGitHubTokens |
| 18 | +from ghutils.resources import load_resource |
16 | 19 | from ghutils.utils.imports import iter_modules |
17 | 20 |
|
18 | 21 | from .env import GHUtilsEnv |
@@ -46,6 +49,7 @@ def __post_init__(self): |
46 | 49 | ) |
47 | 50 | self.engine = create_engine(self.env.db_url) |
48 | 51 | self.start_time = datetime.now() |
| 52 | + self.language_colors = self._load_language_colors() |
49 | 53 |
|
50 | 54 | @classmethod |
51 | 55 | def of(cls, interaction: Interaction): |
@@ -117,3 +121,20 @@ async def github_app(self, user_id: int | Interaction): |
117 | 121 |
|
118 | 122 | def _get_default_installation_app(self): |
119 | 123 | 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