Enka_Genshin_bot/plugins/bind.py
2022-06-04 13:34:58 +08:00

28 lines
1.3 KiB
Python

from pyrogram import filters, Client
from pyrogram.types import Message
from defs.bind import check_bind, get_bind_uid, set_bind, remove_bind
from defs.refresh import refresh_player
from defs.player import Player
from ci import app, me
@app.on_message(filters.command(["bind", f"bind@{me['result']['username']}"]) & filters.private)
async def bind_command(_: Client, message: Message):
if len(message.command) == 1:
if check_bind(message.from_user.id):
data = Player(get_bind_uid(message.from_user.id))
data.restore()
return await message.reply(f"您绑定的游戏 uid 为:{get_bind_uid(message.from_user.id)}\n\n"
f"{data.gen_all_char()}", quote=True)
else:
return await message.reply(f"请使用 <code>/bind [uid]</code> 绑定游戏 uid", quote=True)
if not message.command[1].isdigit():
if message.command[1] == "remove":
remove_bind(message.from_user.id)
return await message.reply("已解除绑定", quote=True)
return await message.reply("uid 非数字", quote=True)
uid = message.command[1]
set_bind(message.from_user.id, uid)
msg = await message.reply(f"绑定成功,您绑定的游戏 uid 为:{uid},请使用 /refresh 刷新数据。", quote=True)
await msg.edit(text)