Skip to content

Commit

Permalink
🦋Fix wrong StrEnum subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
Aluerie committed Jan 17, 2025
1 parent 0c40631 commit 20380ba
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 15 deletions.
13 changes: 10 additions & 3 deletions utils/const/_meta.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

from enum import StrEnum
from typing import Any, NoReturn, override

__all__ = (
"CONSTANTS",
"ImageAsset",
"ASSETS_IMAGES",
"RAW_GITHUB_IMAGES",
)


Expand All @@ -25,12 +25,19 @@ class CONSTANTS(metaclass=ConstantsMeta):
pass


ASSETS_IMAGES = "./assets/images/"
RAW_GITHUB_IMAGES = "https://raw.githubusercontent.com/Aluerie/AluBot/main/assets/images/"

"""
Apparently this does not work because StrEnum is a Final therefore no subclasses.
class ImageAsset(StrEnum):
@override
def __str__(self) -> str:
"""Relative location compared to the workplace directory, i.e. `./assets/images/logo/dota_white.png`"""
"Relative location compared to the workplace directory, i.e. `./assets/images/logo/dota_white.png`"
return f"./assets/images/{self.value}"
@property
def url(self) -> str:
return f"https://raw.githubusercontent.com/Aluerie/AluBot/main/assets/images/{self.value}"
"""
16 changes: 14 additions & 2 deletions utils/const/dota.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

from ._meta import ImageAsset
from enum import StrEnum
from typing import override

from ._meta import ASSETS_IMAGES, RAW_GITHUB_IMAGES

__all__ = (
"TALENT_TREE_ICON",
Expand All @@ -12,7 +15,7 @@
TALENT_TREE_ICON = "https://liquipedia.net/commons/images/5/54/Talents.png"


class DotaAsset(ImageAsset):
class DotaAsset(StrEnum):
"""Dota 2 images saved as .png file in the repository assets folder."""

AbilityUnknown = "dota/ability_unknown.png"
Expand All @@ -25,6 +28,15 @@ class DotaAsset(ImageAsset):
EditFPC = "dota/edit_fpc.png"
SendFPC = "dota/send_fpc.png"

@override
def __str__(self) -> str:
"""Relative location compared to the workplace directory, i.e. `./assets/images/logo/dota_white.png`"""
return ASSETS_IMAGES + 'dota/' + self.value

@property
def url(self) -> str:
return RAW_GITHUB_IMAGES + "dota/" + self.value


FACET_COLOURS = {
# yoinked from https://github.com/mdiller/MangoByte/blob/master/resource/json/facet_colors.json
Expand Down
22 changes: 17 additions & 5 deletions utils/const/lol.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
from __future__ import annotations

from ._meta import ImageAsset
from enum import StrEnum
from typing import override

from ._meta import ASSETS_IMAGES, RAW_GITHUB_IMAGES

__all__ = (
"LoLAsset",
"NEW_CHAMPION_EMOTE",
)


class LoLAsset(ImageAsset):
ItemUnknown = "lol/item_unknown_64x64.png"
RuneUnknown = "lol/rune_unknown_64x64.png"
SummonerSpellUnknown = "lol/summoner_spell_unknown_64x64.png"
class LoLAsset(StrEnum):
ItemUnknown = "item_unknown_64x64.png"
RuneUnknown = "rune_unknown_64x64.png"
SummonerSpellUnknown = "summoner_spell_unknown_64x64.png"

@override
def __str__(self) -> str:
"""Relative location compared to the workplace directory, i.e. `./assets/images/logo/dota_white.png`"""
return ASSETS_IMAGES + "lol/" + self.value

@property
def url(self) -> str:
return RAW_GITHUB_IMAGES + "lol/" + self.value


NEW_CHAMPION_EMOTE = "\N{SQUARED NEW}"
19 changes: 14 additions & 5 deletions utils/const/other.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import StrEnum
from typing import override

from ._meta import CONSTANTS, ImageAsset
from ._meta import ASSETS_IMAGES, CONSTANTS, RAW_GITHUB_IMAGES

__all__ = (
"LogoAsset",
Expand All @@ -18,13 +18,22 @@
)


class LogoAsset(ImageAsset):
DotaWhite = "logo/dota_white.png"
class LogoAsset(StrEnum):
DotaWhite = "dota_white.png"
""" ^ image above is made by removing (R) from:
https://cdn.cloudflare.steamstatic.com/apps/dota2/images/dota_react/global/dota2_logo_symbol.png
"""
TwitchIO = "logo/twitchio.png"
SteamPy = "logo/steampy.png"
TwitchIO = "twitchio.png"
SteamPy = "steampy.png"

@override
def __str__(self) -> str:
"""Relative location compared to the workplace directory, i.e. `./assets/images/logo/dota_white.png`"""
return ASSETS_IMAGES + 'logo/' + self.value

@property
def url(self) -> str:
return RAW_GITHUB_IMAGES + "logo/" + self.value


class Slash(StrEnum):
Expand Down

0 comments on commit 20380ba

Please sign in to comment.