Skip to content

Commit

Permalink
优化接口
Browse files Browse the repository at this point in the history
closed #108
  • Loading branch information
lunzhiPenxil committed Dec 18, 2023
1 parent b90a47e commit e321101
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 7 deletions.
112 changes: 111 additions & 1 deletion OlivOS/adapter/OPQBot/OPQBotSDK.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

gResReg = {}

gUinfoReg = {}

class bot_info_T(object):
def __init__(self, id=-1):
self.id = id
Expand Down Expand Up @@ -186,6 +188,54 @@ def get_Event_from_SDK(target_event):
target_event.data.sender['age'] = 0
target_event.data.sender['role'] = 'member'
target_event.data.host_id = None
elif False and target_event.sdk_event.payload.EventName == 'ON_EVENT_FRIEND_NEW_MSG':
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 '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 = event_action.getUinfo(
target_event = target_event,
Uid = target_event.sdk_event.payload.EventData['ReqUid'],
control_queue = OlivOS.pluginAPI.gProc.Proc_info.control_queue
)
target_event.data = target_event.friend_add_request(
str(uin),
target_event.sdk_event.payload.EventData['MsgAdditional']
)
target_event.data.flag = str(target_event.sdk_event.payload.EventData['ReqUid'])
elif False and target_event.sdk_event.payload.EventName == 'ON_EVENT_GROUP_SYSTEM_MSG_NOTIFY':
if type(target_event.sdk_event.payload.EventData) is dict \
and 'GroupCode' in target_event.sdk_event.payload.EventData \
and type(target_event.sdk_event.payload.EventData['GroupCode']) is int \
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 type(target_event.sdk_event.payload.EventData['Status']) is int \
and target_event.sdk_event.payload.EventData['Status'] in [1, 2] \
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 = event_action.getUinfo(
target_event = target_event,
Uid = target_event.sdk_event.payload.EventData['ReqUid'],
control_queue = OlivOS.pluginAPI.gProc.Proc_info.control_queue
)
target_event.data = target_event.group_add_request(
str(target_event.sdk_event.payload.EventData['GroupCode']),
str(uin),
target_event.sdk_event.payload.EventData['MsgAdditional']
)
target_event.data.flag = str(target_event.sdk_event.payload.EventData['ReqUid'])


'''
Expand Down Expand Up @@ -363,9 +413,69 @@ def __init__(
if Base64Buf is not None:
self.data['CgiRequest']['Base64Buf'] = Base64Buf

class QueryUinByUid(payload_template):
def __init__(self, UidQuery:'list[str]', CurrentQQ:'int|str'):
payload_template.__init__(self)
self.CgiCmd = "QueryUinByUid"
self.CurrentQQ = str(CurrentQQ)
self.data = {
"ReqId": self.ReqId,
"BotUin": str(self.CurrentQQ),
"CgiCmd": self.CgiCmd,
"CgiRequest": {
'Uids': UidQuery
}
}


# 支持OlivOS API调用的方法实现
class event_action(object):
def getUinfo(target_event, Uid, control_queue):
global gUinfoReg
res = Uid
if Uid in gUinfoReg:
res = gUinfoReg[Uid]
else:
res_list = event_action.getUinfoCache(
target_event = target_event,
UidQuery = [Uid],
control_queue = control_queue
)
if len(res_list) == 1:
res = res_list[0]
return res

def getUinfoCache(target_event, UidQuery, control_queue):
global gUinfoReg
res_tmp = {}
res = []
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']
)
this_msg = PAYLOAD.QueryUinByUid(
UidQuery = UidQuery,
CurrentQQ = target_event.base_info['self_id']
)
waitForResReady(str(this_msg.ReqId))
send_ws_event(
plugin_event_bot_hash,
this_msg.dump(),
control_queue
)
res_raw = waitForRes(str(this_msg.ReqId))
raw_obj = init_api_json(res_raw)
if raw_obj is not None:
if type(raw_obj) is list:
for raw_obj_this in raw_obj:
res_tmp[str(raw_obj_this['Uid'])] = raw_obj_this['Uin']
gUinfoReg.update(res_tmp)
for UidQuery_this in UidQuery:
res.append(res_tmp.get(UidQuery_this, None))
return res

def send_solo_msg(target_event, target_type, target_id, message, control_queue):
plugin_event_bot_hash = OlivOS.API.getBotHash(
bot_id=target_event.base_info['self_id'],
Expand Down Expand Up @@ -619,7 +729,7 @@ def init_api_json(raw:dict):
and 'ReqId' in raw \
and type(raw['ReqId']) is int \
and 'ResponseData' in raw \
and type(raw['ResponseData']) is dict:
and type(raw['ResponseData']) in [dict, list]:
res_data = copy.deepcopy(raw['ResponseData'])
return res_data

Expand Down
13 changes: 8 additions & 5 deletions OlivOS/nativeGUI/multiLoginUIAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,6 @@ def __init__(self, action, Account_data, hash_key=None, edit_commit_callback=Non
'type_list': [
'KOOK',
'KOOK/消息兼容',
'QQ/OPQ/默认',
'QQ/OPQ/指定端口',
'钉钉',
'渡渡语音/Dodo/V2',
'渡渡语音/Dodo/V1',
Expand All @@ -387,6 +385,8 @@ def __init__(self, action, Account_data, hash_key=None, edit_commit_callback=Non
'FF14终端',
'虚拟终端',
'接口终端',
'QQ/OPQ/默认',
'QQ/OPQ/指定端口',
'QQ/GoCq/安卓手表',
'QQ/GoCq/安卓手机',
'QQ/GoCq/安卓平板',
Expand All @@ -411,7 +411,10 @@ def __init__(self, action, Account_data, hash_key=None, edit_commit_callback=Non
'QQ/Wq/旧': '密码留空即尝试使用扫码登录',
'微信/ComWeChat': '启动后需要再运行特定版本微信',
'Hack.Chat': '密码可以留空',
'RED协议': 'HTTP可以不填,反正也没实现'
'RED协议': 'HTTP可以不填,反正也没实现',
'QQ/OPQ/默认': '简单对接OPQ,使用闭源框架有账号安全风险,OlivOS不对此负责',
'QQ/OPQ/指定端口': '简单对接OPQ,使用闭源框架有账号安全风险,OlivOS不对此负责',
'QQ/OPQ/指定端口/旧': '简单对接OPQ,使用闭源框架有账号安全风险,OlivOS不对此负责'
},
'type_clear_note_list': {
'QQ/GoCq/默认': './conf/gocqhttp/{bothash}',
Expand Down Expand Up @@ -1537,9 +1540,9 @@ def tree_edit_UI_Combobox_update(self, action, con_action):
self.tree_edit_UI_Label_init(
obj_root='edit_root',
obj_name='edit_root_Label_type_note',
x=100,
x=15,
y=40 + count * (24 + 6),
width=200,
width=400 - 15 * 2,
height=24,
title=self.UIData['edit_root_Combobox_dict']['type_note_list'][tmp_type]
)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
[![OnebotV11](https://img.shields.io/badge/-OnebotV11-111111?style=flat-square&logoColor=white)](https://github.com/botuniverse/onebot)
[![OnebotV12](https://img.shields.io/badge/-OnebotV12-111111?style=flat-square&logoColor=white)](https://github.com/botuniverse/onebot)
[![RED](https://img.shields.io/badge/-RED-111111?style=flat-square&logoColor=white)](https://chrononeko.github.io/QQNTRedProtocol/)
[![OPQBot](https://img.shields.io/badge/-OPQBot-111111?style=flat-square&logoColor=white)](https://opqbot.com/)
[![QQ全域](https://img.shields.io/badge/-QQ%E5%85%A8%E5%9F%9F-EB1923?style=flat-square&logo=Tencent%20QQ&logoColor=white)](https://bot.q.qq.com/wiki/)
[![QQ频道](https://img.shields.io/badge/-QQ%E9%A2%91%E9%81%93-EB1923?style=flat-square&logo=Tencent%20QQ&logoColor=white)](https://bot.q.qq.com/wiki/)
[![DingTalk](https://img.shields.io/badge/-%E9%92%89%E9%92%89-007FFF?style=flat-square&logo=alibabadotcom&logoColor=white)](https://open.dingtalk.com/)
Expand Down

0 comments on commit e321101

Please sign in to comment.