Skip to content

Commit

Permalink
KOOK支持切换消息发送模式为普通消息模式
Browse files Browse the repository at this point in the history
  • Loading branch information
lunzhiPenxil committed Oct 26, 2023
1 parent 8ceb3fa commit 7f26fe0
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 65 deletions.
132 changes: 81 additions & 51 deletions OlivOS/kaiheilaSDK.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,67 +569,97 @@ def get_Event_from_SDK(target_event):

# 支持OlivOS API调用的方法实现
class event_action(object):
def send_msg(target_event, chat_id, message, flag_direct=False):
def send_msg(target_event, chat_id, message, flag_direct=False, message_type='text'):
if message_type not in ['text', 'card']:
message_type = 'card'
this_msg = None
res_data = {
"type": "card",
"theme": "secondary",
"size": "lg",
"modules": []
}
if message_type == 'text':
res_data = ''
elif message_type == 'card':
res_data = {
"type": "card",
"theme": "secondary",
"size": "lg",
"modules": []
}
if flag_direct:
this_msg = API.creatDirectMessage(get_SDK_bot_info_from_Event(target_event))
else:
this_msg = API.creatMessage(get_SDK_bot_info_from_Event(target_event))
this_msg.data.target_id = str(chat_id)
if this_msg is None:
return
msg_type_last = 'text'
for message_this in message.data:
if type(message_this) == OlivOS.messageAPI.PARA.text:
res_data['modules'].append(
{
"type": "section",
"text": {
"type": "plain-text",
"content": message_this.data['text']
}
}
)
elif type(message_this) == OlivOS.messageAPI.PARA.image:
image_path = event_action.setResourceUploadFast(target_event, message_this.data['file'], 'images')
res_data['modules'].append(
{
"type": "image-group",
"elements": [
{
"type": "image",
"src": image_path
if message_type == 'text':
if type(message_this) == OlivOS.messageAPI.PARA.text:
if msg_type_last != 'text':
res_data = ''
res_data += message_this.data['text']
msg_type_last = 'text'
elif type(message_this) == OlivOS.messageAPI.PARA.image:
if msg_type_last == 'text':
if len(res_data) > 0:
this_msg.data.type = 9
this_msg.data.content = res_data
this_msg.do_api()
image_path = event_action.setResourceUploadFast(target_event, message_this.data['file'], 'images')
this_msg.data.type = 2
this_msg.data.content = image_path
this_msg.do_api()
msg_type_last = 'media'
elif message_type == 'card':
if type(message_this) == OlivOS.messageAPI.PARA.text:
res_data['modules'].append(
{
"type": "section",
"text": {
"type": "plain-text",
"content": message_this.data['text']
}
]
}
)
elif type(message_this) == OlivOS.messageAPI.PARA.video:
video_path = event_action.setResourceUploadFast(target_event, message_this.data['file'], 'videos')
res_data['modules'].append(
{
"type": "video",
"title": "video.mp4",
"src": video_path
}
)
elif type(message_this) == OlivOS.messageAPI.PARA.record:
audio_path = event_action.setResourceUploadFast(target_event, message_this.data['file'], 'audios')
res_data['modules'].append(
{
"type": "audio",
"title": "audio.mp4",
"src": audio_path
}
)
if len(res_data['modules']) > 0:
this_msg.data.type = 10
this_msg.data.content = json.dumps([res_data], ensure_ascii=False)
this_msg.do_api()
}
)
elif type(message_this) == OlivOS.messageAPI.PARA.image:
image_path = event_action.setResourceUploadFast(target_event, message_this.data['file'], 'images')
res_data['modules'].append(
{
"type": "image-group",
"elements": [
{
"type": "image",
"src": image_path
}
]
}
)
elif type(message_this) == OlivOS.messageAPI.PARA.video:
video_path = event_action.setResourceUploadFast(target_event, message_this.data['file'], 'videos')
res_data['modules'].append(
{
"type": "video",
"title": "video.mp4",
"src": video_path
}
)
elif type(message_this) == OlivOS.messageAPI.PARA.record:
audio_path = event_action.setResourceUploadFast(target_event, message_this.data['file'], 'audios')
res_data['modules'].append(
{
"type": "audio",
"title": "audio.mp4",
"src": audio_path
}
)
if message_type == 'text':
if len(res_data) > 0:
this_msg.data.type = 9
this_msg.data.content = res_data
this_msg.do_api()
elif message_type == 'card':
if len(res_data['modules']) > 0:
this_msg.data.type = 10
this_msg.data.content = json.dumps([res_data], ensure_ascii=False)
this_msg.do_api()

def get_login_info(target_event):
res_data = OlivOS.contentAPI.api_result_data_template.get_login_info()
Expand Down
28 changes: 14 additions & 14 deletions OlivOS/multiLoginUIAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,18 +353,6 @@ def __init__(self, action, Account_data, hash_key=None, edit_commit_callback=Non
'edit_root_Entry_qsign_num': 1,
'edit_root_Combobox_dict': {
'type_list': [
#'QQ/GoCq/安卓手表',
#'QQ/GoCq/安卓手机',
#'QQ/GoCq/安卓平板',
#'QQ/GoCq/默认',
#'QQ/GoCq/iPad',
#'QQ/GoCq/iMac',
#'QQ/Wq/安卓手表',
#'QQ/Wq/安卓手机',
#'QQ/Wq/安卓平板',
#'微信/ComWeChat',
#'QQ/GoCq/旧',
#'QQ/Wq/旧',
'开黑啦/KOOK',
'钉钉',
'渡渡语音/Dodo',
Expand All @@ -373,15 +361,27 @@ def __init__(self, action, Account_data, hash_key=None, edit_commit_callback=Non
'Discord',
'Telegram',
'Fanbook',
'onebotV11/Http',
'onebotV12/正向WS',
'Hack.Chat',
'onebotV12/正向WS',
'onebotV11/Http',
'RED协议',
'B站直播间/游客',
'B站直播间/登录',
'FF14终端',
'虚拟终端',
'接口终端',
'QQ/GoCq/安卓手表',
'QQ/GoCq/安卓手机',
'QQ/GoCq/安卓平板',
'QQ/GoCq/默认',
'QQ/GoCq/iPad',
'QQ/GoCq/iMac',
'QQ/Wq/安卓手表',
'QQ/Wq/安卓手机',
'QQ/Wq/安卓平板',
'微信/ComWeChat',
'QQ/GoCq/旧',
'QQ/Wq/旧',
'自定义'
],
# 各类账号组合的匹配与注册表
Expand Down

0 comments on commit 7f26fe0

Please sign in to comment.