mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c46ec32bd6 | ||
![]() |
c58a26ed99 | ||
![]() |
a66f5e4971 | ||
![]() |
574c8c6089 | ||
![]() |
67afd95910 | ||
![]() |
f7d0cb0be7 | ||
![]() |
be9b68a0b1 | ||
![]() |
4637414af2 | ||
![]() |
4bd92a72bd | ||
![]() |
a3be26f3e4 | ||
![]() |
675c906cbf | ||
![]() |
6be6023236 | ||
![]() |
42cee0d018 | ||
![]() |
041f725748 | ||
![]() |
0594d61631 | ||
![]() |
15cae6b765 | ||
![]() |
b984116c35 | ||
![]() |
13bda6e3f4 |
@@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "4.2.61",
|
"version": "4.2.65",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "4.2.61",
|
"version": "4.2.65",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
||||||
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
||||||
|
107
src/common/cancel-task.ts
Normal file
107
src/common/cancel-task.ts
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
export type TaskExecutor<T> = (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void, onCancel: (callback: () => void) => void) => void;
|
||||||
|
|
||||||
|
export class CancelableTask<T> {
|
||||||
|
private promise: Promise<T>;
|
||||||
|
private cancelCallback: (() => void) | null = null;
|
||||||
|
private isCanceled = false;
|
||||||
|
private cancelListeners: Array<() => void> = [];
|
||||||
|
|
||||||
|
constructor(executor: TaskExecutor<T>) {
|
||||||
|
this.promise = new Promise<T>((resolve, reject) => {
|
||||||
|
const onCancel = (callback: () => void) => {
|
||||||
|
this.cancelCallback = callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
executor(
|
||||||
|
(value) => {
|
||||||
|
if (!this.isCanceled) {
|
||||||
|
resolve(value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(reason) => {
|
||||||
|
if (!this.isCanceled) {
|
||||||
|
reject(reason);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onCancel
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public cancel() {
|
||||||
|
if (this.cancelCallback) {
|
||||||
|
this.cancelCallback();
|
||||||
|
}
|
||||||
|
this.isCanceled = true;
|
||||||
|
this.cancelListeners.forEach(listener => listener());
|
||||||
|
}
|
||||||
|
|
||||||
|
public isTaskCanceled(): boolean {
|
||||||
|
return this.isCanceled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public onCancel(listener: () => void) {
|
||||||
|
this.cancelListeners.push(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public then<TResult1 = T, TResult2 = never>(
|
||||||
|
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
|
||||||
|
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
|
||||||
|
): Promise<TResult1 | TResult2> {
|
||||||
|
return this.promise.then(onfulfilled, onrejected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public catch<TResult = never>(
|
||||||
|
onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null
|
||||||
|
): Promise<T | TResult> {
|
||||||
|
return this.promise.catch(onrejected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public finally(onfinally?: (() => void) | undefined | null): Promise<T> {
|
||||||
|
return this.promise.finally(onfinally);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Symbol.asyncIterator]() {
|
||||||
|
return {
|
||||||
|
next: () => this.promise.then(value => ({ value, done: true })),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function demoAwait() {
|
||||||
|
const executor: TaskExecutor<number> = (resolve, reject, onCancel) => {
|
||||||
|
let count = 0;
|
||||||
|
const intervalId = setInterval(() => {
|
||||||
|
count++;
|
||||||
|
console.log(`Task is running... Count: ${count}`);
|
||||||
|
if (count === 5) {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
resolve(count);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
onCancel(() => {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
console.log('Task has been canceled.');
|
||||||
|
reject(new Error('Task was canceled'));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const task = new CancelableTask(executor);
|
||||||
|
|
||||||
|
task.onCancel(() => {
|
||||||
|
console.log('Cancel listener triggered.');
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
task.cancel(); // 取消任务
|
||||||
|
}, 6000);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await task;
|
||||||
|
console.log(`Task completed with result: ${result}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Task failed:', error);
|
||||||
|
}
|
||||||
|
}
|
22
src/common/decorator.ts
Normal file
22
src/common/decorator.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// decoratorAsyncMethod(this,function,wrapper)
|
||||||
|
async function decoratorMethod<T, R>(
|
||||||
|
target: T,
|
||||||
|
method: () => Promise<R>,
|
||||||
|
wrapper: (result: R) => Promise<any>,
|
||||||
|
executeImmediately: boolean = true
|
||||||
|
): Promise<any> {
|
||||||
|
const execute = async () => {
|
||||||
|
try {
|
||||||
|
const result = await method.call(target);
|
||||||
|
return wrapper(result);
|
||||||
|
} catch (error) {
|
||||||
|
return Promise.reject(error instanceof Error ? error : new Error(String(error)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (executeImmediately) {
|
||||||
|
return execute();
|
||||||
|
} else {
|
||||||
|
return execute;
|
||||||
|
}
|
||||||
|
}
|
43
src/common/fall-back.ts
Normal file
43
src/common/fall-back.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
type Handler<T> = () => T | Promise<T>;
|
||||||
|
type Checker<T> = (result: T) => T | Promise<T>;
|
||||||
|
|
||||||
|
export class Fallback<T> {
|
||||||
|
private handlers: Handler<T>[] = [];
|
||||||
|
private checker: Checker<T>;
|
||||||
|
|
||||||
|
constructor(checker?: Checker<T>) {
|
||||||
|
this.checker = checker || (async (result: T) => result);
|
||||||
|
}
|
||||||
|
|
||||||
|
add(handler: Handler<T>): this {
|
||||||
|
this.handlers.push(handler);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行处理程序链
|
||||||
|
async run(): Promise<T> {
|
||||||
|
const errors: Error[] = [];
|
||||||
|
for (const handler of this.handlers) {
|
||||||
|
try {
|
||||||
|
const result = await handler();
|
||||||
|
try {
|
||||||
|
return await this.checker(result);
|
||||||
|
} catch (checkerError) {
|
||||||
|
errors.push(checkerError instanceof Error ? checkerError : new Error(String(checkerError)));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
errors.push(error instanceof Error ? error : new Error(String(error)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new AggregateError(errors, 'All handlers failed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export class FallbackUtil{
|
||||||
|
static boolchecker<T>(value: T, condition: boolean): T {
|
||||||
|
if (condition) {
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
throw new Error('Condition is false, throwing error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
import https from 'node:https';
|
import https from 'node:https';
|
||||||
import { napCatVersion } from './version';
|
import { napCatVersion } from './version';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
|
|
||||||
export class UmamiTraceCore {
|
export class UmamiTraceCore {
|
||||||
napcatVersion = napCatVersion;
|
napcatVersion = napCatVersion;
|
||||||
qqversion = '1.0.0';
|
qqversion = '1.0.0';
|
||||||
@@ -13,20 +14,22 @@ export class UmamiTraceCore {
|
|||||||
workname: string = 'default';
|
workname: string = 'default';
|
||||||
bootTime = Date.now();
|
bootTime = Date.now();
|
||||||
cache: string = '';
|
cache: string = '';
|
||||||
|
platform = process.platform;
|
||||||
|
|
||||||
init(qqversion: string, guid: string, workname: string) {
|
init(qqversion: string, guid: string, workname: string) {
|
||||||
this.qqversion = qqversion;
|
this.qqversion = qqversion;
|
||||||
this.workname = workname;
|
this.workname = workname;
|
||||||
let UaList = {
|
const UaList = {
|
||||||
'linux': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/124.0.0.0 Safari/537.36 PTST/240508.140043',
|
linux: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Ubuntu/11.10 Chromium/27.0.1453.93 Chrome/27.0.1453.93 Safari/537.36',
|
||||||
'win32': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.2128.93 Safari/537.36',
|
win32: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.2128.93 Safari/537.36',
|
||||||
'darwin': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
|
darwin: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (process.platform === 'win32') {
|
if (this.platform === 'win32') {
|
||||||
const ntVersion = os.release();
|
const ntVersion = os.release();
|
||||||
UaList.win32 = `Mozilla/5.0 (Windows NT ${ntVersion}; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.2128.93 Safari/537.36`;
|
UaList.win32 = `Mozilla/5.0 (Windows NT ${ntVersion}; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.2128.93 Safari/537.36`;
|
||||||
} else if (process.platform === 'darwin') {
|
} else if (this.platform === 'darwin') {
|
||||||
const macVersion = os.release();
|
const macVersion = os.release();
|
||||||
UaList.darwin = `Mozilla/5.0 (Macintosh; Intel Mac OS X ${macVersion}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36`;
|
UaList.darwin = `Mozilla/5.0 (Macintosh; Intel Mac OS X ${macVersion}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36`;
|
||||||
}
|
}
|
||||||
@@ -34,7 +37,7 @@ export class UmamiTraceCore {
|
|||||||
this.ua = UaList.win32;
|
this.ua = UaList.win32;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ua = UaList[process.platform as keyof typeof UaList] || UaList.win32;
|
this.ua = UaList[this.platform as keyof typeof UaList] || UaList.win32;
|
||||||
|
|
||||||
this.identifyUser(guid);
|
this.identifyUser(guid);
|
||||||
this.startHeartbeat();
|
this.startHeartbeat();
|
||||||
@@ -47,17 +50,17 @@ export class UmamiTraceCore {
|
|||||||
qq_version: this.qqversion,
|
qq_version: this.qqversion,
|
||||||
napcat_working: this.workname,
|
napcat_working: this.workname,
|
||||||
device_guid: this.guid,
|
device_guid: this.guid,
|
||||||
device_platform: os.platform(),
|
device_platform: this.platform,
|
||||||
device_arch: os.arch(),
|
device_arch: os.arch(),
|
||||||
boot_time: new Date(this.bootTime + 8 * 60 * 60 * 1000).toISOString().replace('T', ' ').substring(0, 19),
|
boot_time: new Date(this.bootTime + 8 * 60 * 60 * 1000).toISOString().replace('T', ' ').substring(0, 19),
|
||||||
sys_time: new Date(Date.now() - os.uptime() * 1000 + 8 * 60 * 60 * 1000).toISOString().replace('T', ' ').substring(0, 19)
|
sys_time: new Date(Date.now() - os.uptime() * 1000 + 8 * 60 * 60 * 1000).toISOString().replace('T', ' ').substring(0, 19),
|
||||||
};
|
};
|
||||||
this.sendEvent(
|
this.sendEvent(
|
||||||
{
|
{
|
||||||
website: this.website,
|
website: this.website,
|
||||||
hostname: this.hostname,
|
hostname: this.hostname,
|
||||||
referrer: this.referrer,
|
referrer: this.referrer,
|
||||||
tittle: 'NapCat ' + this.napcatVersion,
|
title: 'NapCat ' + this.napcatVersion,
|
||||||
url: `/${this.qqversion}/${this.napcatVersion}/${this.workname}/identify`,
|
url: `/${this.qqversion}/${this.napcatVersion}/${this.workname}/identify`,
|
||||||
},
|
},
|
||||||
data,
|
data,
|
||||||
@@ -76,8 +79,8 @@ export class UmamiTraceCore {
|
|||||||
language: language || 'en-US',
|
language: language || 'en-US',
|
||||||
screen: '1920x1080',
|
screen: '1920x1080',
|
||||||
data: {
|
data: {
|
||||||
...data
|
...data,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
this.sendRequest(payload, type);
|
this.sendRequest(payload, type);
|
||||||
}
|
}
|
||||||
@@ -87,7 +90,7 @@ export class UmamiTraceCore {
|
|||||||
website: this.website,
|
website: this.website,
|
||||||
hostname: this.hostname,
|
hostname: this.hostname,
|
||||||
title: 'NapCat ' + this.napcatVersion,
|
title: 'NapCat ' + this.napcatVersion,
|
||||||
url: `/${this.qqversion}/${this.napcatVersion}/${this.workname}/${eventName}` + (!!data ? `/${data}` : ''),
|
url: `/${this.qqversion}/${this.napcatVersion}/${this.workname}/${eventName}` + (data ? `/${data}` : ''),
|
||||||
referrer: this.referrer,
|
referrer: this.referrer,
|
||||||
};
|
};
|
||||||
this.sendRequest(payload);
|
this.sendRequest(payload);
|
||||||
@@ -142,4 +145,5 @@ export class UmamiTraceCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UmamiTrace = new UmamiTraceCore();
|
export const UmamiTrace = new UmamiTraceCore();
|
@@ -1 +1 @@
|
|||||||
export const napCatVersion = '4.2.61';
|
export const napCatVersion = '4.2.65';
|
||||||
|
@@ -2,8 +2,7 @@ import { ModifyProfileParams, User, UserDetailSource } from '@/core/types';
|
|||||||
import { RequestUtil } from '@/common/request';
|
import { RequestUtil } from '@/common/request';
|
||||||
import { InstanceContext, NapCatCore, ProfileBizType } from '..';
|
import { InstanceContext, NapCatCore, ProfileBizType } from '..';
|
||||||
import { solveAsyncProblem } from '@/common/helper';
|
import { solveAsyncProblem } from '@/common/helper';
|
||||||
import { promisify } from 'node:util';
|
import { Fallback, FallbackUtil } from '@/common/fall-back';
|
||||||
import { LRUCache } from '@/common/lru-cache';
|
|
||||||
|
|
||||||
export class NTQQUserApi {
|
export class NTQQUserApi {
|
||||||
context: InstanceContext;
|
context: InstanceContext;
|
||||||
@@ -108,6 +107,19 @@ export class NTQQUserApi {
|
|||||||
return retUser;
|
return retUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getUserDetailInfoV2(uid: string): Promise<User> {
|
||||||
|
const fallback = new Fallback<User>((user) => FallbackUtil.boolchecker(user, user !== undefined && user.uin !== '0'))
|
||||||
|
.add(() => this.fetchUserDetailInfo(uid, UserDetailSource.KDB))
|
||||||
|
.add(() => this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER));
|
||||||
|
const retUser = await fallback.run().then(async (user) => {
|
||||||
|
if (user && user.uin === '0') {
|
||||||
|
user.uin = await this.core.apis.UserApi.getUidByUinV2(uid) ?? '0';
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
});
|
||||||
|
return retUser;
|
||||||
|
}
|
||||||
|
|
||||||
async modifySelfProfile(param: ModifyProfileParams) {
|
async modifySelfProfile(param: ModifyProfileParams) {
|
||||||
return this.context.session.getProfileService().modifyDesktopMiniProfile(param);
|
return this.context.session.getProfileService().modifyDesktopMiniProfile(param);
|
||||||
}
|
}
|
||||||
@@ -169,46 +181,34 @@ export class NTQQUserApi {
|
|||||||
return skey;
|
return skey;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUidByUinV2(Uin: string) {
|
async getUidByUinV2(uin: string) {
|
||||||
if (!Uin) {
|
if (!uin) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
const services = [
|
|
||||||
() => this.context.session.getUixConvertService().getUid([Uin]).then((data) => data.uidInfo.get(Uin)).catch(() => undefined),
|
const fallback =
|
||||||
() => promisify<string, string[], Map<string, string>>
|
new Fallback<string | undefined>((uid) => FallbackUtil.boolchecker(uid, uid !== undefined && uid.indexOf('*') === -1 && uid !== ''))
|
||||||
(this.context.session.getProfileService().getUidByUin)('FriendsServiceImpl', [Uin]).then((data) => data.get(Uin)).catch(() => undefined),
|
.add(() => this.context.session.getUixConvertService().getUid([uin]).then((data) => data.uidInfo.get(uin)))
|
||||||
() => this.context.session.getGroupService().getUidByUins([Uin]).then((data) => data.uids.get(Uin)).catch(() => undefined),
|
.add(() => this.context.session.getProfileService().getUidByUin('FriendsServiceImpl', [uin]).get(uin))
|
||||||
() => this.getUserDetailInfoByUin(Uin).then((data) => data.detail.uid).catch(() => undefined),
|
.add(() => this.context.session.getGroupService().getUidByUins([uin]).then((data) => data.uids.get(uin)))
|
||||||
];
|
.add(() => this.getUserDetailInfoByUin(uin).then((data) => data.detail.uid));
|
||||||
let uid: string | undefined = undefined;
|
|
||||||
for (const service of services) {
|
const uid = await fallback.run().catch(() => '0');
|
||||||
uid = await service();
|
|
||||||
if (uid && uid.indexOf('*') == -1 && uid !== '') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uid ?? '';
|
return uid ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUinByUidV2(Uid: string) {
|
async getUinByUidV2(uid: string) {
|
||||||
if (!Uid) {
|
if (!uid) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
const services = [
|
|
||||||
() => this.context.session.getUixConvertService().getUin([Uid]).then((data) => data.uinInfo.get(Uid)).catch(() => undefined),
|
const fallback = new Fallback<string | undefined>((uin) => FallbackUtil.boolchecker(uin, uin !== undefined && uin !== '0' && uin !== ''))
|
||||||
() => this.context.session.getGroupService().getUinByUids([Uid]).then((data) => data.uins.get(Uid)).catch(() => undefined),
|
.add(() => this.context.session.getUixConvertService().getUin([uid]).then((data) => data.uinInfo.get(uid)))
|
||||||
() => promisify<string, string[], Map<string, string>>
|
.add(() => this.context.session.getProfileService().getUinByUid('FriendsServiceImpl', [uid]).get(uid))
|
||||||
(this.context.session.getProfileService().getUinByUid)('FriendsServiceImpl', [Uid]).then((data) => data.get(Uid)).catch(() => undefined),
|
.add(() => this.context.session.getGroupService().getUinByUids([uid]).then((data) => data.uins.get(uid)))
|
||||||
() => this.core.apis.FriendApi.getBuddyIdMap(true).then((data) => data.getKey(Uid)).catch(() => undefined),
|
.add(() => this.getUserDetailInfo(uid).then((data) => data.uin));
|
||||||
() => this.getUserDetailInfo(Uid).then((data) => data.uin).catch(() => undefined),
|
|
||||||
];
|
const uin = await fallback.run().catch(() => '0');
|
||||||
let uin: string | undefined = undefined;
|
|
||||||
for (const service of services) {
|
|
||||||
uin = await service();
|
|
||||||
if (uin && uin !== '0' && uin !== '') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uin ?? '0';
|
return uin ?? '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@ import {
|
|||||||
WebHonorType,
|
WebHonorType,
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import { NapCatCore } from '..';
|
import { NapCatCore } from '..';
|
||||||
import { createReadStream, readFileSync, statSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
import { createHash } from 'node:crypto';
|
import { createHash } from 'node:crypto';
|
||||||
import { basename } from 'node:path';
|
import { basename } from 'node:path';
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@ export class PacketOperationContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async GroupPoke(groupUin: number, uin: number) {
|
async GroupPoke(groupUin: number, uin: number) {
|
||||||
const req = trans.SendPoke.build(groupUin, uin);
|
const req = trans.SendPoke.build(uin, groupUin);
|
||||||
await this.context.client.sendOidbPacket(req);
|
await this.context.client.sendOidbPacket(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -83,5 +83,5 @@ export abstract class OneBotAction<PayloadType, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract _handle(payload: PayloadType, adaptername: string): PromiseLike<ReturnDataType>;
|
abstract _handle(payload: PayloadType, adaptername: string): Promise<ReturnDataType>;
|
||||||
}
|
}
|
||||||
|
@@ -14,22 +14,23 @@ class OCRImageBase extends OneBotAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const { path, success } = (await uriToLocalFile(this.core.NapCatTempPath, payload.image));
|
const { path, success } = await uriToLocalFile(this.core.NapCatTempPath, payload.image);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw new Error(`OCR ${payload.image}失败,image字段可能格式不正确`);
|
throw new Error(`OCR ${payload.image}失败, image字段可能格式不正确`);
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
await checkFileExist(path, 5000); // 避免崩溃
|
try {
|
||||||
const ret = await this.core.apis.SystemApi.ocrImage(path);
|
await checkFileExist(path, 5000); // 避免崩溃
|
||||||
fs.unlink(path, () => { });
|
const ret = await this.core.apis.SystemApi.ocrImage(path);
|
||||||
|
if (!ret) {
|
||||||
if (!ret) {
|
throw new Error(`OCR ${payload.image}失败`);
|
||||||
throw new Error(`OCR ${payload.image}失败`);
|
}
|
||||||
|
return ret.result;
|
||||||
|
} finally {
|
||||||
|
fs.unlink(path, () => { });
|
||||||
}
|
}
|
||||||
return ret.result;
|
|
||||||
}
|
}
|
||||||
fs.unlink(path, () => { });
|
throw new Error(`OCR ${payload.image}失败, 文件可能不存在`);
|
||||||
throw new Error(`OCR ${payload.image}失败,文件可能不存在`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,4 +40,4 @@ export class OCRImage extends OCRImageBase {
|
|||||||
|
|
||||||
export class IOCRImage extends OCRImageBase {
|
export class IOCRImage extends OCRImageBase {
|
||||||
actionName = ActionName.IOCRImage;
|
actionName = ActionName.IOCRImage;
|
||||||
}
|
}
|
@@ -14,6 +14,6 @@ export class GroupPoke extends GetPacketStatusDepends<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
await this.core.apis.PacketApi.pkt.operation.GroupPoke(+payload.user_id, +payload.group_id);
|
await this.core.apis.PacketApi.pkt.operation.GroupPoke(+payload.group_id, +payload.user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,15 +21,9 @@ export class SendGroupAiRecord extends GetPacketStatusDepends<Payload, {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const rawRsp = await this.core.apis.PacketApi.pkt.operation.GetAiVoice(+payload.group_id, payload.character, payload.text, AIVoiceChatType.Sound);
|
await this.core.apis.PacketApi.pkt.operation.GetAiVoice(+payload.group_id, payload.character, payload.text, AIVoiceChatType.Sound);
|
||||||
const url = await this.core.apis.PacketApi.pkt.operation.GetGroupPttUrl(+payload.group_id, rawRsp.msgInfoBody[0].index);
|
return {
|
||||||
const { path, errMsg, success } = (await uriToLocalFile(this.core.NapCatTempPath, url));
|
message_id: 0 // can't get message_id from GetAiVoice
|
||||||
if (!success) {
|
};
|
||||||
throw new Error(errMsg);
|
|
||||||
}
|
|
||||||
const peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() } as Peer;
|
|
||||||
const element = await this.core.apis.FileApi.createValidSendPttElement(path);
|
|
||||||
const sendRes = await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, [element], [path]);
|
|
||||||
return { message_id: sendRes.id ?? -1 };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,9 +15,9 @@ export class SendPoke extends GetPacketStatusDepends<Payload, any> {
|
|||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
if (payload.group_id) {
|
if (payload.group_id) {
|
||||||
this.core.apis.PacketApi.pkt.operation.GroupPoke(+payload.group_id, +payload.user_id);
|
await this.core.apis.PacketApi.pkt.operation.GroupPoke(+payload.group_id, +payload.user_id);
|
||||||
} else {
|
} else {
|
||||||
this.core.apis.PacketApi.pkt.operation.FriendPoke(+payload.user_id);
|
await this.core.apis.PacketApi.pkt.operation.FriendPoke(+payload.user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -797,6 +797,13 @@ export class OneBotMsgApi {
|
|||||||
|
|
||||||
private async handlePrivateMessage(resMsg: OB11Message, msg: RawMessage) {
|
private async handlePrivateMessage(resMsg: OB11Message, msg: RawMessage) {
|
||||||
resMsg.sub_type = 'friend';
|
resMsg.sub_type = 'friend';
|
||||||
|
if (await this.core.apis.FriendApi.isBuddy(msg.senderUid)) {
|
||||||
|
let nickname = (await this.core.apis.UserApi.getCoreAndBaseInfo([msg.senderUid])).get(msg.senderUid)?.coreInfo.nick;
|
||||||
|
if (nickname) {
|
||||||
|
resMsg.sender.nickname = nickname;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
resMsg.sender.nickname = (await this.core.apis.UserApi.getUserDetailInfo(msg.senderUid)).nick;
|
resMsg.sender.nickname = (await this.core.apis.UserApi.getUserDetailInfo(msg.senderUid)).nick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -390,9 +390,6 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.context.logger.logDebug('有加群请求');
|
this.context.logger.logDebug('有加群请求');
|
||||||
try {
|
try {
|
||||||
let requestUin = await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid);
|
let requestUin = await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid);
|
||||||
if (isNaN(parseInt(requestUin))) {
|
|
||||||
requestUin = (await this.core.apis.UserApi.getUserDetailInfo(notify.user1.uid)).uin;
|
|
||||||
}
|
|
||||||
const groupRequestEvent = new OB11GroupRequestEvent(
|
const groupRequestEvent = new OB11GroupRequestEvent(
|
||||||
this.core,
|
this.core,
|
||||||
parseInt(notify.group.groupCode),
|
parseInt(notify.group.groupCode),
|
||||||
|
@@ -90,7 +90,7 @@ export class WebUiConfigWrapper {
|
|||||||
try {
|
try {
|
||||||
const configPath = resolve(webUiPathWrapper.configPath, './webui.json');
|
const configPath = resolve(webUiPathWrapper.configPath, './webui.json');
|
||||||
|
|
||||||
if (!await fs.access(configPath, constants.R_OK).then(() => true).catch(() => false)) {
|
if (!await fs.access(configPath, constants.F_OK).then(() => true).catch(() => false)) {
|
||||||
await fs.writeFile(configPath, JSON.stringify(defaultconfig, null, 4));
|
await fs.writeFile(configPath, JSON.stringify(defaultconfig, null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,12 @@ export class WebUiConfigWrapper {
|
|||||||
if (!parsedConfig.prefix.startsWith('/')) parsedConfig.prefix = '/' + parsedConfig.prefix;
|
if (!parsedConfig.prefix.startsWith('/')) parsedConfig.prefix = '/' + parsedConfig.prefix;
|
||||||
if (parsedConfig.prefix.endsWith('/')) parsedConfig.prefix = parsedConfig.prefix.slice(0, -1);
|
if (parsedConfig.prefix.endsWith('/')) parsedConfig.prefix = parsedConfig.prefix.slice(0, -1);
|
||||||
// 配置已经被操作过了,还是回写一下吧,不然新配置不会出现在配置文件里
|
// 配置已经被操作过了,还是回写一下吧,不然新配置不会出现在配置文件里
|
||||||
await fs.writeFile(configPath, JSON.stringify(parsedConfig, null, 4));
|
if (await fs.access(configPath, constants.W_OK).then(() => true).catch(() => false)) {
|
||||||
|
await fs.writeFile(configPath, JSON.stringify(parsedConfig, null, 4));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.warn(`文件: ${configPath} 没有写入权限, 配置的更改部分可能会在重启后还原.`);
|
||||||
|
}
|
||||||
// 不希望回写的配置放后面
|
// 不希望回写的配置放后面
|
||||||
|
|
||||||
// 查询主机地址是否可用
|
// 查询主机地址是否可用
|
||||||
|
Reference in New Issue
Block a user