🎨 Improve code quality

This commit is contained in:
洛水居室 2023-03-27 10:55:12 +08:00
parent c9d85e774a
commit a06eb61b49
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
4 changed files with 17 additions and 13 deletions

View File

@ -1,7 +1,7 @@
from typing import List, Optional from typing import List, Optional
import genshin 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.base_service import BaseService
from core.basemodel import RegionEnum from core.basemodel import RegionEnum

View File

@ -1,9 +1,9 @@
import html import html
from http.cookies import SimpleCookie from http.cookies import SimpleCookie
from typing import Tuple from typing import Tuple, TYPE_CHECKING
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton from telegram import InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import filters, ContextTypes from telegram.ext import filters
from core.basemodel import RegionEnum from core.basemodel import RegionEnum
from core.plugin import Plugin, handler 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 modules.apihelper.models.genshin.cookies import CookiesModel
from utils.log import logger from utils.log import logger
if TYPE_CHECKING:
from telegram import Update
from telegram.ext import ContextTypes
__all__ = ("PlayersManagesPlugin",) __all__ = ("PlayersManagesPlugin",)
@ -35,7 +40,7 @@ class PlayersManagesPlugin(Plugin):
@handler.command(command="player", filters=filters.ChatType.PRIVATE, block=False) @handler.command(command="player", filters=filters.ChatType.PRIVATE, block=False)
@handler.command(command="players", 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) @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 callback_query = update.callback_query
user = update.effective_user user = update.effective_user
message = update.effective_message message = update.effective_message
@ -64,7 +69,7 @@ class PlayersManagesPlugin(Plugin):
await message.reply_text("从下面的列表中选择一个玩家", reply_markup=InlineKeyboardMarkup(buttons)) await message.reply_text("从下面的列表中选择一个玩家", reply_markup=InlineKeyboardMarkup(buttons))
@handler.callback_query(r"^players_manager\|get\|", block=False) @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 callback_query = update.callback_query
user = callback_query.from_user user = callback_query.from_user
@ -131,7 +136,7 @@ class PlayersManagesPlugin(Plugin):
) )
@handler.callback_query(r"^players_manager\|update\|", block=False) @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 callback_query = update.callback_query
user = callback_query.from_user user = callback_query.from_user
@ -167,7 +172,7 @@ class PlayersManagesPlugin(Plugin):
) )
@handler.callback_query(r"^players_manager\|refresh_cookies\|", block=False) @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 callback_query = update.callback_query
user = callback_query.from_user user = callback_query.from_user
@ -230,7 +235,7 @@ class PlayersManagesPlugin(Plugin):
) )
@handler.callback_query(r"^players_manager\|export_cookies\|", block=False) @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 callback_query = update.callback_query
message = update.effective_message message = update.effective_message
user = callback_query.from_user user = callback_query.from_user
@ -281,7 +286,7 @@ class PlayersManagesPlugin(Plugin):
await message.delete() await message.delete()
@handler.callback_query(r"^players_manager\|main\|", block=False) @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 callback_query = update.callback_query
user = callback_query.from_user user = callback_query.from_user
@ -323,7 +328,7 @@ class PlayersManagesPlugin(Plugin):
) )
@handler.callback_query(r"^players_manager\|del\|", block=False) @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 callback_query = update.callback_query
user = callback_query.from_user user = callback_query.from_user

View File

@ -143,7 +143,7 @@ class ErrorHandler(Plugin):
# notice = self.ERROR_MSG_PREFIX + " 连接 telegram 服务器超时" # notice = self.ERROR_MSG_PREFIX + " 连接 telegram 服务器超时"
logger.error("连接 telegram 服务器超时 [%s]", repr(context.error)) logger.error("连接 telegram 服务器超时 [%s]", repr(context.error))
raise ApplicationHandlerStop raise ApplicationHandlerStop
elif isinstance(context.error, BadRequest): if isinstance(context.error, BadRequest):
if "Replied message not found" in context.error.message: if "Replied message not found" in context.error.message:
notice = "气死我了!怎么有人喜欢发一个命令就秒删了!" notice = "气死我了!怎么有人喜欢发一个命令就秒删了!"
elif "Message is not modified" in context.error.message: elif "Message is not modified" in context.error.message:

View File

@ -1,6 +1,5 @@
import asyncio import asyncio
import random import random
import re
from datetime import datetime, timedelta, time from datetime import datetime, timedelta, time
from typing import Optional, Tuple, Union, TYPE_CHECKING from typing import Optional, Tuple, Union, TYPE_CHECKING