fix: try 2 fix cannot parse msg err

This commit is contained in:
student_2333 2024-05-10 13:33:48 +08:00
parent 1da086ce0a
commit 43e9b070a9
No known key found for this signature in database
GPG Key ID: B36E8DF853C33EE1
6 changed files with 44 additions and 30 deletions

2
.gitignore vendored
View File

@ -3,4 +3,4 @@ package-lock.json
dist/
out/
.idea/
.DS_Store
.DS_Store

View File

@ -1,10 +1,10 @@
{
"manifest_version": 4,
"type": "extension",
"name": "LLOneBot v3.24.1",
"name": "LLOneBot v3.24.2",
"slug": "LLOneBot",
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
"version": "3.24.1",
"version": "3.24.2",
"icon": "./icon.jpg",
"authors": [
{

View File

@ -10,7 +10,8 @@
"deploy-mac": "cp -r dist/* ~/Library/Containers/com.tencent.qq/Data/LiteLoaderQQNT/plugins/LLOneBot/",
"build-win": "npm run build && npm run deploy-win",
"deploy-win": "cmd /c \"xcopy /C /S /Y dist\\* %USERPROFILE%\\documents\\LiteLoaderQQNT\\plugins\\LLOneBot\\\"",
"format": "prettier -cw ."
"format": "prettier -cw .",
"check": "tsc"
},
"author": "",
"license": "MIT",

View File

@ -74,7 +74,11 @@ export class NTQQGroupApi {
}
static async getGroupIgnoreNotifies() {
await NTQQGroupApi.getGroupNotifies()
return await NTQQWindowApi.openWindow(NTQQWindows.GroupNotifyFilterWindow, [], ReceiveCmdS.GROUP_NOTIFY)
return await NTQQWindowApi.openWindow<GeneralCallResult & GroupNotifies>(
NTQQWindows.GroupNotifyFilterWindow,
[],
ReceiveCmdS.GROUP_NOTIFY,
)
}
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)

View File

@ -14,11 +14,13 @@ import { friends, getFriend, getGroup, getGroupMember, getUidByUin, selfInfo } f
import {
OB11MessageCustomMusic,
OB11MessageData,
OB11MessageDataType, OB11MessageFile,
OB11MessageDataType,
OB11MessageFile,
OB11MessageJson,
OB11MessageMixType,
OB11MessageMusic,
OB11MessageNode, OB11MessageVideo,
OB11MessageNode,
OB11MessageVideo,
OB11PostSendMsg,
} from '../../types'
import { NTQQMsgApi, Peer } from '../../../ntqqapi/api/msg'
@ -177,11 +179,18 @@ export async function createSendElements(
}
}
break
case OB11MessageDataType.mface: {
sendElements.push(
SendMsgElementConstructor.mface(sendMsg.data.emoji_package_id, sendMsg.data.emoji_id, sendMsg.data.key, sendMsg.data.summary),
)
}break;
case OB11MessageDataType.mface:
{
sendElements.push(
SendMsgElementConstructor.mface(
sendMsg.data.emoji_package_id,
sendMsg.data.emoji_id,
sendMsg.data.key,
sendMsg.data.summary,
),
)
}
break
case OB11MessageDataType.image:
case OB11MessageDataType.file:
case OB11MessageDataType.video:
@ -303,14 +312,14 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
const messages = convertMessage2List(payload.message)
const fmNum = this.getSpecialMsgNum(payload, OB11MessageDataType.node)
const fmNum = this.getSpecialMsgNum(messages, OB11MessageDataType.node)
if (fmNum && fmNum != messages.length) {
return {
valid: false,
message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素',
}
}
const musicNum = this.getSpecialMsgNum(payload, OB11MessageDataType.music)
const musicNum = this.getSpecialMsgNum(messages, OB11MessageDataType.music)
if (musicNum && messages.length > 1) {
return {
valid: false,
@ -382,14 +391,14 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
payload.message,
payload.auto_escape === true || payload.auto_escape === 'true',
)
if (this.getSpecialMsgNum(payload, OB11MessageDataType.node)) {
if (this.getSpecialMsgNum(messages, OB11MessageDataType.node)) {
try {
const returnMsg = await this.handleForwardNode(peer, messages as OB11MessageNode[], group)
return { message_id: returnMsg.msgShortId }
} catch (e) {
throw '发送转发消息失败 ' + e.toString()
}
} else if (this.getSpecialMsgNum(payload, OB11MessageDataType.music)) {
} else if (this.getSpecialMsgNum(messages, OB11MessageDataType.music)) {
const music = messages[0] as OB11MessageMusic
if (music) {
const { musicSignUrl } = getConfigUtil().getConfig()
@ -402,24 +411,23 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
}
const postData: MusicSignPostData = { ...music.data }
if (type === 'custom' && music.data.content) {
;(postData as CustomMusicSignPostData).singer = music.data.content
delete (postData as OB11MessageCustomMusic['data']).content
}
if (type === 'custom'){
if (type === 'custom') {
const customMusicData = music.data as CustomMusicSignPostData
if (!customMusicData.url){
throw ('自定义音卡缺少参数url');
if (!customMusicData.url) {
throw '自定义音卡缺少参数url'
}
if (!customMusicData.audio){
throw('自定义音卡缺少参数audio');
if (!customMusicData.audio) {
throw '自定义音卡缺少参数audio'
}
if (!customMusicData.title){
throw('自定义音卡缺少参数title');
if (!customMusicData.title) {
throw '自定义音卡缺少参数title'
}
}
if (type === 'qq' || type === '163') {
const idMusicData = music.data as IdMusicSignPostData;
const idMusicData = music.data as IdMusicSignPostData
if (!idMusicData.id) {
throw '音乐卡片缺少id参数'
}
@ -448,9 +456,9 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
return { message_id: returnMsg.msgShortId }
}
private getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType): number {
if (Array.isArray(payload.message)) {
return payload.message.filter((msg) => msg.type == msgType).length
private getSpecialMsgNum(message: OB11MessageData[], msgType: OB11MessageDataType): number {
if (Array.isArray(message)) {
return message.filter((msg) => msg.type == msgType).length
}
return 0
}

View File

@ -7,8 +7,9 @@
"esModuleInterop": true,
"allowJs": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node"
// "sourceMap": true
"moduleResolution": "node",
// "sourceMap": true,
"noEmit": true
},
"include": ["src/*", "src/**/*", "scripts/*"],
"exclude": ["node_modules"]