mirror of
https://github.com/Xtao-Labs/misskey2telegram.git
synced 2024-11-29 07:57:03 +00:00
47 lines
2.1 KiB
Python
47 lines
2.1 KiB
Python
from mipac.errors import NoSuchUserError, NoFollowRequestError
|
|
from pyrogram import Client, filters
|
|
from pyrogram.types import CallbackQuery
|
|
|
|
from misskey_init import get_misskey_bot
|
|
from models.filters import notice_filter
|
|
|
|
|
|
# request_accept:user_id
|
|
@Client.on_callback_query(filters.regex(r"^request_accept:(\w+)$") & notice_filter)
|
|
async def request_accept_callback(_: Client, callback_query: CallbackQuery):
|
|
user_id = callback_query.matches[0].group(1)
|
|
try:
|
|
misskey_bot = get_misskey_bot(callback_query.from_user.id)
|
|
await misskey_bot.core.api.follow_request.action.accept(
|
|
user_id=user_id,
|
|
)
|
|
await callback_query.answer("已接受关注请求", show_alert=True)
|
|
except NoSuchUserError:
|
|
await callback_query.answer("该用户不存在", show_alert=True)
|
|
except NoFollowRequestError:
|
|
await callback_query.answer("该用户没有向你发起关注请求", show_alert=True)
|
|
except Exception as e:
|
|
if callback_query.message:
|
|
await callback_query.message.reply(f"接受关注请求失败:{e}", quote=True)
|
|
await callback_query.answer("接受关注请求失败", show_alert=True)
|
|
|
|
|
|
# request_reject:user_id
|
|
@Client.on_callback_query(filters.regex(r"^request_reject:(\w+)$") & notice_filter)
|
|
async def request_reject_callback(_: Client, callback_query: CallbackQuery):
|
|
user_id = callback_query.matches[0].group(1)
|
|
try:
|
|
misskey_bot = get_misskey_bot(callback_query.from_user.id)
|
|
await misskey_bot.core.api.follow_request.action.reject(
|
|
user_id=user_id,
|
|
)
|
|
await callback_query.answer("已拒绝关注请求", show_alert=True)
|
|
except NoSuchUserError:
|
|
await callback_query.answer("该用户不存在", show_alert=True)
|
|
except NoFollowRequestError:
|
|
await callback_query.answer("该用户没有向你发起关注请求", show_alert=True)
|
|
except Exception as e:
|
|
if callback_query.message:
|
|
await callback_query.message.reply(f"拒绝关注请求失败:{e}", quote=True)
|
|
await callback_query.answer("拒绝关注请求失败", show_alert=True)
|