2022-12-26 09:48:13 +00:00
|
|
|
from mipac.errors import NoSuchUserError, NoFollowRequestError
|
|
|
|
from pyrogram import Client, filters
|
|
|
|
from pyrogram.types import CallbackQuery
|
|
|
|
|
2023-01-27 12:36:41 +00:00
|
|
|
from misskey_init import get_misskey_bot
|
|
|
|
from models.filters import notice_filter
|
2022-12-26 09:48:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
# request_accept:user_id
|
2023-01-27 12:36:41 +00:00
|
|
|
@Client.on_callback_query(filters.regex(r"^request_accept:(\w+)$") & notice_filter)
|
2022-12-26 09:48:13 +00:00
|
|
|
async def request_accept_callback(_: Client, callback_query: CallbackQuery):
|
|
|
|
user_id = callback_query.matches[0].group(1)
|
|
|
|
try:
|
2023-01-27 12:36:41 +00:00
|
|
|
misskey_bot = get_misskey_bot(callback_query.from_user.id)
|
2022-12-26 09:48:13 +00:00
|
|
|
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
|
2023-01-27 12:36:41 +00:00
|
|
|
@Client.on_callback_query(filters.regex(r"^request_reject:(\w+)$") & notice_filter)
|
2022-12-26 09:48:13 +00:00
|
|
|
async def request_reject_callback(_: Client, callback_query: CallbackQuery):
|
|
|
|
user_id = callback_query.matches[0].group(1)
|
|
|
|
try:
|
2023-01-27 12:36:41 +00:00
|
|
|
misskey_bot = get_misskey_bot(callback_query.from_user.id)
|
2022-12-26 09:48:13 +00:00
|
|
|
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)
|