mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: remove some log
This commit is contained in:
parent
0bb7288ad2
commit
75ad495b98
@ -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) {
|
||||
|
@ -14,7 +14,7 @@ export async function checkVersion(): Promise<string> {
|
||||
try {
|
||||
version = (await RequestUtil.HttpGetJson<{ version: string }>(url)).version;
|
||||
} catch (e) {
|
||||
logDebug(e);
|
||||
logDebug("检测更新异常",e);
|
||||
}
|
||||
if (version) {
|
||||
resolve(version);
|
||||
|
2
src/core
2
src/core
@ -1 +1 @@
|
||||
Subproject commit d7677362d108fe4d942a0da8a87dce1e6f9ed5ee
|
||||
Subproject commit 50cb003ab85f62a4b9830e426039d8208b66c5f3
|
@ -20,7 +20,7 @@ export default class Debug extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.Debug;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
logDebug('debug call ntqq api', payload);
|
||||
//logDebug('debug call ntqq api', payload);
|
||||
const ntqqApi = [NTQQMsgApi, NTQQFriendApi, NTQQGroupApi, NTQQUserApi, NTQQFileApi,
|
||||
// NTQQFileCacheApi,
|
||||
];
|
||||
|
@ -39,7 +39,7 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
||||
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);
|
||||
|
@ -38,7 +38,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
||||
chatType: ChatType.group,
|
||||
peerUid: group.groupCode
|
||||
}, 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);
|
||||
|
@ -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<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11User> {
|
||||
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<OB11User> {
|
||||
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<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11User> {
|
||||
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<OB11User> {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
||||
// 无管理员权限通过本地记录获取发言时间
|
||||
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);
|
||||
|
@ -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<OB11MessageData, { type: Key }>,
|
||||
// This picks the correct message type out
|
||||
// How great the type system of TypeScript is!
|
||||
context: MessageContext
|
||||
) => SendMessageElement | undefined | Promise<SendMessageElement | undefined>
|
||||
} = {
|
||||
[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<any>(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<SendMessageElement | undefined>
|
||||
}>_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 = <SendMessageElement[]>(
|
||||
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<OB11MessageData, { type: Key }>,
|
||||
// This picks the correct message type out
|
||||
// How great the type system of TypeScript is!
|
||||
context: MessageContext
|
||||
) => SendMessageElement | undefined | Promise<SendMessageElement | undefined>
|
||||
} = {
|
||||
[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<any>(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<SendMessageElement | undefined>
|
||||
}>_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 = <SendMessageElement[]>(
|
||||
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 };
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ async function cloneMsg(msg: RawMessage): Promise<RawMessage | undefined> {
|
||||
peerUid: selfInfo.uid
|
||||
};
|
||||
|
||||
logDebug('克隆的目标消息', msg);
|
||||
// logDebug('克隆的目标消息', msg);
|
||||
|
||||
const sendElements: SendMessageElement[] = [];
|
||||
|
||||
@ -26,7 +26,7 @@ async function cloneMsg(msg: RawMessage): Promise<RawMessage | undefined> {
|
||||
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<RawMessage>[] = [];
|
||||
@ -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);
|
||||
|
@ -20,7 +20,7 @@ export default class SendLike extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SendLike;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
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<Payload, null> {
|
||||
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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
19
src/vite-env.d.ts
vendored
19
src/vite-env.d.ts
vendored
@ -1,10 +1,9 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_APP_TITLE: string
|
||||
// 更多环境变量...
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv
|
||||
}
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
VITE_BUILD_TYPE: string
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user