Files
NeoBot/core/api/friend.py
2026-01-02 14:22:35 +08:00

54 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
好友相关 API 模块
"""
from typing import List, Dict, Any
from .base import BaseAPI
from models.objects import FriendInfo, StrangerInfo
class FriendAPI(BaseAPI):
"""
好友相关 API Mixin
"""
async def send_like(self, user_id: int, times: int = 1) -> Dict[str, Any]:
"""
发送点赞
:param user_id: 对方 QQ 号
:param times: 点赞次数
:return: API 响应结果
"""
return await self.call_api("send_like", {"user_id": user_id, "times": times})
async def get_stranger_info(self, user_id: int, no_cache: bool = False) -> StrangerInfo:
"""
获取陌生人信息
:param user_id: QQ 号
:param no_cache: 是否不使用缓存
:return: 陌生人信息对象
"""
res = await self.call_api("get_stranger_info", {"user_id": user_id, "no_cache": no_cache})
return StrangerInfo(**res)
async def get_friend_list(self) -> List[FriendInfo]:
"""
获取好友列表
:return: 好友信息对象列表
"""
res = await self.call_api("get_friend_list")
return [FriendInfo(**item) for item in res]
async def set_friend_add_request(self, flag: str, approve: bool = True, remark: str = "") -> Dict[str, Any]:
"""
处理加好友请求
:param flag: 加好友请求的 flag需从上报的数据中获取
:param approve: 是否同意请求
:param remark: 添加后的好友备注(仅在同意时有效)
:return: API 响应结果
"""
return await self.call_api("set_friend_add_request", {"flag": flag, "approve": approve, "remark": remark})