Skip to content

Commit

Permalink
完全支持QQ开放平台V2的全域机器人
Browse files Browse the repository at this point in the history
  • Loading branch information
lunzhiPenxil committed Nov 15, 2023
1 parent 103e9d3 commit 6307232
Show file tree
Hide file tree
Showing 11 changed files with 1,171 additions and 244 deletions.
34 changes: 27 additions & 7 deletions OlivOS/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def get_Event_from_SDK(self):
OlivOS.onebotSDK.get_Event_from_SDK(self)
elif self.sdk_event_type is OlivOS.qqGuildSDK.event:
OlivOS.qqGuildSDK.get_Event_from_SDK(self)
elif self.sdk_event_type is OlivOS.qqGuildv2SDK.event:
OlivOS.qqGuildv2SDK.get_Event_from_SDK(self)
elif self.sdk_event_type is OlivOS.discordSDK.event:
OlivOS.discordSDK.get_Event_from_SDK(self)
elif self.sdk_event_type is OlivOS.telegramSDK.event:
Expand Down Expand Up @@ -818,16 +820,34 @@ def __send(self, send_type, target_id, message, host_id=None, flag_log=True):
elif flag_type == 'group':
OlivOS.qqRedSDK.event_action.send_msg(self, 2, target_id, tmp_message, self.plugin_info['control_queue'])
elif self.platform['sdk'] == 'qqGuild_link':
if flag_type == 'group':
if 'reply_msg_id' in self.data.extend:
OlivOS.qqGuildSDK.event_action.send_msg(self, target_id, tmp_message, self.data.extend['reply_msg_id'])
else:
OlivOS.qqGuildSDK.event_action.send_msg(self, target_id, tmp_message)
elif flag_type == 'private':
if host_id is not None and not flag_log:
OlivOS.qqGuildSDK.event_action.send_msg(self, host_id, tmp_message, self.data.extend['reply_msg_id'], flag_direct=True)
elif 'flag_from_direct' in self.data.extend:
if self.data.extend['flag_from_direct']:
OlivOS.qqGuildSDK.event_action.send_msg(self, host_id, tmp_message, self.data.extend['reply_msg_id'], flag_direct=True)
else:
# 主动私聊待实现
pass
else:
# 主动私聊待实现
pass
elif self.platform['sdk'] == 'qqGuildv2_link':
if self.data.extend.get('flag_from_qq', False):
if flag_type == 'group':
if 'reply_msg_id' in self.data.extend:
OlivOS.qqGuildSDK.event_action.send_qq_msg(self, target_id, tmp_message, self.data.extend['reply_msg_id'])
OlivOS.qqGuildv2SDK.event_action.send_qq_msg(self, target_id, tmp_message, self.data.extend['reply_msg_id'])
else:
OlivOS.qqGuildSDK.event_action.send_qq_msg(self, target_id, tmp_message)
OlivOS.qqGuildv2SDK.event_action.send_qq_msg(self, target_id, tmp_message)
elif flag_type == 'private':
if 'flag_from_direct' in self.data.extend:
if self.data.extend['flag_from_direct']:
OlivOS.qqGuildSDK.event_action.send_qq_msg(self, target_id, tmp_message, self.data.extend['reply_msg_id'], flag_direct=True)
OlivOS.qqGuildv2SDK.event_action.send_qq_msg(self, target_id, tmp_message, self.data.extend['reply_msg_id'], flag_direct=True)
else:
# 主动私聊待实现
pass
Expand All @@ -837,15 +857,15 @@ def __send(self, send_type, target_id, message, host_id=None, flag_log=True):
else:
if flag_type == 'group':
if 'reply_msg_id' in self.data.extend:
OlivOS.qqGuildSDK.event_action.send_msg(self, target_id, tmp_message, self.data.extend['reply_msg_id'])
OlivOS.qqGuildv2SDK.event_action.send_msg(self, target_id, tmp_message, self.data.extend['reply_msg_id'])
else:
OlivOS.qqGuildSDK.event_action.send_msg(self, target_id, tmp_message)
OlivOS.qqGuildv2SDK.event_action.send_msg(self, target_id, tmp_message)
elif flag_type == 'private':
if host_id is not None and not flag_log:
OlivOS.qqGuildSDK.event_action.send_msg(self, host_id, tmp_message, self.data.extend['reply_msg_id'], flag_direct=True)
OlivOS.qqGuildv2SDK.event_action.send_msg(self, host_id, tmp_message, self.data.extend['reply_msg_id'], flag_direct=True)
elif 'flag_from_direct' in self.data.extend:
if self.data.extend['flag_from_direct']:
OlivOS.qqGuildSDK.event_action.send_msg(self, host_id, tmp_message, self.data.extend['reply_msg_id'], flag_direct=True)
OlivOS.qqGuildv2SDK.event_action.send_msg(self, host_id, tmp_message, self.data.extend['reply_msg_id'], flag_direct=True)
else:
# 主动私聊待实现
pass
Expand Down
2 changes: 2 additions & 0 deletions OlivOS/L10NDataAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
'bootAPI_0004': 'OlivOS model [{0}] type init',
'bootAPI_0005': 'OlivOS model [{0}] stopped',
'bootAPI_0006': 'OlivOS model [{0}] will stop',
'qqGuildv2SDK_0001': 'OlivOS qqGuildv2SDK bot [{0}] refresh TOKEN [{1}]',
},
'zh-CN': {
'diagnoseAPI_0001': '欢迎使用 青果核心交互栈 OlivOS {0}',
Expand Down Expand Up @@ -178,5 +179,6 @@
'bootAPI_0004': 'OlivOS 组件 [{0}] 类型 即将初始化',
'bootAPI_0005': 'OlivOS 组件 [{0}] 已被停止',
'bootAPI_0006': 'OlivOS 组件 [{0}] 即将停止',
'qqGuildv2SDK_0001': 'OlivOS QQ官方开放平台 [{0}] 刷新 TOKEN [{1}]',
}
}
2 changes: 2 additions & 0 deletions OlivOS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
from . import virtualTerminalLinkServerAPI
from . import qqGuildSDK
from . import qqGuildLinkServerAPI
from . import qqGuildv2SDK
from . import qqGuildv2LinkServerAPI
from . import qqRedSDK
from . import qqRedLinkServerAPI
from . import telegramSDK
Expand Down
22 changes: 22 additions & 0 deletions OlivOS/bootAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,28 @@ def start(self):
)
Proc_Proc_dict[tmp_Proc_name] = Proc_dict[tmp_Proc_name].start_unity(
tmp_proc_mode)
elif basic_conf_models_this['type'] == 'qqGuildv2_link':
flag_need_enable = False
for bot_info_key in plugin_bot_info_dict:
if plugin_bot_info_dict[bot_info_key].platform['sdk'] == 'qqGuildv2_link':
flag_need_enable = True
if not flag_need_enable:
continue
for bot_info_key in plugin_bot_info_dict:
if plugin_bot_info_dict[bot_info_key].platform['sdk'] == 'qqGuildv2_link':
tmp_Proc_name = basic_conf_models_this['name'] + '=' + bot_info_key
Proc_dict[tmp_Proc_name] = OlivOS.qqGuildv2LinkServerAPI.server(
Proc_name=tmp_Proc_name,
scan_interval=basic_conf_models_this['interval'],
dead_interval=basic_conf_models_this['dead_interval'],
rx_queue=None,
tx_queue=multiprocessing_dict[basic_conf_models_this['tx_queue']],
logger_proc=Proc_dict[basic_conf_models_this['logger_proc']],
bot_info_dict=plugin_bot_info_dict[bot_info_key],
debug_mode=False
)
Proc_Proc_dict[tmp_Proc_name] = Proc_dict[tmp_Proc_name].start_unity(
tmp_proc_mode)
elif basic_conf_models_this['type'] == 'discord_link':
flag_need_enable = False
for bot_info_key in plugin_bot_info_dict:
Expand Down
14 changes: 14 additions & 0 deletions OlivOS/bootDataAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"OlivOS_flask_post_rx",
"OlivOS_onebotV12_link",
"OlivOS_qqGuild_link",
"OlivOS_qqGuildv2_link",
"OlivOS_discord_link",
"OlivOS_telegram_poll",
"OlivOS_fanbook_poll",
Expand Down Expand Up @@ -80,6 +81,7 @@
"OlivOS_flask_post_rx",
"OlivOS_onebotV12_link",
"OlivOS_qqGuild_link",
"OlivOS_qqGuildv2_link",
"OlivOS_discord_link",
"OlivOS_telegram_poll",
"OlivOS_fanbook_poll",
Expand All @@ -100,6 +102,7 @@
"flask_post_rx",
"onebotV12_link",
"qqGuild_link",
"qqGuildv2_link",
"discord_link",
"telegram_poll",
"fanbook_poll",
Expand Down Expand Up @@ -290,6 +293,17 @@
"logger_proc": "OlivOS_logger",
"debug": False
},
"OlivOS_qqGuildv2_link": {
"enable": True,
"name": "OlivOS_qqGuildv2_link",
"type": "qqGuildv2_link",
"interval": 0.2,
"dead_interval": 1,
"rx_queue": None,
"tx_queue": "OlivOS_rx_queue",
"logger_proc": "OlivOS_logger",
"debug": False
},
"OlivOS_discord_link": {
"enable": True,
"name": "OlivOS_discord_link",
Expand Down
5 changes: 5 additions & 0 deletions OlivOS/messageAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
'default': 'olivos_para',
'private': 'olivos_para',
'public': 'olivos_para'
},
'qqGuildv2_link': {
'default': 'olivos_para',
'private': 'olivos_para',
'public': 'olivos_para'
}
},
'telegram': {
Expand Down
34 changes: 27 additions & 7 deletions OlivOS/multiLoginUIAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,10 @@ def __init__(self, action, Account_data, hash_key=None, edit_commit_callback=Non
'钉钉',
'渡渡语音/Dodo/V2',
'渡渡语音/Dodo/V1',
'QQ官方/公域',
'QQ官方/私域',
'QQ官方/公域/V2',
'QQ官方/私域/V2',
'QQ官方/公域/V1',
'QQ官方/私域/V1',
'Discord',
'Telegram',
'Fanbook',
Expand Down Expand Up @@ -575,16 +577,26 @@ def __init__(self, action, Account_data, hash_key=None, edit_commit_callback=Non
'直播间ID': 'edit_root_Entry_Server_access_token'
}
],
'QQ官方/公域': ['qqGuild', 'qqGuild_link', 'public', 'True', 'websocket', {
'BotAppID': 'edit_root_Entry_ID',
'QQ官方/公域/V1': ['qqGuild', 'qqGuild_link', 'public', 'True', 'websocket', {
'AppID': 'edit_root_Entry_ID',
'机器人令牌': 'edit_root_Entry_Server_access_token'
}
],
'QQ官方/私域': ['qqGuild', 'qqGuild_link', 'private', 'True', 'websocket', {
'BotAppID': 'edit_root_Entry_ID',
'QQ官方/私域/V1': ['qqGuild', 'qqGuild_link', 'private', 'True', 'websocket', {
'AppID': 'edit_root_Entry_ID',
'机器人令牌': 'edit_root_Entry_Server_access_token'
}
],
'QQ官方/公域/V2': ['qqGuild', 'qqGuildv2_link', 'public', 'True', 'websocket', {
'AppID': 'edit_root_Entry_ID',
'AppSecret': 'edit_root_Entry_Server_access_token'
}
],
'QQ官方/私域/V2': ['qqGuild', 'qqGuildv2_link', 'private', 'True', 'websocket', {
'AppID': 'edit_root_Entry_ID',
'AppSecret': 'edit_root_Entry_Server_access_token'
}
],
'Telegram': ['telegram', 'telegram_poll', 'default', 'True', 'post', {
'TOKEN': 'edit_root_Entry_Server_access_token'
}
Expand Down Expand Up @@ -670,7 +682,8 @@ def __init__(self, action, Account_data, hash_key=None, edit_commit_callback=Non
'onebot'
],
'qqGuild': [
'qqGuild_link'
'qqGuild_link',
'qqGuildv2_link'
],
'kaiheila': [
'kaiheila_link'
Expand Down Expand Up @@ -741,6 +754,13 @@ def __init__(self, action, Account_data, hash_key=None, edit_commit_callback=Non
'default'
]
},
'qqGuild': {
'qqGuildv2_link': [
'private',
'public',
'default'
]
},
'kaiheila': {
'kaiheila_link': [
'default',
Expand Down
6 changes: 1 addition & 5 deletions OlivOS/qqGuildLinkServerAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def run(self):

def on_message(self, ws, message):
try:
#print(message)
tmp_data_rx_obj = OlivOS.qqGuildSDK.PAYLOAD.rxPacket(
data=json.loads(message)
)
Expand All @@ -80,10 +79,7 @@ def on_message(self, ws, message):
if tmp_data_rx_obj.data.t in [
'MESSAGE_CREATE',
'DIRECT_MESSAGE_CREATE',
'AT_MESSAGE_CREATE',
'GROUP_AT_MESSAGE_CREATE',
'GROUP_MESSAGE_CREATE',
'C2C_MESSAGE_CREATE'
'AT_MESSAGE_CREATE'
]:
sdk_event = OlivOS.qqGuildSDK.event(tmp_data_rx_obj, self.Proc_data['bot_info_dict'])
tx_packet_data = OlivOS.pluginAPI.shallow.rx_packet(sdk_event)
Expand Down
Loading

0 comments on commit 6307232

Please sign in to comment.