mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
refactor: remove some log
This commit is contained in:
src
@@ -37,14 +37,14 @@ export abstract class HttpServerBase {
|
|||||||
const authHeader = req.get('authorization');
|
const authHeader = req.get('authorization');
|
||||||
if (authHeader) {
|
if (authHeader) {
|
||||||
clientToken = authHeader.split('Bearer ').pop() || '';
|
clientToken = authHeader.split('Bearer ').pop() || '';
|
||||||
logDebug('receive http header token', clientToken);
|
//logDebug('receive http header token', clientToken);
|
||||||
} else if (req.query.access_token) {
|
} else if (req.query.access_token) {
|
||||||
if (Array.isArray(req.query.access_token)) {
|
if (Array.isArray(req.query.access_token)) {
|
||||||
clientToken = req.query.access_token[0].toString();
|
clientToken = req.query.access_token[0].toString();
|
||||||
} else {
|
} else {
|
||||||
clientToken = req.query.access_token.toString();
|
clientToken = req.query.access_token.toString();
|
||||||
}
|
}
|
||||||
logDebug('receive http url token', clientToken);
|
//logDebug('receive http url token', clientToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverToken && clientToken != serverToken) {
|
if (serverToken && clientToken != serverToken) {
|
||||||
|
@@ -14,7 +14,7 @@ export async function checkVersion(): Promise<string> {
|
|||||||
try {
|
try {
|
||||||
version = (await RequestUtil.HttpGetJson<{ version: string }>(url)).version;
|
version = (await RequestUtil.HttpGetJson<{ version: string }>(url)).version;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logDebug(e);
|
logDebug("检测更新异常",e);
|
||||||
}
|
}
|
||||||
if (version) {
|
if (version) {
|
||||||
resolve(version);
|
resolve(version);
|
||||||
|
2
src/core
2
src/core
Submodule src/core updated: d7677362d1...50cb003ab8
@@ -20,7 +20,7 @@ export default class Debug extends BaseAction<Payload, any> {
|
|||||||
actionName = ActionName.Debug;
|
actionName = ActionName.Debug;
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<any> {
|
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,
|
const ntqqApi = [NTQQMsgApi, NTQQFriendApi, NTQQGroupApi, NTQQUserApi, NTQQFileApi,
|
||||||
// NTQQFileCacheApi,
|
// NTQQFileCacheApi,
|
||||||
];
|
];
|
||||||
|
@@ -39,7 +39,7 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
|||||||
chatType: friend ? ChatType.friend : ChatType.temp,
|
chatType: friend ? ChatType.friend : ChatType.temp,
|
||||||
peerUid: uid
|
peerUid: uid
|
||||||
}, startMsgId, parseInt(payload.count?.toString()) || 20));
|
}, startMsgId, parseInt(payload.count?.toString()) || 20));
|
||||||
logDebug(historyResult);
|
//logDebug(historyResult);
|
||||||
const msgList = historyResult.msgList;
|
const msgList = historyResult.msgList;
|
||||||
await Promise.all(msgList.map(async msg => {
|
await Promise.all(msgList.map(async msg => {
|
||||||
msg.id = await dbUtil.addMsg(msg);
|
msg.id = await dbUtil.addMsg(msg);
|
||||||
|
@@ -38,7 +38,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
|||||||
chatType: ChatType.group,
|
chatType: ChatType.group,
|
||||||
peerUid: group.groupCode
|
peerUid: group.groupCode
|
||||||
}, startMsgId, parseInt(payload.count?.toString()) || 20));
|
}, startMsgId, parseInt(payload.count?.toString()) || 20));
|
||||||
logDebug(historyResult);
|
//logDebug(historyResult);
|
||||||
const msgList = historyResult.msgList;
|
const msgList = historyResult.msgList;
|
||||||
await Promise.all(msgList.map(async msg => {
|
await Promise.all(msgList.map(async msg => {
|
||||||
msg.id = await dbUtil.addMsg(msg);
|
msg.id = await dbUtil.addMsg(msg);
|
||||||
|
@@ -1,32 +1,32 @@
|
|||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { OB11User } from '../../types';
|
import { OB11User } from '../../types';
|
||||||
import { getUidByUin, uid2UinMap } from '@/core/data';
|
import { getUidByUin, uid2UinMap } from '@/core/data';
|
||||||
import { OB11Constructor } from '../../constructor';
|
import { OB11Constructor } from '../../constructor';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { NTQQUserApi } from '@/core/apis/user';
|
import { NTQQUserApi } from '@/core/apis/user';
|
||||||
import { log, logDebug } from '@/common/utils/log';
|
import { log, logDebug } from '@/common/utils/log';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
user_id: { type: 'number' },
|
user_id: { type: 'number' },
|
||||||
},
|
},
|
||||||
required: ['user_id']
|
required: ['user_id']
|
||||||
} as const satisfies JSONSchema;
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11User> {
|
export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11User> {
|
||||||
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<OB11User> {
|
protected async _handle(payload: Payload): Promise<OB11User> {
|
||||||
const user_id = payload.user_id.toString();
|
const user_id = payload.user_id.toString();
|
||||||
logDebug('uidMaps', uid2UinMap);
|
//logDebug('uidMaps', uidMaps);
|
||||||
const uid = getUidByUin(user_id);
|
const uid = getUidByUin(user_id);
|
||||||
if (!uid) {
|
if (!uid) {
|
||||||
throw new Error('查无此人');
|
throw new Error('查无此人');
|
||||||
}
|
}
|
||||||
return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo(uid));
|
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;
|
const haveAdmin = RetGroupMember[0].last_sent_time !== 0;
|
||||||
if (!haveAdmin) {
|
if (!haveAdmin) {
|
||||||
logDebug('没有管理员权限,使用本地记录');
|
//logDebug('没有管理员权限,使用本地记录');
|
||||||
const _sendAndJoinRember = await getLastSentTimeAndJoinTime(parseInt(group.groupCode));
|
const _sendAndJoinRember = await getLastSentTimeAndJoinTime(parseInt(group.groupCode));
|
||||||
_sendAndJoinRember.forEach((rember) => {
|
_sendAndJoinRember.forEach((rember) => {
|
||||||
const member = RetGroupMember.find(member=>member.user_id == rember.user_id);
|
const member = RetGroupMember.find(member=>member.user_id == rember.user_id);
|
||||||
|
@@ -1,249 +1,249 @@
|
|||||||
import { OB11MessageData, OB11MessageDataType, OB11MessageFileBase } from '@/onebot11/types';
|
import { OB11MessageData, OB11MessageDataType, OB11MessageFileBase } from '@/onebot11/types';
|
||||||
import {
|
import {
|
||||||
AtType,
|
AtType,
|
||||||
CustomMusicSignPostData,
|
CustomMusicSignPostData,
|
||||||
Group,
|
Group,
|
||||||
IdMusicSignPostData,
|
IdMusicSignPostData,
|
||||||
NTQQFileApi,
|
NTQQFileApi,
|
||||||
SendArkElement,
|
SendArkElement,
|
||||||
SendMessageElement,
|
SendMessageElement,
|
||||||
SendMsgElementConstructor
|
SendMsgElementConstructor
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import { getGroupMember } from '@/core/data';
|
import { getGroupMember } from '@/core/data';
|
||||||
import { dbUtil } from '@/core/utils/db';
|
import { dbUtil } from '@/core/utils/db';
|
||||||
import { logDebug, logError } from '@/common/utils/log';
|
import { logDebug, logError } from '@/common/utils/log';
|
||||||
import { uri2local } from '@/common/utils/file';
|
import { uri2local } from '@/common/utils/file';
|
||||||
import { ob11Config } from '@/onebot11/config';
|
import { ob11Config } from '@/onebot11/config';
|
||||||
import { RequestUtil } from '@/common/utils/request';
|
import { RequestUtil } from '@/common/utils/request';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
|
|
||||||
export type MessageContext = {
|
export type MessageContext = {
|
||||||
group?: Group,
|
group?: Group,
|
||||||
deleteAfterSentFiles: string[],
|
deleteAfterSentFiles: string[],
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleOb11FileLikeMessage(
|
async function handleOb11FileLikeMessage(
|
||||||
{ data: { file, name: payloadFileName } }: OB11MessageFileBase,
|
{ data: { file, name: payloadFileName } }: OB11MessageFileBase,
|
||||||
{ deleteAfterSentFiles }: MessageContext
|
{ deleteAfterSentFiles }: MessageContext
|
||||||
) {
|
) {
|
||||||
let uri = file;
|
let uri = file;
|
||||||
|
|
||||||
const cache = await dbUtil.getFileCacheByName(file);
|
const cache = await dbUtil.getFileCacheByName(file);
|
||||||
if (cache) {
|
if (cache) {
|
||||||
if (fs.existsSync(cache.path)) {
|
if (fs.existsSync(cache.path)) {
|
||||||
uri = 'file://' + cache.path;
|
uri = 'file://' + cache.path;
|
||||||
} else if (cache.url) {
|
} else if (cache.url) {
|
||||||
uri = cache.url;
|
uri = cache.url;
|
||||||
} else {
|
} else {
|
||||||
const fileMsg = await dbUtil.getMsgByLongId(cache.msgId);
|
const fileMsg = await dbUtil.getMsgByLongId(cache.msgId);
|
||||||
if (fileMsg) {
|
if (fileMsg) {
|
||||||
cache.path = await NTQQFileApi.downloadMedia(
|
cache.path = await NTQQFileApi.downloadMedia(
|
||||||
fileMsg.msgId, fileMsg.chatType, fileMsg.peerUid,
|
fileMsg.msgId, fileMsg.chatType, fileMsg.peerUid,
|
||||||
cache.elementId, '', ''
|
cache.elementId, '', ''
|
||||||
);
|
);
|
||||||
uri = 'file://' + cache.path;
|
uri = 'file://' + cache.path;
|
||||||
dbUtil.updateFileCache(cache);
|
dbUtil.updateFileCache(cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logDebug('找到文件缓存', uri);
|
logDebug('找到文件缓存', uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { path, isLocal, fileName, errMsg } = (await uri2local(uri));
|
const { path, isLocal, fileName, errMsg } = (await uri2local(uri));
|
||||||
|
|
||||||
if (errMsg) {
|
if (errMsg) {
|
||||||
logError('文件下载失败', errMsg);
|
logError('文件下载失败', errMsg);
|
||||||
throw Error('文件下载失败' + errMsg);
|
throw Error('文件下载失败' + errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||||
deleteAfterSentFiles.push(path);
|
deleteAfterSentFiles.push(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { path, fileName: payloadFileName || fileName };
|
return { path, fileName: payloadFileName || fileName };
|
||||||
}
|
}
|
||||||
|
|
||||||
const _handlers: {
|
const _handlers: {
|
||||||
[Key in OB11MessageDataType]: (
|
[Key in OB11MessageDataType]: (
|
||||||
sendMsg: Extract<OB11MessageData, { type: Key }>,
|
sendMsg: Extract<OB11MessageData, { type: Key }>,
|
||||||
// This picks the correct message type out
|
// This picks the correct message type out
|
||||||
// How great the type system of TypeScript is!
|
// How great the type system of TypeScript is!
|
||||||
context: MessageContext
|
context: MessageContext
|
||||||
) => SendMessageElement | undefined | Promise<SendMessageElement | undefined>
|
) => SendMessageElement | undefined | Promise<SendMessageElement | undefined>
|
||||||
} = {
|
} = {
|
||||||
[OB11MessageDataType.text]: ({ data: { text } }) => SendMsgElementConstructor.text(text),
|
[OB11MessageDataType.text]: ({ data: { text } }) => SendMsgElementConstructor.text(text),
|
||||||
|
|
||||||
[OB11MessageDataType.at]: async ({ data: { qq: atQQ } }, context) => {
|
[OB11MessageDataType.at]: async ({ data: { qq: atQQ } }, context) => {
|
||||||
if (!context.group) return undefined;
|
if (!context.group) return undefined;
|
||||||
|
|
||||||
if (atQQ === 'all') return SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员');
|
if (atQQ === 'all') return SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员');
|
||||||
|
|
||||||
// then the qq is a group member
|
// then the qq is a group member
|
||||||
const atMember = await getGroupMember(context.group.groupCode, atQQ);
|
const atMember = await getGroupMember(context.group.groupCode, atQQ);
|
||||||
return atMember ?
|
return atMember ?
|
||||||
SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick) :
|
SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick) :
|
||||||
undefined;
|
undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
[OB11MessageDataType.reply]: async ({ data: { id } }) => {
|
[OB11MessageDataType.reply]: async ({ data: { id } }) => {
|
||||||
const replyMsg = await dbUtil.getMsgByShortId(parseInt(id));
|
const replyMsg = await dbUtil.getMsgByShortId(parseInt(id));
|
||||||
return replyMsg ?
|
return replyMsg ?
|
||||||
SendMsgElementConstructor.reply(replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, replyMsg.senderUin!) :
|
SendMsgElementConstructor.reply(replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, replyMsg.senderUin!) :
|
||||||
undefined;
|
undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
[OB11MessageDataType.face]: ({ data: { id } }) => SendMsgElementConstructor.face(parseInt(id)),
|
[OB11MessageDataType.face]: ({ data: { id } }) => SendMsgElementConstructor.face(parseInt(id)),
|
||||||
|
|
||||||
[OB11MessageDataType.mface]: ({
|
[OB11MessageDataType.mface]: ({
|
||||||
data: {
|
data: {
|
||||||
emoji_package_id,
|
emoji_package_id,
|
||||||
emoji_id,
|
emoji_id,
|
||||||
key,
|
key,
|
||||||
summary
|
summary
|
||||||
}
|
}
|
||||||
}) => SendMsgElementConstructor.mface(emoji_package_id, emoji_id, key, summary),
|
}) => SendMsgElementConstructor.mface(emoji_package_id, emoji_id, key, summary),
|
||||||
|
|
||||||
// File service
|
// File service
|
||||||
|
|
||||||
[OB11MessageDataType.image]: async (sendMsg, context) => {
|
[OB11MessageDataType.image]: async (sendMsg, context) => {
|
||||||
const PicEle = await SendMsgElementConstructor.pic(
|
const PicEle = await SendMsgElementConstructor.pic(
|
||||||
(await handleOb11FileLikeMessage(sendMsg, context)).path,
|
(await handleOb11FileLikeMessage(sendMsg, context)).path,
|
||||||
sendMsg.data.summary || '',
|
sendMsg.data.summary || '',
|
||||||
sendMsg.data.subType || 0
|
sendMsg.data.subType || 0
|
||||||
);
|
);
|
||||||
context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath);
|
context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath);
|
||||||
return PicEle;
|
return PicEle;
|
||||||
}
|
}
|
||||||
, // currently not supported
|
, // currently not supported
|
||||||
|
|
||||||
[OB11MessageDataType.file]: async (sendMsg, context) => {
|
[OB11MessageDataType.file]: async (sendMsg, context) => {
|
||||||
const { path, fileName } = await handleOb11FileLikeMessage(sendMsg, context);
|
const { path, fileName } = await handleOb11FileLikeMessage(sendMsg, context);
|
||||||
logDebug('发送文件', path, fileName);
|
//logDebug('发送文件', path, fileName);
|
||||||
return SendMsgElementConstructor.file(path, fileName);
|
return SendMsgElementConstructor.file(path, fileName);
|
||||||
},
|
},
|
||||||
|
|
||||||
[OB11MessageDataType.video]: async (sendMsg, context) => {
|
[OB11MessageDataType.video]: async (sendMsg, context) => {
|
||||||
const { path, fileName } = await handleOb11FileLikeMessage(sendMsg, context);
|
const { path, fileName } = await handleOb11FileLikeMessage(sendMsg, context);
|
||||||
|
|
||||||
logDebug('发送视频', path, fileName);
|
//logDebug('发送视频', path, fileName);
|
||||||
let thumb = sendMsg.data.thumb;
|
let thumb = sendMsg.data.thumb;
|
||||||
if (thumb) {
|
if (thumb) {
|
||||||
const uri2LocalRes = await uri2local(thumb);
|
const uri2LocalRes = await uri2local(thumb);
|
||||||
if (uri2LocalRes.success) thumb = uri2LocalRes.path;
|
if (uri2LocalRes.success) thumb = uri2LocalRes.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SendMsgElementConstructor.video(path, fileName, thumb);
|
return SendMsgElementConstructor.video(path, fileName, thumb);
|
||||||
},
|
},
|
||||||
[OB11MessageDataType.miniapp]: async ({ data: any }) => SendMsgElementConstructor.miniapp(),
|
[OB11MessageDataType.miniapp]: async ({ data: any }) => SendMsgElementConstructor.miniapp(),
|
||||||
|
|
||||||
[OB11MessageDataType.voice]: async (sendMsg, context) =>
|
[OB11MessageDataType.voice]: async (sendMsg, context) =>
|
||||||
SendMsgElementConstructor.ptt((await handleOb11FileLikeMessage(sendMsg, context)).path),
|
SendMsgElementConstructor.ptt((await handleOb11FileLikeMessage(sendMsg, context)).path),
|
||||||
|
|
||||||
[OB11MessageDataType.json]: ({ data: { data } }) => SendMsgElementConstructor.ark(data),
|
[OB11MessageDataType.json]: ({ data: { data } }) => SendMsgElementConstructor.ark(data),
|
||||||
|
|
||||||
[OB11MessageDataType.dice]: ({ data: { result } }) => SendMsgElementConstructor.dice(result),
|
[OB11MessageDataType.dice]: ({ data: { result } }) => SendMsgElementConstructor.dice(result),
|
||||||
|
|
||||||
[OB11MessageDataType.RPS]: ({ data: { result } }) => SendMsgElementConstructor.rps(result),
|
[OB11MessageDataType.RPS]: ({ data: { result } }) => SendMsgElementConstructor.rps(result),
|
||||||
|
|
||||||
[OB11MessageDataType.markdown]: ({ data: { content } }) => SendMsgElementConstructor.markdown(content),
|
[OB11MessageDataType.markdown]: ({ data: { content } }) => SendMsgElementConstructor.markdown(content),
|
||||||
|
|
||||||
[OB11MessageDataType.music]: async ({ data }) => {
|
[OB11MessageDataType.music]: async ({ data }) => {
|
||||||
// 保留, 直到...找到更好的解决方案
|
// 保留, 直到...找到更好的解决方案
|
||||||
if (data.type === 'custom') {
|
if (data.type === 'custom') {
|
||||||
if (!data.url) {
|
if (!data.url) {
|
||||||
logError('自定义音卡缺少参数url');
|
logError('自定义音卡缺少参数url');
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (!data.audio) {
|
if (!data.audio) {
|
||||||
logError('自定义音卡缺少参数audio');
|
logError('自定义音卡缺少参数audio');
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (!data.title) {
|
if (!data.title) {
|
||||||
logError('自定义音卡缺少参数title');
|
logError('自定义音卡缺少参数title');
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!['qq', '163'].includes(data.type)) {
|
if (!['qq', '163'].includes(data.type)) {
|
||||||
logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type);
|
logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (!data.id) {
|
if (!data.id) {
|
||||||
logError('音乐卡片缺少参数id');
|
logError('音乐卡片缺少参数id');
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let postData: IdMusicSignPostData | CustomMusicSignPostData;
|
let postData: IdMusicSignPostData | CustomMusicSignPostData;
|
||||||
if (data.type === 'custom' && data.content) {
|
if (data.type === 'custom' && data.content) {
|
||||||
const { content, ...others } = data;
|
const { content, ...others } = data;
|
||||||
postData = { singer: content, ...others };
|
postData = { singer: content, ...others };
|
||||||
} else {
|
} else {
|
||||||
postData = data;
|
postData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const signUrl = ob11Config.musicSignUrl;
|
const signUrl = ob11Config.musicSignUrl;
|
||||||
if (!signUrl) {
|
if (!signUrl) {
|
||||||
throw Error('音乐消息签名地址未配置');
|
throw Error('音乐消息签名地址未配置');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const musicJson = await RequestUtil.HttpGetJson<any>(signUrl, 'POST', postData);
|
const musicJson = await RequestUtil.HttpGetJson<any>(signUrl, 'POST', postData);
|
||||||
return SendMsgElementConstructor.ark(musicJson);
|
return SendMsgElementConstructor.ark(musicJson);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError('生成音乐消息失败', e);
|
logError('生成音乐消息失败', e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
[OB11MessageDataType.node]: () => undefined,
|
[OB11MessageDataType.node]: () => undefined,
|
||||||
|
|
||||||
[OB11MessageDataType.forward]: () => undefined,
|
[OB11MessageDataType.forward]: () => undefined,
|
||||||
|
|
||||||
[OB11MessageDataType.xml]: () => undefined,
|
[OB11MessageDataType.xml]: () => undefined,
|
||||||
|
|
||||||
[OB11MessageDataType.poke]: () => undefined,
|
[OB11MessageDataType.poke]: () => undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlers = <{
|
const handlers = <{
|
||||||
[Key in OB11MessageDataType]: (
|
[Key in OB11MessageDataType]: (
|
||||||
sendMsg: OB11MessageData,
|
sendMsg: OB11MessageData,
|
||||||
context: MessageContext
|
context: MessageContext
|
||||||
) => SendMessageElement | undefined | Promise<SendMessageElement | undefined>
|
) => SendMessageElement | undefined | Promise<SendMessageElement | undefined>
|
||||||
}>_handlers;
|
}>_handlers;
|
||||||
|
|
||||||
export default async function createSendElements(
|
export default async function createSendElements(
|
||||||
messageData: OB11MessageData[],
|
messageData: OB11MessageData[],
|
||||||
group?: Group,
|
group?: Group,
|
||||||
ignoreTypes: OB11MessageDataType[] = []
|
ignoreTypes: OB11MessageDataType[] = []
|
||||||
) {
|
) {
|
||||||
const sendElements: SendMessageElement[] = [];
|
const sendElements: SendMessageElement[] = [];
|
||||||
const deleteAfterSentFiles: string[] = [];
|
const deleteAfterSentFiles: string[] = [];
|
||||||
for (const sendMsg of messageData) {
|
for (const sendMsg of messageData) {
|
||||||
if (ignoreTypes.includes(sendMsg.type)) {
|
if (ignoreTypes.includes(sendMsg.type)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const callResult = await handlers[sendMsg.type](
|
const callResult = await handlers[sendMsg.type](
|
||||||
sendMsg,
|
sendMsg,
|
||||||
{ group, deleteAfterSentFiles }
|
{ group, deleteAfterSentFiles }
|
||||||
);
|
);
|
||||||
if (callResult) sendElements.push(callResult);
|
if (callResult) sendElements.push(callResult);
|
||||||
}
|
}
|
||||||
return { sendElements, deleteAfterSentFiles };
|
return { sendElements, deleteAfterSentFiles };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createSendElementsParallel(
|
export async function createSendElementsParallel(
|
||||||
messageData: OB11MessageData[],
|
messageData: OB11MessageData[],
|
||||||
group?: Group,
|
group?: Group,
|
||||||
ignoreTypes: OB11MessageDataType[] = []
|
ignoreTypes: OB11MessageDataType[] = []
|
||||||
) {
|
) {
|
||||||
const deleteAfterSentFiles: string[] = [];
|
const deleteAfterSentFiles: string[] = [];
|
||||||
const sendElements = <SendMessageElement[]>(
|
const sendElements = <SendMessageElement[]>(
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
||||||
undefined :
|
undefined :
|
||||||
handlers[sendMsg.type](sendMsg, { group, deleteAfterSentFiles }))
|
handlers[sendMsg.type](sendMsg, { group, deleteAfterSentFiles }))
|
||||||
).then(
|
).then(
|
||||||
results => results.filter(
|
results => results.filter(
|
||||||
element => element !== undefined
|
element => element !== undefined
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return { sendElements, deleteAfterSentFiles };
|
return { sendElements, deleteAfterSentFiles };
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ async function cloneMsg(msg: RawMessage): Promise<RawMessage | undefined> {
|
|||||||
peerUid: selfInfo.uid
|
peerUid: selfInfo.uid
|
||||||
};
|
};
|
||||||
|
|
||||||
logDebug('克隆的目标消息', msg);
|
// logDebug('克隆的目标消息', msg);
|
||||||
|
|
||||||
const sendElements: SendMessageElement[] = [];
|
const sendElements: SendMessageElement[] = [];
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ async function cloneMsg(msg: RawMessage): Promise<RawMessage | undefined> {
|
|||||||
logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
logDebug('克隆消息', sendElements);
|
//logDebug('克隆消息', sendElements);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const nodeMsg = await NTQQMsgApi.sendMsg(selfPeer, sendElements, true);
|
const nodeMsg = await NTQQMsgApi.sendMsg(selfPeer, sendElements, true);
|
||||||
@@ -71,7 +71,7 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag
|
|||||||
// 提取消息段,发给自己生成消息id
|
// 提取消息段,发给自己生成消息id
|
||||||
try {
|
try {
|
||||||
const { sendElements } = await createSendElements(normalize(messageNode.data.content), group);
|
const { sendElements } = await createSendElements(normalize(messageNode.data.content), group);
|
||||||
logDebug('开始生成转发节点', sendElements);
|
//logDebug('开始生成转发节点', sendElements);
|
||||||
const sendElementsSplit: SendMessageElement[][] = [];
|
const sendElementsSplit: SendMessageElement[][] = [];
|
||||||
let splitIndex = 0;
|
let splitIndex = 0;
|
||||||
for (const sendElement of sendElements) {
|
for (const sendElement of sendElements) {
|
||||||
@@ -88,7 +88,7 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag
|
|||||||
} else {
|
} else {
|
||||||
sendElementsSplit[splitIndex].push(sendElement);
|
sendElementsSplit[splitIndex].push(sendElement);
|
||||||
}
|
}
|
||||||
logDebug(sendElementsSplit);
|
//logDebug(sendElementsSplit);
|
||||||
}
|
}
|
||||||
// log("分割后的转发节点", sendElementsSplit)
|
// log("分割后的转发节点", sendElementsSplit)
|
||||||
const MsgNodeList: Promise<RawMessage>[] = [];
|
const MsgNodeList: Promise<RawMessage>[] = [];
|
||||||
@@ -100,7 +100,7 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag
|
|||||||
for (const msgNode of MsgNodeList) {
|
for (const msgNode of MsgNodeList) {
|
||||||
const result = await msgNode;
|
const result = await msgNode;
|
||||||
nodeMsgIds.push(result.msgId);
|
nodeMsgIds.push(result.msgId);
|
||||||
logDebug('转发节点生成成功', result.msgId);
|
//logDebug('转发节点生成成功', result.msgId);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logDebug('生成转发消息节点失败', 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);
|
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
|
||||||
if (needSendSelf) {
|
if (needSendSelf) {
|
||||||
logDebug('需要克隆转发消息');
|
//logDebug('需要克隆转发消息');
|
||||||
for (const [index, msg] of nodeMsgArray.entries()) {
|
for (const [index, msg] of nodeMsgArray.entries()) {
|
||||||
if (msg.peerUid !== selfInfo.uid) {
|
if (msg.peerUid !== selfInfo.uid) {
|
||||||
const clonedMsg = await cloneMsg(msg);
|
const clonedMsg = await cloneMsg(msg);
|
||||||
|
@@ -20,7 +20,7 @@ export default class SendLike extends BaseAction<Payload, null> {
|
|||||||
actionName = ActionName.SendLike;
|
actionName = ActionName.SendLike;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
logDebug('点赞参数', payload);
|
//logDebug('点赞参数', payload);
|
||||||
try {
|
try {
|
||||||
const qq = payload.user_id.toString();
|
const qq = payload.user_id.toString();
|
||||||
const friend = await getFriend(qq);
|
const friend = await getFriend(qq);
|
||||||
@@ -31,7 +31,7 @@ export default class SendLike extends BaseAction<Payload, null> {
|
|||||||
uid = friend.uid;
|
uid = friend.uid;
|
||||||
}
|
}
|
||||||
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1);
|
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1);
|
||||||
logDebug('点赞结果', result);
|
//logDebug('点赞结果', result);
|
||||||
if (result.result !== 0) {
|
if (result.result !== 0) {
|
||||||
throw Error(result.errMsg);
|
throw Error(result.errMsg);
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi } from '@/core/apis';
|
|||||||
import createSendElements from '../action/msg/SendMsg/create-send-elements';
|
import createSendElements from '../action/msg/SendMsg/create-send-elements';
|
||||||
|
|
||||||
export type QuickActionEvent = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
export type QuickActionEvent = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
||||||
|
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
||||||
|
|
||||||
interface QuickActionPrivateMessage {
|
interface QuickActionPrivateMessage {
|
||||||
reply?: string;
|
reply?: string;
|
||||||
@@ -97,12 +98,12 @@ export function postOB11Event(msg: QuickActionEvent, reportSelf = false, postWs
|
|||||||
headers,
|
headers,
|
||||||
body: msgStr
|
body: msgStr
|
||||||
}).then(async (res) => {
|
}).then(async (res) => {
|
||||||
logDebug(`新消息事件HTTP上报成功: ${host} `, msgStr);
|
//logDebug(`新消息事件HTTP上报成功: ${host} `, msgStr);
|
||||||
// todo: 处理不够优雅,应该使用高级泛型进行QuickAction类型识别
|
// todo: 处理不够优雅,应该使用高级泛型进行QuickAction类型识别
|
||||||
let resJson: QuickAction;
|
let resJson: QuickAction;
|
||||||
try {
|
try {
|
||||||
resJson = await res.json();
|
resJson = await res.json();
|
||||||
logDebug('新消息事件HTTP上报返回快速操作: ', JSON.stringify(resJson));
|
//logDebug('新消息事件HTTP上报返回快速操作: ', JSON.stringify(resJson));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logDebug('新消息事件HTTP上报没有返回快速操作,不需要处理');
|
logDebug('新消息事件HTTP上报没有返回快速操作,不需要处理');
|
||||||
return;
|
return;
|
||||||
|
@@ -40,7 +40,7 @@ export class ReverseWebsocket {
|
|||||||
try {
|
try {
|
||||||
receiveData = JSON.parse(msg.toString());
|
receiveData = JSON.parse(msg.toString());
|
||||||
echo = receiveData.echo;
|
echo = receiveData.echo;
|
||||||
logDebug('收到反向Websocket消息', receiveData);
|
//logDebug('收到反向Websocket消息', receiveData);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return wsReply(this.websocket!, OB11Response.error('json解析失败,请检查数据格式', 1400, echo));
|
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" />
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
interface ImportMetaEnv {
|
interface ImportMetaEnv {
|
||||||
readonly VITE_APP_TITLE: string
|
VITE_BUILD_TYPE: string
|
||||||
// 更多环境变量...
|
}
|
||||||
}
|
|
||||||
|
interface ImportMeta {
|
||||||
interface ImportMeta {
|
readonly env: ImportMetaEnv
|
||||||
readonly env: ImportMetaEnv
|
}
|
||||||
}
|
|
Reference in New Issue
Block a user