Lawnmower/plugins/need_char.py

49 lines
2.0 KiB
Python
Raw Permalink Normal View History

2022-04-30 14:47:55 +00:00
from asyncio import TimeoutError
from defs.need_char import get_character
import pyromod
from pyrogram import Client, filters
from pyrogram.types import Message
@Client.on_message(filters.incoming &
filters.regex("我想要角色"))
async def need_char(client: Client, message: Message):
# uid
msg = await message.reply("请输入您的游戏 uid 纯数字\n\n例如10001", quote=True)
try:
answer = await client.listen(message.chat.id, filters=filters.user(message.from_user.id)) # noqa
uid = int(answer.text)
except TimeoutError:
return await msg.edit("会话超时,请重试")
except ValueError:
await answer.safe_delete() # noqa
return await msg.edit("请输入正确的 uid")
await msg.safe_delete() # noqa
await answer.safe_delete() # noqa
# char
msg = await message.reply("请输入角色名称", quote=True)
try:
answer = await client.listen(message.chat.id, filters=filters.user(message.from_user.id)) # noqa
except TimeoutError:
return await msg.edit("会话超时,请重试")
await msg.safe_delete() # noqa
await answer.safe_delete() # noqa
char = get_character(answer.text)
if not char:
return await message.reply("没有找到这个角色")
# level
msg = await message.reply("请输入角色等级 纯数字\n\n例如90", quote=True)
try:
answer = await client.listen(message.chat.id, filters=filters.user(message.from_user.id)) # noqa
level = int(answer.text)
except TimeoutError:
return await msg.edit("会话超时,请重试")
except ValueError:
return await msg.edit("请输入正确的等级")
if level < 0 or level > 90:
return await msg.edit("请输入正确的等级")
await msg.safe_delete() # noqa
await answer.safe_delete() # noqa
# answer
await message.reply(f"您的角色生成命令为:`/givechar {uid} {char} {level}`", quote=True)