mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-16 13:20:33 +00:00
Refactor PacketApi status checks and fix typos
Replaced all usages of PacketApi.available with PacketApi.packetStatus for more accurate status checking. Fixed a typo in getFullQQVesion to getFullQQVersion. Updated plugin_onmessage to fetch and parse messages for a user. These changes improve reliability and consistency in API status handling.
This commit is contained in:
parent
5abdc8c538
commit
1b0b5f3494
@ -42,7 +42,7 @@ export class QQBasicInfoWrapper {
|
|||||||
return this.isQuickUpdate ? this.QQVersionConfig?.buildId : this.QQPackageInfo?.buildVersion;
|
return this.isQuickUpdate ? this.QQVersionConfig?.buildId : this.QQPackageInfo?.buildVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFullQQVesion() {
|
getFullQQVersion() {
|
||||||
const version = this.isQuickUpdate ? this.QQVersionConfig?.curVersion : this.QQPackageInfo?.version;
|
const version = this.isQuickUpdate ? this.QQVersionConfig?.curVersion : this.QQPackageInfo?.version;
|
||||||
if (!version) throw new Error('QQ版本获取失败');
|
if (!version) throw new Error('QQ版本获取失败');
|
||||||
return version;
|
return version;
|
||||||
|
|||||||
@ -65,7 +65,7 @@ export class NTQQFileApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getFileUrl(chatType: ChatType, peer: string, fileUUID?: string, file10MMd5?: string | undefined) {
|
async getFileUrl(chatType: ChatType, peer: string, fileUUID?: string, file10MMd5?: string | undefined) {
|
||||||
if (this.core.apis.PacketApi.available) {
|
if (this.core.apis.PacketApi.packetStatus) {
|
||||||
try {
|
try {
|
||||||
if (chatType === ChatType.KCHATTYPEGROUP && fileUUID) {
|
if (chatType === ChatType.KCHATTYPEGROUP && fileUUID) {
|
||||||
return this.core.apis.PacketApi.pkt.operation.GetGroupFileUrl(+peer, fileUUID);
|
return this.core.apis.PacketApi.pkt.operation.GetGroupFileUrl(+peer, fileUUID);
|
||||||
@ -80,7 +80,7 @@ export class NTQQFileApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getPttUrl(peer: string, fileUUID?: string) {
|
async getPttUrl(peer: string, fileUUID?: string) {
|
||||||
if (this.core.apis.PacketApi.available && fileUUID) {
|
if (this.core.apis.PacketApi.packetStatus && fileUUID) {
|
||||||
let appid = new NapProtoMsg(FileId).decode(Buffer.from(fileUUID.replaceAll('-', '+').replaceAll('_', '/'), 'base64')).appid;
|
let appid = new NapProtoMsg(FileId).decode(Buffer.from(fileUUID.replaceAll('-', '+').replaceAll('_', '/'), 'base64')).appid;
|
||||||
try {
|
try {
|
||||||
if (appid && appid === 1403) {
|
if (appid && appid === 1403) {
|
||||||
@ -108,7 +108,7 @@ export class NTQQFileApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getVideoUrlPacket(peer: string, fileUUID?: string) {
|
async getVideoUrlPacket(peer: string, fileUUID?: string) {
|
||||||
if (this.core.apis.PacketApi.available && fileUUID) {
|
if (this.core.apis.PacketApi.packetStatus && fileUUID) {
|
||||||
let appid = new NapProtoMsg(FileId).decode(Buffer.from(fileUUID.replaceAll('-', '+').replaceAll('_', '/'), 'base64')).appid;
|
let appid = new NapProtoMsg(FileId).decode(Buffer.from(fileUUID.replaceAll('-', '+').replaceAll('_', '/'), 'base64')).appid;
|
||||||
try {
|
try {
|
||||||
if (appid && appid === 1415) {
|
if (appid && appid === 1415) {
|
||||||
@ -502,7 +502,7 @@ export class NTQQFileApi {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.core.apis.PacketApi.available) {
|
if (this.core.apis.PacketApi.packetStatus) {
|
||||||
const rkey_expired_private = !this.packetRkey || (this.packetRkey[0] && this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000);
|
const rkey_expired_private = !this.packetRkey || (this.packetRkey[0] && this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000);
|
||||||
const rkey_expired_group = !this.packetRkey || (this.packetRkey[0] && this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000);
|
const rkey_expired_group = !this.packetRkey || (this.packetRkey[0] && this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000);
|
||||||
if (rkey_expired_private || rkey_expired_group) {
|
if (rkey_expired_private || rkey_expired_group) {
|
||||||
|
|||||||
@ -21,20 +21,26 @@ export class NTQQPacketApi {
|
|||||||
qqVersion: string | undefined;
|
qqVersion: string | undefined;
|
||||||
pkt!: PacketClientSession;
|
pkt!: PacketClientSession;
|
||||||
errStack: string[] = [];
|
errStack: string[] = [];
|
||||||
|
packetStatus: boolean = false;
|
||||||
|
|
||||||
constructor(context: InstanceContext, core: NapCatCore) {
|
constructor(context: InstanceContext, core: NapCatCore) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.core = core;
|
this.core = core;
|
||||||
this.logger = core.context.logger;
|
this.logger = core.context.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
async initApi() {
|
async initApi() {
|
||||||
await this.InitSendPacket(this.context.basicInfoWrapper.getFullQQVesion())
|
this.packetStatus = (await this.InitSendPacket(this.context.basicInfoWrapper.getFullQQVersion())
|
||||||
.then()
|
.then((result) => {
|
||||||
|
return result;
|
||||||
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
this.logger.logError(err);
|
this.logger.logError(err);
|
||||||
this.errStack.push(err);
|
this.errStack.push(err);
|
||||||
});
|
return false;
|
||||||
|
})) && this.pkt?.available;
|
||||||
}
|
}
|
||||||
|
|
||||||
get available(): boolean {
|
get available(): boolean {
|
||||||
return this.pkt?.available ?? false;
|
return this.pkt?.available ?? false;
|
||||||
}
|
}
|
||||||
@ -61,6 +67,12 @@ export class NTQQPacketApi {
|
|||||||
}
|
}
|
||||||
this.pkt = new PacketClientSession(this.core);
|
this.pkt = new PacketClientSession(this.core);
|
||||||
await this.pkt.init(process.pid, table.recv, table.send);
|
await this.pkt.init(process.pid, table.recv, table.send);
|
||||||
|
try {
|
||||||
|
await this.pkt.operation.FetchRkey();
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.logError('测试Packet状态异常', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -130,7 +130,7 @@ export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||||
const packetMode = this.core.apis.PacketApi.available;
|
const packetMode = this.core.apis.PacketApi.packetStatus;
|
||||||
let returnMsgAndResId: { message: RawMessage | null, res_id?: string } | null;
|
let returnMsgAndResId: { message: RawMessage | null, res_id?: string } | null;
|
||||||
try {
|
try {
|
||||||
returnMsgAndResId = packetMode
|
returnMsgAndResId = packetMode
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
|||||||
|
|
||||||
export abstract class GetPacketStatusDepends<PT, RT> extends OneBotAction<PT, RT> {
|
export abstract class GetPacketStatusDepends<PT, RT> extends OneBotAction<PT, RT> {
|
||||||
protected override async check(payload: PT): Promise<BaseCheckResult>{
|
protected override async check(payload: PT): Promise<BaseCheckResult>{
|
||||||
if (!this.core.apis.PacketApi.available) {
|
if (!this.core.apis.PacketApi.packetStatus) {
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
message: 'packetBackend不可用,请参照文档 https://napneko.github.io/config/advanced 和启动日志检查packetBackend状态或进行配置!' +
|
message: 'packetBackend不可用,请参照文档 https://napneko.github.io/config/advanced 和启动日志检查packetBackend状态或进行配置!' +
|
||||||
|
|||||||
@ -147,7 +147,7 @@ export class OneBotMsgApi {
|
|||||||
};
|
};
|
||||||
FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, element.fileUuid, element.fileUuid);
|
FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, element.fileUuid, element.fileUuid);
|
||||||
FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, element.fileUuid, element.fileName);
|
FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, element.fileUuid, element.fileName);
|
||||||
if (this.core.apis.PacketApi.available) {
|
if (this.core.apis.PacketApi.packetStatus) {
|
||||||
let url;
|
let url;
|
||||||
try {
|
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)
|
||||||
@ -391,7 +391,7 @@ export class OneBotMsgApi {
|
|||||||
|
|
||||||
//开始兜底
|
//开始兜底
|
||||||
if (!videoDownUrl) {
|
if (!videoDownUrl) {
|
||||||
if (this.core.apis.PacketApi.available) {
|
if (this.core.apis.PacketApi.packetStatus) {
|
||||||
try {
|
try {
|
||||||
videoDownUrl = await this.core.apis.FileApi.getVideoUrlPacket(msg.peerUid, element.fileUuid);
|
videoDownUrl = await this.core.apis.FileApi.getVideoUrlPacket(msg.peerUid, element.fileUuid);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -422,7 +422,7 @@ export class OneBotMsgApi {
|
|||||||
};
|
};
|
||||||
const fileCode = FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, '', element.fileName);
|
const fileCode = FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, '', element.fileName);
|
||||||
let pttUrl = '';
|
let pttUrl = '';
|
||||||
if (this.core.apis.PacketApi.available) {
|
if (this.core.apis.PacketApi.packetStatus) {
|
||||||
try {
|
try {
|
||||||
pttUrl = await this.core.apis.FileApi.getPttUrl(msg.peerUid, element.fileUuid);
|
pttUrl = await this.core.apis.FileApi.getPttUrl(msg.peerUid, element.fileUuid);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -170,7 +170,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.initBuddyListener();
|
this.initBuddyListener();
|
||||||
this.initGroupListener();
|
this.initGroupListener();
|
||||||
|
|
||||||
WebUiDataRuntime.setQQVersion(this.core.context.basicInfoWrapper.getFullQQVesion());
|
WebUiDataRuntime.setQQVersion(this.core.context.basicInfoWrapper.getFullQQVersion());
|
||||||
WebUiDataRuntime.setQQLoginInfo(selfInfo);
|
WebUiDataRuntime.setQQLoginInfo(selfInfo);
|
||||||
WebUiDataRuntime.setQQLoginStatus(true);
|
WebUiDataRuntime.setQQLoginStatus(true);
|
||||||
WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
|
WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
|
||||||
|
|||||||
@ -1,8 +1,17 @@
|
|||||||
import { NapCatOneBot11Adapter, OB11Message } from '@/onebot';
|
import { NapCatOneBot11Adapter, OB11Message } from '@/onebot';
|
||||||
import { NapCatCore } from '@/core';
|
import { ChatType, NapCatCore } from '@/core';
|
||||||
import { ActionMap } from '@/onebot/action';
|
import { ActionMap } from '@/onebot/action';
|
||||||
import { OB11PluginAdapter } from '@/onebot/network/plugin';
|
import { OB11PluginAdapter } from '@/onebot/network/plugin';
|
||||||
|
|
||||||
export const plugin_onmessage = async (adapter: string, _core: NapCatCore, _obCtx: NapCatOneBot11Adapter, message: OB11Message, action: ActionMap, instance: OB11PluginAdapter) => {
|
export const plugin_onmessage = async (adapter: string, _core: NapCatCore, _obCtx: NapCatOneBot11Adapter, message: OB11Message, action: ActionMap, instance: OB11PluginAdapter) => {
|
||||||
|
const uid = await _core.apis.UserApi.getUidByUinV2(message.sender.user_id.toString());
|
||||||
};
|
|
||||||
|
const msgs = (await _core.apis.MsgApi.queryFirstMsgBySender({
|
||||||
|
peerUid: message.group_id ? String(message.group_id) : String(uid),
|
||||||
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
|
}, [uid])).msgList;
|
||||||
|
console.log('parse message ', message.sender.user_id, msgs.length);
|
||||||
|
for (const msg of msgs) {
|
||||||
|
await _obCtx.apis.MsgApi.parseMessageV2(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user