mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-29 11:03:14 +00:00
🎨 Rename AddUserCommandData
to SetUserUidCommandData
This commit is contained in:
parent
38ab907273
commit
7a2efd16dd
@ -19,7 +19,7 @@ from utils.log import logger
|
|||||||
from utils.models.base import RegionEnum
|
from utils.models.base import RegionEnum
|
||||||
|
|
||||||
|
|
||||||
class AddUserCommandData(TelegramObject):
|
class SetUserUidCommandData(TelegramObject):
|
||||||
user: Optional[User] = None
|
user: Optional[User] = None
|
||||||
region: RegionEnum = RegionEnum.HYPERION
|
region: RegionEnum = RegionEnum.HYPERION
|
||||||
game_uid: int = 0
|
game_uid: int = 0
|
||||||
@ -49,10 +49,10 @@ class SetUserUid(Plugin.Conversation, BasePlugin.Conversation):
|
|||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
logger.info(f"用户 {user.full_name}[{user.id}] 绑定账号命令请求")
|
logger.info(f"用户 {user.full_name}[{user.id}] 绑定账号命令请求")
|
||||||
add_user_command_data: AddUserCommandData = context.chat_data.get("add_uid_command_data")
|
set_user_uid_command_data: SetUserUidCommandData = context.chat_data.get("set_user_uid_command_data")
|
||||||
if add_user_command_data is None:
|
if set_user_uid_command_data is None:
|
||||||
cookies_command_data = AddUserCommandData()
|
cookies_command_data = SetUserUidCommandData()
|
||||||
context.chat_data["add_uid_command_data"] = cookies_command_data
|
context.chat_data["set_user_uid_command_data"] = cookies_command_data
|
||||||
text = (
|
text = (
|
||||||
f"你好 {user.mention_markdown_v2()} "
|
f"你好 {user.mention_markdown_v2()} "
|
||||||
f'{escape_markdown("!请输入通行证UID(非游戏UID),BOT将会通过通行证UID查找游戏UID。请选择要绑定的服务器!或回复退出取消操作")}'
|
f'{escape_markdown("!请输入通行证UID(非游戏UID),BOT将会通过通行证UID查找游戏UID。请选择要绑定的服务器!或回复退出取消操作")}'
|
||||||
@ -67,21 +67,22 @@ class SetUserUid(Plugin.Conversation, BasePlugin.Conversation):
|
|||||||
async def check_server(self, update: Update, context: CallbackContext) -> int:
|
async def check_server(self, update: Update, context: CallbackContext) -> int:
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
add_user_command_data: AddUserCommandData = context.chat_data.get("add_uid_command_data")
|
set_user_uid_command_data: SetUserUidCommandData = context.chat_data.get("set_user_uid_command_data")
|
||||||
if message.text == "退出":
|
if message.text == "退出":
|
||||||
await message.reply_text("退出任务", reply_markup=ReplyKeyboardRemove())
|
await message.reply_text("退出任务", reply_markup=ReplyKeyboardRemove())
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
elif message.text == "米游社":
|
elif message.text == "米游社":
|
||||||
region = add_user_command_data.region = RegionEnum.HYPERION
|
region = set_user_uid_command_data.region = RegionEnum.HYPERION
|
||||||
elif message.text == "HoYoLab":
|
elif message.text == "HoYoLab":
|
||||||
region = add_user_command_data.region = RegionEnum.HOYOLAB
|
region = set_user_uid_command_data.region = RegionEnum.HOYOLAB
|
||||||
else:
|
else:
|
||||||
await message.reply_text("选择错误,请重新选择")
|
await message.reply_text("选择错误,请重新选择")
|
||||||
return CHECK_SERVER
|
return CHECK_SERVER
|
||||||
try:
|
try:
|
||||||
user_info = await self.user_service.get_user_by_id(user.id)
|
user_info = await self.user_service.get_user_by_id(user.id)
|
||||||
add_user_command_data.user = user_info
|
set_user_uid_command_data.user = user_info
|
||||||
except UserNotFoundError:
|
except UserNotFoundError:
|
||||||
|
set_user_uid_command_data.user = None
|
||||||
user_info = None
|
user_info = None
|
||||||
if user_info is not None:
|
if user_info is not None:
|
||||||
try:
|
try:
|
||||||
@ -100,8 +101,8 @@ class SetUserUid(Plugin.Conversation, BasePlugin.Conversation):
|
|||||||
async def check_cookies(self, update: Update, context: CallbackContext) -> int:
|
async def check_cookies(self, update: Update, context: CallbackContext) -> int:
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
add_user_command_data: AddUserCommandData = context.chat_data.get("add_uid_command_data")
|
set_user_uid_command_data: SetUserUidCommandData = context.chat_data.get("set_user_uid_command_data")
|
||||||
region = add_user_command_data.region
|
region = set_user_uid_command_data.region
|
||||||
if message.text == "退出":
|
if message.text == "退出":
|
||||||
await message.reply_text("退出任务", reply_markup=ReplyKeyboardRemove())
|
await message.reply_text("退出任务", reply_markup=ReplyKeyboardRemove())
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
@ -147,7 +148,7 @@ class SetUserUid(Plugin.Conversation, BasePlugin.Conversation):
|
|||||||
f"UID:`{user_info.uid}`\n"
|
f"UID:`{user_info.uid}`\n"
|
||||||
f"服务器名称:`{user_info.server_name}`\n"
|
f"服务器名称:`{user_info.server_name}`\n"
|
||||||
)
|
)
|
||||||
add_user_command_data.game_uid = user_info.uid
|
set_user_uid_command_data.game_uid = user_info.uid
|
||||||
await message.reply_markdown_v2(text, reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
|
await message.reply_markdown_v2(text, reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
|
||||||
return COMMAND_RESULT
|
return COMMAND_RESULT
|
||||||
|
|
||||||
@ -157,33 +158,35 @@ class SetUserUid(Plugin.Conversation, BasePlugin.Conversation):
|
|||||||
async def command_result(self, update: Update, context: CallbackContext) -> int:
|
async def command_result(self, update: Update, context: CallbackContext) -> int:
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
add_user_command_data: AddUserCommandData = context.chat_data.get("add_uid_command_data")
|
set_user_uid_command_data: SetUserUidCommandData = context.chat_data.get("set_user_uid_command_data")
|
||||||
if message.text == "退出":
|
if message.text == "退出":
|
||||||
await message.reply_text("退出任务", reply_markup=ReplyKeyboardRemove())
|
await message.reply_text("退出任务", reply_markup=ReplyKeyboardRemove())
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
elif message.text == "确认":
|
elif message.text == "确认":
|
||||||
if add_user_command_data.user is None:
|
if set_user_uid_command_data.user is None:
|
||||||
if add_user_command_data.region == RegionEnum.HYPERION:
|
if set_user_uid_command_data.region == RegionEnum.HYPERION:
|
||||||
user_db = User(
|
user_db = User(
|
||||||
user_id=user.id,
|
user_id=user.id,
|
||||||
yuanshen_uid=add_user_command_data.game_uid,
|
yuanshen_uid=set_user_uid_command_data.game_uid,
|
||||||
region=add_user_command_data.region,
|
region=set_user_uid_command_data.region,
|
||||||
)
|
)
|
||||||
elif add_user_command_data.region == RegionEnum.HOYOLAB:
|
elif set_user_uid_command_data.region == RegionEnum.HOYOLAB:
|
||||||
user_db = User(
|
user_db = User(
|
||||||
user_id=user.id, genshin_uid=add_user_command_data.game_uid, region=add_user_command_data.region
|
user_id=user.id,
|
||||||
|
genshin_uid=set_user_uid_command_data.game_uid,
|
||||||
|
region=set_user_uid_command_data.region,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await message.reply_text("数据错误")
|
await message.reply_text("数据错误")
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
await self.user_service.add_user(user_db)
|
await self.user_service.add_user(user_db)
|
||||||
else:
|
else:
|
||||||
user_db = add_user_command_data.user
|
user_db = set_user_uid_command_data.user
|
||||||
user_db.region = add_user_command_data.region
|
user_db.region = set_user_uid_command_data.region
|
||||||
if add_user_command_data.region == RegionEnum.HYPERION:
|
if set_user_uid_command_data.region == RegionEnum.HYPERION:
|
||||||
user_db.yuanshen_uid = add_user_command_data.game_uid
|
user_db.yuanshen_uid = set_user_uid_command_data.game_uid
|
||||||
elif add_user_command_data.region == RegionEnum.HOYOLAB:
|
elif set_user_uid_command_data.region == RegionEnum.HOYOLAB:
|
||||||
user_db.genshin_uid = add_user_command_data.game_uid
|
user_db.genshin_uid = set_user_uid_command_data.game_uid
|
||||||
else:
|
else:
|
||||||
await message.reply_text("数据错误")
|
await message.reply_text("数据错误")
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
|
Loading…
Reference in New Issue
Block a user