fix init pixiv

This commit is contained in:
2024-06-24 02:03:28 +08:00
parent a617a7e1a0
commit 0433650563
2 changed files with 8 additions and 6 deletions
+5 -3
View File
@@ -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():
+3 -3
View File
@@ -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