misskey2telegram/modules/status.py

31 lines
1.2 KiB
Python
Raw Normal View History

2023-01-27 12:36:41 +00:00
from pyrogram import filters, Client
from pyrogram.types import Message
from glover import admin
from misskey_init import get_misskey_bot, rerun_misskey_bot, misskey_bot_map
from models.models.user import TokenStatusEnum
from models.services.user import UserAction
2023-07-03 14:39:52 +00:00
@Client.on_message(filters.incoming & filters.private & filters.command(["status"]))
2023-01-27 12:36:41 +00:00
async def status_command(_: Client, message: Message):
"""
2023-07-03 14:39:52 +00:00
回应 status
2023-01-27 12:36:41 +00:00
"""
user = await UserAction.get_user_by_id(message.from_user.id)
if not user:
2023-01-27 13:15:40 +00:00
await message.reply("请先私聊发送 /start ,然后点击按钮绑定账号", quote=True)
2023-01-27 12:36:41 +00:00
return
if user.status == TokenStatusEnum.INVALID_TOKEN:
2023-01-27 13:15:40 +00:00
await message.reply("Token 无效,请私聊发送 /start ,然后点击按钮重新绑定", quote=True)
2023-01-27 12:36:41 +00:00
return
misskey = get_misskey_bot(user.user_id)
if not misskey and not await rerun_misskey_bot(user.user_id):
await message.reply("无法启动 Misskey Bot可能是未绑定群组。", quote=True)
return
text = "Bot 运行正常"
if user.user_id == admin:
text += f"\nBot 目前有 {len(misskey_bot_map.values())} 个 ws 任务"
await message.reply(text, quote=True)