Compare commits

...

10 Commits

Author SHA1 Message Date
手瓜一十雪
c45f0dc289 Merge branch 'main' into newApi 2025-05-18 18:23:37 +08:00
手瓜一十雪
c1a0f8915b docs: mai 2025-05-17 17:54:53 +08:00
Mlikiowa
dcdab8e5a1 release: v4.7.63 2025-05-17 05:09:36 +00:00
手瓜一十雪
eb3278fdab feat: 35184 2025-05-17 11:16:39 +08:00
手瓜一十雪
433ce9caef fix 2025-05-16 21:29:16 +08:00
手瓜一十雪
ba1acd624e feat: 迁移at 消息段 2025-05-16 21:21:22 +08:00
手瓜一十雪
a586796339 feat: 彻底扬了没用的 2025-05-16 21:19:04 +08:00
手瓜一十雪
2016a90198 feat: 测试代码 2025-05-16 21:12:28 +08:00
手瓜一十雪
b4bc4da7fc feat: 测试 2025-05-16 21:04:46 +08:00
手瓜一十雪
52c828192e feat: 斩杀快速操作 CQCode 调整消息和会话Id类型 2025-05-16 20:59:14 +08:00
118 changed files with 433 additions and 783 deletions

View File

@@ -53,6 +53,8 @@ _Modern protocol-side framework implemented based on NTQQ._
+ [AstrBot](https://github.com/AstrBotDevs/AstrBot) 是完美适配本项目的LLM Bot框架 在此推荐一下
+ [MaiBot](https://github.com/MaiM-with-u/MaiBot) 一只赛博群友 麦麦 Bot框架 在此推荐一下
+ 不过最最重要的 还是需要感谢屏幕前的你哦~
---

View File

@@ -4,7 +4,7 @@
"name": "NapCatQQ",
"slug": "NapCat.Framework",
"description": "高性能的 OneBot 11 协议实现",
"version": "4.7.62",
"version": "4.7.63",
"icon": "./logo.png",
"authors": [
{

View File

@@ -2,7 +2,7 @@
"name": "napcat",
"private": true,
"type": "module",
"version": "4.7.62",
"version": "4.7.63",
"scripts": {
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",

View File

@@ -8,12 +8,12 @@ import { pipeline } from 'stream/promises';
import { fileURLToPath } from 'url';
import { LogWrapper } from './log';
const downloadOri = "https://github.com/NapNeko/ffmpeg-build/releases/download/v1.0.0/ffmpeg-7.1.1-win64.zip"
const downloadOri = 'https://github.com/NapNeko/ffmpeg-build/releases/download/v1.0.0/ffmpeg-7.1.1-win64.zip';
const urls = [
"https://github.moeyy.xyz/" + downloadOri,
"https://ghp.ci/" + downloadOri,
"https://gh.api.99988866.xyz/" + downloadOri,
"https://gh.api.99988866.xyz/" + downloadOri,
'https://github.moeyy.xyz/' + downloadOri,
'https://ghp.ci/' + downloadOri,
'https://gh.api.99988866.xyz/' + downloadOri,
'https://gh.api.99988866.xyz/' + downloadOri,
downloadOri
];
@@ -350,11 +350,11 @@ export async function downloadFFmpegIfNotExists(log: LogWrapper) {
return {
path: path.join(currentPath, 'ffmpeg'),
reset: true
}
};
}
return {
path: path.join(currentPath, 'ffmpeg'),
reset: true
}
};
}

View File

@@ -182,28 +182,28 @@ export async function uriToLocalFile(dir: string, uri: string, filename: string
const filePath = path.join(dir, filename);
switch (UriType) {
case FileUriType.Local: {
const fileExt = path.extname(HandledUri);
const localFileName = path.basename(HandledUri, fileExt) + fileExt;
const tempFilePath = path.join(dir, filename + fileExt);
fs.copyFileSync(HandledUri, tempFilePath);
return { success: true, errMsg: '', fileName: localFileName, path: tempFilePath };
}
case FileUriType.Local: {
const fileExt = path.extname(HandledUri);
const localFileName = path.basename(HandledUri, fileExt) + fileExt;
const tempFilePath = path.join(dir, filename + fileExt);
fs.copyFileSync(HandledUri, tempFilePath);
return { success: true, errMsg: '', fileName: localFileName, path: tempFilePath };
}
case FileUriType.Remote: {
const buffer = await httpDownload({ url: HandledUri, headers: headers ?? {} });
fs.writeFileSync(filePath, buffer);
return { success: true, errMsg: '', fileName: filename, path: filePath };
}
case FileUriType.Remote: {
const buffer = await httpDownload({ url: HandledUri, headers: headers ?? {} });
fs.writeFileSync(filePath, buffer);
return { success: true, errMsg: '', fileName: filename, path: filePath };
}
case FileUriType.Base64: {
const base64 = HandledUri.replace(/^base64:\/\//, '');
const base64Buffer = Buffer.from(base64, 'base64');
fs.writeFileSync(filePath, base64Buffer);
return { success: true, errMsg: '', fileName: filename, path: filePath };
}
case FileUriType.Base64: {
const base64 = HandledUri.replace(/^base64:\/\//, '');
const base64Buffer = Buffer.from(base64, 'base64');
fs.writeFileSync(filePath, base64Buffer);
return { success: true, errMsg: '', fileName: filename, path: filePath };
}
default:
return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' };
default:
return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' };
}
}

View File

@@ -1,6 +1,4 @@
import { Peer } from '@/core';
import crypto from 'crypto';
export class LimitedHashTable<K, V> {
private readonly keyToValue: Map<K, V> = new Map();
private readonly valueToKey: Map<V, K> = new Map();
@@ -78,65 +76,19 @@ export class LimitedHashTable<K, V> {
}
class MessageUniqueWrapper {
private readonly msgDataMap: LimitedHashTable<string, number>;
private readonly msgIdMap: LimitedHashTable<string, number>;
constructor(maxMap: number = 5000) {
this.msgIdMap = new LimitedHashTable<string, number>(maxMap);
this.msgDataMap = new LimitedHashTable<string, number>(maxMap);
constructor() {
}
getRecentMsgIds(Peer: Peer, size: number): string[] {
const heads = this.msgIdMap.getHeads(size);
if (!heads) {
return [];
getOutputData(peer: Peer, msg_id: string, seq: string): string {
return `${peer.chatType}|${msg_id}|${peer.peerUid}|${seq}`;
}
getInnerData(shortId: string): { MsgId: string; Peer: Peer, seq: string } | undefined {
const [chatType, msgId, peerUid, seq] = shortId.split('|');
if (!chatType || !msgId || !peerUid || !seq) {
return undefined;
}
const data = heads.map((t) => MessageUnique.getMsgIdAndPeerByShortId(t.value));
const ret = data.filter((t) => t?.Peer.chatType === Peer.chatType && t?.Peer.peerUid === Peer.peerUid);
return ret.map((t) => t?.MsgId).filter((t) => t !== undefined);
}
createUniqueMsgId(peer: Peer, msgId: string) {
const key = `${msgId}|${peer.chatType}|${peer.peerUid}`;
const hash = crypto.createHash('md5').update(key).digest();
if (hash[0]) {
//设置第一个bit为0 保证shortId为正数
hash[0] &= 0x7f;
}
const shortId = hash.readInt32BE(0);
//减少性能损耗
this.msgIdMap.set(msgId, shortId);
this.msgDataMap.set(key, shortId);
return shortId;
}
getMsgIdAndPeerByShortId(shortId: number): { MsgId: string; Peer: Peer } | undefined {
const data = this.msgDataMap.getKey(shortId);
if (data) {
const [msgId, chatTypeStr, peerUid] = data.split('|');
const peer: Peer = {
chatType: parseInt(chatTypeStr ?? '0'),
peerUid: peerUid ?? '',
guildId: '',
};
return { MsgId: msgId ?? '0', Peer: peer };
}
return undefined;
}
getShortIdByMsgId(msgId: string): number | undefined {
return this.msgIdMap.getValue(msgId);
}
getPeerByMsgId(msgId: string) {
const shortId = this.msgIdMap.getValue(msgId);
if (!shortId) return undefined;
return this.getMsgIdAndPeerByShortId(shortId);
}
resize(maxSize: number): void {
this.msgIdMap.resize(maxSize);
this.msgDataMap.resize(maxSize);
return { MsgId: msgId, Peer: { chatType: parseInt(chatType), peerUid, guildId: '' }, seq: seq };
}
}

View File

@@ -1 +1 @@
export const napCatVersion = '4.7.62';
export const napCatVersion = '4.7.63';

View File

@@ -9,7 +9,7 @@ export async function runTask<T, R>(workerScript: string, taskData: T): Promise<
console.error('Worker Log--->:', (result as { log: string }).log);
}
if ((result as any)?.error) {
reject(new Error("Worker error: " + (result as { error: string }).error));
reject(new Error('Worker error: ' + (result as { error: string }).error));
}
resolve(result);
});

View File

@@ -45,7 +45,7 @@ export class NTQQFileApi {
'https://secret-service.bietiaop.com/rkeys',
'http://ss.xingzhige.com/music_card/rkey',
],
this.context.logger
this.context.logger
);
}
@@ -379,18 +379,18 @@ export class NTQQFileApi {
element.elementType === ElementType.FILE
) {
switch (element.elementType) {
case ElementType.PIC:
case ElementType.PIC:
element.picElement!.sourcePath = elementResults?.[elementIndex] ?? '';
break;
case ElementType.VIDEO:
break;
case ElementType.VIDEO:
element.videoElement!.filePath = elementResults?.[elementIndex] ?? '';
break;
case ElementType.PTT:
break;
case ElementType.PTT:
element.pttElement!.filePath = elementResults?.[elementIndex] ?? '';
break;
case ElementType.FILE:
break;
case ElementType.FILE:
element.fileElement!.filePath = elementResults?.[elementIndex] ?? '';
break;
break;
}
elementIndex++;
}

View File

@@ -110,7 +110,7 @@ export class NTQQFriendApi {
time: item.reqTime, // 信息字段
type: 'doubt' //保留字段
};
}))
}));
return requests;
}
}

View File

@@ -286,5 +286,13 @@
"9.9.19-34958": {
"appid": 537290742,
"qua": "V1_WIN_NQ_9.9.19_34958_GW_B"
},
"3.2.17-35184": {
"appid": 537291084,
"qua": "V1_LNX_NQ_3.2.17_35184_GW_B"
},
"9.9.19-35184": {
"appid": 537291048,
"qua": "V1_WIN_NQ_9.9.19_35184_GW_B"
}
}

View File

@@ -366,5 +366,17 @@
"9.9.19-34958-x64": {
"send": "3BDD8D0",
"recv": "3BE20D0"
},
"3.2.17-35184-x64": {
"send": "AE0DDE0",
"recv": "AE11800"
},
"3.2.17-35184-arm64": {
"send": "7776028",
"recv": "7779958"
},
"9.9.19-35184-x64": {
"send": "3BE5A10",
"recv": "3BEA210"
}
}

View File

@@ -185,9 +185,9 @@ export class PacketOperationContext {
const ps = msg.map((m) => {
return m.msg.map(async (e) => {
if (e instanceof PacketMsgReplyElement && !e.targetElems) {
this.context.logger.debug(`Cannot find reply element's targetElems, prepare to fetch it...`);
this.context.logger.debug('Cannot find reply element\'s targetElems, prepare to fetch it...');
if (!e.targetPeer?.peerUid) {
this.context.logger.error(`targetPeer is undefined!`);
this.context.logger.error('targetPeer is undefined!');
}
let targetMsg: NapProtoEncodeStructType<typeof PushMsgBody>[] | undefined;
if (e.isGroupReply) {
@@ -200,7 +200,7 @@ export class PacketOperationContext {
}
});
}).flat();
await Promise.all(ps)
await Promise.all(ps);
await this.UploadResources(msg, groupUin);
}
@@ -208,14 +208,14 @@ export class PacketOperationContext {
const req = trans.FetchGroupMessage.build(groupUin, startSeq, endSeq);
const resp = await this.context.client.sendOidbPacket(req, true);
const res = trans.FetchGroupMessage.parse(resp);
return res.body.messages
return res.body.messages;
}
async FetchC2CMessage(targetUid: string, startSeq: number, endSeq: number): Promise<NapProtoDecodeStructType<typeof PushMsgBody>[]> {
const req = trans.FetchC2CMessage.build(targetUid, startSeq, endSeq);
const resp = await this.context.client.sendOidbPacket(req, true);
const res = trans.FetchC2CMessage.parse(resp);
return res.messages
return res.messages;
}
async UploadForwardMsg(msg: PacketMsg[], groupUin: number = 0) {

View File

@@ -477,7 +477,7 @@ export enum SendStatusType {
export interface RawMessage {
parentMsgPeer: Peer; // 父消息的Peer
parentMsgIdList: string[];// 父消息 ID 列表
id?: number;// 扩展字段,与 Ob11 msg ID 有关
id?: string;// 扩展字段,与 Ob11 msg ID 有关
guildId: string;// 频道ID
msgRandom: string;// 消息ID相关
msgId: string;// 雪花ID

View File

@@ -3,7 +3,7 @@ import { OneBotAction } from '../OneBotAction';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
bot_appid: Type.String(),
button_id: Type.String({ default: '' }),
callback_data: Type.String({ default: '' }),
@@ -25,6 +25,6 @@ export class ClickInlineKeyboardButton extends OneBotAction<Payload, unknown> {
callback_data: payload.callback_data,
dmFlag: 0,
chatType: 2
})
});
}
}

View File

@@ -3,7 +3,7 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
import { ActionName } from '@/onebot/action/router';
const SchemaData = Type.Object({
count: Type.Union([Type.Number(), Type.String()], { default: 48 }),
count: Type.Number({ default: 48 }),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -5,7 +5,7 @@ import { MessageUnique } from '@/common/message-unique';
import { type NTQQMsgApi } from '@/core/apis';
const SchemaData = Type.Object({
message_id: Type.Union([Type.Number(), Type.String()]),
message_id: Type.String(),
emojiId: Type.Union([Type.Number(), Type.String()]),
emojiType: Type.Union([Type.Number(), Type.String()]),
count: Type.Union([Type.Number(), Type.String()], { default: 20 }),
@@ -18,7 +18,7 @@ export class FetchEmojiLike extends OneBotAction<Payload, Awaited<ReturnType<NTQ
override payloadSchema = SchemaData;
async _handle(payload: Payload) {
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
const msgIdPeer = MessageUnique.getInnerData(payload.message_id);
if (!msgIdPeer) throw new Error('消息不存在');
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
if (!msg) throw new Error('消息不存在');

View File

@@ -4,7 +4,7 @@ import { AIVoiceChatType } from '@/core/packet/entities/aiChat';
import { Type, Static } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
chat_type: Type.Union([Type.Union([Type.Number(), Type.String()])], { default: 1 }),
});

View File

@@ -4,8 +4,8 @@ import { ActionName } from '@/onebot/action/router';
import { Type, Static } from '@sinclair/typebox';
const SchemaData = Type.Object({
category: Type.Union([Type.Number(), Type.String()]),
count: Type.Union([Type.Union([Type.Number(), Type.String()])], { default: 1 }),
category: Type.Number({ default: 0 }),
count: Type.Number({ default: 1 }),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -2,7 +2,7 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
import { ActionName } from '@/onebot/action/router';
import { Type, Static } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -4,9 +4,9 @@ import { ActionName } from '@/onebot/action/router';
import { Type, Static } from '@sinclair/typebox';
const SchemaData = Type.Object({
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
start: Type.Union([Type.Number(), Type.String()], { default: 0 }),
count: Type.Union([Type.Number(), Type.String()], { default: 10 })
user_id: Type.Optional(Type.String()),
start: Type.String({ default: '0' }),
count: Type.String({ default: '10' })
});
type Payload = Static<typeof SchemaData>;

View File

@@ -36,7 +36,7 @@ export class GetUnidirectionalFriendList extends OneBotAction<void, Friend[]> {
uint64_uin: self_id,
uint64_top: 0,
uint32_req_num: 99,
bytes_cookies: ""
bytes_cookies: ''
};
const packed_data = await this.pack_data(JSON.stringify(req_json));
const data = Buffer.from(packed_data).toString('hex');

View File

@@ -3,7 +3,7 @@ import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -4,7 +4,7 @@ import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
file_id: Type.String(),
current_parent_directory: Type.String(),
target_parent_directory: Type.String(),

View File

@@ -4,7 +4,7 @@ import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
file_id: Type.String(),
current_parent_directory: Type.String(),
new_name: Type.String(),

View File

@@ -3,8 +3,8 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
face_id: Type.Union([Type.Number(), Type.String()]),// 参考 face_config.json 的 QSid
face_type: Type.Union([Type.Number(), Type.String()], { default: '1' }),
face_id: Type.String(),// 参考 face_config.json 的 QSid
face_type: Type.String({ default: '1' }),
wording: Type.String({ default: ' ' }),
});
@@ -16,9 +16,9 @@ export class SetDiyOnlineStatus extends OneBotAction<Payload, string> {
async _handle(payload: Payload) {
const ret = await this.core.apis.UserApi.setDiySelfOnlineStatus(
payload.face_id.toString(),
payload.face_id,
payload.wording,
payload.face_type.toString(),
payload.face_type,
);
if (ret.result !== 0) {
throw new Error('设置在线状态失败');

View File

@@ -3,7 +3,7 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -4,7 +4,7 @@ import { ChatType } from '@/core';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.String(),
event_type: Type.Number(),
});

View File

@@ -3,9 +3,9 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
status: Type.Union([Type.Number(), Type.String()]),
ext_status: Type.Union([Type.Number(), Type.String()]),
battery_status: Type.Union([Type.Number(), Type.String()]),
status: Type.Number(),
ext_status: Type.Number(),
battery_status: Type.Number(),
});
type Payload = Static<typeof SchemaData>;
@@ -16,9 +16,9 @@ export class SetOnlineStatus extends OneBotAction<Payload, null> {
async _handle(payload: Payload) {
const ret = await this.core.apis.UserApi.setSelfOnlineStatus(
+payload.status,
+payload.ext_status,
+payload.battery_status,
payload.status,
payload.ext_status,
payload.battery_status,
);
if (ret.result !== 0) {
throw new Error('设置在线状态失败');

View File

@@ -3,8 +3,8 @@ import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
user_id: Type.String(),
special_title: Type.String({ default: '' }),
});

View File

@@ -4,8 +4,8 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
user_id: Type.Optional(Type.String()),
group_id: Type.Optional(Type.String()),
phoneNumber: Type.String({ default: '' }),
});
@@ -29,7 +29,7 @@ export class SharePeer extends OneBotAction<Payload, GeneralCallResult & {
}
const SchemaDataGroupEx = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
});
type PayloadGroupEx = Static<typeof SchemaDataGroupEx>;

View File

@@ -4,7 +4,7 @@ import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
file_id: Type.String(),
});

View File

@@ -4,7 +4,7 @@ import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
file_id: Type.String(),
});

View File

@@ -3,7 +3,7 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
folder_name: Type.String(),
});

View File

@@ -6,7 +6,7 @@ import { Static, Type } from '@sinclair/typebox';
import { NTQQGroupApi } from '@/core/apis';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
file_id: Type.String(),
});

View File

@@ -4,7 +4,7 @@ import { Static, Type } from '@sinclair/typebox';
import { NTQQGroupApi } from '@/core/apis';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
folder_id: Type.Optional(Type.String()),
folder: Type.Optional(Type.String()),
});

View File

@@ -117,8 +117,7 @@ export class GoCQHTTPGetForwardMsgAction extends OneBotAction<Payload, {
}
throw new Error('ResId无效: 找不到相关的聊天记录');
}
const rootMsgId = MessageUnique.getShortIdByMsgId(msgId.toString());
const rootMsg = MessageUnique.getMsgIdAndPeerByShortId(rootMsgId ?? +msgId);
const rootMsg = MessageUnique.getInnerData(msgId);
if (rootMsg) {
// 5. 获取消息内容

View File

@@ -12,7 +12,7 @@ interface Response {
}
const SchemaData = Type.Object({
user_id: Type.String(),
message_seq: Type.Optional(Type.String()),
message_id: Type.Optional(Type.String()),
count: Type.Number({ default: 20 }),
reverseOrder: Type.Boolean({ default: false })
});
@@ -24,24 +24,24 @@ export default class GetFriendMsgHistory extends OneBotAction<Payload, Response>
override actionName = ActionName.GetFriendMsgHistory;
override payloadSchema = SchemaData;
async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig): Promise<Response> {
async _handle(payload: Payload, _adapter: string, _config: NetworkAdapterConfig): Promise<Response> {
//处理参数
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error(`记录${payload.user_id}不存在`);
const friend = await this.core.apis.FriendApi.isBuddy(uid);
const peer = { chatType: friend ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid: uid };
const hasMessageSeq = !payload.message_seq ? !!payload.message_seq : !(payload.message_seq?.toString() === '' || payload.message_seq?.toString() === '0');
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
const msgList = hasMessageSeq ?
const hasMessageId = !payload.message_id ? !!payload.message_id : !(payload.message_id?.toString() === '' || payload.message_id?.toString() === '0');
const startMsgId = hasMessageId ? (MessageUnique.getInnerData(payload.message_id!)?.MsgId ?? payload.message_id!.toString()) : '0';
const msgList = hasMessageId ?
(await this.core.apis.MsgApi.getMsgHistory(peer, startMsgId, +payload.count, payload.reverseOrder)).msgList : (await this.core.apis.MsgApi.getAioFirstViewLatestMsgs(peer, +payload.count)).msgList;
if (msgList.length === 0) throw new Error(`消息${payload.message_seq}不存在`);
if (msgList.length === 0) throw new Error(`消息${payload.message_id}不存在`);
//转换序号
await Promise.all(msgList.map(async msg => {
msg.id = MessageUnique.createUniqueMsgId({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
msg.id = MessageUnique.getOutputData({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId, msg.msgSeq);
}));
//烘焙消息
const ob11MsgList = (await Promise.all(
msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat)))
msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg)))
).filter(msg => msg !== undefined);
return { 'messages': ob11MsgList };
}

View File

@@ -3,7 +3,7 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()])
group_id: Type.String()
});
type Payload = Static<typeof SchemaData>;

View File

@@ -3,7 +3,7 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()])
group_id: Type.String()
});
type Payload = Static<typeof SchemaData>;

View File

@@ -5,7 +5,7 @@ import { OB11Construct } from '@/onebot/helper/data';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
folder_id: Type.Optional(Type.String()),
folder: Type.Optional(Type.String()),
file_count: Type.Union([Type.Number(), Type.String()], { default: 50 }),

View File

@@ -4,7 +4,7 @@ import { WebHonorType } from '@/core/types';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
type: Type.Optional(Type.Enum(WebHonorType))
});

View File

@@ -4,15 +4,13 @@ import { ActionName } from '@/onebot/action/router';
import { ChatType, Peer } from '@/core/types';
import { MessageUnique } from '@/common/message-unique';
import { Static, Type } from '@sinclair/typebox';
import { NetworkAdapterConfig } from '@/onebot/config/config';
interface Response {
messages: OB11Message[];
}
const SchemaData = Type.Object({
group_id: Type.String(),
message_seq: Type.Optional(Type.String()),
message_id: Type.Optional(Type.String()),
count: Type.Number({ default: 20 }),
reverseOrder: Type.Boolean({ default: false })
});
@@ -25,21 +23,21 @@ export default class GoCQHTTPGetGroupMsgHistory extends OneBotAction<Payload, Re
override actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
override payloadSchema = SchemaData;
async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig): Promise<Response> {
async _handle(payload: Payload, _adapter: string): Promise<Response> {
const peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
const hasMessageSeq = !payload.message_seq ? !!payload.message_seq : !(payload.message_seq?.toString() === '' || payload.message_seq?.toString() === '0');
const hasMessageSeq = !payload.message_id ? !!payload.message_id : !(payload.message_id?.toString() === '' || payload.message_id?.toString() === '0');
//拉取消息
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
const startMsgId = hasMessageSeq ? (MessageUnique.getInnerData(payload.message_id!)?.MsgId ?? payload.message_id!.toString()) : '0';
const msgList = hasMessageSeq ?
(await this.core.apis.MsgApi.getMsgHistory(peer, startMsgId, +payload.count, payload.reverseOrder)).msgList : (await this.core.apis.MsgApi.getAioFirstViewLatestMsgs(peer, +payload.count)).msgList;
if (msgList.length === 0) throw new Error(`消息${payload.message_seq}不存在`);
if (msgList.length === 0) throw new Error(`消息${payload.message_id}不存在`);
//转换序号
await Promise.all(msgList.map(async msg => {
msg.id = MessageUnique.createUniqueMsgId({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
msg.id = MessageUnique.getOutputData({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId, msg.msgSeq);
}));
//烘焙消息
const ob11MsgList = (await Promise.all(
msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat)))
msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg)))
).filter(msg => msg !== undefined);
return { 'messages': ob11MsgList };
}

View File

@@ -6,7 +6,7 @@ import { OB11Construct } from '@/onebot/helper/data';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
file_count: Type.Union([Type.Number(), Type.String()], { default: 50 }),
});

View File

@@ -6,7 +6,7 @@ import { calcQQLevel } from '@/common/helper';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.String(),
no_cache: Type.Union([Type.Boolean(), Type.String()], { default: false }),
});
@@ -28,7 +28,7 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11U
...extendData.detail.simpleInfo.baseInfo,
...extendData.detail.simpleInfo.relationFlags ?? {},
...extendData.detail.simpleInfo.status ?? {},
user_id: parseInt(extendData.detail.uin) ?? 0,
user_id: extendData.detail.uin ?? 0,
uid: info.uid ?? uid,
nickname: extendData.detail.simpleInfo.coreInfo.nick ?? '',
age: extendData.detail.simpleInfo.baseInfo.age ?? info.age,

View File

@@ -3,8 +3,8 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
friend_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
user_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
friend_id: Type.Optional(Type.String()),
user_id: Type.Optional(Type.String()),
temp_block: Type.Optional(Type.Boolean()),
temp_both_del: Type.Optional(Type.Boolean()),
});

View File

@@ -1,19 +0,0 @@
import { OneBotAction } from '@/onebot/action/OneBotAction';
import { ActionName } from '@/onebot/action/router';
import { QuickAction, QuickActionEvent } from '@/onebot/types';
interface Payload {
context: QuickActionEvent,
operation: QuickAction
}
export class GoCQHTTPHandleQuickAction extends OneBotAction<Payload, null> {
override actionName = ActionName.GoCQHTTP_HandleQuickAction;
async _handle(payload: Payload): Promise<null> {
this.obContext.apis.QuickActionApi
.handleQuickOperation(payload.context, payload.operation)
.catch(e => this.core.context.logger.logError(e));
return null;
}
}

View File

@@ -5,7 +5,7 @@ import { unlink } from 'node:fs/promises';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
content: Type.String(),
image: Type.Optional(Type.String()),
pinned: Type.Union([Type.Number(), Type.String()], { default: 0 }),

View File

@@ -6,7 +6,7 @@ import fs from 'node:fs/promises';
import { GeneralCallResult } from '@/core';
const SchemaData = Type.Object({
file: Type.String(),
group_id: Type.Union([Type.Number(), Type.String()])
group_id: Type.String()
});
type Payload = Static<typeof SchemaData>;

View File

@@ -7,7 +7,7 @@ import { SendMessageContext } from '@/onebot/api';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
file: Type.String(),
name: Type.String(),
folder: Type.Optional(Type.String()),

View File

@@ -8,7 +8,7 @@ import { ContextMode, createContext } from '@/onebot/action/msg/SendMsg';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.String(),
file: Type.String(),
name: Type.String(),
});

View File

@@ -4,7 +4,7 @@ import { MessageUnique } from '@/common/message-unique';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
message_id: Type.Union([Type.Number(), Type.String()]),
message_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
@@ -13,7 +13,7 @@ export default class DelEssenceMsg extends OneBotAction<Payload, unknown> {
override payloadSchema = SchemaData;
async _handle(payload: Payload): Promise<unknown> {
const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
const msg = MessageUnique.getInnerData(payload.message_id);
if (!msg) {
const data = this.core.apis.GroupApi.essenceLRU.getValue(+payload.message_id);
if(!data) throw new Error('消息不存在');

View File

@@ -3,7 +3,7 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
notice_id: Type.String()
});

View File

@@ -5,7 +5,7 @@ import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
character: Type.String(),
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
text: Type.String(),
});

View File

@@ -4,10 +4,8 @@ import { ActionName } from '@/onebot/action/router';
import { MessageUnique } from '@/common/message-unique';
import crypto from 'crypto';
import { Static, Type } from '@sinclair/typebox';
import { NetworkAdapterConfig } from '@/onebot/config/config';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
@@ -22,12 +20,12 @@ export class GetGroupEssence extends OneBotAction<Payload, unknown> {
return undefined;
}
return {
id: MessageUnique.createUniqueMsgId(peer, replyMsgList.msgId),
id: MessageUnique.getOutputData(peer, replyMsgList.msgId, replyMsgList.msgSeq),
msg: replyMsgList
};
}
async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig) {
async _handle(payload: Payload, _adapter: string) {
const msglist = (await this.core.apis.WebApi.getGroupEssenceMsgAll(payload.group_id.toString())).flatMap((e) => e.data.msg_list);
if (!msglist) {
throw new Error('获取失败');
@@ -48,7 +46,7 @@ export class GetGroupEssence extends OneBotAction<Payload, unknown> {
operator_nick: msg.add_digest_nick,
message_id: message_id,
operator_time: msg.add_digest_time,
content: (await this.obContext.apis.MsgApi.parseMessage(rawMessage, config.messagePostFormat))?.message
content: (await this.obContext.apis.MsgApi.parseMessage(rawMessage))?.message
};
}
const msgTempData = JSON.stringify({

View File

@@ -5,7 +5,7 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -5,8 +5,8 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
user_id: Type.String(),
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
});

View File

@@ -6,7 +6,7 @@ import { Static, Type } from '@sinclair/typebox';
import { GroupMember } from '@/core';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
});

View File

@@ -17,7 +17,7 @@ interface GroupNotice {
}
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -4,7 +4,7 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -3,8 +3,8 @@ import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
user_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -5,7 +5,7 @@ import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
character: Type.String(),
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
text: Type.String(),
});

View File

@@ -4,7 +4,7 @@ import { MessageUnique } from '@/common/message-unique';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
message_id: Type.Union([Type.Number(), Type.String()]),
message_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
@@ -14,7 +14,7 @@ export default class SetEssenceMsg extends OneBotAction<Payload, unknown> {
override payloadSchema = SchemaData;
async _handle(payload: Payload) {
const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
const msg = MessageUnique.getInnerData(payload.message_id);
if (!msg) {
throw new Error('msg not found');
}

View File

@@ -4,8 +4,8 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
user_id: Type.String(),
enable: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
});

View File

@@ -3,9 +3,9 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.Union([Type.Number(), Type.String()]),
duration: Type.Union([Type.Number(), Type.String()], { default: 0 }),
group_id: Type.String(),
user_id: Type.String(),
duration: Type.String({ default: '0' }),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -3,8 +3,8 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
user_id: Type.String(),
card: Type.Optional(Type.String())
});

View File

@@ -3,8 +3,8 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
user_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
user_id: Type.String(),
reject_add_request: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
});

View File

@@ -3,7 +3,7 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
is_dismiss: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
});

View File

@@ -4,7 +4,7 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
group_name: Type.String(),
});

View File

@@ -3,7 +3,7 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.String(),
enable: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
});

View File

@@ -30,7 +30,6 @@ import SetGroupAdmin from './group/SetGroupAdmin';
import SetGroupCard from './group/SetGroupCard';
import GetImage from './file/GetImage';
import GetRecord from './file/GetRecord';
import { GoCQHTTPMarkMsgAsRead, MarkAllMsgAsRead, MarkGroupMsgAsRead, MarkPrivateMsgAsRead } from './msg/MarkMsgAsRead';
import GoCQHTTPUploadGroupFile from './go-cqhttp/UploadGroupFile';
import SetQQAvatar from '@/onebot/action/extends/SetQQAvatar';
import GoCQHTTPDownloadFile from './go-cqhttp/DownloadFile';
@@ -48,7 +47,6 @@ import { ForwardFriendSingleMsg, ForwardGroupSingleMsg } from '@/onebot/action/m
import { GetFriendWithCategory } from './extends/GetFriendWithCategory';
import { SendGroupNotice } from './go-cqhttp/SendGroupNotice';
import { GetGroupHonorInfo } from './go-cqhttp/GetGroupHonorInfo';
import { GoCQHTTPHandleQuickAction } from './go-cqhttp/QuickAction';
import { GetGroupIgnoredNotifies } from './group/GetGroupIgnoredNotifies';
import { GetOnlineClient } from './go-cqhttp/GetOnlineClient';
import { IOCRImage, OCRImage } from './extends/OCRImage';
@@ -138,8 +136,6 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
new SetLongNick(obContext, core),
new ForwardFriendSingleMsg(obContext, core),
new ForwardGroupSingleMsg(obContext, core),
new MarkGroupMsgAsRead(obContext, core),
new MarkPrivateMsgAsRead(obContext, core),
new SetQQAvatar(obContext, core),
new TranslateEnWordToZn(obContext, core),
new GetGroupRootFiles(obContext, core),
@@ -199,17 +195,14 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
new GoCQHTTPGetStrangerInfo(obContext, core),
new GoCQHTTPDownloadFile(obContext, core),
new GetGuildList(obContext, core),
new GoCQHTTPMarkMsgAsRead(obContext, core),
new GoCQHTTPUploadGroupFile(obContext, core),
new GoCQHTTPGetGroupMsgHistory(obContext, core),
new GoCQHTTPGetForwardMsgAction(obContext, core),
new GetFriendMsgHistory(obContext, core),
new GoCQHTTPHandleQuickAction(obContext, core),
new GetGroupIgnoredNotifies(obContext, core),
new DelEssenceMsg(obContext, core),
new SetEssenceMsg(obContext, core),
new GetRecentContact(obContext, core),
new MarkAllMsgAsRead(obContext, core),
new GetProfileLike(obContext, core),
new SetGroupPortrait(obContext, core),
new FetchCustomFace(obContext, core),

View File

@@ -4,7 +4,7 @@ import { MessageUnique } from '@/common/message-unique';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
message_id: Type.Union([Type.Number(), Type.String()]),
message_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
@@ -14,7 +14,7 @@ class DeleteMsg extends OneBotAction<Payload, void> {
override payloadSchema = SchemaData;
async _handle(payload: Payload) {
const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id));
const msg = MessageUnique.getInnerData(payload.message_id);
if (msg) {
await this.core.apis.MsgApi.recallMsg(msg.Peer, msg.MsgId);
} else {

View File

@@ -5,9 +5,9 @@ import { MessageUnique } from '@/common/message-unique';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
message_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
message_id: Type.String(),
group_id: Type.Optional(Type.String()),
user_id: Type.Optional(Type.String()),
});
type Payload = Static<typeof SchemaData>;
@@ -25,7 +25,7 @@ class ForwardSingleMsg extends OneBotAction<Payload, null> {
}
async _handle(payload: Payload): Promise<null> {
const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
const msg = MessageUnique.getInnerData(payload.message_id);
if (!msg) {
throw new Error(`无法找到消息${payload.message_id}`);
}

View File

@@ -4,12 +4,10 @@ import { ActionName } from '@/onebot/action/router';
import { MessageUnique } from '@/common/message-unique';
import { RawMessage } from '@/core';
import { Static, Type } from '@sinclair/typebox';
import { NetworkAdapterConfig } from '@/onebot/config/config';
export type ReturnDataType = OB11Message
const SchemaData = Type.Object({
message_id: Type.Union([Type.Number(), Type.String()]),
message_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
@@ -18,30 +16,27 @@ class GetMsg extends OneBotAction<Payload, OB11Message> {
override actionName = ActionName.GetMsg;
override payloadSchema = SchemaData;
async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig) {
async _handle(payload: Payload, _adapter: string) {
if (!payload.message_id) {
throw Error('参数message_id不能为空');
}
const MsgShortId = MessageUnique.getShortIdByMsgId(payload.message_id.toString());
const msgIdWithPeer = MessageUnique.getMsgIdAndPeerByShortId(MsgShortId ?? +payload.message_id);
const msgIdWithPeer = MessageUnique.getInnerData(payload.message_id);
if (!msgIdWithPeer) {
throw new Error('消息不存在');
}
const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType };
const orimsg = this.obContext.recallMsgCache.get(msgIdWithPeer.MsgId);
let msg: RawMessage|undefined;
let msg: RawMessage | undefined;
if (orimsg) {
msg = orimsg;
} else {
msg = (await this.core.apis.MsgApi.getMsgsByMsgId(peer, [msgIdWithPeer?.MsgId || payload.message_id.toString()])).msgList[0];
}
if (!msg) throw Error('消息不存在');
const retMsg = await this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat);
const retMsg = await this.obContext.apis.MsgApi.parseMessage(msg);
if (!retMsg) throw Error('消息为空');
try {
retMsg.message_id = MessageUnique.createUniqueMsgId(peer, msg.msgId)!;
retMsg.message_seq = retMsg.message_id;
retMsg.real_id = retMsg.message_id;
retMsg.message_id = MessageUnique.getOutputData(peer, msg.msgId, msg.msgSeq)!;
} catch {
// ignored
}

View File

@@ -1,72 +0,0 @@
import { ChatType, Peer } from '@/core/types';
import { OneBotAction } from '@/onebot/action/OneBotAction';
import { ActionName } from '@/onebot/action/router';
import { MessageUnique } from '@/common/message-unique';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
user_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
group_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
message_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
});
type PlayloadType = Static<typeof SchemaData>;
class MarkMsgAsRead extends OneBotAction<PlayloadType, null> {
async getPeer(payload: PlayloadType): Promise<Peer> {
if (payload.message_id) {
const s_peer = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id)?.Peer;
if (s_peer) {
return s_peer;
}
const l_peer = MessageUnique.getPeerByMsgId(payload.message_id.toString())?.Peer;
if (l_peer) {
return l_peer;
}
}
if (payload.user_id) {
const peerUid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!peerUid) {
throw new Error( `私聊${payload.user_id}不存在`);
}
const isBuddy = await this.core.apis.FriendApi.isBuddy(peerUid);
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
}
if (!payload.group_id) {
throw new Error('缺少参数 group_id 或 user_id');
}
return { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
}
async _handle(payload: PlayloadType): Promise<null> {
const ret = await this.core.apis.MsgApi.setMsgRead(await this.getPeer(payload));
if (ret.result != 0) {
throw new Error('设置已读失败,' + ret.errMsg);
}
return null;
}
}
// 以下为非标准实现
export class MarkPrivateMsgAsRead extends MarkMsgAsRead {
override payloadSchema = SchemaData;
override actionName = ActionName.MarkPrivateMsgAsRead;
}
export class MarkGroupMsgAsRead extends MarkMsgAsRead {
override payloadSchema = SchemaData;
override actionName = ActionName.MarkGroupMsgAsRead;
}
export class GoCQHTTPMarkMsgAsRead extends MarkMsgAsRead {
override actionName = ActionName.GoCQHTTP_MarkMsgAsRead;
}
export class MarkAllMsgAsRead extends OneBotAction<void, null> {
override actionName = ActionName._MarkAllMsgAsRead;
async _handle(): Promise<null> {
await this.core.apis.MsgApi.markAllMsgAsRead();
return null;
}
}

View File

@@ -7,7 +7,6 @@ import {
OB11PostSendMsg,
} from '@/onebot/types';
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
import { decodeCQCode } from '@/onebot/helper/cqcode';
import { MessageUnique } from '@/common/message-unique';
import { ChatType, ElementType, NapCatCore, Peer, RawMessage, SendArkElement, SendMessageElement } from '@/core';
import { OneBotAction } from '@/onebot/action/OneBotAction';
@@ -17,7 +16,7 @@ import { PacketMsg } from '@/core/packet/message/message';
import { rawMsgWithSendMsg } from '@/core/packet/message/converter';
export interface ReturnDataType {
message_id: number;
message_id: string;
res_id?: string;
}
@@ -28,11 +27,9 @@ export enum ContextMode {
}
// Normalizes a mixed type (CQCode/a single segment/segment array) into a segment array.
export function normalize(message: OB11MessageMixType, autoEscape = false): OB11MessageData[] {
export function normalize(message: OB11MessageMixType): OB11MessageData[] {
return typeof message === 'string' ? (
autoEscape ?
[{ type: OB11MessageDataType.text, data: { text: message } }] :
decodeCQCode(message)
[{ type: OB11MessageDataType.text, data: { text: message } }]
) : Array.isArray(message) ? message : [message];
}
@@ -54,7 +51,7 @@ export async function createContext(core: NapCatCore, payload: OB11PostContext |
chatType: ChatType.KCHATTYPEGROUP,
peerUid: payload.group_id.toString(),
guildId: ''
}
};
}
throw new Error('无法获取用户信息');
}
@@ -124,10 +121,7 @@ export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
if (payload.message_type === 'private') this.contextMode = ContextMode.Private;
const peer = await createContext(this.core, payload, this.contextMode);
const messages = normalize(
payload.message,
typeof payload.auto_escape === 'string' ? payload.auto_escape === 'true' : !!payload.auto_escape,
);
const messages = normalize(payload.message);
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
const packetMode = this.core.apis.PacketApi.available;
@@ -143,11 +137,14 @@ export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
throw Error('发送合并转发消息失败returnMsgAndResId 为空!');
}
if (returnMsgAndResId.message) {
const msgShortId = MessageUnique.createUniqueMsgId({
const msgShortId = MessageUnique.getOutputData({
guildId: '',
peerUid: peer.peerUid,
chatType: peer.chatType,
}, (returnMsgAndResId.message).msgId);
},
(returnMsgAndResId.message).msgId,
(returnMsgAndResId.message).msgSeq
);
return { message_id: msgShortId!, res_id: returnMsgAndResId.res_id! };
} else if (returnMsgAndResId.res_id && !returnMsgAndResId.message) {
throw Error(`发送转发消息res_id${returnMsgAndResId.res_id} 失败`);
@@ -214,7 +211,7 @@ export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
packetMsg.push(transformedMsg);
} else if (node.data.id) {
const id = node.data.id;
const nodeMsg = MessageUnique.getMsgIdAndPeerByShortId(+id) || MessageUnique.getPeerByMsgId(id);
const nodeMsg = MessageUnique.getInnerData(id);
if (!nodeMsg) {
this.core.context.logger.logError('转发消息失败,未找到消息', id);
continue;
@@ -273,17 +270,17 @@ export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
chatType: ChatType.KCHATTYPEC2C,
peerUid: this.core.selfInfo.uid,
};
let nodeMsgIds: string[] = [];
let nodeMsgIds: { MsgId: string, Peer: Peer }[] = [];
for (const messageNode of messageNodes) {
const nodeId = messageNode.data.id;
if (nodeId) {
// 对Msgid和OB11ID混用情况兜底
const nodeMsg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(nodeId)) || MessageUnique.getPeerByMsgId(nodeId);
const nodeMsg = MessageUnique.getInnerData(nodeId);
if (!nodeMsg) {
this.core.context.logger.logError('转发消息失败,未找到消息', nodeId);
continue;
}
nodeMsgIds.push(nodeMsg.MsgId);
nodeMsgIds.push({ MsgId: nodeMsg.MsgId, Peer: nodeMsg.Peer });
} else {
// 自定义的消息
try {
@@ -297,8 +294,7 @@ export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
}
const nodeMsg = await this.handleForwardedNodes(selfPeer, OB11Data.filter(e => e.type === OB11MessageDataType.node));
if (nodeMsg) {
nodeMsgIds.push(nodeMsg.message!.msgId);
MessageUnique.createUniqueMsgId(selfPeer, nodeMsg.message!.msgId);
nodeMsgIds.push({ MsgId: nodeMsg.message!.msgId, Peer: selfPeer });
}
//完成子卡片生成跳过后续
continue;
@@ -324,8 +320,8 @@ export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
}
(await Promise.allSettled(MsgNodeList)).map((result) => {
if (result.status === 'fulfilled' && result.value) {
nodeMsgIds.push(result.value.msgId);
MessageUnique.createUniqueMsgId(selfPeer, result.value.msgId);
nodeMsgIds.push({ MsgId: result.value.msgId, Peer: selfPeer });
MessageUnique.getOutputData(selfPeer, result.value.msgId, result.value.msgSeq);
}
});
} catch (e: unknown) {
@@ -337,22 +333,18 @@ export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
let srcPeer: Peer | undefined = undefined;
let needSendSelf = false;
//检测是否处于同一个Peer 不在同一个peer则全部消息由自身发送
for (const msgId of nodeMsgIds) {
const nodeMsgPeer = MessageUnique.getPeerByMsgId(msgId);
if (!nodeMsgPeer) {
this.core.context.logger.logError('转发消息失败,未找到消息', msgId);
continue;
}
const nodeMsg = (await this.core.apis.MsgApi.getMsgsByMsgId(nodeMsgPeer.Peer, [msgId])).msgList[0];
let new_nodeMsgIds: { MsgId: string, Peer: Peer }[] = [];
for (const data of nodeMsgIds) {
const nodeMsg = (await this.core.apis.MsgApi.getMsgsByMsgId(data.Peer, [data.MsgId])).msgList[0];
if (nodeMsg) {
srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid };
if (srcPeer.peerUid !== nodeMsg.peerUid) {
needSendSelf = true;
}
nodeMsgArray.push(nodeMsg);
new_nodeMsgIds.push({ MsgId: nodeMsg.msgId, Peer: data.Peer });
}
}
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
nodeMsgIds = new_nodeMsgIds;
let retMsgIds: string[] = [];
if (needSendSelf) {
for (const [, msg] of nodeMsgArray.entries()) {
@@ -364,7 +356,7 @@ export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
if (ClonedMsg) retMsgIds.push(ClonedMsg.msgId);
}
} else {
retMsgIds = nodeMsgIds;
retMsgIds = nodeMsgIds.map((msg) => msg.MsgId);
}
if (retMsgIds.length === 0) throw Error('转发消息失败,生成节点为空');
try {

View File

@@ -4,7 +4,7 @@ import { MessageUnique } from '@/common/message-unique';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
message_id: Type.Union([Type.Number(), Type.String()]),
message_id: Type.String(),
emoji_id: Type.Union([Type.Number(), Type.String()]),
set: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
});
@@ -16,7 +16,7 @@ export class SetMsgEmojiLike extends OneBotAction<Payload, unknown> {
override payloadSchema = SchemaData;
async _handle(payload: Payload) {
const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
const msg = MessageUnique.getInnerData(payload.message_id);
if (!msg) {
throw new Error('msg not found');
}

View File

@@ -8,7 +8,7 @@ export class GetRkeyEx extends GetPacketStatusDepends<void, unknown> {
let rkeys = await this.core.apis.PacketApi.pkt.operation.FetchRkey();
return rkeys.map(rkey => {
return {
type: rkey.type === 10 ? "private" : "group",
type: rkey.type === 10 ? 'private' : 'group',
rkey: rkey.rkey,
created_at: rkey.time,
ttl: rkey.ttl,

View File

@@ -30,7 +30,7 @@ export class GetRkeyServer extends GetPacketStatusDepends<void, { private_rkey?:
private_rkey: privateRkeyItem ? privateRkeyItem.rkey : undefined,
group_rkey: groupRkeyItem ? groupRkeyItem.rkey : undefined,
expired_time: this.expiryTime,
name: "NapCat 4"
name: 'NapCat 4'
};
return this.rkeyCache;

View File

@@ -3,8 +3,8 @@ import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
user_id: Type.Union([Type.Number(), Type.String()]),
group_id: Type.Optional(Type.String()),
user_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;

View File

@@ -3,7 +3,7 @@ import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()])
user_id: Type.String()
});
type Payload = Static<typeof SchemaData>;

View File

@@ -1,7 +1,6 @@
import { OneBotAction } from '@/onebot/action/OneBotAction';
import { ActionName } from '@/onebot/action/router';
import { NetworkAdapterConfig } from '@/onebot/config/config';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
@@ -14,14 +13,14 @@ export default class GetRecentContact extends OneBotAction<Payload, unknown> {
override actionName = ActionName.GetRecentContact;
override payloadSchema = SchemaData;
async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig) {
async _handle(payload: Payload, _adapter: string) {
const ret = await this.core.apis.UserApi.getRecentContactListSnapShot(+payload.count);
//烘焙消息
return await Promise.all(ret.info.changedList.map(async (t) => {
const FastMsg = await this.core.apis.MsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
if (FastMsg.msgList.length > 0 && FastMsg.msgList[0]) {
//扩展ret.info.changedList
const lastestMsg = await this.obContext.apis.MsgApi.parseMessage(FastMsg.msgList[0], config.messagePostFormat);
const lastestMsg = await this.obContext.apis.MsgApi.parseMessage(FastMsg.msgList[0]);
return {
lastestMsg: lastestMsg,
peerUin: t.peerUin,

View File

@@ -4,7 +4,7 @@ import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
times: Type.Union([Type.Number(), Type.String()], { default: 1 }),
user_id: Type.Union([Type.Number(), Type.String()])
user_id: Type.String()
});
type Payload = Static<typeof SchemaData>;

View File

@@ -19,9 +19,9 @@ export class OneBotFriendApi {
if (poke_uid.length == 2 && poke_uid[0]?.uid && poke_uid[1]?.uid) {
return new OB11FriendPokeEvent(
this.core,
uin,
parseInt((await this.core.apis.UserApi.getUinByUidV2(poke_uid[0].uid))),
parseInt((await this.core.apis.UserApi.getUinByUidV2(poke_uid[1].uid))),
uin.toString(),
await this.core.apis.UserApi.getUinByUidV2(poke_uid[0].uid),
await this.core.apis.UserApi.getUinByUidV2(poke_uid[1].uid),
pokedetail,
);
}

View File

@@ -54,9 +54,9 @@ export class OneBotGroupApi {
if (memberUin && adminUin) {
return new OB11GroupBanEvent(
this.core,
parseInt(GroupCode),
parseInt(memberUin),
parseInt(adminUin),
GroupCode,
memberUin,
adminUin,
duration,
subType,
);
@@ -101,9 +101,9 @@ export class OneBotGroupApi {
}
return new OB11GroupMsgEmojiLikeEvent(
this.core,
parseInt(groupCode),
parseInt(senderUin),
MessageUnique.getShortIdByMsgId(replyMsg.msgId)!,
groupCode,
senderUin,
MessageUnique.getOutputData(peer, replyMsg.msgId, replyMsg.msgSeq),
[{
emoji_id: emojiId,
count: 1,
@@ -116,7 +116,7 @@ export class OneBotGroupApi {
const member = await this.core.apis.GroupApi.getGroupMember(msg.peerUid, msg.senderUin);
if (member && member.cardName !== msg.sendMemberName) {
const newCardName = msg.sendMemberName ?? '';
const event = new OB11GroupCardEvent(this.core, parseInt(msg.peerUid), parseInt(msg.senderUin), newCardName, member.cardName);
const event = new OB11GroupCardEvent(this.core, msg.peerUid, msg.senderUin, newCardName, member.cardName);
member.cardName = newCardName;
return event;
}
@@ -137,9 +137,9 @@ export class OneBotGroupApi {
if (poke_uid.length == 2 && poke_uid[0]?.uid && poke_uid[1]?.uid) {
return new OB11GroupPokeEvent(
this.core,
parseInt(msg.peerUid),
+await this.core.apis.UserApi.getUinByUidV2(poke_uid[0].uid),
+await this.core.apis.UserApi.getUinByUidV2(poke_uid[1].uid),
msg.peerUid,
await this.core.apis.UserApi.getUinByUidV2(poke_uid[0].uid),
await this.core.apis.UserApi.getUinByUidV2(poke_uid[1].uid),
pokedetail,
);
}
@@ -156,8 +156,8 @@ export class OneBotGroupApi {
context.logger.logDebug('收到群成员新头衔消息', json);
return new OB11GroupTitleEvent(
this.core,
+msg.peerUid,
+memberUin,
msg.peerUid,
memberUin,
title,
);
} else if (type === '移出') {
@@ -187,10 +187,10 @@ export class OneBotGroupApi {
if (msgData.msgList[0]) {
return new OB11GroupEssenceEvent(
this.core,
parseInt(msg.peerUid),
MessageUnique.getShortIdByMsgId(msgData.msgList[0].msgId)!,
parseInt(msgData.msgList[0].senderUin),
parseInt(realMsg?.add_digest_uin ?? '0'),
msg.peerUid,
MessageUnique.getOutputData(Peer, msgData.msgList[0].msgId, msgData.msgList[0].msgSeq)!,
msgData.msgList[0].senderUin,
realMsg?.add_digest_uin ?? '0',
);
}
return;
@@ -200,7 +200,8 @@ export class OneBotGroupApi {
async parseGroupUploadFileEvene(msg: RawMessage, element: FileElement, elementWrapper: MessageElement) {
return new OB11GroupUploadNoticeEvent(
this.core,
parseInt(msg.peerUid), parseInt(msg.senderUin || ''),
msg.peerUid,
msg.senderUin,
{
id: FileNapCatOneBotUUID.encode({
chatType: ChatType.KCHATTYPEGROUP,
@@ -218,8 +219,8 @@ export class OneBotGroupApi {
this.core.context.logger.logDebug('收到群名称变更事件', element);
return new OB11GroupNameEvent(
this.core,
parseInt(msg.peerUid),
parseInt(await this.core.apis.UserApi.getUinByUidV2(element.memberUid)),
msg.peerUid,
await this.core.apis.UserApi.getUinByUidV2(element.memberUid),
element.groupName,
);
} else if (element.type === TipGroupElementType.KSHUTUP) {
@@ -231,9 +232,9 @@ export class OneBotGroupApi {
await this.core.apis.GroupApi.refreshGroupMemberCache(msg.peerUid, true);
return new OB11GroupIncreaseEvent(
this.core,
parseInt(msg.peerUid),
+this.core.selfInfo.uin,
element.adminUid ? +await this.core.apis.UserApi.getUinByUidV2(element.adminUid) : 0,
msg.peerUid,
this.core.selfInfo.uin,
element.adminUid ? await this.core.apis.UserApi.getUinByUidV2(element.adminUid) : '0',
'approve'
);
}
@@ -244,9 +245,9 @@ export class OneBotGroupApi {
async parseSelfInviteEvent(msg: RawMessage, inviterUin: string, inviteeUin: string) {
return new OB11GroupIncreaseEvent(
this.core,
parseInt(msg.peerUid),
+inviteeUin,
+inviterUin,
msg.peerUid,
inviteeUin,
inviterUin,
'invite'
);
}
@@ -269,9 +270,9 @@ export class OneBotGroupApi {
if (!new_member) return;
return new OB11GroupIncreaseEvent(
this.core,
+msg.peerUid,
+new_member.uin,
0,
msg.peerUid,
new_member.uin,
'0',
'invite',
);
}

View File

@@ -1,5 +1,4 @@
export * from './friend';
export * from './group';
export * from './user';
export * from './msg';
export * from './quick-action';
export * from './msg';

View File

@@ -31,7 +31,6 @@ import {
} from '@/onebot';
import { OB11Construct } from '@/onebot/helper/data';
import { EventType } from '@/onebot/event/OneBotEvent';
import { encodeCQCode } from '@/onebot/helper/cqcode';
import { uriToLocalFile } from '@/common/file';
import { RequestUtil } from '@/common/request';
import fsPromise from 'node:fs/promises';
@@ -95,15 +94,16 @@ export class OneBotMsgApi {
};
} else {
let qq: string = 'all';
const { atNtUid, atUid, content } = element;
if (element.atType !== NTMsgAtType.ATTYPEALL) {
const { atNtUid, atUid } = element;
qq = !atUid || atUid === '0' ? await this.core.apis.UserApi.getUinByUidV2(atNtUid) : String(Number(atUid) >>> 0);
}
return {
type: OB11MessageDataType.at,
data: {
qq: qq,
// name: content.slice(1);
id: qq,
name: content.slice(1)
},
};
}
@@ -150,7 +150,7 @@ export class OneBotMsgApi {
if (this.core.apis.PacketApi.available) {
let url;
try {
url = await this.core.apis.FileApi.getFileUrl(msg.chatType, msg.peerUid, element.fileUuid, element.file10MMd5)
url = await this.core.apis.FileApi.getFileUrl(msg.chatType, msg.peerUid, element.fileUuid, element.file10MMd5);
} catch (error) {
url = '';
}
@@ -163,7 +163,7 @@ export class OneBotMsgApi {
file_size: element.fileSize,
url: url,
},
}
};
}
}
return {
@@ -248,10 +248,10 @@ export class OneBotMsgApi {
};
// 创建回复数据的通用方法
const createReplyData = (msgId: string): OB11MessageData => ({
const createReplyData = (msgId: string, msgSeq: string): OB11MessageData => ({
type: OB11MessageDataType.reply,
data: {
id: MessageUnique.createUniqueMsgId(peer, msgId).toString(),
id: MessageUnique.getOutputData(peer, msgId, msgSeq).toString(),
},
});
@@ -260,7 +260,7 @@ export class OneBotMsgApi {
// 特定账号的特殊处理
if (records && (records.peerUin === '284840486' || records.peerUin === '1094950020')) {
return createReplyData(records.msgId);
return createReplyData(records.msgId, records.msgSeq);
}
// 获取消息的通用方法组
@@ -326,7 +326,7 @@ export class OneBotMsgApi {
);
if (replyMsg) {
return createReplyData(replyMsg.msgId);
return createReplyData(replyMsg.msgId, replyMsg.msgSeq);
}
this.core.context.logger.logError('所有查找方法均失败,获取不到带记录的引用消息', element.replayMsgSeq);
@@ -337,13 +337,13 @@ export class OneBotMsgApi {
const replyMsg = await tryFetchMethods(element.replayMsgSeq);
if (replyMsg) {
return createReplyData(replyMsg.msgId);
return createReplyData(replyMsg.msgId, replyMsg.msgSeq);
}
this.core.context.logger.logError('所有查找方法均失败,获取不到旧客户端的引用消息', element.replayMsgSeq);
//this.core.context.logger.logError('所有查找方法均失败,获取不到旧客户端的引用消息', element.replayMsgSeq);
}
return null;
return createReplyData('-1', element.replayMsgSeq);
},
videoElement: async (element, msg, elementWrapper) => {
const peer = {
@@ -441,7 +441,7 @@ export class OneBotMsgApi {
url: pttUrl,
file_size: element.fileSize,
},
}
};
}
return {
type: OB11MessageDataType.voice,
@@ -515,7 +515,7 @@ export class OneBotMsgApi {
},
}),
[OB11MessageDataType.at]: async ({ data: { qq: atQQ } }, context) => {
[OB11MessageDataType.at]: async ({ data: { id: atQQ } }, context) => {
function at(atUid: string, atNtUid: string, atType: NTMsgAtType, atName: string): SendTextElement {
return {
elementType: ElementType.TEXT,
@@ -543,7 +543,7 @@ export class OneBotMsgApi {
},
[OB11MessageDataType.reply]: async ({ data: { id } }) => {
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
const replyMsgM = MessageUnique.getInnerData(id);
if (!replyMsgM) {
this.core.context.logger.logWarn('回复消息不存在', id);
return undefined;
@@ -868,7 +868,7 @@ export class OneBotMsgApi {
}
;
} else if (grayTipElement.jsonGrayTipElement.busiId == 19324 && msg.peerUid !== '') {
return new OB11FriendAddNoticeEvent(this.core, Number(await this.core.apis.UserApi.getUinByUidV2(msg.peerUid)));
return new OB11FriendAddNoticeEvent(this.core, await this.core.apis.UserApi.getUinByUidV2(msg.peerUid));
}
}
return;
@@ -898,21 +898,17 @@ export class OneBotMsgApi {
const parsed = await Promise.all(multiMsgs.map(async msg => {
msg.parentMsgPeer = parentMsgPeer;
msg.parentMsgIdList = parentMsgIdList;
msg.id = MessageUnique.createUniqueMsgId(parentMsgPeer, msg.msgId);
msg.id = MessageUnique.getOutputData(parentMsgPeer, msg.msgId, msg.msgSeq);
//该ID仅用查看 无法调用
return await this.parseMessage(msg, 'array', true);
return await this.parseMessage(msg, true);
}));
return parsed.filter(item => item !== undefined);
}
async parseMessage(
msg: RawMessage,
messagePostFormat: string,
parseMultMsg: boolean = true
) {
if (messagePostFormat === 'string') {
return (await this.parseMessageV2(msg, parseMultMsg))?.stringMsg;
}
return (await this.parseMessageV2(msg, parseMultMsg))?.arrayMsg;
}
@@ -941,39 +937,32 @@ export class OneBotMsgApi {
const validSegments = await this.parseMessageSegments(msg, parseMultMsg);
resMsg.message = validSegments;
resMsg.raw_message = validSegments.map(msg => encodeCQCode(msg)).join('').trim();
const stringMsg = await this.convertArrayToStringMessage(resMsg);
return { stringMsg, arrayMsg: resMsg };
return { arrayMsg: resMsg };
}
private initializeMessage(msg: RawMessage): OB11Message {
return {
self_id: parseInt(this.core.selfInfo.uin),
user_id: parseInt(msg.senderUin),
self_id: this.core.selfInfo.uin,
user_id: msg.senderUin,
time: parseInt(msg.msgTime) || Date.now(),
message_id: msg.id!,
message_seq: msg.id!,
real_id: msg.id!,
real_seq: msg.msgSeq,
message_type: msg.chatType == ChatType.KCHATTYPEGROUP ? 'group' : 'private',
sender: {
user_id: +(msg.senderUin ?? 0),
user_id: (msg.senderUin ?? 0).toString(),
nickname: msg.sendNickName,
card: msg.sendMemberName ?? '',
},
raw_message: '',
font: 14,
sub_type: 'friend',
message: [],
message_format: 'array',
post_type: this.core.selfInfo.uin == msg.senderUin ? EventType.MESSAGE_SENT : EventType.MESSAGE,
};
}
private async handleGroupMessage(resMsg: OB11Message, msg: RawMessage) {
resMsg.sub_type = 'normal';
resMsg.group_id = parseInt(msg.peerUin);
resMsg.group_id = msg.peerUin;
let member = await this.core.apis.GroupApi.getGroupMember(msg.peerUin, msg.senderUin);
if (!member) member = await this.core.apis.GroupApi.getGroupMember(msg.peerUin, msg.senderUin);
if (member) {
@@ -999,11 +988,11 @@ export class OneBotMsgApi {
const ret = await this.core.apis.MsgApi.getTempChatInfo(ChatType.KCHATTYPETEMPC2CFROMGROUP, msg.senderUid);
if (ret.result === 0) {
const member = await this.core.apis.GroupApi.getGroupMember(msg.peerUin, msg.senderUin);
resMsg.group_id = parseInt(ret.tmpChatInfo!.groupCode);
resMsg.group_id = ret.tmpChatInfo!.groupCode;
resMsg.sender.nickname = member?.nick ?? member?.cardName ?? '临时会话';
resMsg.temp_source = 0;
} else {
resMsg.group_id = 284840486;
resMsg.group_id = '284840486';
resMsg.temp_source = 0;
resMsg.sender.nickname = '临时会话';
}
@@ -1046,19 +1035,7 @@ export class OneBotMsgApi {
}).map((entry) => (<PromiseFulfilledResult<OB11MessageData>>entry).value).filter(value => value != null);
}
private async convertArrayToStringMessage(originMsg: OB11Message): Promise<OB11Message> {
const msg = structuredClone(originMsg);
msg.message_format = 'string';
msg.message = msg.raw_message;
return msg;
}
async importArrayTostringMsg(originMsg: OB11Message) {
const msg = structuredClone(originMsg);
msg.message_format = 'string';
msg.message = msg.raw_message;
return msg;
}
async createSendElements(
messageData: OB11MessageData[],
@@ -1119,11 +1096,11 @@ export class OneBotMsgApi {
try {
const returnMsg = await this.core.apis.MsgApi.sendMsg(peer, sendElements, timeout);
if (!returnMsg) throw new Error('发送消息失败');
returnMsg.id = MessageUnique.createUniqueMsgId({
returnMsg.id = MessageUnique.getOutputData({
chatType: peer.chatType,
guildId: '',
peerUid: peer.peerUid,
}, returnMsg.msgId);
}, returnMsg.msgId, returnMsg.msgSeq);
return returnMsg;
} catch (error) {
throw new Error((error as Error).message);
@@ -1243,9 +1220,9 @@ export class OneBotMsgApi {
);
return new OB11GroupIncreaseEvent(
this.core,
groupChange.groupUin,
groupChange.memberUid ? +await this.core.apis.UserApi.getUinByUidV2(groupChange.memberUid) : 0,
operatorUid ? +await this.core.apis.UserApi.getUinByUidV2(operatorUid) : 0,
groupChange.groupUin.toString(),
groupChange.memberUid ? await this.core.apis.UserApi.getUinByUidV2(groupChange.memberUid) : '0',
operatorUid ? await this.core.apis.UserApi.getUinByUidV2(operatorUid) : '0',
groupChange.decreaseType == 131 ? 'invite' : 'approve',
);
@@ -1269,9 +1246,9 @@ export class OneBotMsgApi {
}
return new OB11GroupDecreaseEvent(
this.core,
groupChange.groupUin,
groupChange.memberUid ? +await this.core.apis.UserApi.getUinByUidV2(groupChange.memberUid) : 0,
operatorUid ? +await this.core.apis.UserApi.getUinByUidV2(operatorUid) : 0,
groupChange.groupUin.toString(),
groupChange.memberUid ? await this.core.apis.UserApi.getUinByUidV2(groupChange.memberUid) : '0',
operatorUid ? await this.core.apis.UserApi.getUinByUidV2(operatorUid) : '0',
this.groupChangDecreseType2String(groupChange.decreaseType),
);
} else if (SysMessage.contentHead.type == 44 && SysMessage.body?.msgContent) {
@@ -1288,8 +1265,8 @@ export class OneBotMsgApi {
}
return new OB11GroupAdminNoticeEvent(
this.core,
groupAmin.groupUin,
+await this.core.apis.UserApi.getUinByUidV2(uid),
groupAmin.groupUin.toString(),
await this.core.apis.UserApi.getUinByUidV2(uid),
enabled ? 'set' : 'unset'
);
} else if (SysMessage.contentHead.type == 87 && SysMessage.body?.msgContent) {
@@ -1352,8 +1329,8 @@ export class OneBotMsgApi {
});
return new OB11GroupRequestEvent(
this.core,
+groupInvite.groupUin,
+await this.core.apis.UserApi.getUinByUidV2(groupInvite.invitorUid),
groupInvite.groupUin.toString(),
await this.core.apis.UserApi.getUinByUidV2(groupInvite.invitorUid),
'invite',
'',
request_seq

View File

@@ -1,113 +0,0 @@
import type {
NapCatOneBot11Adapter,
OB11Message,
OB11MessageAt,
OB11MessageData,
OB11MessageReply,
QuickAction,
QuickActionEvent,
QuickActionFriendRequest,
QuickActionGroupMessage,
QuickActionGroupRequest,
} from '@/onebot';
import { NTGroupRequestOperateTypes, type NapCatCore, type Peer } from '@/core';
import type { OB11FriendRequestEvent } from '@/onebot/event/request/OB11FriendRequest';
import type { OB11GroupRequestEvent } from '@/onebot/event/request/OB11GroupRequest';
import { ContextMode, createContext, normalize } from '@/onebot/action/msg/SendMsg';
import { isNull } from '@/common/helper';
export class OneBotQuickActionApi {
obContext: NapCatOneBot11Adapter;
core: NapCatCore;
constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
this.obContext = obContext;
this.core = core;
}
async handleQuickOperation(eventContext: QuickActionEvent, quickAction: QuickAction) {
if (eventContext.post_type === 'message') {
await this.handleMsg(eventContext as OB11Message, quickAction)
.catch(e => this.core.context.logger.logError(e));
}
if (eventContext.post_type === 'request') {
const friendRequest = eventContext as OB11FriendRequestEvent;
const groupRequest = eventContext as OB11GroupRequestEvent;
if ((friendRequest).request_type === 'friend') {
await this.handleFriendRequest(friendRequest, quickAction)
.catch(e => this.core.context.logger.logError(e));
} else if (groupRequest.request_type === 'group') {
await this.handleGroupRequest(groupRequest, quickAction)
.catch(e => this.core.context.logger.logError(e));
}
}
}
async handleMsg(msg: OB11Message, quickAction: QuickAction) {
const reply = quickAction.reply;
const peerContextMode = msg.message_type == 'private' ? ContextMode.Private : ContextMode.Group;
const peer: Peer = await createContext(this.core, {
group_id: msg.group_id?.toString(),
user_id: msg.user_id?.toString(),
}, peerContextMode);
if (reply) {
// let group: Group | undefined;
let replyMessage: OB11MessageData[] = [];
if (msg.message_type == 'group') {
// group = await core.apis.GroupApi.getGroup(msg.group_id!.toString());
replyMessage.push({
type: 'reply',
data: {
id: msg.message_id.toString(),
},
} as OB11MessageReply);
if ((quickAction as QuickActionGroupMessage).at_sender) {
replyMessage.push({
type: 'at',
data: {
qq: msg.user_id.toString(),
},
} as OB11MessageAt);
}
}
replyMessage = replyMessage.concat(normalize(reply, quickAction.auto_escape));
const {
sendElements,
deleteAfterSentFiles,
} = await this.obContext.apis.MsgApi.createSendElements(replyMessage, peer);
this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles).then().catch(e => this.core.context.logger.logError(e));
}
}
async findNotify(flag: string) {
let notify = (await this.core.apis.GroupApi.getSingleScreenNotifies(false, 100)).find(e => e.seq == flag);
if (!notify) {
notify = (await this.core.apis.GroupApi.getSingleScreenNotifies(true, 100)).find(e => e.seq == flag);
return { doubt: true, notify };
}
return { doubt: false, notify };
}
async handleGroupRequest(request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) {
const invite_notify = this.obContext.apis.MsgApi.notifyGroupInvite.get(request.flag);
const { doubt, notify } = invite_notify ? { doubt: false, notify: invite_notify } : await this.findNotify(request.flag);
if (!isNull(quickAction.approve) && notify) {
this.core.apis.GroupApi.handleGroupRequest(
doubt,
notify,
quickAction.approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
quickAction.reason,
).catch(e => this.core.context.logger.logError(e));
}
}
async handleFriendRequest(request: OB11FriendRequestEvent, quickAction: QuickActionFriendRequest) {
const notify = (await this.core.apis.FriendApi.getBuddyReq()).buddyReqs.find(e => e.reqTime == request.flag.toString());
if (!isNull(quickAction.approve) && notify) {
this.core.apis.FriendApi.handleFriendRequest(notify, !!quickAction.approve).then().catch(e => this.core.context.logger.logError(e));
}
}
}

View File

@@ -23,7 +23,7 @@ export class OneBotUserApi {
const times = detail.txt.match(/\d+/) ?? '0';
return new OB11ProfileLikeEvent(
this.core,
Number(detail.uin),
detail.uin.toString(),
detail.nickname,
parseInt(times[0], 10),
likeMsg.time,

View File

@@ -3,13 +3,13 @@ import { NapCatCore } from '@/core';
export class BotOfflineEvent extends OB11BaseNoticeEvent {
notice_type = 'bot_offline';
user_id: number;
user_id: string;
tag: string = 'BotOfflineEvent';
message: string = 'BotOfflineEvent';
public constructor(core: NapCatCore, tag: string, message: string) {
super(core);
this.user_id = +core.selfInfo.uin;
this.user_id = core.selfInfo.uin;
this.tag = tag;
this.message = message;
}

View File

@@ -3,9 +3,9 @@ import { NapCatCore } from '@/core';
export class OB11FriendAddNoticeEvent extends OB11BaseNoticeEvent {
notice_type = 'friend_add';
user_id: number;
user_id: string;
public constructor(core: NapCatCore, userId: number) {
public constructor(core: NapCatCore, userId: string) {
super(core);
this.user_id = userId;
}

View File

@@ -3,10 +3,10 @@ import { NapCatCore } from '@/core';
export class OB11FriendRecallNoticeEvent extends OB11BaseNoticeEvent {
notice_type = 'friend_recall';
user_id: number;
message_id: number;
user_id: string;
message_id: string;
public constructor(core: NapCatCore, userId: number, messageId: number) {
public constructor(core: NapCatCore, userId: string, messageId: string) {
super(core);
this.user_id = userId;
this.message_id = messageId;

View File

@@ -5,7 +5,7 @@ export class OB11GroupAdminNoticeEvent extends OB11GroupNoticeEvent {
notice_type = 'group_admin';
sub_type: 'set' | 'unset';
constructor(core: NapCatCore, group_id: number, user_id: number, sub_type: 'set' | 'unset') {
constructor(core: NapCatCore, group_id: string, user_id: string, sub_type: 'set' | 'unset') {
super(core, group_id, user_id);
this.sub_type = sub_type;
}

View File

@@ -3,11 +3,11 @@ import { NapCatCore } from '@/core';
export class OB11GroupBanEvent extends OB11GroupNoticeEvent {
notice_type = 'group_ban';
operator_id: number;
operator_id: string;
duration: number;
sub_type: 'ban' | 'lift_ban';
constructor(core: NapCatCore, groupId: number, userId: number, operatorId: number, duration: number, sub_type: 'ban' | 'lift_ban') {
constructor(core: NapCatCore, groupId: string, userId: string, operatorId: string, duration: number, sub_type: 'ban' | 'lift_ban') {
super(core, groupId, userId);
this.group_id = groupId;
this.operator_id = operatorId;

View File

@@ -7,7 +7,7 @@ export class OB11GroupCardEvent extends OB11GroupNoticeEvent {
card_old: string;
constructor(core: NapCatCore, groupId: number, userId: number, cardNew: string, cardOld: string) {
constructor(core: NapCatCore, groupId: string, userId: string, cardNew: string, cardOld: string) {
super(core, groupId, userId);
this.group_id = groupId;
this.user_id = userId;

View File

@@ -6,9 +6,9 @@ export type GroupDecreaseSubType = 'leave' | 'kick' | 'kick_me' | 'disband';
export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
notice_type = 'group_decrease';
sub_type: GroupDecreaseSubType = 'leave';
operator_id: number;
operator_id: string;
constructor(core: NapCatCore, groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = 'leave') {
constructor(core: NapCatCore, groupId: string, userId: string, operatorId: string, subType: GroupDecreaseSubType = 'leave') {
super(core, groupId, userId);
this.group_id = groupId;
this.operator_id = operatorId;

View File

@@ -3,13 +3,13 @@ import { NapCatCore } from '@/core';
export class OB11GroupEssenceEvent extends OB11GroupNoticeEvent {
notice_type = 'essence';
message_id: number;
sender_id: number;
operator_id: number;
message_id: string;
sender_id: string;
operator_id: string;
sub_type: 'add' | 'delete' = 'add';
constructor(core: NapCatCore, groupId: number, message_id: number, sender_id: number, operator_id: number) {
constructor(core: NapCatCore, groupId: string, message_id: string, sender_id: string, operator_id: string) {
super(core, groupId, sender_id);
this.group_id = groupId;
this.operator_id = operator_id;

View File

@@ -5,10 +5,10 @@ type GroupIncreaseSubType = 'approve' | 'invite';
export class OB11GroupIncreaseEvent extends OB11GroupNoticeEvent {
notice_type = 'group_increase';
operator_id: number;
operator_id: string;
sub_type: GroupIncreaseSubType;
constructor(core: NapCatCore, groupId: number, userId: number, operatorId: number, subType: GroupIncreaseSubType = 'approve') {
constructor(core: NapCatCore, groupId: string, userId: string, operatorId: string, subType: GroupIncreaseSubType = 'approve') {
super(core, groupId, userId);
this.group_id = groupId;
this.operator_id = operatorId;

View File

@@ -6,7 +6,7 @@ export class OB11GroupNameEvent extends OB11GroupNoticeEvent {
sub_type = 'group_name';
name_new: string;
constructor(core: NapCatCore, groupId: number, userId: number, nameNew: string) {
constructor(core: NapCatCore, groupId: string, userId: string, nameNew: string) {
super(core, groupId, userId);
this.name_new = nameNew;
}

View File

@@ -2,10 +2,10 @@ import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
import { NapCatCore } from '@/core';
export abstract class OB11GroupNoticeEvent extends OB11BaseNoticeEvent {
group_id: number;
user_id: number;
group_id: string;
user_id: string;
constructor(core: NapCatCore, group_id: number, user_id: number) {
constructor(core: NapCatCore, group_id: string, user_id: string) {
super(core);
this.group_id = group_id;
this.user_id = user_id;

Some files were not shown because too many files have changed in this diff Show More