From 75ad495b988f9acf773293adb55cfd48ce48f7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Tue, 28 May 2024 19:32:08 +0800 Subject: [PATCH] refactor: remove some log --- src/common/server/http.ts | 4 +- src/common/utils/version.ts | 2 +- src/core | 2 +- src/onebot11/action/extends/Debug.ts | 2 +- .../action/go-cqhttp/GetFriendMsgHistory.ts | 2 +- .../action/go-cqhttp/GetGroupMsgHistory.ts | 2 +- .../action/go-cqhttp/GetStrangerInfo.ts | 64 +-- .../action/group/GetGroupMemberList.ts | 2 +- .../msg/SendMsg/create-send-elements.ts | 498 +++++++++--------- .../action/msg/SendMsg/handle-forward-node.ts | 14 +- src/onebot11/action/user/SendLike.ts | 4 +- src/onebot11/server/postOB11Event.ts | 5 +- src/onebot11/server/ws/ReverseWebsocket.ts | 2 +- src/vite-env.d.ts | 19 +- 14 files changed, 311 insertions(+), 311 deletions(-) diff --git a/src/common/server/http.ts b/src/common/server/http.ts index 72dea6ae..c3c20133 100644 --- a/src/common/server/http.ts +++ b/src/common/server/http.ts @@ -37,14 +37,14 @@ export abstract class HttpServerBase { const authHeader = req.get('authorization'); if (authHeader) { clientToken = authHeader.split('Bearer ').pop() || ''; - logDebug('receive http header token', clientToken); + //logDebug('receive http header token', clientToken); } else if (req.query.access_token) { if (Array.isArray(req.query.access_token)) { clientToken = req.query.access_token[0].toString(); } else { clientToken = req.query.access_token.toString(); } - logDebug('receive http url token', clientToken); + //logDebug('receive http url token', clientToken); } if (serverToken && clientToken != serverToken) { diff --git a/src/common/utils/version.ts b/src/common/utils/version.ts index de735579..fc8452af 100644 --- a/src/common/utils/version.ts +++ b/src/common/utils/version.ts @@ -14,7 +14,7 @@ export async function checkVersion(): Promise { try { version = (await RequestUtil.HttpGetJson<{ version: string }>(url)).version; } catch (e) { - logDebug(e); + logDebug("检测更新异常",e); } if (version) { resolve(version); diff --git a/src/core b/src/core index d7677362..50cb003a 160000 --- a/src/core +++ b/src/core @@ -1 +1 @@ -Subproject commit d7677362d108fe4d942a0da8a87dce1e6f9ed5ee +Subproject commit 50cb003ab85f62a4b9830e426039d8208b66c5f3 diff --git a/src/onebot11/action/extends/Debug.ts b/src/onebot11/action/extends/Debug.ts index 66231c82..6f73ae5d 100644 --- a/src/onebot11/action/extends/Debug.ts +++ b/src/onebot11/action/extends/Debug.ts @@ -20,7 +20,7 @@ export default class Debug extends BaseAction { actionName = ActionName.Debug; protected async _handle(payload: Payload): Promise { - logDebug('debug call ntqq api', payload); + //logDebug('debug call ntqq api', payload); const ntqqApi = [NTQQMsgApi, NTQQFriendApi, NTQQGroupApi, NTQQUserApi, NTQQFileApi, // NTQQFileCacheApi, ]; diff --git a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts index e279a5ba..2492951f 100644 --- a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts @@ -39,7 +39,7 @@ export default class GetFriendMsgHistory extends BaseAction { chatType: friend ? ChatType.friend : ChatType.temp, peerUid: uid }, startMsgId, parseInt(payload.count?.toString()) || 20)); - logDebug(historyResult); + //logDebug(historyResult); const msgList = historyResult.msgList; await Promise.all(msgList.map(async msg => { msg.id = await dbUtil.addMsg(msg); diff --git a/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts index e371d0e5..e89729ce 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts @@ -38,7 +38,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction { msg.id = await dbUtil.addMsg(msg); diff --git a/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts b/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts index 0819234a..c32c03a7 100644 --- a/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts +++ b/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts @@ -1,32 +1,32 @@ -import BaseAction from '../BaseAction'; -import { OB11User } from '../../types'; -import { getUidByUin, uid2UinMap } from '@/core/data'; -import { OB11Constructor } from '../../constructor'; -import { ActionName } from '../types'; -import { NTQQUserApi } from '@/core/apis/user'; -import { log, logDebug } from '@/common/utils/log'; -import { FromSchema, JSONSchema } from 'json-schema-to-ts'; - -const SchemaData = { - type: 'object', - properties: { - user_id: { type: 'number' }, - }, - required: ['user_id'] -} as const satisfies JSONSchema; - -type Payload = FromSchema; - -export default class GoCQHTTPGetStrangerInfo extends BaseAction { - actionName = ActionName.GoCQHTTP_GetStrangerInfo; - - protected async _handle(payload: Payload): Promise { - const user_id = payload.user_id.toString(); - logDebug('uidMaps', uid2UinMap); - const uid = getUidByUin(user_id); - if (!uid) { - throw new Error('查无此人'); - } - return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo(uid)); - } -} +import BaseAction from '../BaseAction'; +import { OB11User } from '../../types'; +import { getUidByUin, uid2UinMap } from '@/core/data'; +import { OB11Constructor } from '../../constructor'; +import { ActionName } from '../types'; +import { NTQQUserApi } from '@/core/apis/user'; +import { log, logDebug } from '@/common/utils/log'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; + +const SchemaData = { + type: 'object', + properties: { + user_id: { type: 'number' }, + }, + required: ['user_id'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; + +export default class GoCQHTTPGetStrangerInfo extends BaseAction { + actionName = ActionName.GoCQHTTP_GetStrangerInfo; + + protected async _handle(payload: Payload): Promise { + const user_id = payload.user_id.toString(); + //logDebug('uidMaps', uidMaps); + const uid = getUidByUin(user_id); + if (!uid) { + throw new Error('查无此人'); + } + return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo(uid)); + } +} diff --git a/src/onebot11/action/group/GetGroupMemberList.ts b/src/onebot11/action/group/GetGroupMemberList.ts index 9a2e500b..a6c0034f 100644 --- a/src/onebot11/action/group/GetGroupMemberList.ts +++ b/src/onebot11/action/group/GetGroupMemberList.ts @@ -62,7 +62,7 @@ class GetGroupMemberList extends BaseAction { // 无管理员权限通过本地记录获取发言时间 const haveAdmin = RetGroupMember[0].last_sent_time !== 0; if (!haveAdmin) { - logDebug('没有管理员权限,使用本地记录'); + //logDebug('没有管理员权限,使用本地记录'); const _sendAndJoinRember = await getLastSentTimeAndJoinTime(parseInt(group.groupCode)); _sendAndJoinRember.forEach((rember) => { const member = RetGroupMember.find(member=>member.user_id == rember.user_id); diff --git a/src/onebot11/action/msg/SendMsg/create-send-elements.ts b/src/onebot11/action/msg/SendMsg/create-send-elements.ts index 9f956eb2..7a23a9d7 100644 --- a/src/onebot11/action/msg/SendMsg/create-send-elements.ts +++ b/src/onebot11/action/msg/SendMsg/create-send-elements.ts @@ -1,249 +1,249 @@ -import { OB11MessageData, OB11MessageDataType, OB11MessageFileBase } from '@/onebot11/types'; -import { - AtType, - CustomMusicSignPostData, - Group, - IdMusicSignPostData, - NTQQFileApi, - SendArkElement, - SendMessageElement, - SendMsgElementConstructor -} from '@/core'; -import { getGroupMember } from '@/core/data'; -import { dbUtil } from '@/core/utils/db'; -import { logDebug, logError } from '@/common/utils/log'; -import { uri2local } from '@/common/utils/file'; -import { ob11Config } from '@/onebot11/config'; -import { RequestUtil } from '@/common/utils/request'; -import fs from 'node:fs'; - -export type MessageContext = { - group?: Group, - deleteAfterSentFiles: string[], -} - -async function handleOb11FileLikeMessage( - { data: { file, name: payloadFileName } }: OB11MessageFileBase, - { deleteAfterSentFiles }: MessageContext -) { - let uri = file; - - const cache = await dbUtil.getFileCacheByName(file); - if (cache) { - if (fs.existsSync(cache.path)) { - uri = 'file://' + cache.path; - } else if (cache.url) { - uri = cache.url; - } else { - const fileMsg = await dbUtil.getMsgByLongId(cache.msgId); - if (fileMsg) { - cache.path = await NTQQFileApi.downloadMedia( - fileMsg.msgId, fileMsg.chatType, fileMsg.peerUid, - cache.elementId, '', '' - ); - uri = 'file://' + cache.path; - dbUtil.updateFileCache(cache); - } - } - logDebug('找到文件缓存', uri); - } - - const { path, isLocal, fileName, errMsg } = (await uri2local(uri)); - - if (errMsg) { - logError('文件下载失败', errMsg); - throw Error('文件下载失败' + errMsg); - } - - if (!isLocal) { // 只删除http和base64转过来的文件 - deleteAfterSentFiles.push(path); - } - - return { path, fileName: payloadFileName || fileName }; -} - -const _handlers: { - [Key in OB11MessageDataType]: ( - sendMsg: Extract, - // This picks the correct message type out - // How great the type system of TypeScript is! - context: MessageContext - ) => SendMessageElement | undefined | Promise -} = { - [OB11MessageDataType.text]: ({ data: { text } }) => SendMsgElementConstructor.text(text), - - [OB11MessageDataType.at]: async ({ data: { qq: atQQ } }, context) => { - if (!context.group) return undefined; - - if (atQQ === 'all') return SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员'); - - // then the qq is a group member - const atMember = await getGroupMember(context.group.groupCode, atQQ); - return atMember ? - SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick) : - undefined; - }, - - [OB11MessageDataType.reply]: async ({ data: { id } }) => { - const replyMsg = await dbUtil.getMsgByShortId(parseInt(id)); - return replyMsg ? - SendMsgElementConstructor.reply(replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, replyMsg.senderUin!) : - undefined; - }, - - [OB11MessageDataType.face]: ({ data: { id } }) => SendMsgElementConstructor.face(parseInt(id)), - - [OB11MessageDataType.mface]: ({ - data: { - emoji_package_id, - emoji_id, - key, - summary - } - }) => SendMsgElementConstructor.mface(emoji_package_id, emoji_id, key, summary), - - // File service - - [OB11MessageDataType.image]: async (sendMsg, context) => { - const PicEle = await SendMsgElementConstructor.pic( - (await handleOb11FileLikeMessage(sendMsg, context)).path, - sendMsg.data.summary || '', - sendMsg.data.subType || 0 - ); - context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath); - return PicEle; - } - , // currently not supported - - [OB11MessageDataType.file]: async (sendMsg, context) => { - const { path, fileName } = await handleOb11FileLikeMessage(sendMsg, context); - logDebug('发送文件', path, fileName); - return SendMsgElementConstructor.file(path, fileName); - }, - - [OB11MessageDataType.video]: async (sendMsg, context) => { - const { path, fileName } = await handleOb11FileLikeMessage(sendMsg, context); - - logDebug('发送视频', path, fileName); - let thumb = sendMsg.data.thumb; - if (thumb) { - const uri2LocalRes = await uri2local(thumb); - if (uri2LocalRes.success) thumb = uri2LocalRes.path; - } - - return SendMsgElementConstructor.video(path, fileName, thumb); - }, - [OB11MessageDataType.miniapp]: async ({ data: any }) => SendMsgElementConstructor.miniapp(), - - [OB11MessageDataType.voice]: async (sendMsg, context) => - SendMsgElementConstructor.ptt((await handleOb11FileLikeMessage(sendMsg, context)).path), - - [OB11MessageDataType.json]: ({ data: { data } }) => SendMsgElementConstructor.ark(data), - - [OB11MessageDataType.dice]: ({ data: { result } }) => SendMsgElementConstructor.dice(result), - - [OB11MessageDataType.RPS]: ({ data: { result } }) => SendMsgElementConstructor.rps(result), - - [OB11MessageDataType.markdown]: ({ data: { content } }) => SendMsgElementConstructor.markdown(content), - - [OB11MessageDataType.music]: async ({ data }) => { - // 保留, 直到...找到更好的解决方案 - if (data.type === 'custom') { - if (!data.url) { - logError('自定义音卡缺少参数url'); - return undefined; - } - if (!data.audio) { - logError('自定义音卡缺少参数audio'); - return undefined; - } - if (!data.title) { - logError('自定义音卡缺少参数title'); - return undefined; - } - } else { - if (!['qq', '163'].includes(data.type)) { - logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type); - return undefined; - } - if (!data.id) { - logError('音乐卡片缺少参数id'); - return undefined; - } - } - - let postData: IdMusicSignPostData | CustomMusicSignPostData; - if (data.type === 'custom' && data.content) { - const { content, ...others } = data; - postData = { singer: content, ...others }; - } else { - postData = data; - } - - const signUrl = ob11Config.musicSignUrl; - if (!signUrl) { - throw Error('音乐消息签名地址未配置'); - } - try { - const musicJson = await RequestUtil.HttpGetJson(signUrl, 'POST', postData); - return SendMsgElementConstructor.ark(musicJson); - } catch (e) { - logError('生成音乐消息失败', e); - } - }, - - [OB11MessageDataType.node]: () => undefined, - - [OB11MessageDataType.forward]: () => undefined, - - [OB11MessageDataType.xml]: () => undefined, - - [OB11MessageDataType.poke]: () => undefined, -}; - -const handlers = <{ - [Key in OB11MessageDataType]: ( - sendMsg: OB11MessageData, - context: MessageContext - ) => SendMessageElement | undefined | Promise -}>_handlers; - -export default async function createSendElements( - messageData: OB11MessageData[], - group?: Group, - ignoreTypes: OB11MessageDataType[] = [] -) { - const sendElements: SendMessageElement[] = []; - const deleteAfterSentFiles: string[] = []; - for (const sendMsg of messageData) { - if (ignoreTypes.includes(sendMsg.type)) { - continue; - } - const callResult = await handlers[sendMsg.type]( - sendMsg, - { group, deleteAfterSentFiles } - ); - if (callResult) sendElements.push(callResult); - } - return { sendElements, deleteAfterSentFiles }; -} - -export async function createSendElementsParallel( - messageData: OB11MessageData[], - group?: Group, - ignoreTypes: OB11MessageDataType[] = [] -) { - const deleteAfterSentFiles: string[] = []; - const sendElements = ( - await Promise.all( - messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ? - undefined : - handlers[sendMsg.type](sendMsg, { group, deleteAfterSentFiles })) - ).then( - results => results.filter( - element => element !== undefined - ) - ) - ); - return { sendElements, deleteAfterSentFiles }; -} +import { OB11MessageData, OB11MessageDataType, OB11MessageFileBase } from '@/onebot11/types'; +import { + AtType, + CustomMusicSignPostData, + Group, + IdMusicSignPostData, + NTQQFileApi, + SendArkElement, + SendMessageElement, + SendMsgElementConstructor +} from '@/core'; +import { getGroupMember } from '@/core/data'; +import { dbUtil } from '@/core/utils/db'; +import { logDebug, logError } from '@/common/utils/log'; +import { uri2local } from '@/common/utils/file'; +import { ob11Config } from '@/onebot11/config'; +import { RequestUtil } from '@/common/utils/request'; +import fs from 'node:fs'; + +export type MessageContext = { + group?: Group, + deleteAfterSentFiles: string[], +} + +async function handleOb11FileLikeMessage( + { data: { file, name: payloadFileName } }: OB11MessageFileBase, + { deleteAfterSentFiles }: MessageContext +) { + let uri = file; + + const cache = await dbUtil.getFileCacheByName(file); + if (cache) { + if (fs.existsSync(cache.path)) { + uri = 'file://' + cache.path; + } else if (cache.url) { + uri = cache.url; + } else { + const fileMsg = await dbUtil.getMsgByLongId(cache.msgId); + if (fileMsg) { + cache.path = await NTQQFileApi.downloadMedia( + fileMsg.msgId, fileMsg.chatType, fileMsg.peerUid, + cache.elementId, '', '' + ); + uri = 'file://' + cache.path; + dbUtil.updateFileCache(cache); + } + } + logDebug('找到文件缓存', uri); + } + + const { path, isLocal, fileName, errMsg } = (await uri2local(uri)); + + if (errMsg) { + logError('文件下载失败', errMsg); + throw Error('文件下载失败' + errMsg); + } + + if (!isLocal) { // 只删除http和base64转过来的文件 + deleteAfterSentFiles.push(path); + } + + return { path, fileName: payloadFileName || fileName }; +} + +const _handlers: { + [Key in OB11MessageDataType]: ( + sendMsg: Extract, + // This picks the correct message type out + // How great the type system of TypeScript is! + context: MessageContext + ) => SendMessageElement | undefined | Promise +} = { + [OB11MessageDataType.text]: ({ data: { text } }) => SendMsgElementConstructor.text(text), + + [OB11MessageDataType.at]: async ({ data: { qq: atQQ } }, context) => { + if (!context.group) return undefined; + + if (atQQ === 'all') return SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员'); + + // then the qq is a group member + const atMember = await getGroupMember(context.group.groupCode, atQQ); + return atMember ? + SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick) : + undefined; + }, + + [OB11MessageDataType.reply]: async ({ data: { id } }) => { + const replyMsg = await dbUtil.getMsgByShortId(parseInt(id)); + return replyMsg ? + SendMsgElementConstructor.reply(replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, replyMsg.senderUin!) : + undefined; + }, + + [OB11MessageDataType.face]: ({ data: { id } }) => SendMsgElementConstructor.face(parseInt(id)), + + [OB11MessageDataType.mface]: ({ + data: { + emoji_package_id, + emoji_id, + key, + summary + } + }) => SendMsgElementConstructor.mface(emoji_package_id, emoji_id, key, summary), + + // File service + + [OB11MessageDataType.image]: async (sendMsg, context) => { + const PicEle = await SendMsgElementConstructor.pic( + (await handleOb11FileLikeMessage(sendMsg, context)).path, + sendMsg.data.summary || '', + sendMsg.data.subType || 0 + ); + context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath); + return PicEle; + } + , // currently not supported + + [OB11MessageDataType.file]: async (sendMsg, context) => { + const { path, fileName } = await handleOb11FileLikeMessage(sendMsg, context); + //logDebug('发送文件', path, fileName); + return SendMsgElementConstructor.file(path, fileName); + }, + + [OB11MessageDataType.video]: async (sendMsg, context) => { + const { path, fileName } = await handleOb11FileLikeMessage(sendMsg, context); + + //logDebug('发送视频', path, fileName); + let thumb = sendMsg.data.thumb; + if (thumb) { + const uri2LocalRes = await uri2local(thumb); + if (uri2LocalRes.success) thumb = uri2LocalRes.path; + } + + return SendMsgElementConstructor.video(path, fileName, thumb); + }, + [OB11MessageDataType.miniapp]: async ({ data: any }) => SendMsgElementConstructor.miniapp(), + + [OB11MessageDataType.voice]: async (sendMsg, context) => + SendMsgElementConstructor.ptt((await handleOb11FileLikeMessage(sendMsg, context)).path), + + [OB11MessageDataType.json]: ({ data: { data } }) => SendMsgElementConstructor.ark(data), + + [OB11MessageDataType.dice]: ({ data: { result } }) => SendMsgElementConstructor.dice(result), + + [OB11MessageDataType.RPS]: ({ data: { result } }) => SendMsgElementConstructor.rps(result), + + [OB11MessageDataType.markdown]: ({ data: { content } }) => SendMsgElementConstructor.markdown(content), + + [OB11MessageDataType.music]: async ({ data }) => { + // 保留, 直到...找到更好的解决方案 + if (data.type === 'custom') { + if (!data.url) { + logError('自定义音卡缺少参数url'); + return undefined; + } + if (!data.audio) { + logError('自定义音卡缺少参数audio'); + return undefined; + } + if (!data.title) { + logError('自定义音卡缺少参数title'); + return undefined; + } + } else { + if (!['qq', '163'].includes(data.type)) { + logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type); + return undefined; + } + if (!data.id) { + logError('音乐卡片缺少参数id'); + return undefined; + } + } + + let postData: IdMusicSignPostData | CustomMusicSignPostData; + if (data.type === 'custom' && data.content) { + const { content, ...others } = data; + postData = { singer: content, ...others }; + } else { + postData = data; + } + + const signUrl = ob11Config.musicSignUrl; + if (!signUrl) { + throw Error('音乐消息签名地址未配置'); + } + try { + const musicJson = await RequestUtil.HttpGetJson(signUrl, 'POST', postData); + return SendMsgElementConstructor.ark(musicJson); + } catch (e) { + logError('生成音乐消息失败', e); + } + }, + + [OB11MessageDataType.node]: () => undefined, + + [OB11MessageDataType.forward]: () => undefined, + + [OB11MessageDataType.xml]: () => undefined, + + [OB11MessageDataType.poke]: () => undefined, +}; + +const handlers = <{ + [Key in OB11MessageDataType]: ( + sendMsg: OB11MessageData, + context: MessageContext + ) => SendMessageElement | undefined | Promise +}>_handlers; + +export default async function createSendElements( + messageData: OB11MessageData[], + group?: Group, + ignoreTypes: OB11MessageDataType[] = [] +) { + const sendElements: SendMessageElement[] = []; + const deleteAfterSentFiles: string[] = []; + for (const sendMsg of messageData) { + if (ignoreTypes.includes(sendMsg.type)) { + continue; + } + const callResult = await handlers[sendMsg.type]( + sendMsg, + { group, deleteAfterSentFiles } + ); + if (callResult) sendElements.push(callResult); + } + return { sendElements, deleteAfterSentFiles }; +} + +export async function createSendElementsParallel( + messageData: OB11MessageData[], + group?: Group, + ignoreTypes: OB11MessageDataType[] = [] +) { + const deleteAfterSentFiles: string[] = []; + const sendElements = ( + await Promise.all( + messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ? + undefined : + handlers[sendMsg.type](sendMsg, { group, deleteAfterSentFiles })) + ).then( + results => results.filter( + element => element !== undefined + ) + ) + ); + return { sendElements, deleteAfterSentFiles }; +} diff --git a/src/onebot11/action/msg/SendMsg/handle-forward-node.ts b/src/onebot11/action/msg/SendMsg/handle-forward-node.ts index 306279ad..3fe9e706 100644 --- a/src/onebot11/action/msg/SendMsg/handle-forward-node.ts +++ b/src/onebot11/action/msg/SendMsg/handle-forward-node.ts @@ -14,7 +14,7 @@ async function cloneMsg(msg: RawMessage): Promise { peerUid: selfInfo.uid }; - logDebug('克隆的目标消息', msg); + // logDebug('克隆的目标消息', msg); const sendElements: SendMessageElement[] = []; @@ -26,7 +26,7 @@ async function cloneMsg(msg: RawMessage): Promise { logDebug('需要clone的消息无法解析,将会忽略掉', msg); } - logDebug('克隆消息', sendElements); + //logDebug('克隆消息', sendElements); try { const nodeMsg = await NTQQMsgApi.sendMsg(selfPeer, sendElements, true); @@ -71,7 +71,7 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag // 提取消息段,发给自己生成消息id try { const { sendElements } = await createSendElements(normalize(messageNode.data.content), group); - logDebug('开始生成转发节点', sendElements); + //logDebug('开始生成转发节点', sendElements); const sendElementsSplit: SendMessageElement[][] = []; let splitIndex = 0; for (const sendElement of sendElements) { @@ -88,7 +88,7 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag } else { sendElementsSplit[splitIndex].push(sendElement); } - logDebug(sendElementsSplit); + //logDebug(sendElementsSplit); } // log("分割后的转发节点", sendElementsSplit) const MsgNodeList: Promise[] = []; @@ -100,7 +100,7 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag for (const msgNode of MsgNodeList) { const result = await msgNode; nodeMsgIds.push(result.msgId); - logDebug('转发节点生成成功', result.msgId); + //logDebug('转发节点生成成功', result.msgId); } } catch (e) { logDebug('生成转发消息节点失败', e); @@ -124,10 +124,10 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag } } } - logDebug('nodeMsgArray', nodeMsgArray); + //logDebug('nodeMsgArray', nodeMsgArray); nodeMsgIds = nodeMsgArray.map(msg => msg.msgId); if (needSendSelf) { - logDebug('需要克隆转发消息'); + //logDebug('需要克隆转发消息'); for (const [index, msg] of nodeMsgArray.entries()) { if (msg.peerUid !== selfInfo.uid) { const clonedMsg = await cloneMsg(msg); diff --git a/src/onebot11/action/user/SendLike.ts b/src/onebot11/action/user/SendLike.ts index 74d37bb4..c4ca2c07 100644 --- a/src/onebot11/action/user/SendLike.ts +++ b/src/onebot11/action/user/SendLike.ts @@ -20,7 +20,7 @@ export default class SendLike extends BaseAction { actionName = ActionName.SendLike; PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { - logDebug('点赞参数', payload); + //logDebug('点赞参数', payload); try { const qq = payload.user_id.toString(); const friend = await getFriend(qq); @@ -31,7 +31,7 @@ export default class SendLike extends BaseAction { uid = friend.uid; } const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1); - logDebug('点赞结果', result); + //logDebug('点赞结果', result); if (result.result !== 0) { throw Error(result.errMsg); } diff --git a/src/onebot11/server/postOB11Event.ts b/src/onebot11/server/postOB11Event.ts index 365a4af4..197943f0 100644 --- a/src/onebot11/server/postOB11Event.ts +++ b/src/onebot11/server/postOB11Event.ts @@ -17,6 +17,7 @@ import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi } from '@/core/apis'; import createSendElements from '../action/msg/SendMsg/create-send-elements'; export type QuickActionEvent = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent +export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent interface QuickActionPrivateMessage { reply?: string; @@ -97,12 +98,12 @@ export function postOB11Event(msg: QuickActionEvent, reportSelf = false, postWs headers, body: msgStr }).then(async (res) => { - logDebug(`新消息事件HTTP上报成功: ${host} `, msgStr); + //logDebug(`新消息事件HTTP上报成功: ${host} `, msgStr); // todo: 处理不够优雅,应该使用高级泛型进行QuickAction类型识别 let resJson: QuickAction; try { resJson = await res.json(); - logDebug('新消息事件HTTP上报返回快速操作: ', JSON.stringify(resJson)); + //logDebug('新消息事件HTTP上报返回快速操作: ', JSON.stringify(resJson)); } catch (e) { logDebug('新消息事件HTTP上报没有返回快速操作,不需要处理'); return; diff --git a/src/onebot11/server/ws/ReverseWebsocket.ts b/src/onebot11/server/ws/ReverseWebsocket.ts index a12d6d42..ad572d93 100644 --- a/src/onebot11/server/ws/ReverseWebsocket.ts +++ b/src/onebot11/server/ws/ReverseWebsocket.ts @@ -40,7 +40,7 @@ export class ReverseWebsocket { try { receiveData = JSON.parse(msg.toString()); echo = receiveData.echo; - logDebug('收到反向Websocket消息', receiveData); + //logDebug('收到反向Websocket消息', receiveData); } catch (e) { return wsReply(this.websocket!, OB11Response.error('json解析失败,请检查数据格式', 1400, echo)); } diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index d07ff4dc..131891b3 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,10 +1,9 @@ -/// - -interface ImportMetaEnv { - readonly VITE_APP_TITLE: string - // 更多环境变量... - } - - interface ImportMeta { - readonly env: ImportMetaEnv - } \ No newline at end of file +/// + +interface ImportMetaEnv { + VITE_BUILD_TYPE: string +} + +interface ImportMeta { + readonly env: ImportMetaEnv +} \ No newline at end of file