上传文件至 core/SNAPI
This commit is contained in:
199
core/SNAPI/Chat.py
Normal file
199
core/SNAPI/Chat.py
Normal file
@@ -0,0 +1,199 @@
|
||||
from ProjectCfg import DOMAIN
|
||||
from CallServer import _make_request
|
||||
from typing import List,Any,Optional,Dict
|
||||
|
||||
###=========================聊天API=================================
|
||||
def ChatSummary(Authorization: str) -> dict:
|
||||
"""获取聊天摘要"""
|
||||
url = f"{DOMAIN}/chat/summary"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('GET', url, headers)
|
||||
|
||||
def GetChatMessages(Authorization: str, room_id: str, offset: int = 0, take: int = 20) -> dict:
|
||||
"""获取聊天消息"""
|
||||
url = f"{DOMAIN}/chat/{room_id}/messages"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
params = {"offset": offset, "take": take}
|
||||
return _make_request('GET', url, headers, params=params)
|
||||
|
||||
def PostChatMessage(Authorization: str, room_id: str, content: str, nonce: Optional[str] = None, attachments_id: Optional[List[str]] = None, meta: Optional[Dict[str, Any]] = None, replied_message_id: Optional[str] = None, forwarded_message_id: Optional[str] = None) -> dict:
|
||||
"""发送聊天消息"""
|
||||
body = {
|
||||
"content": content,
|
||||
"nonce": nonce,
|
||||
"attachments_id": attachments_id,
|
||||
"meta": meta,
|
||||
"replied_message_id": replied_message_id,
|
||||
"forwarded_message_id": forwarded_message_id,
|
||||
}
|
||||
url = f"{DOMAIN}/chat/{room_id}/messages"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('POST', url, headers, request_body=body, normal_codes=[201])
|
||||
|
||||
def GetChatMessageById(Authorization: str, room_id: str, message_id: str) -> dict:
|
||||
"""获取具体聊天消息所有信息"""
|
||||
url = f"{DOMAIN}/chat/{room_id}/messages/{message_id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('GET', url, headers)
|
||||
|
||||
def PatchChatMessage(Authorization: str, room_id: str, message_id: str, content: Optional[str] = None, nonce: Optional[str] = None, attachments_id: Optional[List[str]] = None, meta: Optional[Dict[str, Any]] = None, replied_message_id: Optional[str] = None, forwarded_message_id: Optional[str] = None) -> dict:
|
||||
"""修改聊天消息"""
|
||||
body = {
|
||||
"content": content,
|
||||
"nonce": nonce,
|
||||
"attachments_id": attachments_id,
|
||||
"meta": meta,
|
||||
"replied_message_id": replied_message_id,
|
||||
"forwarded_message_id": forwarded_message_id,
|
||||
}
|
||||
url = f"{DOMAIN}/chat/{room_id}/messages/{message_id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('PATCH', url, headers, request_body=body)
|
||||
|
||||
def DeleteChatMessage(Authorization: str, room_id: str, message_id: str) -> dict:
|
||||
"""删除聊天消息"""
|
||||
url = f"{DOMAIN}/chat/{room_id}/messages/{message_id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('DELETE', url, headers, normal_codes=[204])
|
||||
|
||||
def PostChatSync(Authorization: str, room_id: str, last_sync_timestamp: int) -> dict:
|
||||
"""同步聊天消息"""
|
||||
body = {"last_sync_timestamp": last_sync_timestamp}
|
||||
url = f"{DOMAIN}/chat/{room_id}/sync"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('POST', url, headers, request_body=body)
|
||||
|
||||
###=========================聊天室API=================================
|
||||
def GetChatRoom(Authorization: str, id: str) -> dict:
|
||||
"""获取聊天房间信息"""
|
||||
url = f"{DOMAIN}/chat/{id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('GET', url, headers)
|
||||
|
||||
def PatchChatRoom(Authorization: str, id: str, name: Optional[str] = None, description: Optional[str] = None, picture_id: Optional[str] = None, background_id: Optional[str] = None, realm_id: Optional[str] = None, is_community: Optional[bool] = None, is_public: Optional[bool] = None) -> dict:
|
||||
"""修改聊天房间信息"""
|
||||
body = {
|
||||
"name": name,
|
||||
"description": description,
|
||||
"picture_id": picture_id,
|
||||
"background_id": background_id,
|
||||
"realm_id": realm_id,
|
||||
"is_community": is_community,
|
||||
"is_public": is_public,
|
||||
}
|
||||
url = f"{DOMAIN}/chat/{id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('PATCH', url, headers, request_body=body)
|
||||
|
||||
def DeleteChatRoom(Authorization: str, id: str) -> dict:
|
||||
"""删除聊天房间"""
|
||||
url = f"{DOMAIN}/chat/{id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('DELETE', url, headers, normal_codes=[204])
|
||||
|
||||
def GetChatRooms(Authorization: str) -> dict:
|
||||
"""获取聊天列表"""
|
||||
url = f"{DOMAIN}/chat"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('GET', url, headers)
|
||||
|
||||
def PostChatRoom(Authorization: str, name: str, description: Optional[str] = None, picture_id: Optional[str] = None, background_id: Optional[str] = None, realm_id: Optional[str] = None, is_community: Optional[bool] = None, is_public: Optional[bool] = None) -> dict:
|
||||
"""创建聊天房间"""
|
||||
body = {
|
||||
"name": name,
|
||||
"description": description,
|
||||
"picture_id": picture_id,
|
||||
"background_id": background_id,
|
||||
"realm_id": realm_id,
|
||||
"is_community": is_community,
|
||||
"is_public": is_public,
|
||||
}
|
||||
url = f"{DOMAIN}/chat"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('POST', url, headers, request_body=body, normal_codes=[201])
|
||||
|
||||
def GetDirectChat(Authorization: str, account_id: str) -> dict:
|
||||
"""获取聊天对象用户信息"""
|
||||
url = f"{DOMAIN}/chat/direct/{account_id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('GET', url, headers)
|
||||
|
||||
def GetChatRoomSelfInfo(Authorization: str, room_id: str) -> dict:
|
||||
"""获取聊天房间自己信息"""
|
||||
url = f"{DOMAIN}/chat/{room_id}/members/me"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('GET', url, headers)
|
||||
|
||||
def JoinChatRoom(Authorization: str, room_id: str) -> dict:
|
||||
"""加入聊天房间"""
|
||||
url = f"{DOMAIN}/chat/{room_id}/members/me"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('POST', url, headers, normal_codes=[201])
|
||||
|
||||
def LeaveChatRoom(Authorization: str, room_id: str) -> dict:
|
||||
"""退出聊天房间"""
|
||||
url = f"{DOMAIN}/chat/{room_id}/members/me"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('DELETE', url, headers, normal_codes=[204])
|
||||
|
||||
def GetChatRoomMembers(Authorization: str, room_id: str, offset: int = 0, take: int = 20, with_status: bool = False) -> dict:
|
||||
"""获取聊天房间成员"""
|
||||
params = {
|
||||
"offset": offset,
|
||||
"take": take,
|
||||
"withStatus": with_status,
|
||||
}
|
||||
url = f"{DOMAIN}/chat/{room_id}/members"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('GET', url, headers, params=params)
|
||||
|
||||
def PostChatMemberInvite(Authorization: str, room_id: str, related_user_id: str, role: int) -> dict:
|
||||
"""发送聊天邀请"""
|
||||
body = {
|
||||
"related_user_id": related_user_id,
|
||||
"role": role,
|
||||
}
|
||||
url = f"{DOMAIN}/chat/invites/{room_id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('POST', url, headers, request_body=body, normal_codes=[201])
|
||||
|
||||
def GetChatInvites(Authorization: str) -> dict:
|
||||
"""获取聊天邀请"""
|
||||
url = f"{DOMAIN}/chat/invites"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('GET', url, headers)
|
||||
|
||||
def AcceptChatInvite(Authorization: str, room_id: str) -> dict:
|
||||
"""接受聊天邀请"""
|
||||
url = f"{DOMAIN}/chat/invites/{room_id}/accept"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('POST', url, headers)
|
||||
|
||||
def DeclineChatInvite(Authorization: str, room_id: str) -> dict:
|
||||
"""拒绝聊天邀请"""
|
||||
url = f"{DOMAIN}/chat/invites/{room_id}/decline"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('POST', url, headers)
|
||||
|
||||
def SetChatNotify(Authorization: str, room_id: str, notify_level: int, break_until: Optional[str] = None) -> dict:
|
||||
"""设置聊天通知级别"""
|
||||
body = {
|
||||
"notify_level": notify_level,
|
||||
"break_until": break_until,
|
||||
}
|
||||
url = f"{DOMAIN}/chat/{room_id}/members/me/notify"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('PATCH', url, headers, request_body=body, normal_codes=[201])
|
||||
|
||||
def SetChatMemberRole(Authorization: str, room_id: str, member_id: str, role: int) -> dict:
|
||||
"""设置聊天成员角色"""
|
||||
body = {"role": role}
|
||||
url = f"{DOMAIN}/chat/{room_id}/members/{member_id}/role"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('PATCH', url, headers, request_body=body, normal_codes=[201])
|
||||
|
||||
def KickChatMember(Authorization: str, room_id: str, member_id: str) -> dict:
|
||||
"""踢出聊天成员"""
|
||||
url = f"{DOMAIN}/chat/{room_id}/members/{member_id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('DELETE', url, headers, normal_codes=[204])
|
Reference in New Issue
Block a user