From a06eb61b490093a6b3961a41a213a9bfa33a65d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Mon, 27 Mar 2023 10:55:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20code=20quality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/services/cookies/services.py | 2 +- plugins/account/players.py | 25 +++++++++++++++---------- plugins/system/errorhandler.py | 2 +- plugins/tools/genshin.py | 1 - 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/core/services/cookies/services.py b/core/services/cookies/services.py index ff0fc230..796e9718 100644 --- a/core/services/cookies/services.py +++ b/core/services/cookies/services.py @@ -1,7 +1,7 @@ from typing import List, Optional import genshin -from genshin import Game, GenshinException, InvalidCookies, TooManyRequests, types +from genshin import GenshinException, InvalidCookies, TooManyRequests, types from core.base_service import BaseService from core.basemodel import RegionEnum diff --git a/plugins/account/players.py b/plugins/account/players.py index be56a062..cf2ec3b1 100644 --- a/plugins/account/players.py +++ b/plugins/account/players.py @@ -1,9 +1,9 @@ import html from http.cookies import SimpleCookie -from typing import Tuple +from typing import Tuple, TYPE_CHECKING -from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton -from telegram.ext import filters, ContextTypes +from telegram import InlineKeyboardMarkup, InlineKeyboardButton +from telegram.ext import filters from core.basemodel import RegionEnum from core.plugin import Plugin, handler @@ -14,6 +14,11 @@ from modules.apihelper.client.components.authclient import AuthClient from modules.apihelper.models.genshin.cookies import CookiesModel from utils.log import logger +if TYPE_CHECKING: + from telegram import Update + from telegram.ext import ContextTypes + + __all__ = ("PlayersManagesPlugin",) @@ -35,7 +40,7 @@ class PlayersManagesPlugin(Plugin): @handler.command(command="player", filters=filters.ChatType.PRIVATE, block=False) @handler.command(command="players", filters=filters.ChatType.PRIVATE, block=False) @handler.callback_query(r"^players_manager\|list", block=False) - async def command_start(self, update: Update, _: ContextTypes.DEFAULT_TYPE) -> None: + async def command_start(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> None: callback_query = update.callback_query user = update.effective_user message = update.effective_message @@ -64,7 +69,7 @@ class PlayersManagesPlugin(Plugin): await message.reply_text("从下面的列表中选择一个玩家", reply_markup=InlineKeyboardMarkup(buttons)) @handler.callback_query(r"^players_manager\|get\|", block=False) - async def get_player(self, update: Update, _: ContextTypes.DEFAULT_TYPE) -> None: + async def get_player(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> None: callback_query = update.callback_query user = callback_query.from_user @@ -131,7 +136,7 @@ class PlayersManagesPlugin(Plugin): ) @handler.callback_query(r"^players_manager\|update\|", block=False) - async def update_user(self, update: Update, _: ContextTypes.DEFAULT_TYPE) -> None: + async def update_user(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> None: callback_query = update.callback_query user = callback_query.from_user @@ -167,7 +172,7 @@ class PlayersManagesPlugin(Plugin): ) @handler.callback_query(r"^players_manager\|refresh_cookies\|", block=False) - async def refresh_cookies(self, update: Update, _: ContextTypes.DEFAULT_TYPE) -> None: + async def refresh_cookies(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> None: callback_query = update.callback_query user = callback_query.from_user @@ -230,7 +235,7 @@ class PlayersManagesPlugin(Plugin): ) @handler.callback_query(r"^players_manager\|export_cookies\|", block=False) - async def export_cookies(self, update: Update, _: ContextTypes.DEFAULT_TYPE) -> None: + async def export_cookies(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> None: callback_query = update.callback_query message = update.effective_message user = callback_query.from_user @@ -281,7 +286,7 @@ class PlayersManagesPlugin(Plugin): await message.delete() @handler.callback_query(r"^players_manager\|main\|", block=False) - async def set_main(self, update: Update, _: ContextTypes.DEFAULT_TYPE) -> None: + async def set_main(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> None: callback_query = update.callback_query user = callback_query.from_user @@ -323,7 +328,7 @@ class PlayersManagesPlugin(Plugin): ) @handler.callback_query(r"^players_manager\|del\|", block=False) - async def delete(self, update: Update, _: ContextTypes.DEFAULT_TYPE) -> None: + async def delete(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> None: callback_query = update.callback_query user = callback_query.from_user diff --git a/plugins/system/errorhandler.py b/plugins/system/errorhandler.py index 441ac7d7..bc4bb182 100644 --- a/plugins/system/errorhandler.py +++ b/plugins/system/errorhandler.py @@ -143,7 +143,7 @@ class ErrorHandler(Plugin): # notice = self.ERROR_MSG_PREFIX + " 连接 telegram 服务器超时" logger.error("连接 telegram 服务器超时 [%s]", repr(context.error)) raise ApplicationHandlerStop - elif isinstance(context.error, BadRequest): + if isinstance(context.error, BadRequest): if "Replied message not found" in context.error.message: notice = "气死我了!怎么有人喜欢发一个命令就秒删了!" elif "Message is not modified" in context.error.message: diff --git a/plugins/tools/genshin.py b/plugins/tools/genshin.py index 3a69db63..8b90d612 100644 --- a/plugins/tools/genshin.py +++ b/plugins/tools/genshin.py @@ -1,6 +1,5 @@ import asyncio import random -import re from datetime import datetime, timedelta, time from typing import Optional, Tuple, Union, TYPE_CHECKING