misskey2telegram/modules/start.py

63 lines
2.3 KiB
Python
Raw Normal View History

2022-12-22 14:18:43 +00:00
from pyrogram import Client, filters
2023-01-27 12:36:41 +00:00
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
2022-12-22 14:18:43 +00:00
2023-01-27 12:36:41 +00:00
from glover import misskey_host, web_domain, misskey_domain
from init import bot
from misskey_init import test_token, rerun_misskey_bot
from models.services.user import UserAction
2022-12-22 14:18:43 +00:00
2023-01-27 13:15:40 +00:00
des = f"""欢迎使用 {bot.me.first_name},这是一个用于在 Telegram 上使用 Misskey 的机器人。按下方教程开始使用:
2023-01-27 12:36:41 +00:00
2023-01-27 13:15:40 +00:00
1. 点击下方按钮绑定 Misskey 账号
2023-01-27 12:36:41 +00:00
2. 在论坛群组中使用 /bind_timeline 绑定 Timeline 话题接收时间线更新
3. 在论坛群组中使用 /bind_notice 绑定 Notice 话题接收通知
2023-01-27 13:15:40 +00:00
至此你便可以在 Telegram 接收 Misskey 消息同时你可以私聊我使用 /status 查看 Bot 运行状态
2023-01-27 12:36:41 +00:00
2023-01-27 13:15:40 +00:00
Bot 仅支持绑定 {misskey_host} Misskey 账号"""
2023-01-27 12:36:41 +00:00
async def finish_check(message: Message):
if await rerun_misskey_bot(message.from_user.id):
await message.reply("Token 设置完成,开始链接。", quote=True)
else:
await message.reply("Token 设置完成,请绑定群组。", quote=True)
def gen_url():
return f"https://{web_domain}/gen?host={misskey_domain}&back_host={web_domain}&username={bot.me.username}"
2022-12-22 14:18:43 +00:00
2023-07-03 14:39:52 +00:00
@Client.on_message(filters.incoming & filters.private & filters.command(["start"]))
2022-12-22 14:18:43 +00:00
async def start_command(_: Client, message: Message):
"""
2023-07-03 14:39:52 +00:00
回应 start
2022-12-22 14:18:43 +00:00
"""
2023-01-27 12:36:41 +00:00
if len(message.command) == 2:
token = message.command[1]
if not token:
await message.reply(des, quote=True)
return
if await test_token(token):
await UserAction.change_user_token(message.from_user.id, token)
2023-01-27 13:15:40 +00:00
await message.reply(
2023-07-03 14:39:52 +00:00
"Token 验证成功,绑定账号完成。\n" "当你撤销此登录时,你可以重新点击按钮授权。", quote=True
2023-01-27 13:15:40 +00:00
)
2023-01-27 12:36:41 +00:00
await finish_check(message)
else:
await message.reply("Token 验证失败,请检查 Token 是否正确", quote=True)
return
await message.reply(
des,
quote=True,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(text="绑定 Misskey 账号", url=gen_url()),
]
]
2023-07-03 14:39:52 +00:00
),
2023-01-27 12:36:41 +00:00
)