From 1f7d35ff9558176c9ac298d08da2fc66ea8634b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Thu, 16 Nov 2023 14:11:52 +0800 Subject: [PATCH] :art: Improve Code Remove unnecessary `else / elif` used after `return` Update error handler --- plugins/account/account.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/account/account.py b/plugins/account/account.py index a4df0931..c7cd2dda 100644 --- a/plugins/account/account.py +++ b/plugins/account/account.py @@ -7,6 +7,7 @@ from simnet.errors import ( BadRequest as SimnetBadRequest, DataNotPublic, AccountNotFound, + NeedChallenge, ) from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, TelegramObject from telegram.ext import ConversationHandler, filters @@ -210,20 +211,16 @@ class BindAccountPlugin(Plugin.Conversation): await message.reply_text("角色未公开", reply_markup=ReplyKeyboardRemove()) logger.warning("获取账号信息发生错误 %s 账户信息未公开", player_id) return ConversationHandler.END - except InvalidCookies: + except (InvalidCookies, NeedChallenge): await self.public_cookies_service.undo(user.id) await message.reply_text("出错了呜呜呜 ~ 请稍后重试或者绑定 cookie") return ConversationHandler.END except SimnetBadRequest as exc: - if exc.ret_code == 1034: - await message.reply_text("出错了呜呜呜 ~ 请稍后重试或者绑定 cookie") - return ConversationHandler.END - elif exc.ret_code == -10001: + if exc.ret_code == -10001: await message.reply_text("账号所属服务器与选择服务器不符,请检查", reply_markup=ReplyKeyboardRemove()) return ConversationHandler.END await message.reply_text("获取账号信息发生错误", reply_markup=ReplyKeyboardRemove()) - logger.error("获取账号信息发生错误") - logger.exception(exc) + logger.error("获取账号信息发生错误", exc_info=exc) return ConversationHandler.END except ValueError: await message.reply_text("ID 格式有误,请检查", reply_markup=ReplyKeyboardRemove())