mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
154 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
607dd68620 | ||
![]() |
7c8cbc0799 | ||
![]() |
ec0c2e8c33 | ||
![]() |
7f3dbe0552 | ||
![]() |
0e9044e0c8 | ||
![]() |
3171640193 | ||
![]() |
a56cee3485 | ||
![]() |
c8ee371982 | ||
![]() |
5778daeb60 | ||
![]() |
f51f3b9861 | ||
![]() |
44dd1a0b02 | ||
![]() |
61a00ffcbf | ||
![]() |
4b0a0f0a32 | ||
![]() |
a3088fb8bc | ||
![]() |
88fd1f9eb1 | ||
![]() |
15156bac1e | ||
![]() |
a898d2e7be | ||
![]() |
95b003802c | ||
![]() |
95c9eae4ed | ||
![]() |
e3814403e4 | ||
![]() |
3d16d52dd8 | ||
![]() |
1ae47fffb4 | ||
![]() |
4e7096b9e2 | ||
![]() |
8cc9b7f6a7 | ||
![]() |
fb45c1020e | ||
![]() |
e9db4ae8f4 | ||
![]() |
c46ec32bd6 | ||
![]() |
c58a26ed99 | ||
![]() |
a66f5e4971 | ||
![]() |
574c8c6089 | ||
![]() |
67afd95910 | ||
![]() |
f7d0cb0be7 | ||
![]() |
be9b68a0b1 | ||
![]() |
4637414af2 | ||
![]() |
4bd92a72bd | ||
![]() |
a3be26f3e4 | ||
![]() |
675c906cbf | ||
![]() |
6be6023236 | ||
![]() |
42cee0d018 | ||
![]() |
041f725748 | ||
![]() |
0594d61631 | ||
![]() |
15cae6b765 | ||
![]() |
b984116c35 | ||
![]() |
13bda6e3f4 | ||
![]() |
c0d18549d1 | ||
![]() |
3caff72fce | ||
![]() |
1313e9c3f4 | ||
![]() |
0848d5a39e | ||
![]() |
7660646059 | ||
![]() |
bcd90fc744 | ||
![]() |
638fc22d62 | ||
![]() |
c87d365b88 | ||
![]() |
aee9602f25 | ||
![]() |
976fbd0220 | ||
![]() |
afd955d06f | ||
![]() |
4d548da66b | ||
![]() |
41b70f53d1 | ||
![]() |
a47a618bcd | ||
![]() |
62170a30af | ||
![]() |
780c5ac23c | ||
![]() |
9fba519a5a | ||
![]() |
3cd0e7d26b | ||
![]() |
a8fd6af994 | ||
![]() |
4000b89644 | ||
![]() |
9c00bbc0b7 | ||
![]() |
a2989d3b38 | ||
![]() |
fc731b60d5 | ||
![]() |
193980dd4a | ||
![]() |
35427b0768 | ||
![]() |
73ea130e40 | ||
![]() |
5667e6aaee | ||
![]() |
fbd626131d | ||
![]() |
7b82444338 | ||
![]() |
8108b9f565 | ||
![]() |
c6ddd00cd9 | ||
![]() |
20c0c00fa0 | ||
![]() |
1f90364ba6 | ||
![]() |
49ea4d31a5 | ||
![]() |
dc35f1456a | ||
![]() |
0ebeb90804 | ||
![]() |
3ef5436c98 | ||
![]() |
de7996d789 | ||
![]() |
ac52d9bae2 | ||
![]() |
cb02df3b76 | ||
![]() |
5fc5a6f1a6 | ||
![]() |
726a0d0394 | ||
![]() |
6edf5345a3 | ||
![]() |
242bbfdb14 | ||
![]() |
89e7712676 | ||
![]() |
9525786929 | ||
![]() |
72088e41a8 | ||
![]() |
a3ed9ff2ef | ||
![]() |
ff16dc73ec | ||
![]() |
2da4ef5f0f | ||
![]() |
eaf481799d | ||
![]() |
1f72863aba | ||
![]() |
6b353fd8d8 | ||
![]() |
56cde4ad79 | ||
![]() |
3b86d3c632 | ||
![]() |
4ac7a25afb | ||
![]() |
8248011a12 | ||
![]() |
5f454456d2 | ||
![]() |
e99a619c23 | ||
![]() |
1fc791bb68 | ||
![]() |
f1d83f7c16 | ||
![]() |
527bb72bcf | ||
![]() |
d78409fd07 | ||
![]() |
d5e7e8944f | ||
![]() |
fb405a5c1c | ||
![]() |
a9e471deca | ||
![]() |
9cd15ae337 | ||
![]() |
8ed4cc4b0a | ||
![]() |
a62de441cf | ||
![]() |
02a8999410 | ||
![]() |
59c7979d69 | ||
![]() |
bb7b28cd8f | ||
![]() |
056497b98a | ||
![]() |
ac2fb032c4 | ||
![]() |
c933bdd5d9 | ||
![]() |
89c71a58fa | ||
![]() |
27ba85b4ff | ||
![]() |
79a75fed8e | ||
![]() |
ee7a76b29f | ||
![]() |
c53bdc3ce0 | ||
![]() |
f36e328751 | ||
![]() |
871b5688c2 | ||
![]() |
b96076b297 | ||
![]() |
d4488e40cf | ||
![]() |
7e61497243 | ||
![]() |
e71ccdd12a | ||
![]() |
202129d491 | ||
![]() |
a1700dd503 | ||
![]() |
2954776539 | ||
![]() |
fb1f122ef7 | ||
![]() |
96c63e4689 | ||
![]() |
c94936d3dc | ||
![]() |
8c22f11087 | ||
![]() |
8a089c84a9 | ||
![]() |
b631e6f8a2 | ||
![]() |
b3b48b032c | ||
![]() |
f3e8230eca | ||
![]() |
cc9adf9d40 | ||
![]() |
15a640d1dc | ||
![]() |
c25b9f86db | ||
![]() |
ecfd033afb | ||
![]() |
f3ed8c7dff | ||
![]() |
6089046721 | ||
![]() |
44ff92ad4b | ||
![]() |
892262eb85 | ||
![]() |
2d9cc4d198 | ||
![]() |
a0c479485d | ||
![]() |
5650f18e50 | ||
![]() |
553885d025 | ||
![]() |
35de00c4af |
@@ -1,6 +1,6 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -32,10 +32,12 @@ NapCatQQ 是现代化的基于 NTQQ 的 Bot 协议端实现
|
|||||||
|
|
||||||
[Server.Other](https://docs.napcat.cyou/)
|
[Server.Other](https://docs.napcat.cyou/)
|
||||||
|
|
||||||
|
[Qbot.News](https://neko.qbot.news)
|
||||||
|
|
||||||
## 回家旅途
|
## 回家旅途
|
||||||
[QQ Group#1](https://qm.qq.com/q/I6LU87a0Yq)
|
[QQ Group#1](https://qm.qq.com/q/I6LU87a0Yq)
|
||||||
|
|
||||||
[QQ Group#2](https://qm.qq.com/q/uqh4I87KoM)
|
[QQ Group#2](https://qm.qq.com/q/HaRcfrHpUk)
|
||||||
|
|
||||||
[Telegram](https://t.me/MelodicMoonlight)
|
[Telegram](https://t.me/MelodicMoonlight)
|
||||||
|
|
||||||
|
BIN
external/logo.png
vendored
Normal file
BIN
external/logo.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 204 KiB |
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "qq-chat",
|
"name": "qq-chat",
|
||||||
"version": "9.9.16-29927",
|
"version": "9.9.17-30899",
|
||||||
"verHash": "3e273e30",
|
"verHash": "ececf273",
|
||||||
"linuxVersion": "3.2.13-29927",
|
"linuxVersion": "3.2.15-30899",
|
||||||
"linuxVerHash": "833d113c",
|
"linuxVerHash": "63c751e8",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "QQ",
|
"description": "QQ",
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
"qd": "externals/devtools/cli/index.js"
|
"qd": "externals/devtools/cli/index.js"
|
||||||
},
|
},
|
||||||
"main": "./loadNapCat.js",
|
"main": "./loadNapCat.js",
|
||||||
"buildVersion": "29927",
|
"buildVersion": "30899",
|
||||||
"isPureShell": true,
|
"isPureShell": true,
|
||||||
"isByteCodeShell": true,
|
"isByteCodeShell": true,
|
||||||
"platform": "win32",
|
"platform": "win32",
|
||||||
|
BIN
logo.png
BIN
logo.png
Binary file not shown.
Before Width: | Height: | Size: 335 KiB After Width: | Height: | Size: 684 KiB |
@@ -4,16 +4,12 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "4.2.34",
|
"version": "4.3.4",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "MliKiowa",
|
"name": "NapNeko",
|
||||||
"link": "https://github.com/MliKiowa"
|
"link": "https://github.com/NapNeko"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Young",
|
|
||||||
"link": "https://github.com/Wesley-Young"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "4.2.34",
|
"version": "4.3.4",
|
||||||
"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",
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
"dev:depend": "npm i && cd napcat.webui && npm i"
|
"dev:depend": "npm i && cd napcat.webui && npm i"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"esbuild": "0.24.0",
|
||||||
"@babel/preset-typescript": "^7.24.7",
|
"@babel/preset-typescript": "^7.24.7",
|
||||||
"@eslint/compat": "^1.2.2",
|
"@eslint/compat": "^1.2.2",
|
||||||
"@eslint/eslintrc": "^3.1.0",
|
"@eslint/eslintrc": "^3.1.0",
|
||||||
@@ -36,7 +37,7 @@
|
|||||||
"@typescript-eslint/parser": "^8.3.0",
|
"@typescript-eslint/parser": "^8.3.0",
|
||||||
"ajv": "^8.13.0",
|
"ajv": "^8.13.0",
|
||||||
"async-mutex": "^0.5.0",
|
"async-mutex": "^0.5.0",
|
||||||
"commander": "^12.1.0",
|
"commander": "^13.0.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"eslint": "^9.14.0",
|
"eslint": "^9.14.0",
|
||||||
"eslint-import-resolver-typescript": "^3.6.1",
|
"eslint-import-resolver-typescript": "^3.6.1",
|
||||||
@@ -60,4 +61,4 @@
|
|||||||
"silk-wasm": "^3.6.1",
|
"silk-wasm": "^3.6.1",
|
||||||
"ws": "^8.18.0"
|
"ws": "^8.18.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
|
const data = await this.checker(result);
|
||||||
|
if (data) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
93
src/common/file-uuid.ts
Normal file
93
src/common/file-uuid.ts
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import { Peer } from '@/core';
|
||||||
|
import { randomUUID } from 'crypto';
|
||||||
|
|
||||||
|
interface FileUUIDData {
|
||||||
|
peer: Peer;
|
||||||
|
modelId?: string;
|
||||||
|
fileId?: string;
|
||||||
|
msgId?: string;
|
||||||
|
elementId?: string;
|
||||||
|
fileUUID?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
class TimeBasedCache<K, V> {
|
||||||
|
private cache: Map<K, { value: V, timestamp: number }>;
|
||||||
|
private ttl: number;
|
||||||
|
|
||||||
|
constructor(ttl: number) {
|
||||||
|
this.cache = new Map();
|
||||||
|
this.ttl = ttl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public put(key: K, value: V): void {
|
||||||
|
const timestamp = Date.now();
|
||||||
|
this.cache.set(key, { value, timestamp });
|
||||||
|
this.cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
public get(key: K): V | undefined {
|
||||||
|
const entry = this.cache.get(key);
|
||||||
|
if (entry) {
|
||||||
|
const currentTime = Date.now();
|
||||||
|
if (currentTime - entry.timestamp < this.ttl) {
|
||||||
|
return entry.value;
|
||||||
|
} else {
|
||||||
|
this.cache.delete(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
private cleanup(): void {
|
||||||
|
const currentTime = Date.now();
|
||||||
|
for (const [key, entry] of this.cache.entries()) {
|
||||||
|
if (currentTime - entry.timestamp >= this.ttl) {
|
||||||
|
this.cache.delete(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FileUUIDManager {
|
||||||
|
private cache: TimeBasedCache<string, FileUUIDData>;
|
||||||
|
|
||||||
|
constructor(ttl: number) {
|
||||||
|
this.cache = new TimeBasedCache<string, FileUUIDData>(ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public encode(data: FileUUIDData, endString: string = "", customUUID?: string): string {
|
||||||
|
const uuid = customUUID ? customUUID : randomUUID().replace(/-/g, '') + endString;
|
||||||
|
this.cache.put(uuid, data);
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public decode(uuid: string): FileUUIDData | undefined {
|
||||||
|
return this.cache.get(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class FileNapCatOneBotUUIDWrap {
|
||||||
|
private manager: FileUUIDManager;
|
||||||
|
|
||||||
|
constructor(ttl: number = 86400000) {
|
||||||
|
this.manager = new FileUUIDManager(ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public encodeModelId(peer: Peer, modelId: string, fileId: string, fileUUID: string = "", endString: string = "", customUUID?: string): string {
|
||||||
|
return this.manager.encode({ peer, modelId, fileId, fileUUID }, endString, customUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public decodeModelId(uuid: string): FileUUIDData | undefined {
|
||||||
|
return this.manager.decode(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public encode(peer: Peer, msgId: string, elementId: string, fileUUID: string = "", customUUID?: string): string {
|
||||||
|
return this.manager.encode({ peer, msgId, elementId, fileUUID }, "", customUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public decode(uuid: string): FileUUIDData | undefined {
|
||||||
|
return this.manager.decode(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FileNapCatOneBotUUID = new FileNapCatOneBotUUIDWrap();
|
@@ -175,10 +175,9 @@ export async function checkUriType(Uri: string) {
|
|||||||
return { Uri: Uri, Type: FileUriType.Unknown };
|
return { Uri: Uri, Type: FileUriType.Unknown };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uriToLocalFile(dir: string, uri: string): Promise<Uri2LocalRes> {
|
export async function uriToLocalFile(dir: string, uri: string, filename: string = randomUUID(), headers?: Record<string, string>): Promise<Uri2LocalRes> {
|
||||||
const { Uri: HandledUri, Type: UriType } = await checkUriType(uri);
|
const { Uri: HandledUri, Type: UriType } = await checkUriType(uri);
|
||||||
|
|
||||||
const filename = randomUUID();
|
|
||||||
const filePath = path.join(dir, filename);
|
const filePath = path.join(dir, filename);
|
||||||
|
|
||||||
switch (UriType) {
|
switch (UriType) {
|
||||||
@@ -191,7 +190,7 @@ export async function uriToLocalFile(dir: string, uri: string): Promise<Uri2Loca
|
|||||||
}
|
}
|
||||||
|
|
||||||
case FileUriType.Remote: {
|
case FileUriType.Remote: {
|
||||||
const buffer = await httpDownload(HandledUri);
|
const buffer = await httpDownload({ url: HandledUri, headers: headers });
|
||||||
fs.writeFileSync(filePath, buffer, { flag: 'wx' });
|
fs.writeFileSync(filePath, buffer, { flag: 'wx' });
|
||||||
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
||||||
}
|
}
|
||||||
@@ -206,4 +205,4 @@ export async function uriToLocalFile(dir: string, uri: string): Promise<Uri2Loca
|
|||||||
default:
|
default:
|
||||||
return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' };
|
return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import { Peer, QQLevel } from '@/core';
|
import { QQLevel } from '@/core';
|
||||||
|
|
||||||
export async function solveProblem<T extends (...arg: any[]) => any>(func: T, ...args: Parameters<T>): Promise<ReturnType<T> | undefined> {
|
export async function solveProblem<T extends (...arg: any[]) => any>(func: T, ...args: Parameters<T>): Promise<ReturnType<T> | undefined> {
|
||||||
return new Promise<ReturnType<T> | undefined>((resolve) => {
|
return new Promise<ReturnType<T> | undefined>((resolve) => {
|
||||||
@@ -24,81 +24,6 @@ export async function solveAsyncProblem<T extends (...args: any[]) => Promise<an
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FileNapCatOneBotUUID {
|
|
||||||
static encodeModelId(peer: Peer, modelId: string, fileId: string, fileUUID: string = "", endString: string = ""): string {
|
|
||||||
const data = `NapCatOneBot|ModelIdFile|${peer.chatType}|${peer.peerUid}|${modelId}|${fileId}|${fileUUID}`;
|
|
||||||
//前四个字节塞data长度
|
|
||||||
const length = Buffer.alloc(4 + data.length);
|
|
||||||
length.writeUInt32BE(data.length * 2, 0);//储存data的hex长度
|
|
||||||
length.write(data, 4);
|
|
||||||
return length.toString('hex') + endString;
|
|
||||||
}
|
|
||||||
|
|
||||||
static decodeModelId(uuid: string): undefined | {
|
|
||||||
peer: Peer,
|
|
||||||
modelId: string,
|
|
||||||
fileId: string,
|
|
||||||
fileUUID?: string
|
|
||||||
} {
|
|
||||||
//前四个字节是data长度
|
|
||||||
const length = Buffer.from(uuid.slice(0, 8), 'hex').readUInt32BE(0);
|
|
||||||
//根据length计算需要读取的长度
|
|
||||||
const dataId = uuid.slice(8, 8 + length);
|
|
||||||
//hex还原为string
|
|
||||||
const realData = Buffer.from(dataId, 'hex').toString();
|
|
||||||
if (!realData.startsWith('NapCatOneBot|ModelIdFile|')) return undefined;
|
|
||||||
const data = realData.split('|');
|
|
||||||
if (data.length < 6) return undefined; // compatibility requirement
|
|
||||||
const [, , chatType, peerUid, modelId, fileId, fileUUID = undefined] = data;
|
|
||||||
return {
|
|
||||||
peer: {
|
|
||||||
chatType: +chatType,
|
|
||||||
peerUid: peerUid,
|
|
||||||
},
|
|
||||||
modelId,
|
|
||||||
fileId,
|
|
||||||
fileUUID
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static encode(peer: Peer, msgId: string, elementId: string, fileUUID: string = "", endString: string = ""): string {
|
|
||||||
const data = `NapCatOneBot|MsgFile|${peer.chatType}|${peer.peerUid}|${msgId}|${elementId}|${fileUUID}`;
|
|
||||||
//前四个字节塞data长度
|
|
||||||
//一个字节8位 一个ascii字符1字节 一个hex字符4位 表示一个ascii字符需要两个hex字符
|
|
||||||
const length = Buffer.alloc(4 + data.length);
|
|
||||||
length.writeUInt32BE(data.length * 2, 0);
|
|
||||||
length.write(data, 4);
|
|
||||||
return length.toString('hex') + endString;
|
|
||||||
}
|
|
||||||
|
|
||||||
static decode(uuid: string): undefined | {
|
|
||||||
peer: Peer,
|
|
||||||
msgId: string,
|
|
||||||
elementId: string,
|
|
||||||
fileUUID?: string
|
|
||||||
} {
|
|
||||||
//前四个字节是data长度
|
|
||||||
const length = Buffer.from(uuid.slice(0, 8), 'hex').readUInt32BE(0);
|
|
||||||
//根据length计算需要读取的长度
|
|
||||||
const dataId = uuid.slice(8, 8 + length);
|
|
||||||
//hex还原为string
|
|
||||||
const realData = Buffer.from(dataId, 'hex').toString();
|
|
||||||
if (!realData.startsWith('NapCatOneBot|MsgFile|')) return undefined;
|
|
||||||
const data = realData.split('|');
|
|
||||||
if (data.length < 6) return undefined; // compatibility requirement
|
|
||||||
const [, , chatType, peerUid, msgId, elementId, fileUUID = undefined] = data;
|
|
||||||
return {
|
|
||||||
peer: {
|
|
||||||
chatType: +chatType,
|
|
||||||
peerUid: peerUid,
|
|
||||||
},
|
|
||||||
msgId,
|
|
||||||
elementId,
|
|
||||||
fileUUID
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function sleep(ms: number): Promise<void> {
|
export function sleep(ms: number): Promise<void> {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
@@ -78,7 +78,7 @@ class MessageUniqueWrapper {
|
|||||||
private readonly msgDataMap: LimitedHashTable<string, number>;
|
private readonly msgDataMap: LimitedHashTable<string, number>;
|
||||||
private readonly msgIdMap: LimitedHashTable<string, number>;
|
private readonly msgIdMap: LimitedHashTable<string, number>;
|
||||||
|
|
||||||
constructor(maxMap: number = 1000) {
|
constructor(maxMap: number = 5000) {
|
||||||
this.msgIdMap = new LimitedHashTable<string, number>(maxMap);
|
this.msgIdMap = new LimitedHashTable<string, number>(maxMap);
|
||||||
this.msgDataMap = new LimitedHashTable<string, number>(maxMap);
|
this.msgDataMap = new LimitedHashTable<string, number>(maxMap);
|
||||||
}
|
}
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const napCatVersion = '4.2.34';
|
export const napCatVersion = '4.3.4';
|
||||||
|
@@ -26,7 +26,7 @@ export class NTQQGroupApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchGroupDetail(groupCode: string) {
|
async fetchGroupDetail(groupCode: string) {
|
||||||
let [, detailInfo] = await this.core.eventWrapper.callNormalEventV2(
|
const [, detailInfo] = await this.core.eventWrapper.callNormalEventV2(
|
||||||
'NodeIKernelGroupService/getGroupDetailInfo',
|
'NodeIKernelGroupService/getGroupDetailInfo',
|
||||||
'NodeIKernelGroupListener/onGroupDetailInfoChange',
|
'NodeIKernelGroupListener/onGroupDetailInfoChange',
|
||||||
[groupCode, GroupInfoSource.KDATACARD],
|
[groupCode, GroupInfoSource.KDATACARD],
|
||||||
@@ -44,7 +44,7 @@ export class NTQQGroupApi {
|
|||||||
|
|
||||||
async initCache() {
|
async initCache() {
|
||||||
for (const group of await this.getGroups(true)) {
|
for (const group of await this.getGroups(true)) {
|
||||||
this.refreshGroupMemberCache(group.groupCode).then().catch();
|
this.refreshGroupMemberCache(group.groupCode, false).then().catch(e => this.context.logger.logError(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,14 +126,23 @@ export class NTQQGroupApi {
|
|||||||
return this.context.session.getGroupService().getAllMemberList(groupCode, forced);
|
return this.context.session.getGroupService().getAllMemberList(groupCode, forced);
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshGroupMemberCache(groupCode: string) {
|
async refreshGroupMemberCache(groupCode: string, isWait = true) {
|
||||||
try {
|
const updateCache = async () => {
|
||||||
const members = await this.getGroupMemberAll(groupCode, true);
|
try {
|
||||||
this.groupMemberCache.set(groupCode, members.result.infos);
|
const members = await this.getGroupMemberAll(groupCode, true);
|
||||||
} catch (e) {
|
this.groupMemberCache.set(groupCode, members.result.infos);
|
||||||
this.context.logger.logError(`刷新群成员缓存失败, 群号: ${groupCode}, 错误: ${e}`);
|
} catch (e) {
|
||||||
|
this.context.logger.logError(`刷新群成员缓存失败, 群号: ${groupCode}, 错误: ${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isWait) {
|
||||||
|
await updateCache();
|
||||||
|
} else {
|
||||||
|
updateCache();
|
||||||
}
|
}
|
||||||
return this.groupMemberCache;
|
|
||||||
|
return this.groupMemberCache.get(groupCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroupMember(groupCode: string | number, memberUinOrUid: string | number) {
|
async getGroupMember(groupCode: string | number, memberUinOrUid: string | number) {
|
||||||
@@ -143,7 +152,7 @@ export class NTQQGroupApi {
|
|||||||
// 获取群成员缓存
|
// 获取群成员缓存
|
||||||
let members = this.groupMemberCache.get(groupCodeStr);
|
let members = this.groupMemberCache.get(groupCodeStr);
|
||||||
if (!members) {
|
if (!members) {
|
||||||
members = (await this.refreshGroupMemberCache(groupCodeStr)).get(groupCodeStr);
|
members = (await this.refreshGroupMemberCache(groupCodeStr, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
const getMember = () => {
|
const getMember = () => {
|
||||||
@@ -157,7 +166,7 @@ export class NTQQGroupApi {
|
|||||||
let member = getMember();
|
let member = getMember();
|
||||||
// 如果缓存中不存在该成员,尝试刷新缓存
|
// 如果缓存中不存在该成员,尝试刷新缓存
|
||||||
if (!member) {
|
if (!member) {
|
||||||
members = (await this.refreshGroupMemberCache(groupCodeStr)).get(groupCodeStr);
|
members = (await this.refreshGroupMemberCache(groupCodeStr, true));
|
||||||
member = getMember();
|
member = getMember();
|
||||||
}
|
}
|
||||||
return member;
|
return member;
|
||||||
|
@@ -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(() => '');
|
||||||
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';
|
||||||
|
|
||||||
|
44
src/core/external/appid.json
vendored
44
src/core/external/appid.json
vendored
@@ -134,5 +134,49 @@
|
|||||||
"3.2.15-30594": {
|
"3.2.15-30594": {
|
||||||
"appid": 537258474,
|
"appid": 537258474,
|
||||||
"qua": "V1_LNX_NQ_3.2.15_30594_GW_B"
|
"qua": "V1_LNX_NQ_3.2.15_30594_GW_B"
|
||||||
|
},
|
||||||
|
"9.9.17-30851": {
|
||||||
|
"appid": 537263796,
|
||||||
|
"qua": "V1_WIN_NQ_9.9.17_30851_GW_B"
|
||||||
|
},
|
||||||
|
"3.2.15-30851": {
|
||||||
|
"appid": 537263831,
|
||||||
|
"qua": "V1_LNX_NQ_3.2.15_30851_GW_B"
|
||||||
|
},
|
||||||
|
"6.9.63-30851": {
|
||||||
|
"appid": 537263820,
|
||||||
|
"qua": "V1_MAC_NQ_6.9.63_30851_GW_B"
|
||||||
|
},
|
||||||
|
"9.9.17-30899": {
|
||||||
|
"appid": 537263796,
|
||||||
|
"qua": "V1_WIN_NQ_9.9.17_30899_GW_B"
|
||||||
|
},
|
||||||
|
"3.2.15-30899": {
|
||||||
|
"appid": 537263831,
|
||||||
|
"qua": "V1_LNX_NQ_3.2.15_30899_GW_B"
|
||||||
|
},
|
||||||
|
"6.9.63-30899": {
|
||||||
|
"appid": 537263820,
|
||||||
|
"qua": "V1_MAC_NQ_6.9.63_30899_GW_B"
|
||||||
|
},
|
||||||
|
"9.9.17-31219": {
|
||||||
|
"appid": 537266450,
|
||||||
|
"qua": "V1_WIN_NQ_9.9.17_31219_GW_B"
|
||||||
|
},
|
||||||
|
"9.9.17-31245": {
|
||||||
|
"appid": 537266450,
|
||||||
|
"qua": "V1_WIN_NQ_9.9.17_31245_GW_B"
|
||||||
|
},
|
||||||
|
"3.2.15-31245": {
|
||||||
|
"appid": 537266485,
|
||||||
|
"qua": "V1_LNX_NQ_3.2.15_31245_GW_B"
|
||||||
|
},
|
||||||
|
"6.9.63-31245": {
|
||||||
|
"appid": 537266474,
|
||||||
|
"qua": "V1_MAC_NQ_6.9.63_31245_GW_B"
|
||||||
|
},
|
||||||
|
"9.9.17-31363": {
|
||||||
|
"appid": 537266500,
|
||||||
|
"qua": "V1_WIN_NQ_9.9.17_31363_GW_B"
|
||||||
}
|
}
|
||||||
}
|
}
|
68
src/core/external/offset.json
vendored
68
src/core/external/offset.json
vendored
@@ -162,5 +162,73 @@
|
|||||||
"3.2.15-30594-arm64": {
|
"3.2.15-30594-arm64": {
|
||||||
"send": "70C40E8",
|
"send": "70C40E8",
|
||||||
"recv": "70C7920"
|
"recv": "70C7920"
|
||||||
|
},
|
||||||
|
"9.9.17-30851-x64": {
|
||||||
|
"send": "395C150",
|
||||||
|
"recv": "3960584"
|
||||||
|
},
|
||||||
|
"3.2.15-30851-x64": {
|
||||||
|
"send": "A4A03E0",
|
||||||
|
"recv": "A4A3CE0"
|
||||||
|
},
|
||||||
|
"3.2.15-30851-arm64": {
|
||||||
|
"send": "713A318",
|
||||||
|
"recv": "713DB50"
|
||||||
|
},
|
||||||
|
"6.9.63.30851-x64": {
|
||||||
|
"send": "46C8040",
|
||||||
|
"recv": "46CA8AC"
|
||||||
|
},
|
||||||
|
"6.9.63-30851-arm64": {
|
||||||
|
"send": "41DCBD8",
|
||||||
|
"recv": "41DF3F0"
|
||||||
|
},
|
||||||
|
"9.9.17-30899-x64": {
|
||||||
|
"send": "395C150",
|
||||||
|
"recv": "3960584"
|
||||||
|
},
|
||||||
|
"3.2.15-30899-x64": {
|
||||||
|
"send": "A4A03E0",
|
||||||
|
"recv": "A4A3CE0"
|
||||||
|
},
|
||||||
|
"3.2.15-30899-arm64": {
|
||||||
|
"send": "713A318",
|
||||||
|
"recv": "713DB50"
|
||||||
|
},
|
||||||
|
"6.9.63.30899-x64": {
|
||||||
|
"send": "46C8040",
|
||||||
|
"recv": "46CA8AC"
|
||||||
|
},
|
||||||
|
"6.9.63-30899-arm64": {
|
||||||
|
"send": "41DCBD8",
|
||||||
|
"recv": "41DF3F0"
|
||||||
|
},
|
||||||
|
"9.9.17-31219-x64": {
|
||||||
|
"send": "39C1350",
|
||||||
|
"recv": "39C5784"
|
||||||
|
},
|
||||||
|
"9.9.17-31245-x64": {
|
||||||
|
"send": "39C1350",
|
||||||
|
"recv": "39C5784"
|
||||||
|
},
|
||||||
|
"6.9.63.31245-x64": {
|
||||||
|
"send": "4720A40",
|
||||||
|
"recv": "47232AC"
|
||||||
|
},
|
||||||
|
"6.9.63-31245-arm64": {
|
||||||
|
"send": "41DCBD8",
|
||||||
|
"recv": "422D4E8"
|
||||||
|
},
|
||||||
|
"3.2.15-31245-x64": {
|
||||||
|
"send": "A550F80",
|
||||||
|
"recv": "A554880"
|
||||||
|
},
|
||||||
|
"3.2.15-31245-arm64": {
|
||||||
|
"send": "71BEBB8",
|
||||||
|
"recv": "71C23F0"
|
||||||
|
},
|
||||||
|
"9.9.17-31363-x64": {
|
||||||
|
"send": "39C1910",
|
||||||
|
"recv": "39C5d44"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,49 +0,0 @@
|
|||||||
// TODO: further refactor in NapCat.Packet v2
|
|
||||||
import { NapProtoMsg, ProtoField, ScalarType } from "@napneko/nap-proto-core";
|
|
||||||
|
|
||||||
const BodyInner = {
|
|
||||||
msgType: ProtoField(1, ScalarType.UINT32, true),
|
|
||||||
subType: ProtoField(2, ScalarType.UINT32, true)
|
|
||||||
};
|
|
||||||
|
|
||||||
const NoifyData = {
|
|
||||||
skip: ProtoField(1, ScalarType.BYTES, true),
|
|
||||||
innerData: ProtoField(2, ScalarType.BYTES, true)
|
|
||||||
};
|
|
||||||
|
|
||||||
const MsgHead = {
|
|
||||||
bodyInner: ProtoField(2, () => BodyInner, true),
|
|
||||||
noifyData: ProtoField(3, () => NoifyData, true)
|
|
||||||
};
|
|
||||||
|
|
||||||
const Message = {
|
|
||||||
msgHead: ProtoField(1, () => MsgHead)
|
|
||||||
};
|
|
||||||
|
|
||||||
const SubDetail = {
|
|
||||||
msgSeq: ProtoField(1, ScalarType.UINT32),
|
|
||||||
msgTime: ProtoField(2, ScalarType.UINT32),
|
|
||||||
senderUid: ProtoField(6, ScalarType.STRING)
|
|
||||||
};
|
|
||||||
|
|
||||||
const RecallDetails = {
|
|
||||||
operatorUid: ProtoField(1, ScalarType.STRING),
|
|
||||||
subDetail: ProtoField(3, () => SubDetail)
|
|
||||||
};
|
|
||||||
|
|
||||||
const RecallGroup = {
|
|
||||||
type: ProtoField(1, ScalarType.INT32),
|
|
||||||
peerUid: ProtoField(4, ScalarType.UINT32),
|
|
||||||
recallDetails: ProtoField(11, () => RecallDetails),
|
|
||||||
grayTipsSeq: ProtoField(37, ScalarType.UINT32)
|
|
||||||
};
|
|
||||||
|
|
||||||
export function decodeMessage(buffer: Uint8Array) {
|
|
||||||
const msg = new NapProtoMsg(Message);
|
|
||||||
return msg.decode(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function decodeRecallGroup(buffer: Uint8Array){
|
|
||||||
const msg = new NapProtoMsg(RecallGroup);
|
|
||||||
return msg.decode(buffer);
|
|
||||||
}
|
|
138
src/core/helper/status.ts
Normal file
138
src/core/helper/status.ts
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
import os from "node:os";
|
||||||
|
import EventEmitter from "node:events";
|
||||||
|
|
||||||
|
export interface SystemStatus {
|
||||||
|
cpu: {
|
||||||
|
model: string,
|
||||||
|
speed: string
|
||||||
|
usage: {
|
||||||
|
system: string
|
||||||
|
qq: string
|
||||||
|
},
|
||||||
|
core: number
|
||||||
|
},
|
||||||
|
memory: {
|
||||||
|
total: string
|
||||||
|
usage: {
|
||||||
|
system: string
|
||||||
|
qq: string
|
||||||
|
}
|
||||||
|
},
|
||||||
|
arch: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class StatusHelper {
|
||||||
|
private psCpuUsage = process.cpuUsage();
|
||||||
|
private psCurrentTime = process.hrtime();
|
||||||
|
private cpuTimes = os.cpus().map(cpu => cpu.times);
|
||||||
|
|
||||||
|
private replaceNaN(value: number) {
|
||||||
|
return isNaN(value) ? 0 : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private sysCpuInfo() {
|
||||||
|
const currentTimes = os.cpus().map(cpu => cpu.times);
|
||||||
|
const { total, active } = currentTimes.map((times, index) => {
|
||||||
|
const prevTimes = this.cpuTimes[index];
|
||||||
|
const totalCurrent = times.user + times.nice + times.sys + times.idle + times.irq;
|
||||||
|
const totalPrev = prevTimes.user + prevTimes.nice + prevTimes.sys + prevTimes.idle + prevTimes.irq;
|
||||||
|
const activeCurrent = totalCurrent - times.idle;
|
||||||
|
const activePrev = totalPrev - prevTimes.idle;
|
||||||
|
return {
|
||||||
|
total: totalCurrent - totalPrev,
|
||||||
|
active: activeCurrent - activePrev
|
||||||
|
};
|
||||||
|
}).reduce((acc, cur) => ({
|
||||||
|
total: acc.total + cur.total,
|
||||||
|
active: acc.active + cur.active
|
||||||
|
}), { total: 0, active: 0 });
|
||||||
|
this.cpuTimes = currentTimes;
|
||||||
|
return {
|
||||||
|
usage: this.replaceNaN(((active / total) * 100)).toFixed(2),
|
||||||
|
model: os.cpus()[0].model,
|
||||||
|
speed: os.cpus()[0].speed,
|
||||||
|
core: os.cpus().length
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private sysMemoryUsage() {
|
||||||
|
const { total, free } = { total: os.totalmem(), free: os.freemem() };
|
||||||
|
return ((total - free) / 1024 / 1024).toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private qqUsage() {
|
||||||
|
const mem = process.memoryUsage();
|
||||||
|
const numCpus = os.cpus().length;
|
||||||
|
const usageDiff = process.cpuUsage(this.psCpuUsage);
|
||||||
|
const endTime = process.hrtime(this.psCurrentTime);
|
||||||
|
this.psCpuUsage = process.cpuUsage();
|
||||||
|
this.psCurrentTime = process.hrtime();
|
||||||
|
const usageMS = (usageDiff.user + usageDiff.system) / 1e3;
|
||||||
|
const totalMS = endTime[0] * 1e3 + endTime[1] / 1e6;
|
||||||
|
const normPercent = (usageMS / totalMS / numCpus) * 100;
|
||||||
|
return {
|
||||||
|
cpu: this.replaceNaN(normPercent).toFixed(2),
|
||||||
|
memory: ((mem.heapTotal + mem.external + mem.arrayBuffers) / 1024 / 1024).toFixed(2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
systemStatus(): SystemStatus {
|
||||||
|
const qqUsage = this.qqUsage();
|
||||||
|
const sysCpuInfo = this.sysCpuInfo();
|
||||||
|
return {
|
||||||
|
cpu: {
|
||||||
|
core: sysCpuInfo.core,
|
||||||
|
model: sysCpuInfo.model,
|
||||||
|
speed: (sysCpuInfo.speed / 1000).toFixed(2),
|
||||||
|
usage: {
|
||||||
|
system: sysCpuInfo.usage,
|
||||||
|
qq: qqUsage.cpu
|
||||||
|
},
|
||||||
|
},
|
||||||
|
memory: {
|
||||||
|
total: (os.totalmem() / 1024 / 1024).toFixed(2),
|
||||||
|
usage: {
|
||||||
|
system: this.sysMemoryUsage(),
|
||||||
|
qq: qqUsage.memory
|
||||||
|
}
|
||||||
|
},
|
||||||
|
arch: `${os.platform()} ${os.arch()} ${os.release()}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class StatusHelperSubscription extends EventEmitter {
|
||||||
|
private statusHelper: StatusHelper;
|
||||||
|
private interval: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
|
constructor(time: number = 3000) {
|
||||||
|
super();
|
||||||
|
this.statusHelper = new StatusHelper();
|
||||||
|
this.on('newListener', (event: string) => {
|
||||||
|
if (event === 'statusUpdate' && this.listenerCount('statusUpdate') === 0) {
|
||||||
|
this.startInterval(time);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.on('removeListener', (event: string) => {
|
||||||
|
if (event === 'statusUpdate' && this.listenerCount('statusUpdate') === 0) {
|
||||||
|
this.stopInterval();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private startInterval(time: number) {
|
||||||
|
this.interval ??= setInterval(() => {
|
||||||
|
const status = this.statusHelper.systemStatus();
|
||||||
|
this.emit('statusUpdate', status);
|
||||||
|
}, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
private stopInterval() {
|
||||||
|
if (this.interval) {
|
||||||
|
clearInterval(this.interval);
|
||||||
|
this.interval = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const statusHelperSubscription = new StatusHelperSubscription();
|
@@ -152,6 +152,7 @@ export class NapCatCore {
|
|||||||
// Renamed from 'InitDataListener'
|
// Renamed from 'InitDataListener'
|
||||||
async initNapCatCoreListeners() {
|
async initNapCatCoreListeners() {
|
||||||
const msgListener = new NodeIKernelMsgListener();
|
const msgListener = new NodeIKernelMsgListener();
|
||||||
|
|
||||||
msgListener.onKickedOffLine = (Info: KickedOffLineInfo) => {
|
msgListener.onKickedOffLine = (Info: KickedOffLineInfo) => {
|
||||||
// 下线通知
|
// 下线通知
|
||||||
this.context.logger.logError('[KickedOffLine] [' + Info.tipsTitle + '] ' + Info.tipsDesc);
|
this.context.logger.logError('[KickedOffLine] [' + Info.tipsTitle + '] ' + Info.tipsDesc);
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
import { LRUCache } from "@/common/lru-cache";
|
import { LRUCache } from "@/common/lru-cache";
|
||||||
import crypto, { createHash } from "crypto";
|
import crypto, { createHash } from "crypto";
|
||||||
import { PacketContext } from "@/core/packet/context/packetContext";
|
|
||||||
import { OidbPacket, PacketHexStr } from "@/core/packet/transformer/base";
|
import { OidbPacket, PacketHexStr } from "@/core/packet/transformer/base";
|
||||||
import { LogStack } from "@/core/packet/context/clientContext";
|
import { LogStack } from "@/core/packet/context/clientContext";
|
||||||
|
import { NapCoreContext } from "@/core/packet/context/napCoreContext";
|
||||||
|
import { PacketLogger } from "@/core/packet/context/loggerContext";
|
||||||
|
|
||||||
export interface RecvPacket {
|
export interface RecvPacket {
|
||||||
type: string, // 仅recv
|
type: string, // 仅recv
|
||||||
@@ -27,13 +28,15 @@ function randText(len: number): string {
|
|||||||
|
|
||||||
|
|
||||||
export abstract class IPacketClient {
|
export abstract class IPacketClient {
|
||||||
protected readonly context: PacketContext;
|
protected readonly napcore: NapCoreContext;
|
||||||
|
protected readonly logger: PacketLogger;
|
||||||
protected readonly cb = new LRUCache<string, (json: RecvPacketData) => Promise<void>>(500); // trace_id-type callback
|
protected readonly cb = new LRUCache<string, (json: RecvPacketData) => Promise<void>>(500); // trace_id-type callback
|
||||||
logStack: LogStack;
|
logStack: LogStack;
|
||||||
available: boolean = false;
|
available: boolean = false;
|
||||||
|
|
||||||
protected constructor(context: PacketContext, logStack: LogStack) {
|
protected constructor(napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) {
|
||||||
this.context = context;
|
this.napcore = napCore;
|
||||||
|
this.logger = logger;
|
||||||
this.logStack = logStack;
|
this.logStack = logStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +84,7 @@ export abstract class IPacketClient {
|
|||||||
const md5 = crypto.createHash('md5').update(data).digest('hex');
|
const md5 = crypto.createHash('md5').update(data).digest('hex');
|
||||||
const trace_id = (randText(4) + md5 + data).slice(0, data.length / 2);
|
const trace_id = (randText(4) + md5 + data).slice(0, data.length / 2);
|
||||||
return this.sendCommand(cmd, data, trace_id, rsp, 20000, async () => {
|
return this.sendCommand(cmd, data, trace_id, rsp, 20000, async () => {
|
||||||
await this.context.napcore.sendSsoCmdReqByContend(cmd, trace_id);
|
await this.napcore.sendSsoCmdReqByContend(cmd, trace_id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,8 +5,9 @@ import fs from "fs";
|
|||||||
import { IPacketClient } from "@/core/packet/client/baseClient";
|
import { IPacketClient } from "@/core/packet/client/baseClient";
|
||||||
import { constants } from "node:os";
|
import { constants } from "node:os";
|
||||||
import { LRUCache } from "@/common/lru-cache";
|
import { LRUCache } from "@/common/lru-cache";
|
||||||
import { PacketContext } from "@/core/packet/context/packetContext";
|
|
||||||
import { LogStack } from "@/core/packet/context/clientContext";
|
import { LogStack } from "@/core/packet/context/clientContext";
|
||||||
|
import { NapCoreContext } from "@/core/packet/context/napCoreContext";
|
||||||
|
import { PacketLogger } from "@/core/packet/context/loggerContext";
|
||||||
|
|
||||||
// 0 send 1 recv
|
// 0 send 1 recv
|
||||||
export interface NativePacketExportType {
|
export interface NativePacketExportType {
|
||||||
@@ -19,8 +20,8 @@ export class NativePacketClient extends IPacketClient {
|
|||||||
private readonly MoeHooExport: { exports: NativePacketExportType } = { exports: {} };
|
private readonly MoeHooExport: { exports: NativePacketExportType } = { exports: {} };
|
||||||
private readonly sendEvent = new LRUCache<number, string>(500); // seq->trace_id
|
private readonly sendEvent = new LRUCache<number, string>(500); // seq->trace_id
|
||||||
|
|
||||||
constructor(context: PacketContext, logStack: LogStack) {
|
constructor(napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) {
|
||||||
super(context, logStack);
|
super(napCore, logger, logStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
check(): boolean {
|
check(): boolean {
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
import { Data, WebSocket, ErrorEvent } from "ws";
|
import { Data, WebSocket, ErrorEvent } from "ws";
|
||||||
import { IPacketClient, RecvPacket } from "@/core/packet/client/baseClient";
|
import { IPacketClient, RecvPacket } from "@/core/packet/client/baseClient";
|
||||||
import { PacketContext } from "@/core/packet/context/packetContext";
|
|
||||||
import { LogStack } from "@/core/packet/context/clientContext";
|
import { LogStack } from "@/core/packet/context/clientContext";
|
||||||
|
import { NapCoreContext } from "@/core/packet/context/napCoreContext";
|
||||||
|
import { PacketLogger } from "@/core/packet/context/loggerContext";
|
||||||
|
|
||||||
export class WsPacketClient extends IPacketClient {
|
export class WsPacketClient extends IPacketClient {
|
||||||
private websocket: WebSocket | null = null;
|
private websocket: WebSocket | null = null;
|
||||||
@@ -13,15 +14,15 @@ export class WsPacketClient extends IPacketClient {
|
|||||||
private isInitialized: boolean = false;
|
private isInitialized: boolean = false;
|
||||||
private initPayload: { pid: number, recv: string, send: string } | null = null;
|
private initPayload: { pid: number, recv: string, send: string } | null = null;
|
||||||
|
|
||||||
constructor(context: PacketContext, logStack: LogStack) {
|
constructor(napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) {
|
||||||
super(context, logStack);
|
super(napCore, logger, logStack);
|
||||||
this.clientUrl = this.context.napcore.config.packetServer
|
this.clientUrl = this.napcore.config.packetServer
|
||||||
? this.clientUrlWrap(this.context.napcore.config.packetServer)
|
? this.clientUrlWrap(this.napcore.config.packetServer)
|
||||||
: this.clientUrlWrap('127.0.0.1:8083');
|
: this.clientUrlWrap('127.0.0.1:8083');
|
||||||
}
|
}
|
||||||
|
|
||||||
check(): boolean {
|
check(): boolean {
|
||||||
if (!this.context.napcore.config.packetServer) {
|
if (!this.napcore.config.packetServer) {
|
||||||
this.logStack.pushLogWarn(`wsPacketClient 未配置服务器地址`);
|
this.logStack.pushLogWarn(`wsPacketClient 未配置服务器地址`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -67,7 +68,7 @@ export class WsPacketClient extends IPacketClient {
|
|||||||
this.websocket.onopen = () => {
|
this.websocket.onopen = () => {
|
||||||
this.available = true;
|
this.available = true;
|
||||||
this.reconnectAttempts = 0;
|
this.reconnectAttempts = 0;
|
||||||
this.context.logger.info(`wsPacketClient 已连接到 ${this.clientUrl}`);
|
this.logger.info(`wsPacketClient 已连接到 ${this.clientUrl}`);
|
||||||
if (!this.isInitialized && this.initPayload) {
|
if (!this.isInitialized && this.initPayload) {
|
||||||
this.websocket!.send(JSON.stringify({
|
this.websocket!.send(JSON.stringify({
|
||||||
action: 'init',
|
action: 'init',
|
||||||
@@ -79,15 +80,15 @@ export class WsPacketClient extends IPacketClient {
|
|||||||
};
|
};
|
||||||
this.websocket.onclose = () => {
|
this.websocket.onclose = () => {
|
||||||
this.available = false;
|
this.available = false;
|
||||||
this.context.logger.warn(`WebSocket 连接关闭,尝试重连...`);
|
this.logger.warn(`WebSocket 连接关闭,尝试重连...`);
|
||||||
reject(new Error('WebSocket 连接关闭'));
|
reject(new Error('WebSocket 连接关闭'));
|
||||||
};
|
};
|
||||||
this.websocket.onmessage = (event) => this.handleMessage(event.data).catch(err => {
|
this.websocket.onmessage = (event) => this.handleMessage(event.data).catch(err => {
|
||||||
this.context.logger.error(`处理消息时出错: ${err}`);
|
this.logger.error(`处理消息时出错: ${err}`);
|
||||||
});
|
});
|
||||||
this.websocket.onerror = (event: ErrorEvent) => {
|
this.websocket.onerror = (event: ErrorEvent) => {
|
||||||
this.available = false;
|
this.available = false;
|
||||||
this.context.logger.error(`WebSocket 出错: ${event.message}`);
|
this.logger.error(`WebSocket 出错: ${event.message}`);
|
||||||
this.websocket?.close();
|
this.websocket?.close();
|
||||||
reject(new Error(`WebSocket 出错: ${event.message}`));
|
reject(new Error(`WebSocket 出错: ${event.message}`));
|
||||||
};
|
};
|
||||||
@@ -106,7 +107,7 @@ export class WsPacketClient extends IPacketClient {
|
|||||||
const event = this.cb.get(`${trace_id_md5}${action}`);
|
const event = this.cb.get(`${trace_id_md5}${action}`);
|
||||||
if (event) await event(json.data);
|
if (event) await event(json.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.context.logger.error(`解析ws消息时出错: ${(error as Error).message}`);
|
this.logger.error(`解析ws消息时出错: ${(error as Error).message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,17 @@
|
|||||||
import { PacketContext } from "@/core/packet/context/packetContext";
|
|
||||||
import { IPacketClient } from "@/core/packet/client/baseClient";
|
import { IPacketClient } from "@/core/packet/client/baseClient";
|
||||||
import { NativePacketClient } from "@/core/packet/client/nativeClient";
|
import { NativePacketClient } from "@/core/packet/client/nativeClient";
|
||||||
import { WsPacketClient } from "@/core/packet/client/wsClient";
|
import { WsPacketClient } from "@/core/packet/client/wsClient";
|
||||||
import { OidbPacket } from "@/core/packet/transformer/base";
|
import { OidbPacket } from "@/core/packet/transformer/base";
|
||||||
import { PacketLogger } from "@/core/packet/context/loggerContext";
|
import { PacketLogger } from "@/core/packet/context/loggerContext";
|
||||||
|
import { NapCoreContext } from "@/core/packet/context/napCoreContext";
|
||||||
|
|
||||||
type clientPriority = {
|
type clientPriority = {
|
||||||
[key: number]: (context: PacketContext, logStack: LogStack) => IPacketClient;
|
[key: number]: (napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) => IPacketClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientPriority: clientPriority = {
|
const clientPriority: clientPriority = {
|
||||||
10: (context: PacketContext, logStack: LogStack) => new NativePacketClient(context, logStack),
|
10: (napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) => new NativePacketClient(napCore, logger, logStack),
|
||||||
1: (context: PacketContext, logStack: LogStack) => new WsPacketClient(context, logStack),
|
1: (napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) => new WsPacketClient(napCore, logger, logStack),
|
||||||
};
|
};
|
||||||
|
|
||||||
export class LogStack {
|
export class LogStack {
|
||||||
@@ -51,13 +51,15 @@ export class LogStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PacketClientContext {
|
export class PacketClientContext {
|
||||||
private readonly context: PacketContext;
|
private readonly napCore: NapCoreContext;
|
||||||
|
private readonly logger: PacketLogger;
|
||||||
private readonly logStack: LogStack;
|
private readonly logStack: LogStack;
|
||||||
private readonly _client: IPacketClient;
|
private readonly _client: IPacketClient;
|
||||||
|
|
||||||
constructor(context: PacketContext) {
|
constructor(napCore: NapCoreContext, logger: PacketLogger) {
|
||||||
this.context = context;
|
this.napCore = napCore;
|
||||||
this.logStack = new LogStack(context.logger);
|
this.logger = logger;
|
||||||
|
this.logStack = new LogStack(logger);
|
||||||
this._client = this.newClient();
|
this._client = this.newClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,23 +81,23 @@ export class PacketClientContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private newClient(): IPacketClient {
|
private newClient(): IPacketClient {
|
||||||
const prefer = this.context.napcore.config.packetBackend;
|
const prefer = this.napCore.config.packetBackend;
|
||||||
let client: IPacketClient | null;
|
let client: IPacketClient | null;
|
||||||
switch (prefer) {
|
switch (prefer) {
|
||||||
case "native":
|
case "native":
|
||||||
this.context.logger.info("使用指定的 NativePacketClient 作为后端");
|
this.logger.info("使用指定的 NativePacketClient 作为后端");
|
||||||
client = new NativePacketClient(this.context, this.logStack);
|
client = new NativePacketClient(this.napCore, this.logger, this.logStack);
|
||||||
break;
|
break;
|
||||||
case "frida":
|
case "frida":
|
||||||
this.context.logger.info("[Core] [Packet] 使用指定的 FridaPacketClient 作为后端");
|
this.logger.info("[Core] [Packet] 使用指定的 FridaPacketClient 作为后端");
|
||||||
client = new WsPacketClient(this.context, this.logStack);
|
client = new WsPacketClient(this.napCore, this.logger, this.logStack);
|
||||||
break;
|
break;
|
||||||
case "auto":
|
case "auto":
|
||||||
case undefined:
|
case undefined:
|
||||||
client = this.judgeClient();
|
client = this.judgeClient();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.context.logger.error(`未知的PacketBackend ${prefer},请检查配置文件!`);
|
this.logger.error(`未知的PacketBackend ${prefer},请检查配置文件!`);
|
||||||
client = null;
|
client = null;
|
||||||
}
|
}
|
||||||
if (!client?.check()) {
|
if (!client?.check()) {
|
||||||
@@ -110,7 +112,7 @@ export class PacketClientContext {
|
|||||||
private judgeClient(): IPacketClient {
|
private judgeClient(): IPacketClient {
|
||||||
const sortedClients = Object.entries(clientPriority)
|
const sortedClients = Object.entries(clientPriority)
|
||||||
.map(([priority, clientFactory]) => {
|
.map(([priority, clientFactory]) => {
|
||||||
const client = clientFactory(this.context, this.logStack);
|
const client = clientFactory(this.napCore, this.logger, this.logStack);
|
||||||
const score = +priority * +client.check();
|
const score = +priority * +client.check();
|
||||||
return { client, score };
|
return { client, score };
|
||||||
})
|
})
|
||||||
@@ -120,7 +122,7 @@ export class PacketClientContext {
|
|||||||
if (!selectedClient) {
|
if (!selectedClient) {
|
||||||
throw new Error("[Core] [Packet] 无可用的后端,NapCat.Packet将不会加载!");
|
throw new Error("[Core] [Packet] 无可用的后端,NapCat.Packet将不会加载!");
|
||||||
}
|
}
|
||||||
this.context.logger.info(`自动选择 ${selectedClient.constructor.name} 作为后端`);
|
this.logger.info(`自动选择 ${selectedClient.constructor.name} 作为后端`);
|
||||||
return selectedClient;
|
return selectedClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
import { LogLevel, LogWrapper } from "@/common/log";
|
import { LogLevel, LogWrapper } from "@/common/log";
|
||||||
import { PacketContext } from "@/core/packet/context/packetContext";
|
import { NapCoreContext } from "@/core/packet/context/napCoreContext";
|
||||||
|
|
||||||
// TODO: check bind?
|
// TODO: check bind?
|
||||||
export class PacketLogger {
|
export class PacketLogger {
|
||||||
private readonly napLogger: LogWrapper;
|
private readonly napLogger: LogWrapper;
|
||||||
|
|
||||||
constructor(context: PacketContext) {
|
constructor(napcore: NapCoreContext) {
|
||||||
this.napLogger = context.napcore.logger;
|
this.napLogger = napcore.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _log(level: LogLevel, ...msg: any[]): void {
|
private _log(level: LogLevel, ...msg: any[]): void {
|
||||||
|
@@ -13,15 +13,22 @@ import { MiniAppRawData, MiniAppReqParams } from "@/core/packet/entities/miniApp
|
|||||||
import { AIVoiceChatType } from "@/core/packet/entities/aiChat";
|
import { AIVoiceChatType } from "@/core/packet/entities/aiChat";
|
||||||
import { NapProtoDecodeStructType, NapProtoEncodeStructType } from "@napneko/nap-proto-core";
|
import { NapProtoDecodeStructType, NapProtoEncodeStructType } from "@napneko/nap-proto-core";
|
||||||
import { IndexNode, MsgInfo } from "@/core/packet/transformer/proto";
|
import { IndexNode, MsgInfo } from "@/core/packet/transformer/proto";
|
||||||
|
import { OidbPacket } from "@/core/packet/transformer/base";
|
||||||
|
import { ImageOcrResult } from "@/core/packet/entities/ocrResult";
|
||||||
|
|
||||||
export class PacketOperationContext {
|
export class PacketOperationContext {
|
||||||
private readonly context: PacketContext;
|
private readonly context: PacketContext;
|
||||||
|
|
||||||
constructor(context: PacketContext) {
|
constructor(context: PacketContext) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async sendPacket<T extends boolean = false>(pkt: OidbPacket, rsp?: T): Promise<T extends true ? Buffer : void> {
|
||||||
|
return await this.context.client.sendOidbPacket(pkt, rsp);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +97,46 @@ export class PacketOperationContext {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async UploadImage(img: PacketMsgPicElement) {
|
||||||
|
await this.context.highway.uploadImage({
|
||||||
|
chatType: ChatType.KCHATTYPEC2C,
|
||||||
|
peerUid: this.context.napcore.basicInfo.uid
|
||||||
|
}, img);
|
||||||
|
const index = img.msgInfo?.msgInfoBody?.at(0)?.index;
|
||||||
|
if (!index) {
|
||||||
|
throw new Error('img.msgInfo?.msgInfoBody![0].index! is undefined');
|
||||||
|
}
|
||||||
|
return await this.GetImageUrl(this.context.napcore.basicInfo.uid, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
async GetImageUrl(selfUid: string, node: NapProtoEncodeStructType<typeof IndexNode>) {
|
||||||
|
const req = trans.DownloadImage.build(selfUid, node);
|
||||||
|
const resp = await this.context.client.sendOidbPacket(req, true);
|
||||||
|
const res = trans.DownloadImage.parse(resp);
|
||||||
|
return `https://${res.download.info.domain}${res.download.info.urlPath}${res.download.rKeyParam}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async ImageOCR(imgUrl: string) {
|
||||||
|
const req = trans.ImageOCR.build(imgUrl);
|
||||||
|
const resp = await this.context.client.sendOidbPacket(req, true);
|
||||||
|
const res = trans.ImageOCR.parse(resp);
|
||||||
|
return {
|
||||||
|
texts: res.ocrRspBody.textDetections.map((item) => {
|
||||||
|
return {
|
||||||
|
text: item.detectedText,
|
||||||
|
confidence: item.confidence,
|
||||||
|
coordinates: item.polygon.coordinates.map((c) => {
|
||||||
|
return {
|
||||||
|
x: c.x,
|
||||||
|
y: c.y
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
language: res.ocrRspBody.language
|
||||||
|
} as ImageOcrResult;
|
||||||
|
}
|
||||||
|
|
||||||
async UploadForwardMsg(msg: PacketMsg[], groupUin: number = 0) {
|
async UploadForwardMsg(msg: PacketMsg[], groupUin: number = 0) {
|
||||||
await this.UploadResources(msg, groupUin);
|
await this.UploadResources(msg, groupUin);
|
||||||
const req = trans.UploadForwardMsg.build(this.context.napcore.basicInfo.uid, msg, groupUin);
|
const req = trans.UploadForwardMsg.build(this.context.napcore.basicInfo.uid, msg, groupUin);
|
||||||
|
@@ -7,19 +7,19 @@ import { PacketOperationContext } from "@/core/packet/context/operationContext";
|
|||||||
import { PacketMsgConverter } from "@/core/packet/message/converter";
|
import { PacketMsgConverter } from "@/core/packet/message/converter";
|
||||||
|
|
||||||
export class PacketContext {
|
export class PacketContext {
|
||||||
|
readonly msgConverter: PacketMsgConverter;
|
||||||
readonly napcore: NapCoreContext;
|
readonly napcore: NapCoreContext;
|
||||||
readonly logger: PacketLogger;
|
readonly logger: PacketLogger;
|
||||||
readonly client: PacketClientContext;
|
readonly client: PacketClientContext;
|
||||||
readonly highway: PacketHighwayContext;
|
readonly highway: PacketHighwayContext;
|
||||||
readonly msgConverter: PacketMsgConverter;
|
|
||||||
readonly operation: PacketOperationContext;
|
readonly operation: PacketOperationContext;
|
||||||
|
|
||||||
constructor(core: NapCatCore) {
|
constructor(core: NapCatCore) {
|
||||||
this.napcore = new NapCoreContext(core);
|
|
||||||
this.logger = new PacketLogger(this);
|
|
||||||
this.client = new PacketClientContext(this);
|
|
||||||
this.highway = new PacketHighwayContext(this);
|
|
||||||
this.msgConverter = new PacketMsgConverter();
|
this.msgConverter = new PacketMsgConverter();
|
||||||
|
this.napcore = new NapCoreContext(core);
|
||||||
|
this.logger = new PacketLogger(this.napcore);
|
||||||
|
this.client = new PacketClientContext(this.napcore, this.logger);
|
||||||
|
this.highway = new PacketHighwayContext(this.napcore, this.logger, this.client);
|
||||||
this.operation = new PacketOperationContext(this);
|
this.operation = new PacketOperationContext(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
src/core/packet/entities/ocrResult.ts
Normal file
15
src/core/packet/entities/ocrResult.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export interface ImageOcrResult {
|
||||||
|
texts: TextDetection[];
|
||||||
|
language: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TextDetection {
|
||||||
|
text: string;
|
||||||
|
confidence: number;
|
||||||
|
coordinates: Coordinate[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Coordinate {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
}
|
@@ -1,5 +1,4 @@
|
|||||||
import { PacketHighwayClient } from "@/core/packet/highway/client";
|
import { PacketHighwayClient } from "@/core/packet/highway/client";
|
||||||
import { PacketContext } from "@/core/packet/context/packetContext";
|
|
||||||
import { PacketLogger } from "@/core/packet/context/loggerContext";
|
import { PacketLogger } from "@/core/packet/context/loggerContext";
|
||||||
import FetchSessionKey from "@/core/packet/transformer/highway/FetchSessionKey";
|
import FetchSessionKey from "@/core/packet/transformer/highway/FetchSessionKey";
|
||||||
import { int32ip2str, oidbIpv4s2HighwayIpv4s } from "@/core/packet/highway/utils";
|
import { int32ip2str, oidbIpv4s2HighwayIpv4s } from "@/core/packet/highway/utils";
|
||||||
@@ -16,6 +15,8 @@ import { NapProtoMsg } from "@napneko/nap-proto-core";
|
|||||||
import * as proto from "@/core/packet/transformer/proto";
|
import * as proto from "@/core/packet/transformer/proto";
|
||||||
import * as trans from "@/core/packet/transformer";
|
import * as trans from "@/core/packet/transformer";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import { NapCoreContext } from "@/core/packet/context/napCoreContext";
|
||||||
|
import { PacketClientContext } from "@/core/packet/context/clientContext";
|
||||||
|
|
||||||
export const BlockSize = 1024 * 1024;
|
export const BlockSize = 1024 * 1024;
|
||||||
|
|
||||||
@@ -33,23 +34,25 @@ export interface PacketHighwaySig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PacketHighwayContext {
|
export class PacketHighwayContext {
|
||||||
private readonly context: PacketContext;
|
private readonly napcore: NapCoreContext;
|
||||||
|
private readonly client: PacketClientContext;
|
||||||
protected sig: PacketHighwaySig;
|
protected sig: PacketHighwaySig;
|
||||||
protected logger: PacketLogger;
|
protected logger: PacketLogger;
|
||||||
protected hwClient: PacketHighwayClient;
|
protected hwClient: PacketHighwayClient;
|
||||||
private cachedPrepareReq: Promise<void> | null = null;
|
private cachedPrepareReq: Promise<void> | null = null;
|
||||||
|
|
||||||
constructor(context: PacketContext) {
|
constructor(napcore: NapCoreContext, logger: PacketLogger, client: PacketClientContext) {
|
||||||
this.context = context;
|
this.napcore = napcore;
|
||||||
|
this.client = client;
|
||||||
this.sig = {
|
this.sig = {
|
||||||
uin: String(context.napcore.basicInfo.uin),
|
uin: String(this.napcore.basicInfo.uin),
|
||||||
uid: context.napcore.basicInfo.uid,
|
uid: this.napcore.basicInfo.uid,
|
||||||
sigSession: null,
|
sigSession: null,
|
||||||
sessionKey: null,
|
sessionKey: null,
|
||||||
serverAddr: [],
|
serverAddr: [],
|
||||||
};
|
};
|
||||||
this.logger = context.logger;
|
this.logger = logger;
|
||||||
this.hwClient = new PacketHighwayClient(this.sig, context.logger);
|
this.hwClient = new PacketHighwayClient(this.sig, this.logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async checkAvailable() {
|
private async checkAvailable() {
|
||||||
@@ -66,7 +69,7 @@ export class PacketHighwayContext {
|
|||||||
private async prepareUpload(): Promise<void> {
|
private async prepareUpload(): Promise<void> {
|
||||||
this.logger.debug('[Highway] on prepareUpload!');
|
this.logger.debug('[Highway] on prepareUpload!');
|
||||||
const packet = FetchSessionKey.build();
|
const packet = FetchSessionKey.build();
|
||||||
const req = await this.context.client.sendOidbPacket(packet, true);
|
const req = await this.client.sendOidbPacket(packet, true);
|
||||||
const rsp = FetchSessionKey.parse(req);
|
const rsp = FetchSessionKey.parse(req);
|
||||||
this.sig.sigSession = rsp.httpConn.sigSession;
|
this.sig.sigSession = rsp.httpConn.sigSession;
|
||||||
this.sig.sessionKey = rsp.httpConn.sessionKey;
|
this.sig.sessionKey = rsp.httpConn.sessionKey;
|
||||||
@@ -136,7 +139,7 @@ export class PacketHighwayContext {
|
|||||||
private async uploadGroupImage(groupUin: number, img: PacketMsgPicElement): Promise<void> {
|
private async uploadGroupImage(groupUin: number, img: PacketMsgPicElement): Promise<void> {
|
||||||
img.sha1 = Buffer.from(await calculateSha1(img.path)).toString('hex');
|
img.sha1 = Buffer.from(await calculateSha1(img.path)).toString('hex');
|
||||||
const req = UploadGroupImage.build(groupUin, img);
|
const req = UploadGroupImage.build(groupUin, img);
|
||||||
const resp = await this.context.client.sendOidbPacket(req, true);
|
const resp = await this.client.sendOidbPacket(req, true);
|
||||||
const preRespData = UploadGroupImage.parse(resp);
|
const preRespData = UploadGroupImage.parse(resp);
|
||||||
const ukey = preRespData.upload.uKey;
|
const ukey = preRespData.upload.uKey;
|
||||||
if (ukey && ukey != "") {
|
if (ukey && ukey != "") {
|
||||||
@@ -173,7 +176,7 @@ export class PacketHighwayContext {
|
|||||||
private async uploadC2CImage(peerUid: string, img: PacketMsgPicElement): Promise<void> {
|
private async uploadC2CImage(peerUid: string, img: PacketMsgPicElement): Promise<void> {
|
||||||
img.sha1 = Buffer.from(await calculateSha1(img.path)).toString('hex');
|
img.sha1 = Buffer.from(await calculateSha1(img.path)).toString('hex');
|
||||||
const req = trans.UploadPrivateImage.build(peerUid, img);
|
const req = trans.UploadPrivateImage.build(peerUid, img);
|
||||||
const resp = await this.context.client.sendOidbPacket(req, true);
|
const resp = await this.client.sendOidbPacket(req, true);
|
||||||
const preRespData = trans.UploadPrivateImage.parse(resp);
|
const preRespData = trans.UploadPrivateImage.parse(resp);
|
||||||
const ukey = preRespData.upload.uKey;
|
const ukey = preRespData.upload.uKey;
|
||||||
if (ukey && ukey != "") {
|
if (ukey && ukey != "") {
|
||||||
@@ -211,7 +214,7 @@ export class PacketHighwayContext {
|
|||||||
video.fileSha1 = Buffer.from(await calculateSha1(video.filePath)).toString('hex');
|
video.fileSha1 = Buffer.from(await calculateSha1(video.filePath)).toString('hex');
|
||||||
video.thumbSha1 = Buffer.from(await calculateSha1(video.thumbPath)).toString('hex');
|
video.thumbSha1 = Buffer.from(await calculateSha1(video.thumbPath)).toString('hex');
|
||||||
const req = trans.UploadGroupVideo.build(groupUin, video);
|
const req = trans.UploadGroupVideo.build(groupUin, video);
|
||||||
const resp = await this.context.client.sendOidbPacket(req, true);
|
const resp = await this.client.sendOidbPacket(req, true);
|
||||||
const preRespData = trans.UploadGroupVideo.parse(resp);
|
const preRespData = trans.UploadGroupVideo.parse(resp);
|
||||||
const ukey = preRespData.upload.uKey;
|
const ukey = preRespData.upload.uKey;
|
||||||
if (ukey && ukey != "") {
|
if (ukey && ukey != "") {
|
||||||
@@ -276,7 +279,7 @@ export class PacketHighwayContext {
|
|||||||
video.fileSha1 = Buffer.from(await calculateSha1(video.filePath)).toString('hex');
|
video.fileSha1 = Buffer.from(await calculateSha1(video.filePath)).toString('hex');
|
||||||
video.thumbSha1 = Buffer.from(await calculateSha1(video.thumbPath)).toString('hex');
|
video.thumbSha1 = Buffer.from(await calculateSha1(video.thumbPath)).toString('hex');
|
||||||
const req = trans.UploadPrivateVideo.build(peerUid, video);
|
const req = trans.UploadPrivateVideo.build(peerUid, video);
|
||||||
const resp = await this.context.client.sendOidbPacket(req, true);
|
const resp = await this.client.sendOidbPacket(req, true);
|
||||||
const preRespData = trans.UploadPrivateVideo.parse(resp);
|
const preRespData = trans.UploadPrivateVideo.parse(resp);
|
||||||
const ukey = preRespData.upload.uKey;
|
const ukey = preRespData.upload.uKey;
|
||||||
if (ukey && ukey != "") {
|
if (ukey && ukey != "") {
|
||||||
@@ -339,7 +342,7 @@ export class PacketHighwayContext {
|
|||||||
private async uploadGroupPtt(groupUin: number, ptt: PacketMsgPttElement): Promise<void> {
|
private async uploadGroupPtt(groupUin: number, ptt: PacketMsgPttElement): Promise<void> {
|
||||||
ptt.fileSha1 = Buffer.from(await calculateSha1(ptt.filePath)).toString('hex');
|
ptt.fileSha1 = Buffer.from(await calculateSha1(ptt.filePath)).toString('hex');
|
||||||
const req = trans.UploadGroupPtt.build(groupUin, ptt);
|
const req = trans.UploadGroupPtt.build(groupUin, ptt);
|
||||||
const resp = await this.context.client.sendOidbPacket(req, true);
|
const resp = await this.client.sendOidbPacket(req, true);
|
||||||
const preRespData = trans.UploadGroupPtt.parse(resp);
|
const preRespData = trans.UploadGroupPtt.parse(resp);
|
||||||
const ukey = preRespData.upload.uKey;
|
const ukey = preRespData.upload.uKey;
|
||||||
if (ukey && ukey != "") {
|
if (ukey && ukey != "") {
|
||||||
@@ -375,7 +378,7 @@ export class PacketHighwayContext {
|
|||||||
private async uploadC2CPtt(peerUid: string, ptt: PacketMsgPttElement): Promise<void> {
|
private async uploadC2CPtt(peerUid: string, ptt: PacketMsgPttElement): Promise<void> {
|
||||||
ptt.fileSha1 = Buffer.from(await calculateSha1(ptt.filePath)).toString('hex');
|
ptt.fileSha1 = Buffer.from(await calculateSha1(ptt.filePath)).toString('hex');
|
||||||
const req = trans.UploadPrivatePtt.build(peerUid, ptt);
|
const req = trans.UploadPrivatePtt.build(peerUid, ptt);
|
||||||
const resp = await this.context.client.sendOidbPacket(req, true);
|
const resp = await this.client.sendOidbPacket(req, true);
|
||||||
const preRespData = trans.UploadPrivatePtt.parse(resp);
|
const preRespData = trans.UploadPrivatePtt.parse(resp);
|
||||||
const ukey = preRespData.upload.uKey;
|
const ukey = preRespData.upload.uKey;
|
||||||
if (ukey && ukey != "") {
|
if (ukey && ukey != "") {
|
||||||
@@ -413,7 +416,7 @@ export class PacketHighwayContext {
|
|||||||
file.fileMd5 = await computeMd5AndLengthWithLimit(file.filePath);
|
file.fileMd5 = await computeMd5AndLengthWithLimit(file.filePath);
|
||||||
file.fileSha1 = await calculateSha1(file.filePath);
|
file.fileSha1 = await calculateSha1(file.filePath);
|
||||||
const req = trans.UploadGroupFile.build(groupUin, file);
|
const req = trans.UploadGroupFile.build(groupUin, file);
|
||||||
const resp = await this.context.client.sendOidbPacket(req, true);
|
const resp = await this.client.sendOidbPacket(req, true);
|
||||||
const preRespData = trans.UploadGroupFile.parse(resp);
|
const preRespData = trans.UploadGroupFile.parse(resp);
|
||||||
if (!preRespData?.upload?.boolFileExist) {
|
if (!preRespData?.upload?.boolFileExist) {
|
||||||
this.logger.debug(`[Highway] uploadGroupFileReq file not exist, need upload!`);
|
this.logger.debug(`[Highway] uploadGroupFileReq file not exist, need upload!`);
|
||||||
@@ -476,7 +479,7 @@ export class PacketHighwayContext {
|
|||||||
file.fileMd5 = await computeMd5AndLengthWithLimit(file.filePath);
|
file.fileMd5 = await computeMd5AndLengthWithLimit(file.filePath);
|
||||||
file.fileSha1 = await calculateSha1(file.filePath);
|
file.fileSha1 = await calculateSha1(file.filePath);
|
||||||
const req = await trans.UploadPrivateFile.build(this.sig.uid, peerUid, file);
|
const req = await trans.UploadPrivateFile.build(this.sig.uid, peerUid, file);
|
||||||
const res = await this.context.client.sendOidbPacket(req, true);
|
const res = await this.client.sendOidbPacket(req, true);
|
||||||
const preRespData = trans.UploadPrivateFile.parse(res);
|
const preRespData = trans.UploadPrivateFile.parse(res);
|
||||||
if (!preRespData.upload?.boolFileExist) {
|
if (!preRespData.upload?.boolFileExist) {
|
||||||
this.logger.debug(`[Highway] uploadC2CFileReq file not exist, need upload!`);
|
this.logger.debug(`[Highway] uploadC2CFileReq file not exist, need upload!`);
|
||||||
@@ -531,7 +534,7 @@ export class PacketHighwayContext {
|
|||||||
file.fileUuid = preRespData.upload?.uuid;
|
file.fileUuid = preRespData.upload?.uuid;
|
||||||
file.fileHash = preRespData.upload?.fileAddon;
|
file.fileHash = preRespData.upload?.fileAddon;
|
||||||
const fileExistReq = trans.DownloadOfflineFile.build(file.fileUuid!, file.fileHash!, this.sig.uid, peerUid);
|
const fileExistReq = trans.DownloadOfflineFile.build(file.fileUuid!, file.fileHash!, this.sig.uid, peerUid);
|
||||||
const fileExistRes = await this.context.client.sendOidbPacket(fileExistReq, true);
|
const fileExistRes = await this.client.sendOidbPacket(fileExistReq, true);
|
||||||
file._e37_800_rsp = trans.DownloadOfflineFile.parse(fileExistRes);
|
file._e37_800_rsp = trans.DownloadOfflineFile.parse(fileExistRes);
|
||||||
file._private_send_uid = this.sig.uid;
|
file._private_send_uid = this.sig.uid;
|
||||||
file._private_recv_uid = peerUid;
|
file._private_recv_uid = peerUid;
|
||||||
|
@@ -256,6 +256,8 @@ export class PacketMsgPicElement extends IPacketMsgElement<SendPicElement> {
|
|||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
picType: PicType;
|
picType: PicType;
|
||||||
|
picSubType: number;
|
||||||
|
summary: string;
|
||||||
sha1: string | null = null;
|
sha1: string | null = null;
|
||||||
msgInfo: NapProtoEncodeStructType<typeof MsgInfo> | null = null;
|
msgInfo: NapProtoEncodeStructType<typeof MsgInfo> | null = null;
|
||||||
groupPicExt: NapProtoEncodeStructType<typeof CustomFace> | null = null;
|
groupPicExt: NapProtoEncodeStructType<typeof CustomFace> | null = null;
|
||||||
@@ -270,6 +272,10 @@ export class PacketMsgPicElement extends IPacketMsgElement<SendPicElement> {
|
|||||||
this.width = element.picElement.picWidth;
|
this.width = element.picElement.picWidth;
|
||||||
this.height = element.picElement.picHeight;
|
this.height = element.picElement.picHeight;
|
||||||
this.picType = element.picElement.picType;
|
this.picType = element.picElement.picType;
|
||||||
|
this.picSubType = element.picElement.picSubType ?? 0;
|
||||||
|
this.summary = element.picElement.summary === '' ? (
|
||||||
|
element.picElement.picSubType === 0 ? '[图片]' : '[动画表情]'
|
||||||
|
) : element.picElement.summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
get valid(): boolean {
|
get valid(): boolean {
|
||||||
@@ -288,7 +294,7 @@ export class PacketMsgPicElement extends IPacketMsgElement<SendPicElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toPreview(): string {
|
toPreview(): string {
|
||||||
return "[图片]";
|
return this.summary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
37
src/core/packet/transformer/action/ImageOCR.ts
Normal file
37
src/core/packet/transformer/action/ImageOCR.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import * as proto from "@/core/packet/transformer/proto";
|
||||||
|
import { NapProtoMsg } from "@napneko/nap-proto-core";
|
||||||
|
import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base";
|
||||||
|
import OidbBase from "@/core/packet/transformer/oidb/oidbBase";
|
||||||
|
|
||||||
|
class ImageOCR extends PacketTransformer<typeof proto.OidbSvcTrpcTcp0xE07_0_Response> {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
build(url: string): OidbPacket {
|
||||||
|
const body = new NapProtoMsg(proto.OidbSvcTrpcTcp0xE07_0).encode(
|
||||||
|
{
|
||||||
|
version: 1,
|
||||||
|
client: 0,
|
||||||
|
entrance: 1,
|
||||||
|
ocrReqBody: {
|
||||||
|
imageUrl: url,
|
||||||
|
originMd5: "",
|
||||||
|
afterCompressMd5: "",
|
||||||
|
afterCompressFileSize: "",
|
||||||
|
afterCompressWeight: "",
|
||||||
|
afterCompressHeight: "",
|
||||||
|
isCut: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return OidbBase.build(0XEB7, 1, body, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
parse(data: Buffer) {
|
||||||
|
const base = OidbBase.parse(data);
|
||||||
|
return new NapProtoMsg(proto.OidbSvcTrpcTcp0xE07_0_Response).decode(base.body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new ImageOCR();
|
@@ -5,3 +5,4 @@ export { default as GroupSign } from './GroupSign';
|
|||||||
export { default as GetStrangerInfo } from './GetStrangerInfo';
|
export { default as GetStrangerInfo } from './GetStrangerInfo';
|
||||||
export { default as SendPoke } from './SendPoke';
|
export { default as SendPoke } from './SendPoke';
|
||||||
export { default as SetSpecialTitle } from './SetSpecialTitle';
|
export { default as SetSpecialTitle } from './SetSpecialTitle';
|
||||||
|
export { default as ImageOCR } from './ImageOCR';
|
||||||
|
51
src/core/packet/transformer/highway/DownloadImage.ts
Normal file
51
src/core/packet/transformer/highway/DownloadImage.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import * as proto from "@/core/packet/transformer/proto";
|
||||||
|
import { NapProtoEncodeStructType, NapProtoMsg } from "@napneko/nap-proto-core";
|
||||||
|
import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base";
|
||||||
|
import OidbBase from "@/core/packet/transformer/oidb/oidbBase";
|
||||||
|
import { IndexNode } from "@/core/packet/transformer/proto";
|
||||||
|
|
||||||
|
class DownloadImage extends PacketTransformer<typeof proto.NTV2RichMediaResp> {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
build(selfUid: string, node: NapProtoEncodeStructType<typeof IndexNode>): OidbPacket {
|
||||||
|
const body = new NapProtoMsg(proto.NTV2RichMediaReq).encode({
|
||||||
|
reqHead: {
|
||||||
|
common: {
|
||||||
|
requestId: 1,
|
||||||
|
command: 100
|
||||||
|
},
|
||||||
|
scene: {
|
||||||
|
requestType: 2,
|
||||||
|
businessType: 1,
|
||||||
|
sceneType: 1,
|
||||||
|
c2C: {
|
||||||
|
accountType: 2,
|
||||||
|
targetUid: selfUid
|
||||||
|
},
|
||||||
|
},
|
||||||
|
client: {
|
||||||
|
agentType: 2,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
download: {
|
||||||
|
node: node,
|
||||||
|
download: {
|
||||||
|
video: {
|
||||||
|
busiType: 0,
|
||||||
|
sceneType: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return OidbBase.build(0x11C5, 200, body, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
parse(data: Buffer) {
|
||||||
|
const oidbBody = OidbBase.parse(data).body;
|
||||||
|
return new NapProtoMsg(proto.NTV2RichMediaResp).decode(oidbBody);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new DownloadImage();
|
@@ -58,8 +58,11 @@ class UploadGroupImage extends PacketTransformer<typeof proto.NTV2RichMediaResp>
|
|||||||
compatQMsgSceneType: 2,
|
compatQMsgSceneType: 2,
|
||||||
extBizInfo: {
|
extBizInfo: {
|
||||||
pic: {
|
pic: {
|
||||||
bytesPbReserveTroop: Buffer.from("0800180020004200500062009201009a0100a2010c080012001800200028003a00", 'hex'),
|
bizType: img.picSubType,
|
||||||
textSummary: "Nya~", // TODO:
|
bytesPbReserveTroop: {
|
||||||
|
subType: img.picSubType,
|
||||||
|
},
|
||||||
|
textSummary: img.summary,
|
||||||
},
|
},
|
||||||
video: {
|
video: {
|
||||||
bytesPbReserve: Buffer.alloc(0),
|
bytesPbReserve: Buffer.alloc(0),
|
||||||
|
@@ -58,8 +58,11 @@ class UploadPrivateImage extends PacketTransformer<typeof proto.NTV2RichMediaRes
|
|||||||
compatQMsgSceneType: 1,
|
compatQMsgSceneType: 1,
|
||||||
extBizInfo: {
|
extBizInfo: {
|
||||||
pic: {
|
pic: {
|
||||||
bytesPbReserveTroop: Buffer.from("0800180020004200500062009201009a0100a2010c080012001800200028003a00", 'hex'),
|
bizType: img.picSubType,
|
||||||
textSummary: "Nya~", // TODO:
|
bytesPbReserveC2C: {
|
||||||
|
subType: img.picSubType,
|
||||||
|
},
|
||||||
|
textSummary: img.summary,
|
||||||
},
|
},
|
||||||
video: {
|
video: {
|
||||||
bytesPbReserve: Buffer.alloc(0),
|
bytesPbReserve: Buffer.alloc(0),
|
||||||
|
@@ -11,3 +11,4 @@ export { default as UploadPrivateFile } from './UploadPrivateFile';
|
|||||||
export { default as UploadPrivateImage } from './UploadPrivateImage';
|
export { default as UploadPrivateImage } from './UploadPrivateImage';
|
||||||
export { default as UploadPrivatePtt } from './UploadPrivatePtt';
|
export { default as UploadPrivatePtt } from './UploadPrivatePtt';
|
||||||
export { default as UploadPrivateVideo } from './UploadPrivateVideo';
|
export { default as UploadPrivateVideo } from './UploadPrivateVideo';
|
||||||
|
export { default as DownloadImage } from './DownloadImage';
|
||||||
|
@@ -29,3 +29,4 @@ export * from "./oidb/Oidb.0xEB7";
|
|||||||
export * from "./oidb/Oidb.0xED3_1";
|
export * from "./oidb/Oidb.0xED3_1";
|
||||||
export * from "./oidb/Oidb.0XFE1_2";
|
export * from "./oidb/Oidb.0XFE1_2";
|
||||||
export * from "./oidb/OidbBase";
|
export * from "./oidb/OidbBase";
|
||||||
|
export * from "./oidb/Oidb.0xE07";
|
||||||
|
@@ -72,6 +72,14 @@ export const GroupChange = {
|
|||||||
field7: ProtoField(7, ScalarType.BYTES, true),
|
field7: ProtoField(7, ScalarType.BYTES, true),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const GroupInvite = {
|
||||||
|
groupUin: ProtoField(1, ScalarType.UINT32),
|
||||||
|
field2: ProtoField(2, ScalarType.UINT32),
|
||||||
|
field3: ProtoField(2, ScalarType.UINT32),
|
||||||
|
field4: ProtoField(2, ScalarType.UINT32),
|
||||||
|
invitorUid: ProtoField(5, ScalarType.STRING),
|
||||||
|
};
|
||||||
|
|
||||||
export const PushMsgBody = {
|
export const PushMsgBody = {
|
||||||
responseHead: ProtoField(1, () => ResponseHead),
|
responseHead: ProtoField(1, () => ResponseHead),
|
||||||
contentHead: ProtoField(2, () => ContentHead),
|
contentHead: ProtoField(2, () => ContentHead),
|
||||||
|
59
src/core/packet/transformer/proto/oidb/Oidb.0xE07.ts
Normal file
59
src/core/packet/transformer/proto/oidb/Oidb.0xE07.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import { ProtoField, ScalarType } from "@napneko/nap-proto-core";
|
||||||
|
|
||||||
|
export const OidbSvcTrpcTcp0xE07_0 = {
|
||||||
|
version: ProtoField(1, ScalarType.UINT32),
|
||||||
|
client: ProtoField(2, ScalarType.UINT32),
|
||||||
|
entrance: ProtoField(3, ScalarType.UINT32),
|
||||||
|
ocrReqBody: ProtoField(10, () => OcrReqBody, true),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const OcrReqBody = {
|
||||||
|
imageUrl: ProtoField(1, ScalarType.STRING),
|
||||||
|
languageType: ProtoField(2, ScalarType.UINT32),
|
||||||
|
scene: ProtoField(3, ScalarType.UINT32),
|
||||||
|
originMd5: ProtoField(10, ScalarType.STRING),
|
||||||
|
afterCompressMd5: ProtoField(11, ScalarType.STRING),
|
||||||
|
afterCompressFileSize: ProtoField(12, ScalarType.STRING),
|
||||||
|
afterCompressWeight: ProtoField(13, ScalarType.STRING),
|
||||||
|
afterCompressHeight: ProtoField(14, ScalarType.STRING),
|
||||||
|
isCut: ProtoField(15, ScalarType.BOOL),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const OidbSvcTrpcTcp0xE07_0_Response = {
|
||||||
|
retCode: ProtoField(1, ScalarType.INT32),
|
||||||
|
errMsg: ProtoField(2, ScalarType.STRING),
|
||||||
|
wording: ProtoField(3, ScalarType.STRING),
|
||||||
|
ocrRspBody: ProtoField(10, () => OcrRspBody),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const OcrRspBody = {
|
||||||
|
textDetections: ProtoField(1, () => TextDetection, false, true),
|
||||||
|
language: ProtoField(2, ScalarType.STRING),
|
||||||
|
requestId: ProtoField(3, ScalarType.STRING),
|
||||||
|
ocrLanguageList: ProtoField(101, ScalarType.STRING, false, true),
|
||||||
|
dstTranslateLanguageList: ProtoField(102, ScalarType.STRING, false, true),
|
||||||
|
languageList: ProtoField(103, () => Language, false, true),
|
||||||
|
afterCompressWeight: ProtoField(111, ScalarType.UINT32),
|
||||||
|
afterCompressHeight: ProtoField(112, ScalarType.UINT32),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const TextDetection = {
|
||||||
|
detectedText: ProtoField(1, ScalarType.STRING),
|
||||||
|
confidence: ProtoField(2, ScalarType.UINT32),
|
||||||
|
polygon: ProtoField(3, () => Polygon),
|
||||||
|
advancedInfo: ProtoField(4, ScalarType.STRING),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Polygon = {
|
||||||
|
coordinates: ProtoField(1, () => Coordinate, false, true),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Coordinate = {
|
||||||
|
x: ProtoField(1, ScalarType.INT32),
|
||||||
|
y: ProtoField(2, ScalarType.INT32),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Language = {
|
||||||
|
languageCode: ProtoField(1, ScalarType.STRING),
|
||||||
|
languageDesc: ProtoField(2, ScalarType.STRING),
|
||||||
|
};
|
@@ -189,8 +189,8 @@ export const VideoExtBizInfo = {
|
|||||||
export const PicExtBizInfo = {
|
export const PicExtBizInfo = {
|
||||||
BizType: ProtoField(1, ScalarType.UINT32),
|
BizType: ProtoField(1, ScalarType.UINT32),
|
||||||
TextSummary: ProtoField(2, ScalarType.STRING),
|
TextSummary: ProtoField(2, ScalarType.STRING),
|
||||||
BytesPbReserveC2c: ProtoField(11, ScalarType.BYTES),
|
BytesPbReserveC2c: ProtoField(11, () => BytesPbReserveC2c),
|
||||||
BytesPbReserveTroop: ProtoField(12, ScalarType.BYTES),
|
BytesPbReserveTroop: ProtoField(12, () => BytesPbReserveTroop),
|
||||||
FromScene: ProtoField(1001, ScalarType.UINT32),
|
FromScene: ProtoField(1001, ScalarType.UINT32),
|
||||||
ToScene: ProtoField(1002, ScalarType.UINT32),
|
ToScene: ProtoField(1002, ScalarType.UINT32),
|
||||||
OldFileId: ProtoField(1003, ScalarType.UINT32),
|
OldFileId: ProtoField(1003, ScalarType.UINT32),
|
||||||
@@ -211,3 +211,27 @@ export const UploadInfo = {
|
|||||||
FileInfo: ProtoField(1, () => FileInfo),
|
FileInfo: ProtoField(1, () => FileInfo),
|
||||||
SubFileType: ProtoField(2, ScalarType.UINT32),
|
SubFileType: ProtoField(2, ScalarType.UINT32),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const BytesPbReserveC2c = {
|
||||||
|
subType: ProtoField(1, ScalarType.UINT32),
|
||||||
|
field3: ProtoField(3, ScalarType.UINT32),
|
||||||
|
field4: ProtoField(4, ScalarType.UINT32),
|
||||||
|
field8: ProtoField(8, ScalarType.STRING),
|
||||||
|
field10: ProtoField(10, ScalarType.UINT32),
|
||||||
|
field12: ProtoField(12, ScalarType.STRING),
|
||||||
|
field18: ProtoField(18, ScalarType.STRING),
|
||||||
|
field19: ProtoField(19, ScalarType.STRING),
|
||||||
|
field20: ProtoField(20, ScalarType.BYTES),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const BytesPbReserveTroop = {
|
||||||
|
subType: ProtoField(1, ScalarType.UINT32),
|
||||||
|
field3: ProtoField(3, ScalarType.UINT32),
|
||||||
|
field4: ProtoField(4, ScalarType.UINT32),
|
||||||
|
field9: ProtoField(9, ScalarType.STRING),
|
||||||
|
field10: ProtoField(10, ScalarType.UINT32),
|
||||||
|
field12: ProtoField(12, ScalarType.STRING),
|
||||||
|
field18: ProtoField(18, ScalarType.STRING),
|
||||||
|
field19: ProtoField(19, ScalarType.STRING),
|
||||||
|
field21: ProtoField(21, ScalarType.BYTES),
|
||||||
|
};
|
||||||
|
@@ -56,6 +56,7 @@ export interface GrayTipElement {
|
|||||||
aioOpGrayTipElement: TipAioOpGrayTipElement;
|
aioOpGrayTipElement: TipAioOpGrayTipElement;
|
||||||
groupElement: TipGroupElement;
|
groupElement: TipGroupElement;
|
||||||
xmlElement: {
|
xmlElement: {
|
||||||
|
busiId: string;
|
||||||
content: string;
|
content: string;
|
||||||
templId: string;
|
templId: string;
|
||||||
};
|
};
|
||||||
|
@@ -9,4 +9,5 @@ export * from './sign';
|
|||||||
export * from './element';
|
export * from './element';
|
||||||
export * from './constant';
|
export * from './constant';
|
||||||
export * from './graytip';
|
export * from './graytip';
|
||||||
export * from './emoji';
|
export * from './emoji';
|
||||||
|
export * from './service';
|
@@ -508,7 +508,7 @@ export interface RawMessage {
|
|||||||
*/
|
*/
|
||||||
export interface QueryMsgsParams {
|
export interface QueryMsgsParams {
|
||||||
chatInfo: Peer;
|
chatInfo: Peer;
|
||||||
filterMsgType: [];
|
filterMsgType: Array<{ type: NTMsgType, subType: Array<number> }>;
|
||||||
filterSendersUid: string[];
|
filterSendersUid: string[];
|
||||||
filterMsgFromTime: string;
|
filterMsgFromTime: string;
|
||||||
filterMsgToTime: string;
|
filterMsgToTime: string;
|
||||||
|
35
src/core/types/service.ts
Normal file
35
src/core/types/service.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
export enum LoginErrorCode {
|
||||||
|
KLOGINERRORACCOUNTNOTUIN = 140022018,
|
||||||
|
KLOGINERRORACCOUNTORPASSWORDERROR = 140022013,
|
||||||
|
KLOGINERRORBLACKACCOUNT = 150022021,
|
||||||
|
KLOGINERRORDEFAULT = 140022000,
|
||||||
|
KLOGINERROREXPIRETICKET = 140022014,
|
||||||
|
KLOGINERRORFROZEN = 140022005,
|
||||||
|
KLOGINERRORILLAGETICKET = 140022016,
|
||||||
|
KLOGINERRORINVAILDCOOKIE = 140022012,
|
||||||
|
KLOGINERRORINVALIDPARAMETER = 140022001,
|
||||||
|
KLOGINERRORKICKEDTICKET = 140022015,
|
||||||
|
KLOGINERRORMUTIPLEPASSWORDINCORRECT = 150022029,
|
||||||
|
KLOGINERRORNEEDUPDATE = 140022004,
|
||||||
|
KLOGINERRORNEEDVERIFYREALNAME = 140022019,
|
||||||
|
KLOGINERRORNEWDEVICE = 140022010,
|
||||||
|
KLOGINERRORNICEACCOUNTEXPIRED = 150022020,
|
||||||
|
KLOGINERRORNICEACCOUNTPARENTCHILDEXPIRED = 150022025,
|
||||||
|
KLOGINERRORPASSWORD = 2,
|
||||||
|
KLOGINERRORPROOFWATER = 140022008,
|
||||||
|
KLOGINERRORPROTECT = 140022006,
|
||||||
|
KLOGINERRORREFUSEPASSOWRDLOGIN = 140022009,
|
||||||
|
KLOGINERRORREMINDCANAELLATEDSTATUS = 150022028,
|
||||||
|
KLOGINERRORSCAN = 1,
|
||||||
|
KLOGINERRORSCCESS = 0,
|
||||||
|
KLOGINERRORSECBEAT = 140022017,
|
||||||
|
KLOGINERRORSMSINVALID = 150022026,
|
||||||
|
KLOGINERRORSTRICK = 140022007,
|
||||||
|
KLOGINERRORSYSTEMFAILED = 140022002,
|
||||||
|
KLOGINERRORTGTGTEXCHAGEA1FORBID = 150022027,
|
||||||
|
KLOGINERRORTIMEOUTRETRY = 140022003,
|
||||||
|
KLOGINERRORTOOMANYTIMESTODAY = 150022023,
|
||||||
|
KLOGINERRORTOOOFTEN = 150022022,
|
||||||
|
KLOGINERRORUNREGISTERED = 150022024,
|
||||||
|
KLOGINERRORUNUSUALDEVICE = 140022011,
|
||||||
|
}
|
@@ -27,6 +27,7 @@ export async function NCoreInitFramework(
|
|||||||
process.on('uncaughtException', (err) => {
|
process.on('uncaughtException', (err) => {
|
||||||
console.log('[NapCat] [Error] Unhandled Exception:', err.message);
|
console.log('[NapCat] [Error] Unhandled Exception:', err.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('unhandledRejection', (reason, promise) => {
|
process.on('unhandledRejection', (reason, promise) => {
|
||||||
console.log('[NapCat] [Error] unhandledRejection:', reason);
|
console.log('[NapCat] [Error] unhandledRejection:', reason);
|
||||||
});
|
});
|
||||||
|
@@ -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
src/onebot/action/extends/GetClientkey.ts
Normal file
14
src/onebot/action/extends/GetClientkey.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
import { OneBotAction } from '../OneBotAction';
|
||||||
|
|
||||||
|
interface GetClientkeyResponse {
|
||||||
|
clientkey?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GetClientkey extends OneBotAction<void, GetClientkeyResponse> {
|
||||||
|
actionName = ActionName.GetClientkey;
|
||||||
|
|
||||||
|
async _handle() {
|
||||||
|
return { clientkey: (await this.core.apis.UserApi.forceFetchClientKey()).clientKey };
|
||||||
|
}
|
||||||
|
}
|
@@ -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;
|
||||||
}
|
}
|
21
src/onebot/action/extends/SendPacket.ts
Normal file
21
src/onebot/action/extends/SendPacket.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||||
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
|
const SchemaData = Type.Object({
|
||||||
|
cmd: Type.String(),
|
||||||
|
data: Type.String(),
|
||||||
|
rsp: Type.Union([Type.String(), Type.Boolean()], { default: true }),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
|
export class SendPacket extends GetPacketStatusDepends<Payload, any> {
|
||||||
|
payloadSchema = SchemaData;
|
||||||
|
actionName = ActionName.SendPacket;
|
||||||
|
async _handle(payload: Payload) {
|
||||||
|
const rsp = typeof payload.rsp === 'boolean' ? payload.rsp : payload.rsp === 'true';
|
||||||
|
const data = await this.core.apis.PacketApi.pkt.operation.sendPacket({ cmd: payload.cmd, data: payload.data as any }, rsp);
|
||||||
|
return typeof data === 'object' ? data.toString('hex') : undefined;
|
||||||
|
}
|
||||||
|
}
|
@@ -17,7 +17,7 @@ class SetGroupSignBase extends GetPacketStatusDepends<Payload, any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class SetGroupSign extends SetGroupSignBase {
|
export class SetGroupSign extends SetGroupSignBase {
|
||||||
actionName = ActionName.SendGroupSign;
|
actionName = ActionName.SetGroupSign;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SendGroupSign extends SetGroupSignBase {
|
export class SendGroupSign extends SetGroupSignBase {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import { FileNapCatOneBotUUID } from '@/common/helper';
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { OB11MessageImage, OB11MessageVideo } from '@/onebot/types';
|
import { OB11MessageImage, OB11MessageVideo } from '@/onebot/types';
|
||||||
import { Static, Type } from '@sinclair/typebox';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
@@ -28,7 +28,7 @@ export class GetFileBase extends OneBotAction<GetFilePayload, GetFileResponse> {
|
|||||||
payload.file ||= payload.file_id || '';
|
payload.file ||= payload.file_id || '';
|
||||||
//接收消息标记模式
|
//接收消息标记模式
|
||||||
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file);
|
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file);
|
||||||
if (contextMsgFile) {
|
if (contextMsgFile && contextMsgFile.msgId && contextMsgFile.elementId) {
|
||||||
const { peer, msgId, elementId } = contextMsgFile;
|
const { peer, msgId, elementId } = contextMsgFile;
|
||||||
const downloadPath = await this.core.apis.FileApi.downloadMedia(msgId, peer.chatType, peer.peerUid, elementId, '', '');
|
const downloadPath = await this.core.apis.FileApi.downloadMedia(msgId, peer.chatType, peer.peerUid, elementId, '', '');
|
||||||
const rawMessage = (await this.core.apis.MsgApi.getMsgsByMsgId(peer, [msgId]))?.msgList
|
const rawMessage = (await this.core.apis.MsgApi.getMsgsByMsgId(peer, [msgId]))?.msgList
|
||||||
@@ -68,7 +68,7 @@ export class GetFileBase extends OneBotAction<GetFilePayload, GetFileResponse> {
|
|||||||
|
|
||||||
//群文件模式
|
//群文件模式
|
||||||
const contextModelIdFile = FileNapCatOneBotUUID.decodeModelId(payload.file);
|
const contextModelIdFile = FileNapCatOneBotUUID.decodeModelId(payload.file);
|
||||||
if (contextModelIdFile) {
|
if (contextModelIdFile && contextModelIdFile.modelId) {
|
||||||
const { peer, modelId } = contextModelIdFile;
|
const { peer, modelId } = contextModelIdFile;
|
||||||
const downloadPath = await this.core.apis.FileApi.downloadFileForModelId(peer, modelId, '');
|
const downloadPath = await this.core.apis.FileApi.downloadFileForModelId(peer, modelId, '');
|
||||||
const res: GetFileResponse = {
|
const res: GetFileResponse = {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FileNapCatOneBotUUID } from "@/common/helper";
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
import { Static, Type } from '@sinclair/typebox';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FileNapCatOneBotUUID } from '@/common/helper';
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
import { Static, Type } from '@sinclair/typebox';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = Type.Object({
|
const SchemaData = Type.Object({
|
||||||
@@ -16,7 +16,7 @@ export class DeleteGroupFile extends OneBotAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const data = FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
const data = FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
||||||
if (!data) throw new Error('Invalid file_id');
|
if (!data || !data.fileId) throw new Error('Invalid file_id');
|
||||||
return await this.core.apis.GroupApi.delGroupFile(payload.group_id.toString(), [data.fileId]);
|
return await this.core.apis.GroupApi.delGroupFile(payload.group_id.toString(), [data.fileId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { join as joinPath } from 'node:path';
|
import { join as joinPath } from 'node:path';
|
||||||
import { calculateFileMD5, httpDownload } from '@/common/file';
|
import { calculateFileMD5, uriToLocalFile } from '@/common/file';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { Static, Type } from '@sinclair/typebox';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
@@ -26,17 +26,20 @@ export default class GoCQHTTPDownloadFile extends OneBotAction<Payload, FileResp
|
|||||||
async _handle(payload: Payload): Promise<FileResponse> {
|
async _handle(payload: Payload): Promise<FileResponse> {
|
||||||
const isRandomName = !payload.name;
|
const isRandomName = !payload.name;
|
||||||
const name = payload.name || randomUUID();
|
const name = payload.name || randomUUID();
|
||||||
const filePath = joinPath(this.core.NapCatTempPath, name);
|
let result: Awaited<ReturnType<typeof uriToLocalFile>>;
|
||||||
|
|
||||||
if (payload.base64) {
|
if (payload.base64) {
|
||||||
fs.writeFileSync(filePath, payload.base64, 'base64');
|
result = await uriToLocalFile(this.core.NapCatTempPath, `base64://${payload.base64}`, name);
|
||||||
} else if (payload.url) {
|
} else if (payload.url) {
|
||||||
const headers = this.getHeaders(payload.headers);
|
const headers = this.getHeaders(payload.headers);
|
||||||
const buffer = await httpDownload({ url: payload.url, headers: headers });
|
result = await uriToLocalFile(this.core.NapCatTempPath, payload.url, name, headers);
|
||||||
fs.writeFileSync(filePath, Buffer.from(buffer), 'binary');
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('不存在任何文件, 无法下载');
|
throw new Error('不存在任何文件, 无法下载');
|
||||||
}
|
}
|
||||||
|
if (!result.success) {
|
||||||
|
throw new Error(result.errMsg);
|
||||||
|
}
|
||||||
|
const filePath = result.path;
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
|
|
||||||
if (isRandomName) {
|
if (isRandomName) {
|
||||||
|
@@ -13,7 +13,7 @@ type Payload = Static<typeof SchemaData>;
|
|||||||
|
|
||||||
export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11User> {
|
export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11User> {
|
||||||
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||||
|
payloadSchema = SchemaData;
|
||||||
async _handle(payload: Payload): Promise<OB11User> {
|
async _handle(payload: Payload): Promise<OB11User> {
|
||||||
const user_id = payload.user_id.toString();
|
const user_id = payload.user_id.toString();
|
||||||
const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id);
|
const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id);
|
||||||
|
@@ -24,7 +24,7 @@ class GetGroupInfo extends OneBotAction<Payload, OB11Group> {
|
|||||||
group_name: data.groupName,
|
group_name: data.groupName,
|
||||||
member_count: data.memberNum,
|
member_count: data.memberNum,
|
||||||
max_member_count: data.maxMemberNum,
|
max_member_count: data.maxMemberNum,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
return OB11Construct.group(group);
|
return OB11Construct.group(group);
|
||||||
}
|
}
|
||||||
|
@@ -26,20 +26,29 @@ class GetGroupMemberInfo extends OneBotAction<Payload, OB11GroupMember> {
|
|||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
private async getGroupMemberInfo(payload: Payload, uid: string, isNocache: boolean) {
|
||||||
const isNocache = this.parseBoolean(payload.no_cache ?? true);
|
const groupMemberCache = this.core.apis.GroupApi.groupMemberCache.get(payload.group_id.toString());
|
||||||
const uid = await this.getUid(payload.user_id);
|
const groupMember = groupMemberCache?.get(uid);
|
||||||
const groupMember = this.core.apis.GroupApi.groupMemberCache.get(payload.group_id.toString())?.get(uid);
|
|
||||||
let [member, info] = await Promise.all([
|
const [member, info] = await Promise.all([
|
||||||
this.core.apis.GroupApi.getGroupMemberEx(payload.group_id.toString(), uid, isNocache),
|
this.core.apis.GroupApi.getGroupMemberEx(payload.group_id.toString(), uid, isNocache),
|
||||||
this.core.apis.UserApi.getUserDetailInfo(uid),
|
this.core.apis.UserApi.getUserDetailInfo(uid),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!member || !groupMember) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`);
|
if (!member || !groupMember) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`);
|
||||||
if (info) {
|
|
||||||
member = { ...groupMember, ...member, ...info };
|
return info ? { ...groupMember, ...member, ...info } : member;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
async _handle(payload: Payload) {
|
||||||
|
const isNocache = this.parseBoolean(payload.no_cache ?? true);
|
||||||
|
const uid = await this.getUid(payload.user_id);
|
||||||
|
const member = await this.getGroupMemberInfo(payload, uid, isNocache);
|
||||||
|
|
||||||
|
if (!member) {
|
||||||
this.core.context.logger.logDebug(`获取群成员详细信息失败, 只能返回基础信息`);
|
this.core.context.logger.logDebug(`获取群成员详细信息失败, 只能返回基础信息`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return OB11Construct.groupMember(payload.group_id.toString(), member);
|
return OB11Construct.groupMember(payload.group_id.toString(), member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ import { OB11Construct } from '@/onebot/helper/data';
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { Static, Type } from '@sinclair/typebox';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
import { GroupMember } from '@/core';
|
||||||
|
|
||||||
const SchemaData = Type.Object({
|
const SchemaData = Type.Object({
|
||||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
@@ -17,25 +18,32 @@ export class GetGroupMemberList extends OneBotAction<Payload, OB11GroupMember[]>
|
|||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const groupIdStr = payload.group_id.toString();
|
const groupIdStr = payload.group_id.toString();
|
||||||
const noCache = payload.no_cache ? this.stringToBoolean(payload.no_cache) : false;
|
const noCache = this.parseBoolean(payload.no_cache ?? false);
|
||||||
|
const groupMembers = await this.getGroupMembers(groupIdStr, noCache);
|
||||||
|
const _groupMembers = await Promise.all(
|
||||||
|
Array.from(groupMembers.values()).map(item =>
|
||||||
|
OB11Construct.groupMember(groupIdStr, item)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return Array.from(new Map(_groupMembers.map(member => [member.user_id, member])).values());
|
||||||
|
}
|
||||||
|
|
||||||
|
private parseBoolean(value: boolean | string): boolean {
|
||||||
|
return typeof value === 'string' ? value === 'true' : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getGroupMembers(groupIdStr: string, noCache: boolean): Promise<Map<string, GroupMember>> {
|
||||||
const memberCache = this.core.apis.GroupApi.groupMemberCache;
|
const memberCache = this.core.apis.GroupApi.groupMemberCache;
|
||||||
let groupMembers = memberCache.get(groupIdStr);
|
let groupMembers = memberCache.get(groupIdStr);
|
||||||
|
|
||||||
if (noCache || !groupMembers) {
|
if (noCache || !groupMembers) {
|
||||||
this.core.apis.GroupApi.refreshGroupMemberCache(groupIdStr).then().catch();
|
const data = this.core.apis.GroupApi.refreshGroupMemberCache(groupIdStr, true).then().catch();
|
||||||
//下次刷新
|
groupMembers = memberCache.get(groupIdStr) || (await data);
|
||||||
groupMembers = memberCache.get(groupIdStr);
|
|
||||||
if (!groupMembers) {
|
if (!groupMembers) {
|
||||||
throw new Error(`Failed to get group member list for group ${groupIdStr}`);
|
throw new Error(`Failed to get group member list for group ${groupIdStr}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const memberPromises = Array.from(groupMembers.values()).map(item =>
|
|
||||||
OB11Construct.groupMember(groupIdStr, item)
|
return groupMembers;
|
||||||
);
|
|
||||||
const _groupMembers = await Promise.all(memberPromises);
|
|
||||||
const MemberMap = new Map(_groupMembers.map(member => [member.user_id, member]));
|
|
||||||
return Array.from(MemberMap.values());
|
|
||||||
}
|
}
|
||||||
stringToBoolean(str: string | boolean): boolean {
|
}
|
||||||
return typeof str === 'boolean' ? str : str.toLowerCase() === "true";
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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 };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import {ContextMode, SendMsgBase} from '@/onebot/action/msg/SendMsg';
|
import { ContextMode, SendMsgBase } from '@/onebot/action/msg/SendMsg';
|
||||||
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
||||||
import { OB11PostSendMsg } from '@/onebot/types';
|
import { OB11PostSendMsg } from '@/onebot/types';
|
||||||
|
|
||||||
|
@@ -19,12 +19,11 @@ export default class SetGroupAddRequest extends OneBotAction<Payload, null> {
|
|||||||
const flag = payload.flag.toString();
|
const flag = payload.flag.toString();
|
||||||
const approve = payload.approve?.toString() !== 'false';
|
const approve = payload.approve?.toString() !== 'false';
|
||||||
const reason = payload.reason ?? ' ';
|
const reason = payload.reason ?? ' ';
|
||||||
|
const invite_notify = this.obContext.apis.MsgApi.notifyGroupInvite.get(flag);
|
||||||
const notify = await this.findNotify(flag);
|
const notify = invite_notify ?? await this.findNotify(flag);
|
||||||
if (!notify) {
|
if (!notify) {
|
||||||
throw new Error('No such request');
|
throw new Error('No such request');
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.core.apis.GroupApi.handleGroupRequest(
|
await this.core.apis.GroupApi.handleGroupRequest(
|
||||||
notify,
|
notify,
|
||||||
approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
||||||
|
@@ -102,6 +102,9 @@ import { SendGroupAiRecord } from "@/onebot/action/group/SendGroupAiRecord";
|
|||||||
import { GetAiCharacters } from "@/onebot/action/extends/GetAiCharacters";
|
import { GetAiCharacters } from "@/onebot/action/extends/GetAiCharacters";
|
||||||
import { GetGuildList } from './guild/GetGuildList';
|
import { GetGuildList } from './guild/GetGuildList';
|
||||||
import { GetGuildProfile } from './guild/GetGuildProfile';
|
import { GetGuildProfile } from './guild/GetGuildProfile';
|
||||||
|
import { GetClientkey } from './extends/GetClientkey';
|
||||||
|
import { SendPacket } from './extends/SendPacket';
|
||||||
|
import { SendPoke } from "@/onebot/action/packet/SendPoke";
|
||||||
|
|
||||||
export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
||||||
|
|
||||||
@@ -123,6 +126,7 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
|
|||||||
new GetGroupRootFiles(obContext, core),
|
new GetGroupRootFiles(obContext, core),
|
||||||
new SetGroupSign(obContext, core),
|
new SetGroupSign(obContext, core),
|
||||||
new SendGroupSign(obContext, core),
|
new SendGroupSign(obContext, core),
|
||||||
|
new GetClientkey(obContext, core),
|
||||||
// onebot11
|
// onebot11
|
||||||
new SendLike(obContext, core),
|
new SendLike(obContext, core),
|
||||||
new GetMsg(obContext, core),
|
new GetMsg(obContext, core),
|
||||||
@@ -216,6 +220,8 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
|
|||||||
new GetAiRecord(obContext, core),
|
new GetAiRecord(obContext, core),
|
||||||
new SendGroupAiRecord(obContext, core),
|
new SendGroupAiRecord(obContext, core),
|
||||||
new GetAiCharacters(obContext, core),
|
new GetAiCharacters(obContext, core),
|
||||||
|
new SendPacket(obContext, core),
|
||||||
|
new SendPoke(obContext, core),
|
||||||
];
|
];
|
||||||
|
|
||||||
type HandlerUnion = typeof actionHandlers[number];
|
type HandlerUnion = typeof actionHandlers[number];
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import {ContextMode, SendMsgBase} from './SendMsg';
|
import { ContextMode, SendMsgBase } from './SendMsg';
|
||||||
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
||||||
import { OB11PostSendMsg } from '@/onebot/types';
|
import { OB11PostSendMsg } from '@/onebot/types';
|
||||||
|
|
||||||
|
23
src/onebot/action/packet/SendPoke.ts
Normal file
23
src/onebot/action/packet/SendPoke.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
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()]),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
|
export class SendPoke extends GetPacketStatusDepends<Payload, any> {
|
||||||
|
actionName = ActionName.SendPoke;
|
||||||
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
|
async _handle(payload: Payload) {
|
||||||
|
if (payload.group_id) {
|
||||||
|
await this.core.apis.PacketApi.pkt.operation.GroupPoke(+payload.group_id, +payload.user_id);
|
||||||
|
} else {
|
||||||
|
await this.core.apis.PacketApi.pkt.operation.FriendPoke(+payload.user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -13,134 +13,138 @@ export interface InvalidCheckResult {
|
|||||||
[k: string | number]: any;
|
[k: string | number]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ActionName = {
|
export const ActionName = {
|
||||||
// onebot 11
|
// onebot 11
|
||||||
SendPrivateMsg : 'send_private_msg',
|
SendPrivateMsg: 'send_private_msg',
|
||||||
SendGroupMsg : 'send_group_msg',
|
SendGroupMsg: 'send_group_msg',
|
||||||
SendMsg : 'send_msg',
|
SendMsg: 'send_msg',
|
||||||
DeleteMsg : 'delete_msg',
|
DeleteMsg: 'delete_msg',
|
||||||
GetMsg : 'get_msg',
|
GetMsg: 'get_msg',
|
||||||
GoCQHTTP_GetForwardMsg : 'get_forward_msg',
|
GoCQHTTP_GetForwardMsg: 'get_forward_msg',
|
||||||
SendLike : 'send_like',
|
SendLike: 'send_like',
|
||||||
SetGroupKick : 'set_group_kick',
|
SetGroupKick: 'set_group_kick',
|
||||||
SetGroupBan : 'set_group_ban',
|
SetGroupBan: 'set_group_ban',
|
||||||
// SetGroupAnoymousBan : 'set_group_anonymous_ban',
|
// SetGroupAnoymousBan : 'set_group_anonymous_ban',
|
||||||
SetGroupWholeBan : 'set_group_whole_ban',
|
SetGroupWholeBan: 'set_group_whole_ban',
|
||||||
SetGroupAdmin : 'set_group_admin',
|
SetGroupAdmin: 'set_group_admin',
|
||||||
// SetGroupAnoymous : 'set_group_anonymous',
|
// SetGroupAnoymous : 'set_group_anonymous',
|
||||||
SetGroupCard : 'set_group_card',
|
SetGroupCard: 'set_group_card',
|
||||||
SetGroupName : 'set_group_name',
|
SetGroupName: 'set_group_name',
|
||||||
SetGroupLeave : 'set_group_leave',
|
SetGroupLeave: 'set_group_leave',
|
||||||
SetSpecialTittle : 'set_group_special_title',
|
SetSpecialTittle: 'set_group_special_title',
|
||||||
SetFriendAddRequest : 'set_friend_add_request',
|
SetFriendAddRequest: 'set_friend_add_request',
|
||||||
SetGroupAddRequest : 'set_group_add_request',
|
SetGroupAddRequest: 'set_group_add_request',
|
||||||
GetLoginInfo : 'get_login_info',
|
GetLoginInfo: 'get_login_info',
|
||||||
GoCQHTTP_GetStrangerInfo : 'get_stranger_info',
|
GoCQHTTP_GetStrangerInfo: 'get_stranger_info',
|
||||||
GetFriendList : 'get_friend_list',
|
GetFriendList: 'get_friend_list',
|
||||||
GetGroupInfo : 'get_group_info',
|
GetGroupInfo: 'get_group_info',
|
||||||
GetGroupList : 'get_group_list',
|
GetGroupList: 'get_group_list',
|
||||||
GetGroupMemberInfo : 'get_group_member_info',
|
GetGroupMemberInfo: 'get_group_member_info',
|
||||||
GetGroupMemberList : 'get_group_member_list',
|
GetGroupMemberList: 'get_group_member_list',
|
||||||
GetGroupHonorInfo : 'get_group_honor_info',
|
GetGroupHonorInfo: 'get_group_honor_info',
|
||||||
GetCookies : 'get_cookies',
|
GetCookies: 'get_cookies',
|
||||||
GetCSRF : 'get_csrf_token',
|
GetCSRF: 'get_csrf_token',
|
||||||
GetCredentials : 'get_credentials',
|
GetCredentials: 'get_credentials',
|
||||||
GetRecord : 'get_record',
|
GetRecord: 'get_record',
|
||||||
GetImage : 'get_image',
|
GetImage: 'get_image',
|
||||||
CanSendImage : 'can_send_image',
|
CanSendImage: 'can_send_image',
|
||||||
CanSendRecord : 'can_send_record',
|
CanSendRecord: 'can_send_record',
|
||||||
GetStatus : 'get_status',
|
GetStatus: 'get_status',
|
||||||
GetVersionInfo : 'get_version_info',
|
GetVersionInfo: 'get_version_info',
|
||||||
// Reboot : 'set_restart',
|
// Reboot : 'set_restart',
|
||||||
// CleanCache : 'clean_cache',
|
// CleanCache : 'clean_cache',
|
||||||
|
|
||||||
// go-cqhttp
|
// go-cqhttp
|
||||||
SetQQProfile : 'set_qq_profile',
|
SetQQProfile: 'set_qq_profile',
|
||||||
// QidianGetAccountInfo : 'qidian_get_account_info',
|
// QidianGetAccountInfo : 'qidian_get_account_info',
|
||||||
GoCQHTTP_GetModelShow : '_get_model_show',
|
GoCQHTTP_GetModelShow: '_get_model_show',
|
||||||
GoCQHTTP_SetModelShow : '_set_model_show',
|
GoCQHTTP_SetModelShow: '_set_model_show',
|
||||||
GetOnlineClient : 'get_online_clients',
|
GetOnlineClient: 'get_online_clients',
|
||||||
// GetUnidirectionalFriendList : 'get_unidirectional_friend_list',
|
// GetUnidirectionalFriendList : 'get_unidirectional_friend_list',
|
||||||
GoCQHTTP_DeleteFriend : 'delete_friend',
|
GoCQHTTP_DeleteFriend: 'delete_friend',
|
||||||
// DeleteUnidirectionalFriendList : 'delete_unidirectional_friend',
|
// DeleteUnidirectionalFriendList : 'delete_unidirectional_friend',
|
||||||
GoCQHTTP_MarkMsgAsRead : 'mark_msg_as_read',
|
GoCQHTTP_MarkMsgAsRead: 'mark_msg_as_read',
|
||||||
GoCQHTTP_SendGroupForwardMsg : 'send_group_forward_msg',
|
GoCQHTTP_SendGroupForwardMsg: 'send_group_forward_msg',
|
||||||
GoCQHTTP_SendPrivateForwardMsg : 'send_private_forward_msg',
|
GoCQHTTP_SendPrivateForwardMsg: 'send_private_forward_msg',
|
||||||
GoCQHTTP_GetGroupMsgHistory : 'get_group_msg_history',
|
GoCQHTTP_GetGroupMsgHistory: 'get_group_msg_history',
|
||||||
OCRImage : 'ocr_image',
|
OCRImage: 'ocr_image',
|
||||||
IOCRImage : '.ocr_image',
|
IOCRImage: '.ocr_image',
|
||||||
GetGroupSystemMsg : 'get_group_system_msg',
|
GetGroupSystemMsg: 'get_group_system_msg',
|
||||||
GoCQHTTP_GetEssenceMsg : 'get_essence_msg_list',
|
GoCQHTTP_GetEssenceMsg: 'get_essence_msg_list',
|
||||||
GoCQHTTP_GetGroupAtAllRemain : 'get_group_at_all_remain',
|
GoCQHTTP_GetGroupAtAllRemain: 'get_group_at_all_remain',
|
||||||
SetGroupPortrait : 'set_group_portrait',
|
SetGroupPortrait: 'set_group_portrait',
|
||||||
SetEssenceMsg : 'set_essence_msg',
|
SetEssenceMsg: 'set_essence_msg',
|
||||||
DelEssenceMsg : 'delete_essence_msg',
|
DelEssenceMsg: 'delete_essence_msg',
|
||||||
GoCQHTTP_SendGroupNotice : '_send_group_notice',
|
GoCQHTTP_SendGroupNotice: '_send_group_notice',
|
||||||
GoCQHTTP_GetGroupNotice : '_get_group_notice',
|
GoCQHTTP_GetGroupNotice: '_get_group_notice',
|
||||||
GoCQHTTP_UploadGroupFile : 'upload_group_file',
|
GoCQHTTP_UploadGroupFile: 'upload_group_file',
|
||||||
GOCQHTTP_DeleteGroupFile : 'delete_group_file',
|
GOCQHTTP_DeleteGroupFile: 'delete_group_file',
|
||||||
GoCQHTTP_CreateGroupFileFolder : 'create_group_file_folder',
|
GoCQHTTP_CreateGroupFileFolder: 'create_group_file_folder',
|
||||||
GoCQHTTP_DeleteGroupFileFolder : 'delete_group_folder',
|
GoCQHTTP_DeleteGroupFileFolder: 'delete_group_folder',
|
||||||
GoCQHTTP_GetGroupFileSystemInfo : 'get_group_file_system_info',
|
GoCQHTTP_GetGroupFileSystemInfo: 'get_group_file_system_info',
|
||||||
GoCQHTTP_GetGroupRootFiles : 'get_group_root_files',
|
GoCQHTTP_GetGroupRootFiles: 'get_group_root_files',
|
||||||
GoCQHTTP_GetGroupFilesByFolder : 'get_group_files_by_folder',
|
GoCQHTTP_GetGroupFilesByFolder: 'get_group_files_by_folder',
|
||||||
GOCQHTTP_GetGroupFileUrl : 'get_group_file_url',
|
GOCQHTTP_GetGroupFileUrl: 'get_group_file_url',
|
||||||
GOCQHTTP_UploadPrivateFile : 'upload_private_file',
|
GOCQHTTP_UploadPrivateFile: 'upload_private_file',
|
||||||
// GOCQHTTP_ReloadEventFilter : 'reload_event_filter',
|
// GOCQHTTP_ReloadEventFilter : 'reload_event_filter',
|
||||||
GoCQHTTP_DownloadFile : 'download_file',
|
GoCQHTTP_DownloadFile: 'download_file',
|
||||||
GoCQHTTP_CheckUrlSafely : 'check_url_safely',
|
GoCQHTTP_CheckUrlSafely: 'check_url_safely',
|
||||||
GoCQHTTP_GetWordSlices : '.get_word_slices',
|
GoCQHTTP_GetWordSlices: '.get_word_slices',
|
||||||
GoCQHTTP_HandleQuickAction : '.handle_quick_operation',
|
GoCQHTTP_HandleQuickAction: '.handle_quick_operation',
|
||||||
|
|
||||||
// 以下为扩展napcat扩展
|
// 以下为扩展napcat扩展
|
||||||
Unknown : 'unknown',
|
Unknown: 'unknown',
|
||||||
SharePeer : 'ArkSharePeer',
|
SharePeer: 'ArkSharePeer',
|
||||||
ShareGroupEx : 'ArkShareGroup',
|
ShareGroupEx: 'ArkShareGroup',
|
||||||
// RebootNormal : 'reboot_normal', //无快速登录重新启动
|
// RebootNormal : 'reboot_normal', //无快速登录重新启动
|
||||||
GetRobotUinRange : 'get_robot_uin_range',
|
GetRobotUinRange: 'get_robot_uin_range',
|
||||||
SetOnlineStatus : 'set_online_status',
|
SetOnlineStatus: 'set_online_status',
|
||||||
GetFriendsWithCategory : 'get_friends_with_category',
|
GetFriendsWithCategory: 'get_friends_with_category',
|
||||||
SetQQAvatar : 'set_qq_avatar',
|
SetQQAvatar: 'set_qq_avatar',
|
||||||
GetFile : 'get_file',
|
GetFile: 'get_file',
|
||||||
ForwardFriendSingleMsg : 'forward_friend_single_msg',
|
ForwardFriendSingleMsg: 'forward_friend_single_msg',
|
||||||
ForwardGroupSingleMsg : 'forward_group_single_msg',
|
ForwardGroupSingleMsg: 'forward_group_single_msg',
|
||||||
TranslateEnWordToZn : 'translate_en2zh',
|
TranslateEnWordToZn: 'translate_en2zh',
|
||||||
SetMsgEmojiLike : 'set_msg_emoji_like',
|
SetMsgEmojiLike: 'set_msg_emoji_like',
|
||||||
GoCQHTTP_SendForwardMsg : 'send_forward_msg',
|
GoCQHTTP_SendForwardMsg: 'send_forward_msg',
|
||||||
MarkPrivateMsgAsRead : 'mark_private_msg_as_read',
|
MarkPrivateMsgAsRead: 'mark_private_msg_as_read',
|
||||||
MarkGroupMsgAsRead : 'mark_group_msg_as_read',
|
MarkGroupMsgAsRead: 'mark_group_msg_as_read',
|
||||||
GetFriendMsgHistory : 'get_friend_msg_history',
|
GetFriendMsgHistory: 'get_friend_msg_history',
|
||||||
CreateCollection : 'create_collection',
|
CreateCollection: 'create_collection',
|
||||||
GetCollectionList : 'get_collection_list',
|
GetCollectionList: 'get_collection_list',
|
||||||
SetLongNick : 'set_self_longnick',
|
SetLongNick: 'set_self_longnick',
|
||||||
GetRecentContact : 'get_recent_contact',
|
GetRecentContact: 'get_recent_contact',
|
||||||
_MarkAllMsgAsRead : '_mark_all_as_read',
|
_MarkAllMsgAsRead: '_mark_all_as_read',
|
||||||
GetProfileLike : 'get_profile_like',
|
GetProfileLike: 'get_profile_like',
|
||||||
FetchCustomFace : 'fetch_custom_face',
|
FetchCustomFace: 'fetch_custom_face',
|
||||||
FetchEmojiLike : 'fetch_emoji_like',
|
FetchEmojiLike: 'fetch_emoji_like',
|
||||||
SetInputStatus : 'set_input_status',
|
SetInputStatus: 'set_input_status',
|
||||||
GetGroupInfoEx : 'get_group_info_ex',
|
GetGroupInfoEx: 'get_group_info_ex',
|
||||||
GetGroupIgnoreAddRequest : 'get_group_ignore_add_request',
|
GetGroupIgnoreAddRequest: 'get_group_ignore_add_request',
|
||||||
DelGroupNotice : '_del_group_notice',
|
DelGroupNotice: '_del_group_notice',
|
||||||
FetchUserProfileLike : 'fetch_user_profile_like',
|
FetchUserProfileLike: 'fetch_user_profile_like',
|
||||||
FriendPoke : 'friend_poke',
|
FriendPoke: 'friend_poke',
|
||||||
GroupPoke : 'group_poke',
|
GroupPoke: 'group_poke',
|
||||||
GetPacketStatus : 'nc_get_packet_status',
|
GetPacketStatus: 'nc_get_packet_status',
|
||||||
GetUserStatus : 'nc_get_user_status',
|
GetUserStatus: 'nc_get_user_status',
|
||||||
GetRkey : 'nc_get_rkey',
|
GetRkey: 'nc_get_rkey',
|
||||||
GetGroupShutList : 'get_group_shut_list',
|
GetGroupShutList: 'get_group_shut_list',
|
||||||
|
|
||||||
GetGuildList : 'get_guild_list',
|
GetGuildList: 'get_guild_list',
|
||||||
GetGuildProfile : 'get_guild_service_profile',
|
GetGuildProfile: 'get_guild_service_profile',
|
||||||
|
|
||||||
GetGroupIgnoredNotifies : 'get_group_ignored_notifies',
|
GetGroupIgnoredNotifies: 'get_group_ignored_notifies',
|
||||||
|
|
||||||
SetGroupSign : "set_group_sign",
|
SetGroupSign: "set_group_sign",
|
||||||
SendGroupSign : "send_group_sign",
|
SendGroupSign: "send_group_sign",
|
||||||
|
SendPacket: "send_packet",
|
||||||
GetMiniAppArk : "get_mini_app_ark",
|
GetMiniAppArk: "get_mini_app_ark",
|
||||||
// UploadForwardMsg : "upload_forward_msg",
|
// UploadForwardMsg : "upload_forward_msg",
|
||||||
GetAiRecord : "get_ai_record",
|
GetAiRecord: "get_ai_record",
|
||||||
GetAiCharacters : "get_ai_characters",
|
GetAiCharacters: "get_ai_characters",
|
||||||
SendGroupAiRecord : "send_group_ai_record",
|
SendGroupAiRecord: "send_group_ai_record",
|
||||||
|
|
||||||
|
GetClientkey: "get_clientkey",
|
||||||
|
|
||||||
|
SendPoke: 'send_poke',
|
||||||
} as const;
|
} as const;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import CanSendRecord, {CanSend} from './CanSendRecord';
|
import CanSendRecord, { CanSend } from './CanSendRecord';
|
||||||
|
|
||||||
interface ReturnType {
|
interface ReturnType {
|
||||||
yes: boolean;
|
yes: boolean;
|
||||||
|
@@ -12,16 +12,17 @@ export class OneBotFriendApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//使用前预先判断 busiId 1061
|
//使用前预先判断 busiId 1061
|
||||||
async parsePrivatePokeEvent(grayTipElement: GrayTipElement) {
|
async parsePrivatePokeEvent(grayTipElement: GrayTipElement, uin: number) {
|
||||||
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr);
|
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr);
|
||||||
let pokedetail: Array<{ uid: string }> = json.items;
|
const pokedetail: Array<{ uid: string }> = json.items;
|
||||||
//筛选item带有uid的元素
|
//筛选item带有uid的元素
|
||||||
pokedetail = pokedetail.filter(item => item.uid);
|
const poke_uid = pokedetail.filter(item => item.uid);
|
||||||
if (pokedetail.length == 2) {
|
if (poke_uid.length == 2) {
|
||||||
return new OB11FriendPokeEvent(
|
return new OB11FriendPokeEvent(
|
||||||
this.core,
|
this.core,
|
||||||
parseInt((await this.core.apis.UserApi.getUinByUidV2(pokedetail[0].uid))),
|
uin,
|
||||||
parseInt((await this.core.apis.UserApi.getUinByUidV2(pokedetail[1].uid))),
|
parseInt((await this.core.apis.UserApi.getUinByUidV2(poke_uid[0].uid))),
|
||||||
|
parseInt((await this.core.apis.UserApi.getUinByUidV2(poke_uid[1].uid))),
|
||||||
pokedetail,
|
pokedetail,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,8 @@ import {
|
|||||||
NapCatCore,
|
NapCatCore,
|
||||||
NTGrayTipElementSubTypeV2,
|
NTGrayTipElementSubTypeV2,
|
||||||
RawMessage,
|
RawMessage,
|
||||||
|
TipGroupElement,
|
||||||
|
TipGroupElementType,
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import { NapCatOneBot11Adapter } from '@/onebot';
|
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||||
import { OB11GroupBanEvent } from '@/onebot/event/notice/OB11GroupBanEvent';
|
import { OB11GroupBanEvent } from '@/onebot/event/notice/OB11GroupBanEvent';
|
||||||
@@ -19,8 +21,10 @@ import { OB11GroupPokeEvent } from '@/onebot/event/notice/OB11PokeEvent';
|
|||||||
import { OB11GroupEssenceEvent } from '@/onebot/event/notice/OB11GroupEssenceEvent';
|
import { OB11GroupEssenceEvent } from '@/onebot/event/notice/OB11GroupEssenceEvent';
|
||||||
import { OB11GroupTitleEvent } from '@/onebot/event/notice/OB11GroupTitleEvent';
|
import { OB11GroupTitleEvent } from '@/onebot/event/notice/OB11GroupTitleEvent';
|
||||||
import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNoticeEvent';
|
import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNoticeEvent';
|
||||||
|
import { OB11GroupNameEvent } from '../event/notice/OB11GroupNameEvent';
|
||||||
import { pathToFileURL } from 'node:url';
|
import { pathToFileURL } from 'node:url';
|
||||||
import { FileNapCatOneBotUUID } from '@/common/helper';
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
|
import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
||||||
|
|
||||||
export class OneBotGroupApi {
|
export class OneBotGroupApi {
|
||||||
obContext: NapCatOneBot11Adapter;
|
obContext: NapCatOneBot11Adapter;
|
||||||
@@ -195,7 +199,7 @@ export class OneBotGroupApi {
|
|||||||
id: FileNapCatOneBotUUID.encode({
|
id: FileNapCatOneBotUUID.encode({
|
||||||
chatType: ChatType.KCHATTYPEGROUP,
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
}, msg.msgId, elementWrapper.elementId, elementWrapper?.fileElement?.fileUuid, "." + element.fileName),
|
}, msg.msgId, elementWrapper.elementId, elementWrapper?.fileElement?.fileUuid, element.fileName),
|
||||||
url: pathToFileURL(element.filePath).href,
|
url: pathToFileURL(element.filePath).href,
|
||||||
name: element.fileName,
|
name: element.fileName,
|
||||||
size: parseInt(element.fileSize),
|
size: parseInt(element.fileSize),
|
||||||
@@ -204,13 +208,63 @@ export class OneBotGroupApi {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async parseGroupElement(msg: RawMessage, element: TipGroupElement, elementWrapper: GrayTipElement) {
|
||||||
|
if (element.type === TipGroupElementType.KGROUPNAMEMODIFIED) {
|
||||||
|
this.core.context.logger.logDebug('收到群名称变更事件', element);
|
||||||
|
return new OB11GroupNameEvent(
|
||||||
|
this.core,
|
||||||
|
parseInt(msg.peerUid),
|
||||||
|
parseInt(await this.core.apis.UserApi.getUinByUidV2(element.memberUid)),
|
||||||
|
element.groupName,
|
||||||
|
);
|
||||||
|
} else if (element.type === TipGroupElementType.KSHUTUP) {
|
||||||
|
const event = await this.parseGroupBanEvent(msg.peerUid, elementWrapper);
|
||||||
|
return event;
|
||||||
|
} else if (element.type === TipGroupElementType.KMEMBERADD) {
|
||||||
|
// 自己的通知 协议推送为type->85 在这里实现为了避免邀请出现问题
|
||||||
|
if (element.memberUid == this.core.selfInfo.uid) {
|
||||||
|
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,
|
||||||
|
'approve'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async parseSelfInviteEvent(msg: RawMessage, inviterUin: string, inviteeUin: string) {
|
||||||
|
return new OB11GroupIncreaseEvent(
|
||||||
|
this.core,
|
||||||
|
parseInt(msg.peerUid),
|
||||||
|
+inviteeUin,
|
||||||
|
+inviterUin,
|
||||||
|
'invite'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async parseGrayTipElement(msg: RawMessage, grayTipElement: GrayTipElement) {
|
async parseGrayTipElement(msg: RawMessage, grayTipElement: GrayTipElement) {
|
||||||
if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_GROUP) {
|
if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_GROUP) {
|
||||||
// 解析群组事件 由sysmsg解析
|
// 解析群组事件 由sysmsg解析
|
||||||
// return await this.parseGroupElement(msg, grayTipElement.groupElement, grayTipElement);
|
return await this.parseGroupElement(msg, grayTipElement.groupElement, grayTipElement);
|
||||||
|
|
||||||
} else if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) {
|
} else if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) {
|
||||||
// 筛选出表情回应 事件
|
// 筛选自身入群情况
|
||||||
|
// if (grayTipElement.xmlElement.busiId === '10145') {
|
||||||
|
// const inviteData = new fastXmlParser.XMLParser({
|
||||||
|
// ignoreAttributes: false,
|
||||||
|
// attributeNamePrefix: '',
|
||||||
|
// }).parse(grayTipElement.xmlElement.content);
|
||||||
|
|
||||||
|
// const inviterUin: string = inviteData.gtip.qq[0].jp;
|
||||||
|
// const inviteeUin: string = inviteData.gtip.qq[1].jp;
|
||||||
|
// //刷新群缓存
|
||||||
|
// if (inviteeUin === this.core.selfInfo.uin) {
|
||||||
|
// this.core.apis.GroupApi.refreshGroupMemberCache(msg.peerUid).then().catch();
|
||||||
|
// return this.parseSelfInviteEvent(msg, inviterUin, inviteeUin);
|
||||||
|
// }
|
||||||
|
// } else
|
||||||
if (grayTipElement.xmlElement?.templId === '10382') {
|
if (grayTipElement.xmlElement?.templId === '10382') {
|
||||||
return await this.obContext.apis.GroupApi.parseGroupEmojiLikeEventByGrayTip(msg.peerUid, grayTipElement);
|
return await this.obContext.apis.GroupApi.parseGroupEmojiLikeEventByGrayTip(msg.peerUid, grayTipElement);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { FileNapCatOneBotUUID } from '@/common/helper';
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
import { pathToFileURL } from 'node:url';
|
import { pathToFileURL } from 'node:url';
|
||||||
import {
|
import {
|
||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
SendTextElement,
|
SendTextElement,
|
||||||
FaceType,
|
FaceType,
|
||||||
GrayTipElement,
|
GrayTipElement,
|
||||||
|
GroupNotify,
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import faceConfig from '@/core/external/face_config.json';
|
import faceConfig from '@/core/external/face_config.json';
|
||||||
import { NapCatOneBot11Adapter, OB11Message, OB11MessageData, OB11MessageDataType, OB11MessageFileBase, OB11MessageForward, } from '@/onebot';
|
import { NapCatOneBot11Adapter, OB11Message, OB11MessageData, OB11MessageDataType, OB11MessageFileBase, OB11MessageForward, } from '@/onebot';
|
||||||
@@ -33,7 +34,9 @@ import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
|||||||
import { OB11GroupDecreaseEvent, GroupDecreaseSubType } from '../event/notice/OB11GroupDecreaseEvent';
|
import { OB11GroupDecreaseEvent, GroupDecreaseSubType } from '../event/notice/OB11GroupDecreaseEvent';
|
||||||
import { GroupAdmin } from '@/core/packet/transformer/proto/message/groupAdmin';
|
import { GroupAdmin } from '@/core/packet/transformer/proto/message/groupAdmin';
|
||||||
import { OB11GroupAdminNoticeEvent } from '../event/notice/OB11GroupAdminNoticeEvent';
|
import { OB11GroupAdminNoticeEvent } from '../event/notice/OB11GroupAdminNoticeEvent';
|
||||||
import { GroupChange, GroupChangeInfo, PushMsgBody } from '@/core/packet/transformer/proto';
|
import { GroupChange, GroupChangeInfo, GroupInvite, PushMsgBody } from '@/core/packet/transformer/proto';
|
||||||
|
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
|
||||||
|
import { LRUCache } from '@/common/lru-cache';
|
||||||
|
|
||||||
type RawToOb11Converters = {
|
type RawToOb11Converters = {
|
||||||
[Key in keyof MessageElement as Key extends `${string}Element` ? Key : never]: (
|
[Key in keyof MessageElement as Key extends `${string}Element` ? Key : never]: (
|
||||||
@@ -67,7 +70,8 @@ function keyCanBeParsed(key: string, parser: RawToOb11Converters): key is keyof
|
|||||||
export class OneBotMsgApi {
|
export class OneBotMsgApi {
|
||||||
obContext: NapCatOneBot11Adapter;
|
obContext: NapCatOneBot11Adapter;
|
||||||
core: NapCatCore;
|
core: NapCatCore;
|
||||||
|
notifyGroupInvite: LRUCache<string, GroupNotify> = new LRUCache(50);
|
||||||
|
// seq -> notify
|
||||||
rawToOb11Converters: RawToOb11Converters = {
|
rawToOb11Converters: RawToOb11Converters = {
|
||||||
textElement: async element => {
|
textElement: async element => {
|
||||||
if (element.atType === NTMsgAtType.ATTYPEUNKNOWN) {
|
if (element.atType === NTMsgAtType.ATTYPEUNKNOWN) {
|
||||||
@@ -112,18 +116,22 @@ export class OneBotMsgApi {
|
|||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
guildId: '',
|
guildId: '',
|
||||||
};
|
};
|
||||||
const encodedFileId = FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, element.fileUuid, "." + element.fileName);
|
FileNapCatOneBotUUID.encode(
|
||||||
|
peer,
|
||||||
|
msg.msgId,
|
||||||
|
elementWrapper.elementId,
|
||||||
|
element.fileUuid,
|
||||||
|
element.fileName
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
type: OB11MessageDataType.image,
|
type: OB11MessageDataType.image,
|
||||||
data: {
|
data: {
|
||||||
summary: element.summary,
|
summary: element.summary,
|
||||||
file: encodedFileId,
|
file: element.fileName,
|
||||||
sub_type: element.picSubType,
|
sub_type: element.picSubType,
|
||||||
file_id: encodedFileId,
|
|
||||||
url: await this.core.apis.FileApi.getImageUrl(element),
|
url: await this.core.apis.FileApi.getImageUrl(element),
|
||||||
path: element.filePath,
|
path: element.filePath,
|
||||||
file_size: element.fileSize,
|
file_size: element.fileSize,
|
||||||
file_unique: element.md5HexStr ?? element.fileName,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
@@ -138,15 +146,15 @@ export class OneBotMsgApi {
|
|||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
guildId: '',
|
guildId: '',
|
||||||
};
|
};
|
||||||
|
const file = FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, element.fileUuid, element.fileName);
|
||||||
return {
|
return {
|
||||||
type: OB11MessageDataType.file,
|
type: OB11MessageDataType.file,
|
||||||
data: {
|
data: {
|
||||||
file: element.fileName,
|
file: file,
|
||||||
path: element.filePath,
|
path: element.filePath,
|
||||||
url: pathToFileURL(element.filePath).href,
|
url: pathToFileURL(element.filePath).href,
|
||||||
file_id: FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, element.fileUuid, "." + element.fileName),
|
file_id: file,
|
||||||
file_size: element.fileSize,
|
file_size: element.fileSize,
|
||||||
file_unique: element.fileMd5 ?? element.fileSha ?? element.fileName,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -197,18 +205,18 @@ export class OneBotMsgApi {
|
|||||||
const { emojiId } = _;
|
const { emojiId } = _;
|
||||||
const dir = emojiId.substring(0, 2);
|
const dir = emojiId.substring(0, 2);
|
||||||
const url = `https://gxh.vip.qq.com/club/item/parcel/item/${dir}/${emojiId}/raw300.gif`;
|
const url = `https://gxh.vip.qq.com/club/item/parcel/item/${dir}/${emojiId}/raw300.gif`;
|
||||||
|
const filename = `${dir}-${emojiId}.gif`;
|
||||||
|
FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, "", filename);
|
||||||
return {
|
return {
|
||||||
type: OB11MessageDataType.image,
|
type: OB11MessageDataType.image,
|
||||||
data: {
|
data: {
|
||||||
summary: _.faceName, // 商城表情名称
|
summary: _.faceName, // 商城表情名称
|
||||||
file: 'marketface',
|
file: filename,
|
||||||
file_id: FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, "", "." + _.key + ".jpg"),
|
|
||||||
path: url,
|
path: url,
|
||||||
url: url,
|
url: url,
|
||||||
key: _.key,
|
key: _.key,
|
||||||
emoji_id: _.emojiId,
|
emoji_id: _.emojiId,
|
||||||
emoji_package_id: _.emojiPackageId,
|
emoji_package_id: _.emojiPackageId,
|
||||||
file_unique: _.key
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -323,16 +331,14 @@ export class OneBotMsgApi {
|
|||||||
if (!videoDownUrl) {
|
if (!videoDownUrl) {
|
||||||
videoDownUrl = element.filePath;
|
videoDownUrl = element.filePath;
|
||||||
}
|
}
|
||||||
const fileCode = FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, "", "." + element.fileName);
|
const fileCode = FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, element.fileUuid, element.fileName);
|
||||||
return {
|
return {
|
||||||
type: OB11MessageDataType.video,
|
type: OB11MessageDataType.video,
|
||||||
data: {
|
data: {
|
||||||
file: fileCode,
|
file: fileCode,
|
||||||
path: videoDownUrl,
|
path: videoDownUrl,
|
||||||
url: videoDownUrl ?? pathToFileURL(element.filePath).href,
|
url: videoDownUrl ?? pathToFileURL(element.filePath).href,
|
||||||
file_id: fileCode,
|
|
||||||
file_size: element.fileSize,
|
file_size: element.fileSize,
|
||||||
file_unique: element.videoMd5 ?? element.thumbMd5 ?? element.fileName,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -343,16 +349,14 @@ export class OneBotMsgApi {
|
|||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
guildId: '',
|
guildId: '',
|
||||||
};
|
};
|
||||||
const fileCode = FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, "", "." + element.fileName);
|
const fileCode = FileNapCatOneBotUUID.encode(peer, msg.msgId, elementWrapper.elementId, "", element.fileName);
|
||||||
return {
|
return {
|
||||||
type: OB11MessageDataType.voice,
|
type: OB11MessageDataType.voice,
|
||||||
data: {
|
data: {
|
||||||
file: fileCode,
|
file: fileCode,
|
||||||
path: element.filePath,
|
path: element.filePath,
|
||||||
url: pathToFileURL(element.filePath).href,
|
url: pathToFileURL(element.filePath).href,
|
||||||
file_id: fileCode,
|
|
||||||
file_size: element.fileSize,
|
file_size: element.fileSize,
|
||||||
file_unique: element.fileUuid
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -679,7 +683,7 @@ export class OneBotMsgApi {
|
|||||||
async parsePrivateMsgEvent(msg: RawMessage, grayTipElement: GrayTipElement) {
|
async parsePrivateMsgEvent(msg: RawMessage, grayTipElement: GrayTipElement) {
|
||||||
if (grayTipElement.subElementType == NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_JSON) {
|
if (grayTipElement.subElementType == NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_JSON) {
|
||||||
if (grayTipElement.jsonGrayTipElement.busiId == 1061) {
|
if (grayTipElement.jsonGrayTipElement.busiId == 1061) {
|
||||||
const PokeEvent = await this.obContext.apis.FriendApi.parsePrivatePokeEvent(grayTipElement);
|
const PokeEvent = await this.obContext.apis.FriendApi.parsePrivatePokeEvent(grayTipElement, Number(await this.core.apis.UserApi.getUinByUidV2(msg.peerUid)));
|
||||||
if (PokeEvent) { return PokeEvent; };
|
if (PokeEvent) { return PokeEvent; };
|
||||||
} else if (grayTipElement.jsonGrayTipElement.busiId == 19324 && msg.peerUid !== '') {
|
} 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, Number(await this.core.apis.UserApi.getUinByUidV2(msg.peerUid)));
|
||||||
@@ -793,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)) {
|
||||||
|
const 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -895,16 +906,16 @@ export class OneBotMsgApi {
|
|||||||
const calculateTotalSize = async (elements: SendMessageElement[]): Promise<number> => {
|
const calculateTotalSize = async (elements: SendMessageElement[]): Promise<number> => {
|
||||||
const sizePromises = elements.map(async element => {
|
const sizePromises = elements.map(async element => {
|
||||||
switch (element.elementType) {
|
switch (element.elementType) {
|
||||||
case ElementType.PTT:
|
case ElementType.PTT:
|
||||||
return (await fsPromise.stat(element.pttElement.filePath)).size;
|
return (await fsPromise.stat(element.pttElement.filePath)).size;
|
||||||
case ElementType.FILE:
|
case ElementType.FILE:
|
||||||
return (await fsPromise.stat(element.fileElement.filePath)).size;
|
return (await fsPromise.stat(element.fileElement.filePath)).size;
|
||||||
case ElementType.VIDEO:
|
case ElementType.VIDEO:
|
||||||
return (await fsPromise.stat(element.videoElement.filePath)).size;
|
return (await fsPromise.stat(element.videoElement.filePath)).size;
|
||||||
case ElementType.PIC:
|
case ElementType.PIC:
|
||||||
return (await fsPromise.stat(element.picElement.sourcePath)).size;
|
return (await fsPromise.stat(element.picElement.sourcePath)).size;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const sizes = await Promise.all(sizePromises);
|
const sizes = await Promise.all(sizePromises);
|
||||||
@@ -968,25 +979,55 @@ export class OneBotMsgApi {
|
|||||||
|
|
||||||
return { path, fileName: inputdata.name ?? fileName };
|
return { path, fileName: inputdata.name ?? fileName };
|
||||||
}
|
}
|
||||||
|
|
||||||
groupChangDecreseType2String(type: number): GroupDecreaseSubType {
|
groupChangDecreseType2String(type: number): GroupDecreaseSubType {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 130:
|
case 130:
|
||||||
return 'leave';
|
return 'leave';
|
||||||
case 131:
|
case 131:
|
||||||
return 'kick';
|
return 'kick';
|
||||||
case 3:
|
case 3:
|
||||||
return 'kick_me';
|
return 'kick_me';
|
||||||
default:
|
default:
|
||||||
return 'kick';
|
return 'kick';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async waitGroupNotify(groupUin: string, memberUid?: string, operatorUid?: string) {
|
||||||
|
const groupRole = this.core.apis.GroupApi.groupMemberCache.get(groupUin)?.get(this.core.selfInfo.uid.toString())?.role;
|
||||||
|
const isAdminOrOwner = groupRole === 3 || groupRole === 4;
|
||||||
|
|
||||||
|
if (isAdminOrOwner && !operatorUid) {
|
||||||
|
let dataNotify: GroupNotify | undefined;
|
||||||
|
await this.core.eventWrapper.registerListen('NodeIKernelGroupListener/onGroupNotifiesUpdated',
|
||||||
|
(doubt, notifies) => {
|
||||||
|
for (const notify of notifies) {
|
||||||
|
if (notify.group.groupCode === groupUin && notify.user1.uid === memberUid) {
|
||||||
|
dataNotify = notify;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}, 1, 1000).catch(undefined);
|
||||||
|
if (dataNotify) {
|
||||||
|
return !dataNotify.actionUser.uid ? dataNotify.user2.uid : dataNotify.actionUser.uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return operatorUid;
|
||||||
|
}
|
||||||
|
|
||||||
async parseSysMessage(msg: number[]) {
|
async parseSysMessage(msg: number[]) {
|
||||||
const SysMessage = new NapProtoMsg(PushMsgBody).decode(Uint8Array.from(msg));
|
const SysMessage = new NapProtoMsg(PushMsgBody).decode(Uint8Array.from(msg));
|
||||||
|
// 邀请需要解grayTipElement
|
||||||
if (SysMessage.contentHead.type == 33 && SysMessage.body?.msgContent) {
|
if (SysMessage.contentHead.type == 33 && SysMessage.body?.msgContent) {
|
||||||
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
||||||
this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString()).then().catch();
|
await this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString(), true);
|
||||||
const operatorUid = groupChange.operatorInfo?.toString();
|
const operatorUid = await this.waitGroupNotify(
|
||||||
|
groupChange.groupUin.toString(),
|
||||||
|
groupChange.memberUid,
|
||||||
|
groupChange.operatorInfo ? Buffer.from(groupChange.operatorInfo).toString() : ''
|
||||||
|
);
|
||||||
return new OB11GroupIncreaseEvent(
|
return new OB11GroupIncreaseEvent(
|
||||||
this.core,
|
this.core,
|
||||||
groupChange.groupUin,
|
groupChange.groupUin,
|
||||||
@@ -994,19 +1035,24 @@ export class OneBotMsgApi {
|
|||||||
operatorUid ? +await this.core.apis.UserApi.getUinByUidV2(operatorUid) : 0,
|
operatorUid ? +await this.core.apis.UserApi.getUinByUidV2(operatorUid) : 0,
|
||||||
groupChange.decreaseType == 131 ? 'invite' : 'approve',
|
groupChange.decreaseType == 131 ? 'invite' : 'approve',
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if (SysMessage.contentHead.type == 34 && SysMessage.body?.msgContent) {
|
} else if (SysMessage.contentHead.type == 34 && SysMessage.body?.msgContent) {
|
||||||
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
||||||
// 自身被踢出时operatorInfo会是一个protobuf 否则大多数情况为一个string
|
// 自身被踢出时operatorInfo会是一个protobuf 否则大多数情况为一个string
|
||||||
const operatorUid = groupChange.decreaseType === 3 && groupChange.operatorInfo ?
|
const operatorUid = await this.waitGroupNotify(
|
||||||
new NapProtoMsg(GroupChangeInfo).decode(groupChange.operatorInfo).operator?.operatorUid :
|
groupChange.groupUin.toString(),
|
||||||
groupChange.operatorInfo?.toString();
|
groupChange.memberUid,
|
||||||
|
groupChange.decreaseType === 3 && groupChange.operatorInfo ?
|
||||||
|
new NapProtoMsg(GroupChangeInfo).decode(groupChange.operatorInfo).operator?.operatorUid :
|
||||||
|
groupChange.operatorInfo?.toString()
|
||||||
|
);
|
||||||
if (groupChange.memberUid === this.core.selfInfo.uid) {
|
if (groupChange.memberUid === this.core.selfInfo.uid) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.core.apis.GroupApi.groupMemberCache.delete(groupChange.groupUin.toString());
|
this.core.apis.GroupApi.groupMemberCache.delete(groupChange.groupUin.toString());
|
||||||
}, 5000);
|
}, 5000);
|
||||||
// 自己被踢了 5S后回收
|
// 自己被踢了 5S后回收
|
||||||
} else {
|
} else {
|
||||||
this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString()).then().catch();
|
await this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString(), true);
|
||||||
}
|
}
|
||||||
return new OB11GroupDecreaseEvent(
|
return new OB11GroupDecreaseEvent(
|
||||||
this.core,
|
this.core,
|
||||||
@@ -1017,7 +1063,7 @@ export class OneBotMsgApi {
|
|||||||
);
|
);
|
||||||
} else if (SysMessage.contentHead.type == 44 && SysMessage.body?.msgContent) {
|
} else if (SysMessage.contentHead.type == 44 && SysMessage.body?.msgContent) {
|
||||||
const groupAmin = new NapProtoMsg(GroupAdmin).decode(SysMessage.body.msgContent);
|
const groupAmin = new NapProtoMsg(GroupAdmin).decode(SysMessage.body.msgContent);
|
||||||
this.core.apis.GroupApi.refreshGroupMemberCache(groupAmin.groupUin.toString()).then().catch();
|
await this.core.apis.GroupApi.refreshGroupMemberCache(groupAmin.groupUin.toString(), true);
|
||||||
let enabled = false;
|
let enabled = false;
|
||||||
let uid = '';
|
let uid = '';
|
||||||
if (groupAmin.body.extraEnable != null) {
|
if (groupAmin.body.extraEnable != null) {
|
||||||
@@ -1033,6 +1079,72 @@ export class OneBotMsgApi {
|
|||||||
+await this.core.apis.UserApi.getUinByUidV2(uid),
|
+await this.core.apis.UserApi.getUinByUidV2(uid),
|
||||||
enabled ? 'set' : 'unset'
|
enabled ? 'set' : 'unset'
|
||||||
);
|
);
|
||||||
|
} else if (SysMessage.contentHead.type == 87 && SysMessage.body?.msgContent) {
|
||||||
|
const groupInvite = new NapProtoMsg(GroupInvite).decode(SysMessage.body.msgContent);
|
||||||
|
let request_seq = '';
|
||||||
|
try {
|
||||||
|
await this.core.eventWrapper.registerListen('NodeIKernelMsgListener/onRecvMsg', (msgs) => {
|
||||||
|
for (const msg of msgs) {
|
||||||
|
if (msg.senderUid === groupInvite.invitorUid && msg.msgType === 11) {
|
||||||
|
const jumpUrl = JSON.parse(msg.elements.find(e => e.elementType === 10)?.arkElement?.bytesData ?? '').meta?.news?.jumpUrl;
|
||||||
|
const jumpUrlParams = new URLSearchParams(jumpUrl);
|
||||||
|
const groupcode = jumpUrlParams.get('groupcode');
|
||||||
|
const receiveruin = jumpUrlParams.get('receiveruin');
|
||||||
|
const msgseq = jumpUrlParams.get('msgseq');
|
||||||
|
request_seq = msgseq ?? '';
|
||||||
|
if (groupcode === groupInvite.groupUin.toString() && receiveruin === this.core.selfInfo.uin) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}, 1, 1000);
|
||||||
|
} catch (error) {
|
||||||
|
request_seq = '';
|
||||||
|
}
|
||||||
|
// 未拉取到seq
|
||||||
|
if (request_seq === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 创建个假的
|
||||||
|
this.notifyGroupInvite.put(request_seq, {
|
||||||
|
seq: request_seq,
|
||||||
|
type: 1,
|
||||||
|
group: {
|
||||||
|
groupCode: groupInvite.groupUin.toString(),
|
||||||
|
groupName: '',
|
||||||
|
},
|
||||||
|
user1: {
|
||||||
|
uid: groupInvite.invitorUid,
|
||||||
|
nickName: '',
|
||||||
|
},
|
||||||
|
user2: {
|
||||||
|
uid: this.core.selfInfo.uid,
|
||||||
|
nickName: '',
|
||||||
|
},
|
||||||
|
actionUser: {
|
||||||
|
uid: groupInvite.invitorUid,
|
||||||
|
nickName: '',
|
||||||
|
},
|
||||||
|
actionTime: Date.now().toString(),
|
||||||
|
postscript: '',
|
||||||
|
repeatSeqs: [],
|
||||||
|
warningTips: '',
|
||||||
|
invitationExt: {
|
||||||
|
srcType: 1,
|
||||||
|
groupCode: groupInvite.groupUin.toString(),
|
||||||
|
waitStatus: 1,
|
||||||
|
},
|
||||||
|
status: 1
|
||||||
|
});
|
||||||
|
return new OB11GroupRequestEvent(
|
||||||
|
this.core,
|
||||||
|
+groupInvite.groupUin,
|
||||||
|
+await this.core.apis.UserApi.getUinByUidV2(groupInvite.invitorUid),
|
||||||
|
'invite',
|
||||||
|
'',
|
||||||
|
request_seq
|
||||||
|
);
|
||||||
} else if (SysMessage.contentHead.type == 528 && SysMessage.contentHead.subType == 39 && SysMessage.body?.msgContent) {
|
} else if (SysMessage.contentHead.type == 528 && SysMessage.contentHead.subType == 39 && SysMessage.body?.msgContent) {
|
||||||
return await this.obContext.apis.UserApi.parseLikeEvent(SysMessage.body?.msgContent);
|
return await this.obContext.apis.UserApi.parseLikeEvent(SysMessage.body?.msgContent);
|
||||||
}
|
}
|
||||||
|
@@ -91,11 +91,13 @@ export class OneBotQuickActionApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleGroupRequest(request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) {
|
async handleGroupRequest(request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) {
|
||||||
let noify = await this.findNotify(request.flag);
|
|
||||||
|
const invite_notify = this.obContext.apis.MsgApi.notifyGroupInvite.get(request.flag);
|
||||||
|
const notify = invite_notify ?? await this.findNotify(request.flag);
|
||||||
|
|
||||||
if (!isNull(quickAction.approve) && noify) {
|
if (!isNull(quickAction.approve) && notify) {
|
||||||
this.core.apis.GroupApi.handleGroupRequest(
|
this.core.apis.GroupApi.handleGroupRequest(
|
||||||
noify,
|
notify,
|
||||||
quickAction.approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
quickAction.approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
||||||
quickAction.reason,
|
quickAction.reason,
|
||||||
).catch(e => this.core.context.logger.logError(e));
|
).catch(e => this.core.context.logger.logError(e));
|
||||||
|
@@ -38,6 +38,14 @@ export interface AdapterConfig extends AdapterConfigInner {
|
|||||||
|
|
||||||
const createDefaultAdapterConfig = <T extends AdapterConfig>(config: T): T => config;
|
const createDefaultAdapterConfig = <T extends AdapterConfig>(config: T): T => config;
|
||||||
|
|
||||||
|
export interface PluginConfig extends AdapterConfig {
|
||||||
|
name: string;
|
||||||
|
enable: boolean;
|
||||||
|
messagePostFormat: string;
|
||||||
|
reportSelfMessage: boolean;
|
||||||
|
debug: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export const httpServerDefaultConfigs = createDefaultAdapterConfig({
|
export const httpServerDefaultConfigs = createDefaultAdapterConfig({
|
||||||
name: 'http-server',
|
name: 'http-server',
|
||||||
enable: false as boolean,
|
enable: false as boolean,
|
||||||
@@ -51,6 +59,13 @@ export const httpServerDefaultConfigs = createDefaultAdapterConfig({
|
|||||||
});
|
});
|
||||||
export type HttpServerConfig = typeof httpServerDefaultConfigs;
|
export type HttpServerConfig = typeof httpServerDefaultConfigs;
|
||||||
|
|
||||||
|
export const httpSseServerDefaultConfigs = createDefaultAdapterConfig({
|
||||||
|
...httpServerDefaultConfigs,
|
||||||
|
name: 'http-sse-server',
|
||||||
|
reportSelfMessage: false,
|
||||||
|
});
|
||||||
|
export type HttpSseServerConfig = typeof httpSseServerDefaultConfigs;
|
||||||
|
|
||||||
export const httpClientDefaultConfigs = createDefaultAdapterConfig({
|
export const httpClientDefaultConfigs = createDefaultAdapterConfig({
|
||||||
name: 'http-client',
|
name: 'http-client',
|
||||||
enable: false as boolean,
|
enable: false as boolean,
|
||||||
@@ -91,6 +106,7 @@ export type WebsocketClientConfig = typeof websocketClientDefaultConfigs;
|
|||||||
|
|
||||||
export interface NetworkConfig {
|
export interface NetworkConfig {
|
||||||
httpServers: Array<HttpServerConfig>;
|
httpServers: Array<HttpServerConfig>;
|
||||||
|
httpSseServers: Array<HttpSseServerConfig>;
|
||||||
httpClients: Array<HttpClientConfig>;
|
httpClients: Array<HttpClientConfig>;
|
||||||
websocketServers: Array<WebsocketServerConfig>;
|
websocketServers: Array<WebsocketServerConfig>;
|
||||||
websocketClients: Array<WebsocketClientConfig>;
|
websocketClients: Array<WebsocketClientConfig>;
|
||||||
@@ -112,6 +128,7 @@ const createDefaultConfig = <T>(config: T): T => config;
|
|||||||
export const defaultOneBotConfigs = createDefaultConfig<OneBotConfig>({
|
export const defaultOneBotConfigs = createDefaultConfig<OneBotConfig>({
|
||||||
network: {
|
network: {
|
||||||
httpServers: [],
|
httpServers: [],
|
||||||
|
httpSseServers: [],
|
||||||
httpClients: [],
|
httpClients: [],
|
||||||
websocketServers: [],
|
websocketServers: [],
|
||||||
websocketClients: [],
|
websocketClients: [],
|
||||||
@@ -128,7 +145,7 @@ export const mergeNetworkDefaultConfig = {
|
|||||||
websocketClients: websocketClientDefaultConfigs,
|
websocketClients: websocketClientDefaultConfigs,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type NetworkConfigAdapter = HttpServerConfig | HttpClientConfig | WebsocketServerConfig | WebsocketClientConfig | AdapterConfig;
|
export type NetworkConfigAdapter = HttpServerConfig | HttpClientConfig | WebsocketServerConfig | WebsocketClientConfig | PluginConfig;
|
||||||
type NetworkConfigKeys = keyof typeof mergeNetworkDefaultConfig;
|
type NetworkConfigKeys = keyof typeof mergeNetworkDefaultConfig;
|
||||||
|
|
||||||
export function mergeOneBotConfigs(
|
export function mergeOneBotConfigs(
|
||||||
@@ -234,4 +251,4 @@ export function getConfigBoolKey(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
13
src/onebot/event/notice/OB11GroupNameEvent.ts
Normal file
13
src/onebot/event/notice/OB11GroupNameEvent.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||||
|
import { NapCatCore } from '@/core';
|
||||||
|
|
||||||
|
export class OB11GroupNameEvent extends OB11GroupNoticeEvent {
|
||||||
|
notice_type = 'notify';
|
||||||
|
sub_type = 'group_name';
|
||||||
|
name_new: string;
|
||||||
|
|
||||||
|
constructor(core: NapCatCore, groupId: number, userId: number, nameNew: string) {
|
||||||
|
super(core, groupId, userId);
|
||||||
|
this.name_new = nameNew;
|
||||||
|
}
|
||||||
|
}
|
@@ -10,12 +10,14 @@ class OB11PokeEvent extends OB11BaseNoticeEvent {
|
|||||||
|
|
||||||
export class OB11FriendPokeEvent extends OB11PokeEvent {
|
export class OB11FriendPokeEvent extends OB11PokeEvent {
|
||||||
raw_info: any;
|
raw_info: any;
|
||||||
|
sender_id: number;
|
||||||
|
|
||||||
//raw_message nb等框架标准为string
|
//raw_message nb等框架标准为string
|
||||||
constructor(core: NapCatCore, user_id: number, target_id: number, raw_message: any) {
|
constructor(core: NapCatCore, user_id: number, sender_id: number, target_id: number, raw_message: any) {
|
||||||
super(core);
|
super(core);
|
||||||
this.target_id = target_id;
|
this.target_id = target_id;
|
||||||
this.user_id = user_id;
|
this.user_id = user_id;
|
||||||
|
this.sender_id = sender_id;
|
||||||
this.raw_info = raw_message;
|
this.raw_info = raw_message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { calcQQLevel, FileNapCatOneBotUUID } from '@/common/helper';
|
import { calcQQLevel } from '@/common/helper';
|
||||||
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
import { FriendV2, Group, GroupFileInfoUpdateParamType, GroupMember, SelfInfo, NTSex } from '@/core';
|
import { FriendV2, Group, GroupFileInfoUpdateParamType, GroupMember, SelfInfo, NTSex } from '@/core';
|
||||||
import {
|
import {
|
||||||
OB11Group,
|
OB11Group,
|
||||||
@@ -90,6 +91,7 @@ export class OB11Construct {
|
|||||||
file_name: file.fileName,
|
file_name: file.fileName,
|
||||||
busid: file.busId,
|
busid: file.busId,
|
||||||
size: +file.fileSize,
|
size: +file.fileSize,
|
||||||
|
file_size: +file.fileSize,
|
||||||
upload_time: file.uploadTime,
|
upload_time: file.uploadTime,
|
||||||
dead_time: file.deadTime,
|
dead_time: file.deadTime,
|
||||||
modify_time: file.modifyTime,
|
modify_time: file.modifyTime,
|
||||||
|
@@ -16,7 +16,6 @@ import {
|
|||||||
} from '@/core';
|
} from '@/core';
|
||||||
import { OB11ConfigLoader } from '@/onebot/config';
|
import { OB11ConfigLoader } from '@/onebot/config';
|
||||||
import {
|
import {
|
||||||
IOB11NetworkAdapter,
|
|
||||||
OB11ActiveHttpAdapter,
|
OB11ActiveHttpAdapter,
|
||||||
OB11ActiveWebSocketAdapter,
|
OB11ActiveWebSocketAdapter,
|
||||||
OB11NetworkManager,
|
OB11NetworkManager,
|
||||||
@@ -44,9 +43,17 @@ import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecal
|
|||||||
import { LRUCache } from '@/common/lru-cache';
|
import { LRUCache } from '@/common/lru-cache';
|
||||||
import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener';
|
import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener';
|
||||||
import { BotOfflineEvent } from './event/notice/BotOfflineEvent';
|
import { BotOfflineEvent } from './event/notice/BotOfflineEvent';
|
||||||
import { AdapterConfigWrap, mergeOneBotConfigs, migrateOneBotConfigsV1, NetworkConfigAdapter, OneBotConfig } from './config/config';
|
import {
|
||||||
|
AdapterConfigWrap,
|
||||||
|
mergeOneBotConfigs,
|
||||||
|
migrateOneBotConfigsV1,
|
||||||
|
NetworkConfigAdapter,
|
||||||
|
OneBotConfig,
|
||||||
|
} from './config/config';
|
||||||
import { OB11Message } from './types';
|
import { OB11Message } from './types';
|
||||||
import { OB11PluginAdapter } from './network/plugin';
|
import { OB11PluginAdapter } from './network/plugin';
|
||||||
|
import { IOB11NetworkAdapter } from "@/onebot/network/adapter";
|
||||||
|
import { OB11ActiveHttpSSEAdapter } from './network/active-http-sse';
|
||||||
|
|
||||||
//OneBot实现类
|
//OneBot实现类
|
||||||
export class NapCatOneBot11Adapter {
|
export class NapCatOneBot11Adapter {
|
||||||
@@ -81,6 +88,9 @@ export class NapCatOneBot11Adapter {
|
|||||||
for (const key of ob11Config.network.httpServers) {
|
for (const key of ob11Config.network.httpServers) {
|
||||||
log += `HTTP服务: ${key.host}:${key.port}, : ${key.enable ? '已启动' : '未启动'}\n`;
|
log += `HTTP服务: ${key.host}:${key.port}, : ${key.enable ? '已启动' : '未启动'}\n`;
|
||||||
}
|
}
|
||||||
|
for (const key of ob11Config.network.httpSseServers) {
|
||||||
|
log += `HTTP-SSE服务: ${key.host}:${key.port}, : ${key.enable ? '已启动' : '未启动'}\n`;
|
||||||
|
}
|
||||||
for (const key of ob11Config.network.httpClients) {
|
for (const key of ob11Config.network.httpClients) {
|
||||||
log += `HTTP上报服务: ${key.url}, : ${key.enable ? '已启动' : '未启动'}\n`;
|
log += `HTTP上报服务: ${key.url}, : ${key.enable ? '已启动' : '未启动'}\n`;
|
||||||
}
|
}
|
||||||
@@ -110,12 +120,19 @@ export class NapCatOneBot11Adapter {
|
|||||||
|
|
||||||
// 注册Plugin 如果需要基于NapCat进行快速开发
|
// 注册Plugin 如果需要基于NapCat进行快速开发
|
||||||
// this.networkManager.registerAdapter(
|
// this.networkManager.registerAdapter(
|
||||||
// new OB11PluginAdapter('plugin', this.core, this,this.actions)
|
// new OB11PluginAdapter('myPlugin', this.core, this,this.actions)
|
||||||
// );
|
// );
|
||||||
for (const key of ob11Config.network.httpServers) {
|
for (const key of ob11Config.network.httpServers) {
|
||||||
if (key.enable) {
|
if (key.enable) {
|
||||||
this.networkManager.registerAdapter(
|
this.networkManager.registerAdapter(
|
||||||
new OB11PassiveHttpAdapter(key.name, key, this.core, this.actions)
|
new OB11PassiveHttpAdapter(key.name, key, this.core, this, this.actions)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(const key of ob11Config.network.httpSseServers){
|
||||||
|
if(key.enable) {
|
||||||
|
this.networkManager.registerAdapter(
|
||||||
|
new OB11ActiveHttpSSEAdapter(key.name, key, this.core, this, this.actions)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,6 +150,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
key.name,
|
key.name,
|
||||||
key,
|
key,
|
||||||
this.core,
|
this.core,
|
||||||
|
this,
|
||||||
this.actions
|
this.actions
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -145,6 +163,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
key.name,
|
key.name,
|
||||||
key,
|
key,
|
||||||
this.core,
|
this.core,
|
||||||
|
this,
|
||||||
this.actions
|
this.actions
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -156,12 +175,16 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.initBuddyListener();
|
this.initBuddyListener();
|
||||||
this.initGroupListener();
|
this.initGroupListener();
|
||||||
|
|
||||||
|
WebUiDataRuntime.setQQVersion(this.core.context.basicInfoWrapper.getFullQQVesion());
|
||||||
WebUiDataRuntime.setQQLoginInfo(selfInfo);
|
WebUiDataRuntime.setQQLoginInfo(selfInfo);
|
||||||
WebUiDataRuntime.setQQLoginStatus(true);
|
WebUiDataRuntime.setQQLoginStatus(true);
|
||||||
WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
|
WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
|
||||||
const prev = this.configLoader.configData;
|
const prev = this.configLoader.configData;
|
||||||
|
// 保证默认配置
|
||||||
|
newConfig = mergeOneBotConfigs(newConfig);
|
||||||
|
|
||||||
this.configLoader.save(newConfig);
|
this.configLoader.save(newConfig);
|
||||||
this.context.logger.log(`OneBot11 配置更改:${JSON.stringify(prev)} -> ${JSON.stringify(newConfig)}`);
|
//this.context.logger.log(`OneBot11 配置更改:${JSON.stringify(prev)} -> ${JSON.stringify(newConfig)}`);
|
||||||
await this.reloadNetwork(prev, newConfig);
|
await this.reloadNetwork(prev, newConfig);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -191,10 +214,12 @@ export class NapCatOneBot11Adapter {
|
|||||||
await this.handleConfigChange(prev.network.websocketClients, now.network.websocketClients, OB11ActiveWebSocketAdapter);
|
await this.handleConfigChange(prev.network.websocketClients, now.network.websocketClients, OB11ActiveWebSocketAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleConfigChange(
|
private async handleConfigChange<CT extends NetworkConfigAdapter>(
|
||||||
prevConfig: NetworkConfigAdapter[],
|
prevConfig: NetworkConfigAdapter[],
|
||||||
nowConfig: NetworkConfigAdapter[],
|
nowConfig: NetworkConfigAdapter[],
|
||||||
adapterClass: new (...args: any[]) => IOB11NetworkAdapter
|
adapterClass: new (
|
||||||
|
...args: ConstructorParameters<typeof IOB11NetworkAdapter<CT>>
|
||||||
|
) => IOB11NetworkAdapter<CT>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// 比较旧的在新的找不到的回收
|
// 比较旧的在新的找不到的回收
|
||||||
for (const adapterConfig of prevConfig) {
|
for (const adapterConfig of prevConfig) {
|
||||||
@@ -215,7 +240,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
await this.networkManager.closeSomeAdaterWhenOpen([existingAdapter]);
|
await this.networkManager.closeSomeAdaterWhenOpen([existingAdapter]);
|
||||||
}
|
}
|
||||||
} else if (adapterConfig.enable) {
|
} else if (adapterConfig.enable) {
|
||||||
const newAdapter = new adapterClass(adapterConfig.name, adapterConfig, this.core, this.actions);
|
const newAdapter = new adapterClass(adapterConfig.name, adapterConfig as CT, this.core, this, this.actions);
|
||||||
await this.networkManager.registerAdapterAndOpen(newAdapter);
|
await this.networkManager.registerAdapterAndOpen(newAdapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,7 +325,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
guildId: ''
|
guildId: ''
|
||||||
};
|
};
|
||||||
const msg = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, msgSeq)).msgList.find(e => e.msgType == NTMsgType.KMSGTYPEGRAYTIPS);
|
const msg = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, msgSeq)).msgList.find(e => e.msgType == NTMsgType.KMSGTYPEGRAYTIPS);
|
||||||
const element = msg?.elements[0];
|
const element = msg?.elements.find(e => !!e.grayTipElement?.revokeElement);
|
||||||
if (msg && element) {
|
if (msg && element) {
|
||||||
const recallEvent = await this.emitRecallMsg(msg, element);
|
const recallEvent = await this.emitRecallMsg(msg, element);
|
||||||
try {
|
try {
|
||||||
@@ -378,10 +403,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
) {
|
) {
|
||||||
this.context.logger.logDebug('有加群请求');
|
this.context.logger.logDebug('有加群请求');
|
||||||
try {
|
try {
|
||||||
let requestUin = await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid);
|
const 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),
|
||||||
@@ -457,6 +479,10 @@ export class NapCatOneBot11Adapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleMsg(message: RawMessage, network: Array<AdapterConfigWrap>) {
|
private async handleMsg(message: RawMessage, network: Array<AdapterConfigWrap>) {
|
||||||
|
// 过滤无效消息
|
||||||
|
if (message.msgType === NTMsgType.KMSGTYPENULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const ob11Msg = await this.apis.MsgApi.parseMessageV2(message, this.configLoader.configData.parseMultMsg);
|
const ob11Msg = await this.apis.MsgApi.parseMessageV2(message, this.configLoader.configData.parseMultMsg);
|
||||||
if (ob11Msg) {
|
if (ob11Msg) {
|
||||||
|
34
src/onebot/network/active-http-sse.ts
Normal file
34
src/onebot/network/active-http-sse.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { OB11EmitEventContent } from './index';
|
||||||
|
import { Request, Response } from 'express';
|
||||||
|
import { OB11Response } from '@/onebot/action/OneBotAction';
|
||||||
|
import { OB11PassiveHttpAdapter } from './passive-http';
|
||||||
|
|
||||||
|
export class OB11ActiveHttpSSEAdapter extends OB11PassiveHttpAdapter {
|
||||||
|
private sseClients: Response[] = [];
|
||||||
|
|
||||||
|
async handleRequest(req: Request, res: Response): Promise<any> {
|
||||||
|
if (req.path === '/_events') {
|
||||||
|
return this.createSseSupport(req, res);
|
||||||
|
} else {
|
||||||
|
super.httpApiRequest(req, res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async createSseSupport(req: Request, res: Response) {
|
||||||
|
res.setHeader('Content-Type', 'text/event-stream');
|
||||||
|
res.setHeader('Cache-Control', 'no-cache');
|
||||||
|
res.setHeader('Connection', 'keep-alive');
|
||||||
|
res.flushHeaders();
|
||||||
|
|
||||||
|
this.sseClients.push(res);
|
||||||
|
req.on('close', () => {
|
||||||
|
this.sseClients = this.sseClients.filter((client) => client !== res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||||
|
this.sseClients.forEach((res) => {
|
||||||
|
res.write(`data: ${JSON.stringify(event)}\n\n`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -1,27 +1,18 @@
|
|||||||
import { IOB11NetworkAdapter, OB11EmitEventContent, OB11NetworkReloadType } from '@/onebot/network/index';
|
import { OB11EmitEventContent, OB11NetworkReloadType } from '@/onebot/network/index';
|
||||||
import { createHmac } from 'crypto';
|
import { createHmac } from 'crypto';
|
||||||
import { LogWrapper } from '@/common/log';
|
|
||||||
import { QuickAction, QuickActionEvent } from '@/onebot/types';
|
import { QuickAction, QuickActionEvent } from '@/onebot/types';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { NapCatOneBot11Adapter } from '..';
|
import { NapCatOneBot11Adapter } from '..';
|
||||||
import { RequestUtil } from '@/common/request';
|
import { RequestUtil } from '@/common/request';
|
||||||
import { HttpClientConfig } from '@/onebot/config/config';
|
import { HttpClientConfig } from '@/onebot/config/config';
|
||||||
import { ActionMap } from '@/onebot/action';
|
import { ActionMap } from '@/onebot/action';
|
||||||
|
import { IOB11NetworkAdapter } from "@/onebot/network/adapter";
|
||||||
|
|
||||||
export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
export class OB11ActiveHttpAdapter extends IOB11NetworkAdapter<HttpClientConfig> {
|
||||||
logger: LogWrapper;
|
|
||||||
isEnable: boolean = false;
|
|
||||||
config: HttpClientConfig;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public name: string,
|
name: string, config: HttpClientConfig, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap
|
||||||
config: HttpClientConfig,
|
|
||||||
public core: NapCatCore,
|
|
||||||
public obContext: NapCatOneBot11Adapter,
|
|
||||||
public actions: ActionMap,
|
|
||||||
) {
|
) {
|
||||||
this.logger = core.context.logger;
|
super(name, config, core, obContext, actions);
|
||||||
this.config = structuredClone(config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||||
@@ -45,9 +36,6 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
const data = await RequestUtil.HttpGetText(this.config.url, 'POST', msgStr, headers);
|
const data = await RequestUtil.HttpGetText(this.config.url, 'POST', msgStr, headers);
|
||||||
const resJson: QuickAction = data ? JSON.parse(data) : {};
|
const resJson: QuickAction = data ? JSON.parse(data) : {};
|
||||||
|
|
||||||
if (!this.obContext.apis || !this.obContext.apis.QuickActionApi.handleQuickOperation) {
|
|
||||||
throw new Error('apis.QuickActionApi.handleQuickOperation 异常');
|
|
||||||
}
|
|
||||||
await this.obContext.apis.QuickActionApi.handleQuickOperation(event as QuickActionEvent, resJson);
|
await this.obContext.apis.QuickActionApi.handleQuickOperation(event as QuickActionEvent, resJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,4 +66,4 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
|
|
||||||
return OB11NetworkReloadType.Normal;
|
return OB11NetworkReloadType.Normal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,29 +1,21 @@
|
|||||||
import { IOB11NetworkAdapter, OB11EmitEventContent, OB11NetworkReloadType } from '@/onebot/network/index';
|
import { OB11EmitEventContent, OB11NetworkReloadType } from '@/onebot/network/index';
|
||||||
import { WebSocket } from 'ws';
|
import { WebSocket } from 'ws';
|
||||||
import { OB11HeartbeatEvent } from '@/onebot/event/meta/OB11HeartbeatEvent';
|
import { OB11HeartbeatEvent } from '@/onebot/event/meta/OB11HeartbeatEvent';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { OB11Response } from '@/onebot/action/OneBotAction';
|
import { OB11Response } from '@/onebot/action/OneBotAction';
|
||||||
import { LogWrapper } from '@/common/log';
|
|
||||||
import { ActionMap } from '@/onebot/action';
|
import { ActionMap } from '@/onebot/action';
|
||||||
import { LifeCycleSubType, OB11LifeCycleEvent } from '@/onebot/event/meta/OB11LifeCycleEvent';
|
import { LifeCycleSubType, OB11LifeCycleEvent } from '@/onebot/event/meta/OB11LifeCycleEvent';
|
||||||
import { WebsocketClientConfig } from '@/onebot/config/config';
|
import { WebsocketClientConfig } from '@/onebot/config/config';
|
||||||
|
import { NapCatOneBot11Adapter } from "@/onebot";
|
||||||
|
import { IOB11NetworkAdapter } from "@/onebot/network/adapter";
|
||||||
|
|
||||||
export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
export class OB11ActiveWebSocketAdapter extends IOB11NetworkAdapter<WebsocketClientConfig> {
|
||||||
isEnable: boolean = false;
|
|
||||||
logger: LogWrapper;
|
|
||||||
private connection: WebSocket | null = null;
|
private connection: WebSocket | null = null;
|
||||||
private heartbeatRef: NodeJS.Timeout | null = null;
|
private heartbeatRef: NodeJS.Timeout | null = null;
|
||||||
public config: WebsocketClientConfig;
|
|
||||||
|
|
||||||
constructor(
|
constructor(name: string, config: WebsocketClientConfig, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap) {
|
||||||
public name: string,
|
super(name, config, core, obContext, actions);
|
||||||
confg: WebsocketClientConfig,
|
|
||||||
public core: NapCatCore,
|
|
||||||
public actions: ActionMap,
|
|
||||||
) {
|
|
||||||
this.logger = core.context.logger;
|
|
||||||
this.config = structuredClone(confg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||||
|
33
src/onebot/network/adapter.ts
Normal file
33
src/onebot/network/adapter.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { NetworkConfigAdapter } from "@/onebot/config/config";
|
||||||
|
import { LogWrapper } from "@/common/log";
|
||||||
|
import { NapCatCore } from "@/core";
|
||||||
|
import { NapCatOneBot11Adapter } from "@/onebot";
|
||||||
|
import { ActionMap } from "@/onebot/action";
|
||||||
|
import { OB11EmitEventContent, OB11NetworkReloadType } from "@/onebot/network/index";
|
||||||
|
|
||||||
|
export abstract class IOB11NetworkAdapter<CT extends NetworkConfigAdapter> {
|
||||||
|
name: string;
|
||||||
|
isEnable: boolean = false;
|
||||||
|
config: CT;
|
||||||
|
readonly logger: LogWrapper;
|
||||||
|
readonly core: NapCatCore;
|
||||||
|
readonly obContext: NapCatOneBot11Adapter;
|
||||||
|
readonly actions: ActionMap;
|
||||||
|
|
||||||
|
constructor(name: string, config: CT, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap) {
|
||||||
|
this.name = name;
|
||||||
|
this.config = structuredClone(config);
|
||||||
|
this.core = core;
|
||||||
|
this.obContext = obContext;
|
||||||
|
this.actions = actions;
|
||||||
|
this.logger = core.context.logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract onEvent<T extends OB11EmitEventContent>(event: T): void;
|
||||||
|
|
||||||
|
abstract open(): void | Promise<void>;
|
||||||
|
|
||||||
|
abstract close(): void | Promise<void>;
|
||||||
|
|
||||||
|
abstract reload(config: any): OB11NetworkReloadType | Promise<OB11NetworkReloadType>;
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import { OneBotEvent } from '@/onebot/event/OneBotEvent';
|
import { OneBotEvent } from '@/onebot/event/OneBotEvent';
|
||||||
import { OB11Message } from '@/onebot';
|
import { OB11Message } from '@/onebot';
|
||||||
import { ActionMap } from '@/onebot/action';
|
|
||||||
import { NetworkConfigAdapter } from '@/onebot/config/config';
|
import { NetworkConfigAdapter } from '@/onebot/config/config';
|
||||||
|
import { IOB11NetworkAdapter } from "@/onebot/network/adapter";
|
||||||
|
|
||||||
export type OB11EmitEventContent = OneBotEvent | OB11Message;
|
export type OB11EmitEventContent = OneBotEvent | OB11Message;
|
||||||
export enum OB11NetworkReloadType {
|
export enum OB11NetworkReloadType {
|
||||||
@@ -11,23 +11,9 @@ export enum OB11NetworkReloadType {
|
|||||||
NetWorkClose = 3,
|
NetWorkClose = 3,
|
||||||
NetWorkOpen = 4
|
NetWorkOpen = 4
|
||||||
}
|
}
|
||||||
export interface IOB11NetworkAdapter {
|
|
||||||
actions: ActionMap;
|
|
||||||
name: string;
|
|
||||||
isEnable: boolean;
|
|
||||||
config: NetworkConfigAdapter;
|
|
||||||
|
|
||||||
onEvent<T extends OB11EmitEventContent>(event: T): void;
|
|
||||||
|
|
||||||
open(): void | Promise<void>;
|
|
||||||
|
|
||||||
close(): void | Promise<void>;
|
|
||||||
|
|
||||||
reload(config: any): OB11NetworkReloadType | Promise<OB11NetworkReloadType>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class OB11NetworkManager {
|
export class OB11NetworkManager {
|
||||||
adapters: Map<string, IOB11NetworkAdapter> = new Map();
|
adapters: Map<string, IOB11NetworkAdapter<NetworkConfigAdapter>> = new Map();
|
||||||
|
|
||||||
async openAllAdapters() {
|
async openAllAdapters() {
|
||||||
return Promise.all(Array.from(this.adapters.values()).map(adapter => adapter.open()));
|
return Promise.all(Array.from(this.adapters.values()).map(adapter => adapter.open()));
|
||||||
@@ -63,22 +49,22 @@ export class OB11NetworkManager {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
registerAdapter(adapter: IOB11NetworkAdapter) {
|
registerAdapter<CT extends NetworkConfigAdapter>(adapter: IOB11NetworkAdapter<CT>) {
|
||||||
this.adapters.set(adapter.name, adapter);
|
this.adapters.set(adapter.name, adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
async registerAdapterAndOpen(adapter: IOB11NetworkAdapter) {
|
async registerAdapterAndOpen<CT extends NetworkConfigAdapter>(adapter: IOB11NetworkAdapter<CT>) {
|
||||||
this.registerAdapter(adapter);
|
this.registerAdapter(adapter);
|
||||||
await adapter.open();
|
await adapter.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
async closeSomeAdapters(adaptersToClose: IOB11NetworkAdapter[]) {
|
async closeSomeAdapters<CT extends NetworkConfigAdapter>(adaptersToClose: IOB11NetworkAdapter<CT>[]) {
|
||||||
for (const adapter of adaptersToClose) {
|
for (const adapter of adaptersToClose) {
|
||||||
this.adapters.delete(adapter.name);
|
this.adapters.delete(adapter.name);
|
||||||
await adapter.close();
|
await adapter.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async closeSomeAdaterWhenOpen(adaptersToClose: IOB11NetworkAdapter[]) {
|
async closeSomeAdaterWhenOpen<CT extends NetworkConfigAdapter>(adaptersToClose: IOB11NetworkAdapter<CT>[]) {
|
||||||
for (const adapter of adaptersToClose) {
|
for (const adapter of adaptersToClose) {
|
||||||
this.adapters.delete(adapter.name);
|
this.adapters.delete(adapter.name);
|
||||||
if (adapter.isEnable) {
|
if (adapter.isEnable) {
|
||||||
@@ -91,7 +77,7 @@ export class OB11NetworkManager {
|
|||||||
return this.adapters.get(name);
|
return this.adapters.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
async closeAdapterByPredicate(closeFilter: (adapter: IOB11NetworkAdapter) => boolean) {
|
async closeAdapterByPredicate(closeFilter: (adapter: IOB11NetworkAdapter<NetworkConfigAdapter>) => boolean) {
|
||||||
const adaptersToClose = Array.from(this.adapters.values()).filter(closeFilter);
|
const adaptersToClose = Array.from(this.adapters.values()).filter(closeFilter);
|
||||||
await this.closeSomeAdapters(adaptersToClose);
|
await this.closeSomeAdapters(adaptersToClose);
|
||||||
}
|
}
|
||||||
@@ -118,4 +104,4 @@ export class OB11NetworkManager {
|
|||||||
export * from './active-http';
|
export * from './active-http';
|
||||||
export * from './active-websocket';
|
export * from './active-websocket';
|
||||||
export * from './passive-http';
|
export * from './passive-http';
|
||||||
export * from './passive-websocket';
|
export * from './passive-websocket';
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { IOB11NetworkAdapter, OB11NetworkReloadType } from './index';
|
import { OB11EmitEventContent, OB11NetworkReloadType } from './index';
|
||||||
import express, { Express, Request, Response } from 'express';
|
import express, { Express, Request, Response } from 'express';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
@@ -6,23 +6,18 @@ import { OB11Response } from '@/onebot/action/OneBotAction';
|
|||||||
import { ActionMap } from '@/onebot/action';
|
import { ActionMap } from '@/onebot/action';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import { HttpServerConfig } from '@/onebot/config/config';
|
import { HttpServerConfig } from '@/onebot/config/config';
|
||||||
|
import { NapCatOneBot11Adapter } from "@/onebot";
|
||||||
|
import { IOB11NetworkAdapter } from "@/onebot/network/adapter";
|
||||||
|
|
||||||
export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
export class OB11PassiveHttpAdapter extends IOB11NetworkAdapter<HttpServerConfig> {
|
||||||
private app: Express | undefined;
|
private app: Express | undefined;
|
||||||
private server: http.Server | undefined;
|
private server: http.Server | undefined;
|
||||||
isEnable: boolean = false;
|
|
||||||
public config: HttpServerConfig;
|
|
||||||
|
|
||||||
constructor(
|
constructor(name: string, config: HttpServerConfig, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap) {
|
||||||
public name: string,
|
super(name, config, core, obContext, actions);
|
||||||
config: HttpServerConfig,
|
|
||||||
public core: NapCatCore,
|
|
||||||
public actions: ActionMap,
|
|
||||||
) {
|
|
||||||
this.config = structuredClone(config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onEvent() {
|
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||||
// http server is passive, no need to emit event
|
// http server is passive, no need to emit event
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,12 +82,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleRequest(req: Request, res: Response) {
|
async httpApiRequest(req: Request, res: Response) {
|
||||||
if (!this.isEnable) {
|
|
||||||
this.core.context.logger.log(`[OneBot] [HTTP Server Adapter] Server is closed`);
|
|
||||||
return res.json(OB11Response.error('Server is closed', 200));
|
|
||||||
}
|
|
||||||
|
|
||||||
let payload = req.body;
|
let payload = req.body;
|
||||||
if (req.method == 'get') {
|
if (req.method == 'get') {
|
||||||
payload = req.query;
|
payload = req.query;
|
||||||
@@ -118,6 +108,15 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async handleRequest(req: Request, res: Response) {
|
||||||
|
if (!this.isEnable) {
|
||||||
|
this.core.context.logger.log(`[OneBot] [HTTP Server Adapter] Server is closed`);
|
||||||
|
return res.json(OB11Response.error('Server is closed', 200));
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.httpApiRequest(req, res);
|
||||||
|
}
|
||||||
|
|
||||||
async reload(newConfig: HttpServerConfig) {
|
async reload(newConfig: HttpServerConfig) {
|
||||||
const wasEnabled = this.isEnable;
|
const wasEnabled = this.isEnable;
|
||||||
const oldPort = this.config.port;
|
const oldPort = this.config.port;
|
||||||
|
@@ -1,36 +1,29 @@
|
|||||||
import { IOB11NetworkAdapter, OB11EmitEventContent, OB11NetworkReloadType } from './index';
|
import { OB11EmitEventContent, OB11NetworkReloadType } from './index';
|
||||||
import urlParse from 'url';
|
import urlParse from 'url';
|
||||||
import { WebSocket, WebSocketServer } from 'ws';
|
import { WebSocket, WebSocketServer } from 'ws';
|
||||||
import { Mutex } from 'async-mutex';
|
import { Mutex } from 'async-mutex';
|
||||||
import { OB11Response } from '@/onebot/action/OneBotAction';
|
import { OB11Response } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { LogWrapper } from '@/common/log';
|
|
||||||
import { OB11HeartbeatEvent } from '@/onebot/event/meta/OB11HeartbeatEvent';
|
import { OB11HeartbeatEvent } from '@/onebot/event/meta/OB11HeartbeatEvent';
|
||||||
import { IncomingMessage } from 'http';
|
import { IncomingMessage } from 'http';
|
||||||
import { ActionMap } from '@/onebot/action';
|
import { ActionMap } from '@/onebot/action';
|
||||||
import { LifeCycleSubType, OB11LifeCycleEvent } from '@/onebot/event/meta/OB11LifeCycleEvent';
|
import { LifeCycleSubType, OB11LifeCycleEvent } from '@/onebot/event/meta/OB11LifeCycleEvent';
|
||||||
import { WebsocketServerConfig } from '@/onebot/config/config';
|
import { WebsocketServerConfig } from '@/onebot/config/config';
|
||||||
|
import { NapCatOneBot11Adapter } from "@/onebot";
|
||||||
|
import { IOB11NetworkAdapter } from "@/onebot/network/adapter";
|
||||||
|
|
||||||
export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
export class OB11PassiveWebSocketAdapter extends IOB11NetworkAdapter<WebsocketServerConfig> {
|
||||||
wsServer: WebSocketServer;
|
wsServer: WebSocketServer;
|
||||||
wsClients: WebSocket[] = [];
|
wsClients: WebSocket[] = [];
|
||||||
wsClientsMutex = new Mutex();
|
wsClientsMutex = new Mutex();
|
||||||
isEnable: boolean = false;
|
|
||||||
heartbeatInterval: number = 0;
|
|
||||||
logger: LogWrapper;
|
|
||||||
public config: WebsocketServerConfig;
|
|
||||||
private heartbeatIntervalId: NodeJS.Timeout | null = null;
|
private heartbeatIntervalId: NodeJS.Timeout | null = null;
|
||||||
wsClientWithEvent: WebSocket[] = [];
|
wsClientWithEvent: WebSocket[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public name: string,
|
name: string, config: WebsocketServerConfig, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap
|
||||||
config: WebsocketServerConfig,
|
|
||||||
public core: NapCatCore,
|
|
||||||
public actions: ActionMap,
|
|
||||||
) {
|
) {
|
||||||
this.config = structuredClone(config);
|
super(name, config, core, obContext, actions);
|
||||||
this.logger = core.context.logger;
|
|
||||||
this.wsServer = new WebSocketServer({
|
this.wsServer = new WebSocketServer({
|
||||||
port: this.config.port,
|
port: this.config.port,
|
||||||
host: this.config.host === '0.0.0.0' ? '' : this.config.host,
|
host: this.config.host === '0.0.0.0' ? '' : this.config.host,
|
||||||
@@ -106,7 +99,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port);
|
this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port);
|
||||||
|
|
||||||
this.isEnable = true;
|
this.isEnable = true;
|
||||||
if (this.heartbeatInterval > 0) {
|
if (this.config.heartInterval > 0) {
|
||||||
this.registerHeartBeat();
|
this.registerHeartBeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,11 +133,11 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
this.wsClientsMutex.runExclusive(async () => {
|
this.wsClientsMutex.runExclusive(async () => {
|
||||||
this.wsClientWithEvent.forEach((wsClient) => {
|
this.wsClientWithEvent.forEach((wsClient) => {
|
||||||
if (wsClient.readyState === WebSocket.OPEN) {
|
if (wsClient.readyState === WebSocket.OPEN) {
|
||||||
wsClient.send(JSON.stringify(new OB11HeartbeatEvent(this.core, this.heartbeatInterval, this.core.selfInfo.online ?? true, true)));
|
wsClient.send(JSON.stringify(new OB11HeartbeatEvent(this.core, this.config.heartInterval, this.core.selfInfo.online ?? true, true)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, this.heartbeatInterval);
|
}, this.config.heartInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
private authorize(token: string | undefined, wsClient: WebSocket, wsReq: IncomingMessage) {
|
private authorize(token: string | undefined, wsClient: WebSocket, wsReq: IncomingMessage) {
|
||||||
@@ -191,7 +184,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
const wasEnabled = this.isEnable;
|
const wasEnabled = this.isEnable;
|
||||||
const oldPort = this.config.port;
|
const oldPort = this.config.port;
|
||||||
const oldHost = this.config.host;
|
const oldHost = this.config.host;
|
||||||
const oldHeartbeatInterval = this.heartbeatInterval;
|
const oldHeartbeatInterval = this.config.heartInterval;
|
||||||
this.config = newConfig;
|
this.config = newConfig;
|
||||||
|
|
||||||
if (newConfig.enable && !wasEnabled) {
|
if (newConfig.enable && !wasEnabled) {
|
||||||
@@ -220,7 +213,6 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
clearInterval(this.heartbeatIntervalId);
|
clearInterval(this.heartbeatIntervalId);
|
||||||
this.heartbeatIntervalId = null;
|
this.heartbeatIntervalId = null;
|
||||||
}
|
}
|
||||||
this.heartbeatInterval = newConfig.heartInterval;
|
|
||||||
if (newConfig.heartInterval > 0 && this.isEnable) {
|
if (newConfig.heartInterval > 0 && this.isEnable) {
|
||||||
this.registerHeartBeat();
|
this.registerHeartBeat();
|
||||||
}
|
}
|
||||||
|
@@ -1,42 +1,37 @@
|
|||||||
import { IOB11NetworkAdapter, OB11EmitEventContent, OB11NetworkReloadType } from './index';
|
import { OB11EmitEventContent, OB11NetworkReloadType } from './index';
|
||||||
import { NapCatOneBot11Adapter, OB11Message } from '@/onebot';
|
import { NapCatOneBot11Adapter, OB11Message } from '@/onebot';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { AdapterConfig } from '../config/config';
|
import { PluginConfig } from '../config/config';
|
||||||
import { plugin_onmessage } from '@/plugin';
|
import { plugin_onmessage } from '@/plugin';
|
||||||
import { ActionMap } from '../action';
|
import { ActionMap } from '../action';
|
||||||
|
import { IOB11NetworkAdapter } from "@/onebot/network/adapter";
|
||||||
|
|
||||||
export class OB11PluginAdapter implements IOB11NetworkAdapter {
|
export class OB11PluginAdapter extends IOB11NetworkAdapter<PluginConfig> {
|
||||||
isEnable: boolean = true;
|
|
||||||
public config: AdapterConfig;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public name: string,
|
name: string, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap
|
||||||
public core: NapCatCore,
|
|
||||||
public obCore: NapCatOneBot11Adapter,
|
|
||||||
public actions: ActionMap,
|
|
||||||
) {
|
) {
|
||||||
// 基础配置
|
const config = {
|
||||||
this.config = {
|
|
||||||
name: name,
|
name: name,
|
||||||
messagePostFormat: 'array',
|
messagePostFormat: 'array',
|
||||||
reportSelfMessage: false,
|
reportSelfMessage: false,
|
||||||
enable: true,
|
enable: true,
|
||||||
debug: false,
|
debug: false,
|
||||||
}
|
};
|
||||||
|
super(name, config, core, obContext, actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||||
if (event.post_type === 'message') {
|
if (event.post_type === 'message') {
|
||||||
plugin_onmessage(this.config.name, this.core, this.obCore, event as OB11Message,this.actions).then().catch();
|
plugin_onmessage(this.config.name, this.core, this.obContext, event as OB11Message,this.actions).then().catch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
|
this.isEnable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
|
this.isEnable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async reload() {
|
async reload() {
|
||||||
|
@@ -75,6 +75,7 @@ export interface OB11Sender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface OB11GroupFile {
|
export interface OB11GroupFile {
|
||||||
|
file_size: number; // 文件大小 GOCQHTTP 群文件Api扩展
|
||||||
group_id: number; // 群ID
|
group_id: number; // 群ID
|
||||||
file_id: string; // 文件ID
|
file_id: string; // 文件ID
|
||||||
file_name: string; // 文件名称
|
file_name: string; // 文件名称
|
||||||
|
@@ -110,7 +110,6 @@ export interface OB11MessageContext {
|
|||||||
// 文件消息基础接口定义
|
// 文件消息基础接口定义
|
||||||
export interface OB11MessageFileBase {
|
export interface OB11MessageFileBase {
|
||||||
data: {
|
data: {
|
||||||
file_unique?: string;
|
|
||||||
path?: string;
|
path?: string;
|
||||||
thumb?: string;
|
thumb?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
import { NapCatOneBot11Adapter, OB11Message } from "@/onebot";
|
import { NapCatOneBot11Adapter, OB11Message } from "@/onebot";
|
||||||
import { NapCatCore } from "../core";
|
import { NapCatCore } from "@/core";
|
||||||
import { ActionMap } from "@/onebot/action";
|
import { ActionMap } from "@/onebot/action";
|
||||||
|
|
||||||
export const plugin_onmessage = async (adapter: string, core: NapCatCore, obCore: NapCatOneBot11Adapter, message: OB11Message, action: ActionMap) => {
|
export const plugin_onmessage = async (adapter: string, core: NapCatCore, obCtx: NapCatOneBot11Adapter, message: OB11Message, action: ActionMap) => {
|
||||||
if (message.raw_message === 'ping') {
|
if (message.raw_message === 'ping') {
|
||||||
const ret = await action.get('send_group_msg')?.handle({ group_id: String(message.group_id), message: 'pong' }, adapter);
|
const ret = await action.get('send_group_msg')?.handle({ group_id: String(message.group_id), message: 'pong' }, adapter);
|
||||||
console.log(ret);
|
console.log(ret);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
@@ -152,7 +152,7 @@ async function handleLogin(
|
|||||||
|
|
||||||
loginListener.onQRCodeSessionFailed = (errType: number, errCode: number, errMsg: string) => {
|
loginListener.onQRCodeSessionFailed = (errType: number, errCode: number, errMsg: string) => {
|
||||||
if (!isLogined) {
|
if (!isLogined) {
|
||||||
logger.logError('[Core] [Login] Login Error,ErrCode: ', errCode, ' ErrMsg:', errMsg);
|
logger.logError('[Core] [Login] Login Error,ErrType: ', errType, ' ErrCode:', errCode);
|
||||||
if (errType == 1 && errCode == 3) {
|
if (errType == 1 && errCode == 3) {
|
||||||
// 二维码过期刷新
|
// 二维码过期刷新
|
||||||
}
|
}
|
||||||
@@ -160,8 +160,8 @@ async function handleLogin(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
loginListener.onLoginFailed = (args) => {
|
loginListener.onLoginFailed = (...args) => {
|
||||||
logger.logError('[Core] [Login] Login Error , ErrInfo: ', args);
|
logger.logError('[Core] [Login] Login Error , ErrInfo: ', JSON.stringify(args));
|
||||||
};
|
};
|
||||||
|
|
||||||
loginService.addKernelLoginListener(proxiedListenerOf(loginListener, logger));
|
loginService.addKernelLoginListener(proxiedListenerOf(loginListener, logger));
|
||||||
@@ -266,7 +266,6 @@ export async function NCoreInitShell() {
|
|||||||
const pathWrapper = new NapCatPathWrapper();
|
const pathWrapper = new NapCatPathWrapper();
|
||||||
const logger = new LogWrapper(pathWrapper.logsPath);
|
const logger = new LogWrapper(pathWrapper.logsPath);
|
||||||
handleUncaughtExceptions(logger);
|
handleUncaughtExceptions(logger);
|
||||||
|
|
||||||
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
||||||
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
||||||
|
|
||||||
@@ -295,9 +294,7 @@ export async function NCoreInitShell() {
|
|||||||
|
|
||||||
const dataTimestape = new Date().getTime().toString();
|
const dataTimestape = new Date().getTime().toString();
|
||||||
o3Service.reportAmgomWeather('login', 'a1', [dataTimestape, '0', '0']);
|
o3Service.reportAmgomWeather('login', 'a1', [dataTimestape, '0', '0']);
|
||||||
|
|
||||||
const selfInfo = await handleLogin(loginService, logger, pathWrapper, quickLoginUin, historyLoginList);
|
const selfInfo = await handleLogin(loginService, logger, pathWrapper, quickLoginUin, historyLoginList);
|
||||||
|
|
||||||
const amgomDataPiece = 'eb1fd6ac257461580dc7438eb099f23aae04ca679f4d88f53072dc56e3bb1129';
|
const amgomDataPiece = 'eb1fd6ac257461580dc7438eb099f23aae04ca679f4d88f53072dc56e3bb1129';
|
||||||
o3Service.setAmgomDataPiece(basicInfoWrapper.QQVersionAppid, new Uint8Array(Buffer.from(amgomDataPiece, 'hex')));
|
o3Service.setAmgomDataPiece(basicInfoWrapper.QQVersionAppid, new Uint8Array(Buffer.from(amgomDataPiece, 'hex')));
|
||||||
|
|
||||||
|
@@ -7,3 +7,9 @@ export const PackageInfoHandler: RequestHandler = (_, res) => {
|
|||||||
const data = WebUiDataRuntime.getPackageJson();
|
const data = WebUiDataRuntime.getPackageJson();
|
||||||
sendSuccess(res, data);
|
sendSuccess(res, data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const QQVersionHandler: RequestHandler = (_, res) => {
|
||||||
|
const data = WebUiDataRuntime.getQQVersion();
|
||||||
|
sendSuccess(res, data);
|
||||||
|
};
|
||||||
|
19
src/webui/src/api/Status.ts
Normal file
19
src/webui/src/api/Status.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { RequestHandler } from 'express';
|
||||||
|
import { SystemStatus, statusHelperSubscription } from "@/core/helper/status";
|
||||||
|
|
||||||
|
export const StatusRealTimeHandler: RequestHandler = async (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'text/event-stream');
|
||||||
|
res.setHeader('Connection', 'keep-alive');
|
||||||
|
const sendStatus = (status: SystemStatus) => {
|
||||||
|
try{
|
||||||
|
res.write(`data: ${JSON.stringify(status)}\n\n`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`An error occurred when writing sendStatus data to client: ${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
statusHelperSubscription.on('statusUpdate', sendStatus);
|
||||||
|
req.on('close', () => {
|
||||||
|
statusHelperSubscription.off('statusUpdate', sendStatus);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
};
|
@@ -11,6 +11,7 @@ const LoginRuntime: LoginRuntimeType = {
|
|||||||
uin: '',
|
uin: '',
|
||||||
nick: '',
|
nick: '',
|
||||||
},
|
},
|
||||||
|
QQVersion: 'unknown',
|
||||||
NapCatHelper: {
|
NapCatHelper: {
|
||||||
onOB11ConfigChanged: async () => {
|
onOB11ConfigChanged: async () => {
|
||||||
return;
|
return;
|
||||||
@@ -100,4 +101,12 @@ export const WebUiDataRuntime = {
|
|||||||
getPackageJson() {
|
getPackageJson() {
|
||||||
return LoginRuntime.packageJson;
|
return LoginRuntime.packageJson;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setQQVersion(version: string) {
|
||||||
|
LoginRuntime.QQVersion = version;
|
||||||
|
},
|
||||||
|
|
||||||
|
getQQVersion() {
|
||||||
|
return LoginRuntime.QQVersion;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@@ -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 | constants.W_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} 没有写入权限, 配置的更改部分可能会在重启后还原.`);
|
||||||
|
}
|
||||||
// 不希望回写的配置放后面
|
// 不希望回写的配置放后面
|
||||||
|
|
||||||
// 查询主机地址是否可用
|
// 查询主机地址是否可用
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import { PackageInfoHandler } from '../api/BaseInfo';
|
import { PackageInfoHandler, QQVersionHandler } from '../api/BaseInfo';
|
||||||
|
import { StatusRealTimeHandler } from "@webapi/api/Status";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
// router: 获取nc的package.json信息
|
// router: 获取nc的package.json信息
|
||||||
|
router.get('/QQVersion', QQVersionHandler);
|
||||||
router.get('/PackageInfo', PackageInfoHandler);
|
router.get('/PackageInfo', PackageInfoHandler);
|
||||||
|
router.get('/GetSysStatusRealTime', StatusRealTimeHandler);
|
||||||
|
|
||||||
export { router as BaseRouter };
|
export { router as BaseRouter };
|
||||||
|
2
src/webui/src/types/data.d.ts
vendored
2
src/webui/src/types/data.d.ts
vendored
@@ -1,4 +1,5 @@
|
|||||||
import type { LoginListItem, SelfInfo } from '@/core';
|
import type { LoginListItem, SelfInfo } from '@/core';
|
||||||
|
import type { OneBotConfig } from "@/onebot/config/config";
|
||||||
|
|
||||||
interface LoginRuntimeType {
|
interface LoginRuntimeType {
|
||||||
LoginCurrentTime: number;
|
LoginCurrentTime: number;
|
||||||
@@ -7,6 +8,7 @@ interface LoginRuntimeType {
|
|||||||
QQQRCodeURL: string;
|
QQQRCodeURL: string;
|
||||||
QQLoginUin: string;
|
QQLoginUin: string;
|
||||||
QQLoginInfo: SelfInfo;
|
QQLoginInfo: SelfInfo;
|
||||||
|
QQVersion: string;
|
||||||
NapCatHelper: {
|
NapCatHelper: {
|
||||||
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
|
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
|
||||||
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
|
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
"target": "ES2021",
|
||||||
"useDefineForClassFields": true,
|
"useDefineForClassFields": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"lib": [
|
"lib": [
|
||||||
"ES2020",
|
"ES2021",
|
||||||
"DOM",
|
"DOM",
|
||||||
"DOM.Iterable"
|
"DOM.Iterable"
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user