Skip to content

Commit

Permalink
OPQ:修复好友请求相关接口适配
Browse files Browse the repository at this point in the history
  • Loading branch information
lunzhiPenxil committed May 15, 2024
1 parent 331d01e commit 349e44e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
73 changes: 68 additions & 5 deletions OlivOS/adapter/OPQBot/OPQBotSDK.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

gMsgSeqToGroupCodeReg = {}

gFriendReqTsReg = {}

class bot_info_T(object):
def __init__(self, id=-1):
self.id = id
Expand Down Expand Up @@ -74,7 +76,7 @@ def get_message(Content:str, AtUinLists:list):
return res_msg

def get_Event_from_SDK(target_event):
global sdkSubSelfInfo
global gFriendReqTsReg
target_event.base_info['time'] = target_event.sdk_event.base_info['time']
target_event.base_info['self_id'] = str(target_event.sdk_event.base_info['self_id'])
target_event.base_info['type'] = target_event.sdk_event.base_info['post_type']
Expand Down Expand Up @@ -156,6 +158,31 @@ def get_Event_from_SDK(target_event):
if type(target_event.sdk_event.payload.EventData) is dict \
and 'MsgHead' in target_event.sdk_event.payload.EventData \
and type(target_event.sdk_event.payload.EventData['MsgHead']) is dict \
and 'MsgType' in target_event.sdk_event.payload.EventData['MsgHead'] \
and target_event.sdk_event.payload.EventData['MsgHead']['MsgType'] == 528 \
and 'C2cCmd' in target_event.sdk_event.payload.EventData['MsgHead'] \
and target_event.sdk_event.payload.EventData['MsgHead']['C2cCmd'] == 35 \
and 'ToUin' in target_event.sdk_event.payload.EventData['MsgHead'] \
and type(target_event.sdk_event.payload.EventData['MsgHead']['ToUin']) is int \
and 'FromUin' in target_event.sdk_event.payload.EventData['MsgHead'] \
and type(target_event.sdk_event.payload.EventData['MsgHead']['FromUin']) is int \
and 'FromUid' in target_event.sdk_event.payload.EventData['MsgHead'] \
and type(target_event.sdk_event.payload.EventData['MsgHead']['FromUid']) is str:
tmp_ToUin = str(target_event.sdk_event.payload.EventData['MsgHead']['ToUin'])
tmp_FromUin = str(target_event.sdk_event.payload.EventData['MsgHead']['FromUin'])
if tmp_ToUin != tmp_FromUin:
if int(time.time()) - gFriendReqTsReg.get(tmp_FromUin, -1) >= 5:
gFriendReqTsReg[tmp_FromUin] = int(time.time())
target_event.active = True
target_event.plugin_info['func_type'] = 'friend_add_request'
target_event.data = target_event.friend_add_request(
tmp_FromUin,
''
)
target_event.data.flag = str(target_event.sdk_event.payload.EventData['MsgHead']['FromUid'])
elif type(target_event.sdk_event.payload.EventData) is dict \
and 'MsgHead' in target_event.sdk_event.payload.EventData \
and type(target_event.sdk_event.payload.EventData['MsgHead']) is dict \
and 'FromUin' in target_event.sdk_event.payload.EventData['MsgHead'] \
and type(target_event.sdk_event.payload.EventData['MsgHead']['FromUin']) is int \
and 'ToUin' in target_event.sdk_event.payload.EventData['MsgHead'] \
Expand Down Expand Up @@ -210,23 +237,25 @@ def get_Event_from_SDK(target_event):
str(target_event.sdk_event.payload.EventData['Event']['Invitee'])
)
target_event.data.action = 'approve'
elif False and target_event.sdk_event.payload.EventName == 'ON_EVENT_FRIEND_NEW_MSG':
elif False and target_event.sdk_event.payload.EventName == 'ON_EVENT_FRIEND_SYSTEM_MSG_NOTIFY':
if type(target_event.sdk_event.payload.EventData) is dict \
and 'ReqUid' in target_event.sdk_event.payload.EventData \
and type(target_event.sdk_event.payload.EventData['ReqUid']) is str \
and 'Status' in target_event.sdk_event.payload.EventData \
and target_event.sdk_event.payload.EventData['Status'] == 7 \
and type(target_event.sdk_event.payload.EventData['Status']) is int \
and 'MsgAdditional' in target_event.sdk_event.payload.EventData \
and type(target_event.sdk_event.payload.EventData['MsgAdditional']) is str:
target_event.active = True
target_event.plugin_info['func_type'] = 'friend_add_request'
uin = str(target_event.sdk_event.payload.EventData['ReqUid'])
if OlivOS.pluginAPI.gProc is not None:
uin = None
if False and OlivOS.pluginAPI.gProc is not None:
uin = event_action.getUinfo(
target_event = target_event,
Uid = target_event.sdk_event.payload.EventData['ReqUid'],
control_queue = OlivOS.pluginAPI.gProc.Proc_info.control_queue
)
if uin is None:
uin = -1
target_event.data = target_event.friend_add_request(
str(uin),
target_event.sdk_event.payload.EventData['MsgAdditional']
Expand Down Expand Up @@ -457,6 +486,21 @@ def __init__(self, UidQuery:'list[str]', CurrentQQ:'int|str'):
}
}

class SystemMsgAction_Friend(payload_template):
def __init__(self, ReqUid:int, OpCode:int, CurrentQQ:'int|str'):
payload_template.__init__(self)
self.CgiCmd = "SystemMsgAction.Friend"
self.CurrentQQ = str(CurrentQQ)
self.data = {
"ReqId": self.ReqId,
"BotUin": str(self.CurrentQQ),
"CgiCmd": self.CgiCmd,
"CgiRequest": {
"ReqUid": ReqUid,
"OpCode": OpCode
}
}

class SystemMsgAction_Group(payload_template):
def __init__(self, MsgSeq:int, MsgType:int, GroupCode:int, OpCode:int, CurrentQQ:'int|str'):
payload_template.__init__(self)
Expand Down Expand Up @@ -704,6 +748,25 @@ def set_group_leave(target_event, group_id, control_queue):
control_queue
)

def set_friend_add_request(target_event, flag:str, approve:bool, control_queue):
if target_event.bot_info != None:
plugin_event_bot_hash = OlivOS.API.getBotHash(
bot_id=target_event.base_info['self_id'],
platform_sdk=target_event.platform['sdk'],
platform_platform=target_event.platform['platform'],
platform_model=target_event.platform['model']
)
OpCode_int = 3 if approve is True else 5
send_ws_event(
plugin_event_bot_hash,
PAYLOAD.SystemMsgAction_Friend(
ReqUid = flag,
OpCode = OpCode_int,
CurrentQQ = target_event.base_info['self_id']
).dump(),
control_queue
)

def set_group_add_request(target_event, flag:str, sub_type:str, approve:bool, control_queue):
if target_event.bot_info != None:
plugin_event_bot_hash = OlivOS.API.getBotHash(
Expand Down
2 changes: 2 additions & 0 deletions OlivOS/core/core/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,8 @@ def __set_friend_add_request(self, flag, approve, remark, flag_log=True):
OlivOS.onebotV12SDK.event_action.set_friend_add_request(self, flag, approve, remark)
elif self.platform['model'] in OlivOS.flaskServerAPI.gCheckList:
OlivOS.onebotSDK.event_action.set_friend_add_request(self, flag, approve, remark)
elif self.platform['model'] in OlivOS.OPQBotLinkServerAPI.gCheckList:
OlivOS.OPQBotSDK.event_action.set_friend_add_request(self, flag, approve, self.plugin_info['control_queue'])
elif self.platform['sdk'] == 'telegram_poll':
pass

Expand Down

0 comments on commit 349e44e

Please sign in to comment.