mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-16 12:51:45 +00:00
♻️ 批量优化插件代码
This commit is contained in:
parent
ae7cd186bd
commit
9e6bc8cfed
@ -137,10 +137,8 @@ class AddUser(BasePlugins):
|
||||
if len(cookie) == 0:
|
||||
await update.message.reply_text("Cookies格式有误,请检查", reply_markup=ReplyKeyboardRemove())
|
||||
return ConversationHandler.END
|
||||
cookies = {}
|
||||
for key, morsel in cookie.items():
|
||||
cookies[key] = morsel.value
|
||||
if len(cookies) == 0:
|
||||
cookies = {key: morsel.value for key, morsel in cookie.items()}
|
||||
if not cookies:
|
||||
await update.message.reply_text("Cookies格式有误,请检查", reply_markup=ReplyKeyboardRemove())
|
||||
return ConversationHandler.END
|
||||
if add_user_command_data.region == RegionEnum.HYPERION:
|
||||
@ -162,10 +160,7 @@ class AddUser(BasePlugins):
|
||||
await update.message.reply_text(f"获取账号信息发生错误,错误信息为 {str(error)},请检查Cookie或者账号是否正常",
|
||||
reply_markup=ReplyKeyboardRemove())
|
||||
return ConversationHandler.END
|
||||
except AttributeError:
|
||||
await update.message.reply_text("Cookies错误,请检查是否正确", reply_markup=ReplyKeyboardRemove())
|
||||
return ConversationHandler.END
|
||||
except ValueError:
|
||||
except (AttributeError, ValueError):
|
||||
await update.message.reply_text("Cookies错误,请检查是否正确", reply_markup=ReplyKeyboardRemove())
|
||||
return ConversationHandler.END
|
||||
add_user_command_data.cookies = cookies
|
||||
@ -178,8 +173,10 @@ class AddUser(BasePlugins):
|
||||
f"角色等级:{user_info.level}\n" \
|
||||
f"UID:`{user_info.uid}`\n" \
|
||||
f"服务器名称:`{user_info.server_name}`\n"
|
||||
await update.message.reply_markdown_v2(message,
|
||||
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
|
||||
await update.message.reply_markdown_v2(
|
||||
message,
|
||||
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)
|
||||
)
|
||||
return self.COMMAND_RESULT
|
||||
|
||||
@error_callable
|
||||
|
@ -85,4 +85,3 @@ async def error_handler(update: object, context: CallbackContext) -> None:
|
||||
parse_mode=ParseMode.HTML)
|
||||
except BadRequest as exc:
|
||||
Log.error(f"发送 update_id[{update.update_id}] 错误信息失败 错误信息为 {str(exc)}")
|
||||
pass
|
||||
|
@ -29,12 +29,12 @@ def check_ledger_month(context: CallbackContext) -> int:
|
||||
month = args[0]
|
||||
elif isinstance(month, int):
|
||||
pass
|
||||
elif re_data := re.findall(r"\d+", month):
|
||||
elif re_data := re.findall(r"\d+", str(month)):
|
||||
month = int(re_data[0])
|
||||
else:
|
||||
num_dict = {"一": 1, "二": 2, "三": 3, "四": 4, "五": 5,
|
||||
"六": 6, "七": 7, "八": 8, "九": 9, "十": 10}
|
||||
month = sum(num_dict.get(i, 0) for i in month)
|
||||
month = sum(num_dict.get(i, 0) for i in str(month))
|
||||
# check right
|
||||
now_time = datetime.now()
|
||||
allow_month = [datetime.now().month]
|
||||
|
@ -1,5 +1,6 @@
|
||||
import os
|
||||
import random
|
||||
from typing import Optional
|
||||
|
||||
from genshin import DataNotPublic, GenshinException, Client
|
||||
from telegram import Update
|
||||
@ -126,15 +127,14 @@ class Uid(BasePlugins):
|
||||
|
||||
@error_callable
|
||||
@restricts(return_data=ConversationHandler.END)
|
||||
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
||||
async def command_start(self, update: Update, context: CallbackContext) -> Optional[int]:
|
||||
user = update.effective_user
|
||||
message = update.message
|
||||
Log.info(f"用户 {user.full_name}[{user.id}] 查询游戏用户命令请求")
|
||||
uid: int = -1
|
||||
try:
|
||||
args = context.args
|
||||
if args is not None:
|
||||
if len(args) >= 1:
|
||||
if args is not None and len(args) >= 1:
|
||||
uid = int(args[0])
|
||||
except ValueError as error:
|
||||
Log.error("获取 uid 发生错误! 错误信息为", error)
|
||||
@ -142,19 +142,20 @@ class Uid(BasePlugins):
|
||||
return ConversationHandler.END
|
||||
try:
|
||||
client = await get_genshin_client(user.id, self.user_service, self.cookies_service)
|
||||
|
||||
png_data = await self._start_get_user_info(client, uid)
|
||||
except UserNotFoundError:
|
||||
reply_message = await message.reply_text("未查询到账号信息,请先私聊派蒙绑定账号")
|
||||
if filters.ChatType.GROUPS.filter(message):
|
||||
self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id, 30)
|
||||
|
||||
self._add_delete_message_job(context, message.chat_id, message.message_id, 30)
|
||||
return
|
||||
except ValueError as exc:
|
||||
if "洞庭湖未解锁" in str(exc):
|
||||
if "洞庭湖未解锁" not in str(exc):
|
||||
raise exc
|
||||
await message.reply_text("角色尘歌壶未解锁 如果想要查看具体数据 嗯...... 咕咕咕~")
|
||||
return ConversationHandler.END
|
||||
else:
|
||||
raise exc
|
||||
except AttributeError as exc:
|
||||
Log.warning("角色数据有误", exc)
|
||||
await message.reply_text("角色数据有误 估计是派蒙晕了")
|
||||
|
Loading…
Reference in New Issue
Block a user