diff --git a/src/bot/bot.py b/src/bot/bot.py index 9b5bdadc..e7c8196a 100644 --- a/src/bot/bot.py +++ b/src/bot/bot.py @@ -10,7 +10,7 @@ from cachetools import TTLCache from discord.ext import commands, tasks -from ..hoyo.novelai_client import NAIClient +from ..hoyo.clients.novelai_client import NAIClient from ..utils import get_now from .command_tree import CommandTree from .translator import AppCommandTranslator, Translator diff --git a/src/cogs/admin.py b/src/cogs/admin.py index 30880f47..7732d9f6 100644 --- a/src/cogs/admin.py +++ b/src/cogs/admin.py @@ -6,7 +6,7 @@ from discord import ButtonStyle, ui from discord.ext import commands -from ..hoyo.daily_checkin import DailyCheckin +from ..hoyo.auto_tasks.daily_checkin import DailyCheckin if TYPE_CHECKING: from discord.ext.commands.context import Context diff --git a/src/cogs/hoyo.py b/src/cogs/hoyo.py index 2a5d1d02..9f99e503 100644 --- a/src/cogs/hoyo.py +++ b/src/cogs/hoyo.py @@ -13,10 +13,9 @@ from ..emojis import PROJECT_AMBER from ..enums import Game from ..exceptions import IncompleteParamError, InvalidQueryError, NoAccountFoundError -from ..hoyo.enka_client import EnkaAPI -from ..hoyo.genshin import ambr -from ..hoyo.hsr import yatta -from ..hoyo.mihomo_client import MihomoAPI +from ..hoyo.clients import ambr_client, yatta_client +from ..hoyo.clients.enka_client import EnkaAPI +from ..hoyo.clients.mihomo_client import MihomoAPI from ..hoyo.transformers import HoyoAccountTransformer # noqa: TCH001 from ..models import DrawInput from ..ui import URLButtonView @@ -40,15 +39,15 @@ def __init__(self, bot: "HoyoBuddy") -> None: self.bot = bot self._search_categories: dict[Game, list[str]] = { - Game.GENSHIN: [c.value for c in ambr.ItemCategory], - Game.STARRAIL: [c.value for c in yatta.ItemCategory], + Game.GENSHIN: [c.value for c in ambr_client.ItemCategory], + Game.STARRAIL: [c.value for c in yatta_client.ItemCategory], } # [game][category][locale][item_name] -> item_id self._search_autocomplete_choices: dict[ Game, dict[ - ambr.ItemCategory | yatta.ItemCategory, + ambr_client.ItemCategory | yatta_client.ItemCategory, dict[str, dict[str, str]], ], ] = {} @@ -61,15 +60,17 @@ async def cog_unload(self) -> None: async def _fetch_item_task( self, - api: ambr.AmbrAPIClient | yatta.YattaAPIClient, - item_category: ambr.ItemCategory | yatta.ItemCategory, + api: ambr_client.AmbrAPIClient | yatta_client.YattaAPIClient, + item_category: ambr_client.ItemCategory | yatta_client.ItemCategory, locale: discord.Locale, ) -> None: - if isinstance(api, ambr.AmbrAPIClient) and isinstance(item_category, ambr.ItemCategory): + if isinstance(api, ambr_client.AmbrAPIClient) and isinstance( + item_category, ambr_client.ItemCategory + ): game = Game.GENSHIN items = await api.fetch_items(item_category) - elif isinstance(api, yatta.YattaAPIClient) and isinstance( - item_category, yatta.ItemCategory + elif isinstance(api, yatta_client.YattaAPIClient) and isinstance( + item_category, yatta_client.ItemCategory ): game = Game.STARRAIL items = await api.fetch_items_(item_category) @@ -89,14 +90,14 @@ async def _setup_search_autocomplete_choices(self) -> None: LOGGER_.info("Setting up search autocomplete choices") start = self.bot.loop.time() - for locale in ambr.LOCALE_TO_AMBR_LANG: - async with ambr.AmbrAPIClient(locale, self.bot.translator) as api: - for item_category in ambr.ItemCategory: + for locale in ambr_client.LOCALE_TO_AMBR_LANG: + async with ambr_client.AmbrAPIClient(locale, self.bot.translator) as api: + for item_category in ambr_client.ItemCategory: await self._fetch_item_task(api, item_category, locale) - for locale in yatta.LOCALE_TO_YATTA_LANG: - async with yatta.YattaAPIClient(locale, self.bot.translator) as api: - for item_category in yatta.ItemCategory: + for locale in yatta_client.LOCALE_TO_YATTA_LANG: + async with yatta_client.YattaAPIClient(locale, self.bot.translator) as api: + for item_category in yatta_client.ItemCategory: await self._fetch_item_task(api, item_category, locale) LOGGER_.info( @@ -249,11 +250,11 @@ async def search_command( # noqa: C901, PLR0911, PLR0912, PLR0914, PLR0915 if game is Game.GENSHIN: try: - category = ambr.ItemCategory(category_value) + category = ambr_client.ItemCategory(category_value) except ValueError as e: raise InvalidQueryError from e - if category is ambr.ItemCategory.CHARACTERS: + if category is ambr_client.ItemCategory.CHARACTERS: character_ui = CharacterUI( query, author=i.user, @@ -262,7 +263,7 @@ async def search_command( # noqa: C901, PLR0911, PLR0912, PLR0914, PLR0915 ) return await character_ui.update(i) - if category is ambr.ItemCategory.WEAPONS: + if category is ambr_client.ItemCategory.WEAPONS: weapon_ui = WeaponUI( query, author=i.user, @@ -271,14 +272,14 @@ async def search_command( # noqa: C901, PLR0911, PLR0912, PLR0914, PLR0915 ) return await weapon_ui.start(i) - if category is ambr.ItemCategory.NAMECARDS: - async with ambr.AmbrAPIClient(locale, i.client.translator) as api: + if category is ambr_client.ItemCategory.NAMECARDS: + async with ambr_client.AmbrAPIClient(locale, i.client.translator) as api: await i.response.defer() namecard_detail = await api.fetch_namecard_detail(int(query)) embed = api.get_namecard_embed(namecard_detail) return await i.followup.send(embed=embed) - if category is ambr.ItemCategory.ARTIFACT_SETS: + if category is ambr_client.ItemCategory.ARTIFACT_SETS: artifact_set_ui = ArtifactSetUI( query, author=i.user, @@ -287,22 +288,22 @@ async def search_command( # noqa: C901, PLR0911, PLR0912, PLR0914, PLR0915 ) return await artifact_set_ui.start(i) - if category is ambr.ItemCategory.FOOD: - async with ambr.AmbrAPIClient(locale, i.client.translator) as api: + if category is ambr_client.ItemCategory.FOOD: + async with ambr_client.AmbrAPIClient(locale, i.client.translator) as api: await i.response.defer() food_detail = await api.fetch_food_detail(int(query)) embed = api.get_food_embed(food_detail) return await i.followup.send(embed=embed) - if category is ambr.ItemCategory.MATERIALS: - async with ambr.AmbrAPIClient(locale, i.client.translator) as api: + if category is ambr_client.ItemCategory.MATERIALS: + async with ambr_client.AmbrAPIClient(locale, i.client.translator) as api: await i.response.defer() material_detail = await api.fetch_material_detail(int(query)) embed = api.get_material_embed(material_detail) return await i.followup.send(embed=embed) - if category is ambr.ItemCategory.FURNISHINGS: - async with ambr.AmbrAPIClient(locale, i.client.translator) as api: + if category is ambr_client.ItemCategory.FURNISHINGS: + async with ambr_client.AmbrAPIClient(locale, i.client.translator) as api: await i.response.defer() furniture_detail = await api.fetch_furniture_detail(int(query)) embed = api.get_furniture_embed(furniture_detail) @@ -317,8 +318,8 @@ async def search_command( # noqa: C901, PLR0911, PLR0912, PLR0914, PLR0915 ), ) - if category is ambr.ItemCategory.FURNISHING_SETS: - async with ambr.AmbrAPIClient(locale, i.client.translator) as api: + if category is ambr_client.ItemCategory.FURNISHING_SETS: + async with ambr_client.AmbrAPIClient(locale, i.client.translator) as api: await i.response.defer() furniture_set_detail = await api.fetch_furniture_set_detail(int(query)) embed = api.get_furniture_set_embed(furniture_set_detail) @@ -333,8 +334,8 @@ async def search_command( # noqa: C901, PLR0911, PLR0912, PLR0914, PLR0915 ), ) - if category is ambr.ItemCategory.LIVING_BEINGS: - async with ambr.AmbrAPIClient(locale, i.client.translator) as api: + if category is ambr_client.ItemCategory.LIVING_BEINGS: + async with ambr_client.AmbrAPIClient(locale, i.client.translator) as api: await i.response.defer() monster_detail = await api.fetch_monster_detail(int(query)) embed = api.get_monster_embed(monster_detail) @@ -349,8 +350,8 @@ async def search_command( # noqa: C901, PLR0911, PLR0912, PLR0914, PLR0915 ), ) - if category is ambr.ItemCategory.BOOKS: - async with ambr.AmbrAPIClient(locale, i.client.translator) as api: + if category is ambr_client.ItemCategory.BOOKS: + async with ambr_client.AmbrAPIClient(locale, i.client.translator) as api: await i.response.defer() book = await api.fetch_book_detail(int(query)) book_volume_ui = BookVolumeUI( @@ -362,25 +363,25 @@ async def search_command( # noqa: C901, PLR0911, PLR0912, PLR0914, PLR0915 ) return await book_volume_ui.start(i) - if category is ambr.ItemCategory.TCG: + if category is ambr_client.ItemCategory.TCG: tcg_card_ui = TCGCardUI( int(query), author=i.user, locale=locale, translator=i.client.translator ) return await tcg_card_ui.start(i) elif game is Game.STARRAIL: try: - category = yatta.ItemCategory(category_value) + category = yatta_client.ItemCategory(category_value) except ValueError as e: raise InvalidQueryError from e - if category is yatta.ItemCategory.ITEMS: - async with yatta.YattaAPIClient(locale, i.client.translator) as api: + if category is yatta_client.ItemCategory.ITEMS: + async with yatta_client.YattaAPIClient(locale, i.client.translator) as api: await i.response.defer() item = await api.fetch_item_detail(int(query)) embed = api.get_item_embed(item) return await i.followup.send(embed=embed) - if category is yatta.ItemCategory.LIGHT_CONES: + if category is yatta_client.ItemCategory.LIGHT_CONES: light_cone_ui = LightConeUI( query, author=i.user, @@ -389,19 +390,19 @@ async def search_command( # noqa: C901, PLR0911, PLR0912, PLR0914, PLR0915 ) return await light_cone_ui.start(i) - if category is yatta.ItemCategory.BOOKS: + if category is yatta_client.ItemCategory.BOOKS: book_ui = BookUI( query, author=i.user, locale=locale, translator=i.client.translator ) return await book_ui.start(i) - if category is yatta.ItemCategory.RELICS: + if category is yatta_client.ItemCategory.RELICS: relic_set_ui = RelicSetUI( query, author=i.user, locale=locale, translator=i.client.translator ) return await relic_set_ui.start(i) - if category is yatta.ItemCategory.CHARACTERS: + if category is yatta_client.ItemCategory.CHARACTERS: try: character_id = int(query) except ValueError as e: @@ -444,9 +445,9 @@ async def search_command_query_autocomplete( try: if game is Game.GENSHIN: - category = ambr.ItemCategory(i.namespace.category) + category = ambr_client.ItemCategory(i.namespace.category) elif game is Game.STARRAIL: - category = yatta.ItemCategory(i.namespace.category) + category = yatta_client.ItemCategory(i.namespace.category) else: return [self._get_error_app_command_choice("Invalid game selected")] except ValueError: diff --git a/src/cogs/schedule.py b/src/cogs/schedule.py index 51b63e36..41ef1f1b 100644 --- a/src/cogs/schedule.py +++ b/src/cogs/schedule.py @@ -3,8 +3,8 @@ from discord.ext import commands, tasks -from ..hoyo.daily_checkin import DailyCheckin -from ..hoyo.notes_check import NotesChecker +from ..hoyo.auto_tasks.daily_checkin import DailyCheckin +from ..hoyo.auto_tasks.notes_check import NotesChecker from ..utils import get_now if TYPE_CHECKING: diff --git a/src/db/models.py b/src/db/models.py index 4c8f54dd..9d2e883c 100644 --- a/src/db/models.py +++ b/src/db/models.py @@ -5,7 +5,7 @@ from tortoise import fields from ..enums import GAME_CONVERTER, Game, NotesNotifyType -from ..hoyo.gpy_client import GenshinClient +from ..hoyo.clients.gpy_client import GenshinClient if TYPE_CHECKING: import datetime diff --git a/src/hoyo/daily_checkin.py b/src/hoyo/auto_tasks/daily_checkin.py similarity index 95% rename from src/hoyo/daily_checkin.py rename to src/hoyo/auto_tasks/daily_checkin.py index 21e53510..7167a563 100644 --- a/src/hoyo/daily_checkin.py +++ b/src/hoyo/auto_tasks/daily_checkin.py @@ -6,16 +6,16 @@ import discord import genshin -from ..bot.error_handler import get_error_embed -from ..bot.translator import LocaleStr, Translator -from ..db.models import HoyoAccount, User -from ..embeds import DefaultEmbed, Embed, ErrorEmbed -from ..enums import GAME_THUMBNAILS +from ...bot.error_handler import get_error_embed +from ...bot.translator import LocaleStr, Translator +from ...db.models import HoyoAccount, User +from ...embeds import DefaultEmbed, Embed, ErrorEmbed +from ...enums import GAME_THUMBNAILS if TYPE_CHECKING: import aiohttp - from ..bot.bot import HoyoBuddy + from ...bot.bot import HoyoBuddy LOGGER_ = logging.getLogger(__name__) diff --git a/src/hoyo/notes_check.py b/src/hoyo/auto_tasks/notes_check.py similarity index 96% rename from src/hoyo/notes_check.py rename to src/hoyo/auto_tasks/notes_check.py index 48d64d5d..4101c435 100644 --- a/src/hoyo/notes_check.py +++ b/src/hoyo/auto_tasks/notes_check.py @@ -6,19 +6,19 @@ from discord import Locale from genshin.models import Notes, StarRailNote -from ..bot.error_handler import get_error_embed -from ..bot.translator import LocaleStr -from ..db.models import NotesNotify -from ..draw.main_funcs import draw_gi_notes_card, draw_hsr_notes_card -from ..embeds import DefaultEmbed, ErrorEmbed -from ..enums import Game, NotesNotifyType -from ..icons import RESIN_ICON, RTBP_ICON, TBP_ICON -from ..models import DrawInput -from ..ui.hoyo.notes.view import NotesView -from ..utils import get_now +from ...bot.error_handler import get_error_embed +from ...bot.translator import LocaleStr +from ...db.models import NotesNotify +from ...draw.main_funcs import draw_gi_notes_card, draw_hsr_notes_card +from ...embeds import DefaultEmbed, ErrorEmbed +from ...enums import Game, NotesNotifyType +from ...icons import RESIN_ICON, RTBP_ICON, TBP_ICON +from ...models import DrawInput +from ...ui.hoyo.notes.view import NotesView +from ...utils import get_now if TYPE_CHECKING: - from ..bot.bot import HoyoBuddy + from ...bot.bot import HoyoBuddy LOGGER_ = logging.getLogger(__name__) diff --git a/src/hoyo/genshin/ambr.py b/src/hoyo/clients/ambr_client.py similarity index 100% rename from src/hoyo/genshin/ambr.py rename to src/hoyo/clients/ambr_client.py diff --git a/src/hoyo/enka_client.py b/src/hoyo/clients/enka_client.py similarity index 96% rename from src/hoyo/enka_client.py rename to src/hoyo/clients/enka_client.py index 9cc4a116..dfc7be3b 100644 --- a/src/hoyo/enka_client.py +++ b/src/hoyo/clients/enka_client.py @@ -4,8 +4,8 @@ import enka -from ..constants import LOCALE_TO_ENKA_LANG -from ..db.models import EnkaCache +from ...constants import LOCALE_TO_ENKA_LANG +from ...db.models import EnkaCache if TYPE_CHECKING: import discord diff --git a/src/hoyo/gpy_client.py b/src/hoyo/clients/gpy_client.py similarity index 86% rename from src/hoyo/gpy_client.py rename to src/hoyo/clients/gpy_client.py index fa1286fc..7a8088cb 100644 --- a/src/hoyo/gpy_client.py +++ b/src/hoyo/clients/gpy_client.py @@ -2,10 +2,10 @@ import genshin -from ..bot.translator import LocaleStr, Translator -from ..constants import LOCALE_TO_GPY_LANG -from ..embeds import DefaultEmbed -from ..enums import GAME_CONVERTER, GAME_THUMBNAILS +from ...bot.translator import LocaleStr, Translator +from ...constants import LOCALE_TO_GPY_LANG +from ...embeds import DefaultEmbed +from ...enums import GAME_CONVERTER, GAME_THUMBNAILS if TYPE_CHECKING: from discord import Locale diff --git a/src/hoyo/mihomo_client.py b/src/hoyo/clients/mihomo_client.py similarity index 96% rename from src/hoyo/mihomo_client.py rename to src/hoyo/clients/mihomo_client.py index fc191461..b1bc38c6 100644 --- a/src/hoyo/mihomo_client.py +++ b/src/hoyo/clients/mihomo_client.py @@ -4,8 +4,8 @@ import mihomo -from ..constants import LOCALE_TO_MIHOMO_LANG -from ..db.models import EnkaCache +from ...constants import LOCALE_TO_MIHOMO_LANG +from ...db.models import EnkaCache if TYPE_CHECKING: import discord diff --git a/src/hoyo/novelai_client.py b/src/hoyo/clients/novelai_client.py similarity index 100% rename from src/hoyo/novelai_client.py rename to src/hoyo/clients/novelai_client.py diff --git a/src/hoyo/hsr/yatta.py b/src/hoyo/clients/yatta_client.py similarity index 100% rename from src/hoyo/hsr/yatta.py rename to src/hoyo/clients/yatta_client.py diff --git a/src/ui/account/items/enter_cookies_btn.py b/src/ui/account/items/enter_cookies_btn.py index a15043a9..9deb6bc9 100644 --- a/src/ui/account/items/enter_cookies_btn.py +++ b/src/ui/account/items/enter_cookies_btn.py @@ -6,7 +6,7 @@ from src.bot.translator import LocaleStr from src.embeds import ErrorEmbed from src.emojis import COOKIE -from src.hoyo.gpy_client import GenshinClient +from src.hoyo.clients.gpy_client import GenshinClient from ...components import Button, GoBackButton, Modal, TextInput from .add_acc_select import AddAccountSelect diff --git a/src/ui/hoyo/genshin/abyss.py b/src/ui/hoyo/genshin/abyss.py index 67eae742..16becedb 100644 --- a/src/ui/hoyo/genshin/abyss.py +++ b/src/ui/hoyo/genshin/abyss.py @@ -4,7 +4,7 @@ from src.bot.translator import LocaleStr from src.draw.main_funcs import draw_item_list_card -from src.hoyo.genshin.ambr import AmbrAPIClient +from src.hoyo.clients.ambr_client import AmbrAPIClient from src.models import DrawInput from ...components import Button, Select, SelectOption, View diff --git a/src/ui/hoyo/genshin/search/artifact_set.py b/src/ui/hoyo/genshin/search/artifact_set.py index 94fed799..8a9baac6 100644 --- a/src/ui/hoyo/genshin/search/artifact_set.py +++ b/src/ui/hoyo/genshin/search/artifact_set.py @@ -5,7 +5,7 @@ from src.constants import EQUIP_ID_TO_ARTIFACT_POS from src.emojis import get_artifact_pos_emoji from src.exceptions import InvalidQueryError -from src.hoyo.genshin.ambr import AmbrAPIClient +from src.hoyo.clients.ambr_client import AmbrAPIClient from src.ui import Button, View if TYPE_CHECKING: diff --git a/src/ui/hoyo/genshin/search/book.py b/src/ui/hoyo/genshin/search/book.py index 67a3efeb..412edde4 100644 --- a/src/ui/hoyo/genshin/search/book.py +++ b/src/ui/hoyo/genshin/search/book.py @@ -6,7 +6,7 @@ from src.bot.translator import LocaleStr from src.emojis import PROJECT_AMBER -from src.hoyo.genshin.ambr import AmbrAPIClient +from src.hoyo.clients.ambr_client import AmbrAPIClient from src.ui import Button, Select, SelectOption, View if TYPE_CHECKING: diff --git a/src/ui/hoyo/genshin/search/character.py b/src/ui/hoyo/genshin/search/character.py index d8d649c1..e53d93d5 100644 --- a/src/ui/hoyo/genshin/search/character.py +++ b/src/ui/hoyo/genshin/search/character.py @@ -4,7 +4,7 @@ from discord import ButtonStyle, InteractionResponded, Locale, Member, User from src.bot.translator import LocaleStr -from src.hoyo.genshin.ambr import AmbrAPIClient +from src.hoyo.clients.ambr_client import AmbrAPIClient from src.ui import Button, Modal, PaginatorSelect, Select, SelectOption, TextInput, View if TYPE_CHECKING: diff --git a/src/ui/hoyo/genshin/search/tcg.py b/src/ui/hoyo/genshin/search/tcg.py index 9c7c098a..5973fabc 100644 --- a/src/ui/hoyo/genshin/search/tcg.py +++ b/src/ui/hoyo/genshin/search/tcg.py @@ -3,7 +3,7 @@ from discord import ButtonStyle from src.bot.translator import LocaleStr -from src.hoyo.genshin.ambr import AmbrAPIClient +from src.hoyo.clients.ambr_client import AmbrAPIClient from src.ui import Button, Select, SelectOption, View if TYPE_CHECKING: diff --git a/src/ui/hoyo/genshin/search/weapon.py b/src/ui/hoyo/genshin/search/weapon.py index 745f6168..2a842c57 100644 --- a/src/ui/hoyo/genshin/search/weapon.py +++ b/src/ui/hoyo/genshin/search/weapon.py @@ -4,7 +4,7 @@ from src.bot.translator import LocaleStr from src.exceptions import InvalidQueryError -from src.hoyo.genshin.ambr import AmbrAPIClient +from src.hoyo.clients.ambr_client import AmbrAPIClient from src.ui import Button, Modal, Select, SelectOption, TextInput, View if TYPE_CHECKING: diff --git a/src/ui/hoyo/hsr/search/book.py b/src/ui/hoyo/hsr/search/book.py index b4bd76a4..47267208 100644 --- a/src/ui/hoyo/hsr/search/book.py +++ b/src/ui/hoyo/hsr/search/book.py @@ -1,7 +1,7 @@ from typing import TYPE_CHECKING, Any from src.exceptions import InvalidQueryError -from src.hoyo.hsr.yatta import YattaAPIClient +from src.hoyo.clients.yatta_client import YattaAPIClient from src.ui import Select, SelectOption, View if TYPE_CHECKING: diff --git a/src/ui/hoyo/hsr/search/character.py b/src/ui/hoyo/hsr/search/character.py index 758e5163..8896965b 100644 --- a/src/ui/hoyo/hsr/search/character.py +++ b/src/ui/hoyo/hsr/search/character.py @@ -3,7 +3,7 @@ from discord import ButtonStyle from src.bot.translator import LocaleStr -from src.hoyo.hsr.yatta import YattaAPIClient +from src.hoyo.clients.yatta_client import YattaAPIClient from src.ui import Button, Modal, Select, SelectOption, TextInput, View if TYPE_CHECKING: diff --git a/src/ui/hoyo/hsr/search/light_cone.py b/src/ui/hoyo/hsr/search/light_cone.py index b2b85898..1407e698 100644 --- a/src/ui/hoyo/hsr/search/light_cone.py +++ b/src/ui/hoyo/hsr/search/light_cone.py @@ -4,7 +4,7 @@ from src.bot.translator import LocaleStr from src.exceptions import InvalidQueryError -from src.hoyo.hsr.yatta import YattaAPIClient +from src.hoyo.clients.yatta_client import YattaAPIClient from src.ui import Button, Modal, Select, SelectOption, TextInput, View if TYPE_CHECKING: diff --git a/src/ui/hoyo/hsr/search/relic.py b/src/ui/hoyo/hsr/search/relic.py index 0a0232d9..5fb77239 100644 --- a/src/ui/hoyo/hsr/search/relic.py +++ b/src/ui/hoyo/hsr/search/relic.py @@ -4,7 +4,7 @@ from src.emojis import get_relic_pos_emoji from src.exceptions import InvalidQueryError -from src.hoyo.hsr.yatta import YattaAPIClient +from src.hoyo.clients.yatta_client import YattaAPIClient from src.ui import Button, View if TYPE_CHECKING: