diff --git a/main.py b/main.py index 9a500be..ea64d84 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,8 @@ from telegram.ext import (ApplicationBuilder, CallbackQueryHandler, CommandHandl import common import utils.regex as regex from utils.logger import get_logger +from utils.net import NetClient +from utils.pixiv import ProcessPixiv from utils.telegram import Telegram if TYPE_CHECKING: @@ -208,9 +210,9 @@ async def post_init(application: Application) -> None: DESCRIPTION = "A bot to fetch tweets from Twitter." await application.bot.set_my_description(DESCRIPTION) await application.bot.set_my_short_description(DESCRIPTION) - Telegram.init_client() + NetClient.init_client() if common.PIXIV_REFRESH_TOKEN: - await Pixiv.init_client(common.PIXIV_REFRESH_TOKEN) + await ProcessPixiv.init_client(common.PIXIV_REFRESH_TOKEN) async def post_stop(application: Application) -> None: @@ -218,7 +220,7 @@ async def post_stop(application: Application) -> None: async def post_shutdown(application: Application) -> None: - await Telegram.close_client() + await NetClient.close_client() def main(): diff --git a/utils/telegram.py b/utils/telegram.py index c060503..583f013 100644 --- a/utils/telegram.py +++ b/utils/telegram.py @@ -1,12 +1,12 @@ from __future__ import annotations -from .net import NetClient +from common import PIXIV_REFRESH_TOKEN from .pixiv import TelegramPixiv from .regex import pixiv_url, x_url from .tweet import TelegramTweet -class Telegram(NetClient): +class Telegram: def __init__(self, url: str): self._url = url @@ -14,7 +14,7 @@ class Telegram(NetClient): if x_url.match(self._url): async with TelegramTweet(self._url) as tweet: return tweet - elif pixiv_url.match(self._url): + elif PIXIV_REFRESH_TOKEN and pixiv_url.match(self._url): async with TelegramPixiv(self._url) as pixiv: return pixiv