mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
af052242fa | ||
![]() |
85e0b71545 | ||
![]() |
1206d1fcf6 | ||
![]() |
f7534dc438 | ||
![]() |
97f317254e | ||
![]() |
9eaf51e15f | ||
![]() |
7221f4ac02 | ||
![]() |
1bb6dce239 | ||
![]() |
d13db5e8eb | ||
![]() |
040b5535f3 | ||
![]() |
b44e1618fb | ||
![]() |
1e13483bc3 | ||
![]() |
f9519d3923 | ||
![]() |
86cdfbb79b | ||
![]() |
a70585e854 | ||
![]() |
040d0a8635 | ||
![]() |
efa512ab21 | ||
![]() |
9b04aed8b3 | ||
![]() |
7087eafe37 | ||
![]() |
c81c4af653 |
2
.env.universal
Normal file
2
.env.universal
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
VITE_BUILD_TYPE = Production
|
||||||
|
VITE_BUILD_PLATFORM = Universal
|
11
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
11
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -10,13 +10,12 @@ body:
|
|||||||
在提交新的 Bug 反馈前,请确保您:
|
在提交新的 Bug 反馈前,请确保您:
|
||||||
* 已经搜索了现有的 issues,并且没有找到可以解决您问题的方法
|
* 已经搜索了现有的 issues,并且没有找到可以解决您问题的方法
|
||||||
* 不与现有的某一 issue 重复
|
* 不与现有的某一 issue 重复
|
||||||
* 不涉及[已经停止维护的特性](https://github.com/NapNeko/NapCatQQ?tab=readme-ov-file#挥别昨日),例如 CQ 码
|
|
||||||
- type: input
|
- type: input
|
||||||
id: system-version
|
id: system-version
|
||||||
attributes:
|
attributes:
|
||||||
label: 系统版本
|
label: 系统版本
|
||||||
description: 运行 QQNT 的系统版本
|
description: 运行 QQNT 的系统版本
|
||||||
placeholder: Windows 10 Pro Workstation 22H2
|
placeholder: Windows 11 24H2
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: input
|
- type: input
|
||||||
@@ -24,7 +23,7 @@ body:
|
|||||||
attributes:
|
attributes:
|
||||||
label: QQNT 版本
|
label: QQNT 版本
|
||||||
description: 可在 QQNT 的「关于」的设置页中找到
|
description: 可在 QQNT 的「关于」的设置页中找到
|
||||||
placeholder: 9.9.7-21804
|
placeholder: 9.9.16-29927
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: input
|
- type: input
|
||||||
@@ -40,21 +39,21 @@ body:
|
|||||||
attributes:
|
attributes:
|
||||||
label: OneBot 客户端
|
label: OneBot 客户端
|
||||||
description: 连接至 NapCat 的客户端版本信息
|
description: 连接至 NapCat 的客户端版本信息
|
||||||
placeholder: Overflow 2.16.0-2cf7991-SNAPSHOT
|
placeholder: Karin 1.0.0
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: what-happened
|
id: what-happened
|
||||||
attributes:
|
attributes:
|
||||||
label: 发生了什么?
|
label: 发生了什么?
|
||||||
description: 填写你认为的 NapCat 的不正常行为
|
description: 填写你认为的 NapCat 的异常行为
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: how-reproduce
|
id: how-reproduce
|
||||||
attributes:
|
attributes:
|
||||||
label: 如何复现
|
label: 如何复现
|
||||||
description: 填写应当如何操作才能触发这个不正常行为
|
description: 填写应当如何操作才能触发这个异常行为
|
||||||
placeholder: |
|
placeholder: |
|
||||||
1. xxx
|
1. xxx
|
||||||
2. xxx
|
2. xxx
|
||||||
|
11
.github/dependabot.yml
vendored
11
.github/dependabot.yml
vendored
@@ -1,11 +1,6 @@
|
|||||||
# To get started with Dependabot version updates, you'll need to specify which
|
|
||||||
# package ecosystems to update and where the package manifests are located.
|
|
||||||
# Please see the documentation for all configuration options:
|
|
||||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
||||||
|
|
||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: "npm" # See documentation for possible values
|
- package-ecosystem: "npm"
|
||||||
directory: "/" # Location of package manifests
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: "weekly"
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "4.2.6",
|
"version": "4.2.9",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -2,11 +2,13 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "4.2.6",
|
"version": "4.2.9",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
||||||
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
||||||
"build:shell": "npm run build:webui && vite build --mode shell || exit 1",
|
"build:shell": "npm run build:webui && vite build --mode shell || exit 1",
|
||||||
"build:webui": "cd napcat.webui && vite build",
|
"build:webui": "cd napcat.webui && vite build",
|
||||||
|
"dev:universal": "vite build --mode universal",
|
||||||
"dev:framework": "vite build --mode framework",
|
"dev:framework": "vite build --mode framework",
|
||||||
"dev:shell": "vite build --mode shell",
|
"dev:shell": "vite build --mode shell",
|
||||||
"dev:webui": "cd napcat.webui && npm run webui:dev",
|
"dev:webui": "cd napcat.webui && npm run webui:dev",
|
||||||
@@ -41,13 +43,13 @@
|
|||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"globals": "^15.12.0",
|
"globals": "^15.12.0",
|
||||||
"image-size": "^1.1.1",
|
"image-size": "^1.1.1",
|
||||||
"json-schema-to-ts": "^3.1.1",
|
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
"typescript-eslint": "^8.13.0",
|
"typescript-eslint": "^8.13.0",
|
||||||
"vite": "^6.0.1",
|
"vite": "^6.0.1",
|
||||||
"vite-plugin-cp": "^4.0.8",
|
"vite-plugin-cp": "^4.0.8",
|
||||||
"vite-tsconfig-paths": "^5.1.0",
|
"vite-tsconfig-paths": "^5.1.0",
|
||||||
"winston": "^3.17.0"
|
"winston": "^3.17.0",
|
||||||
|
"@sinclair/typebox": "^0.34.9"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^5.0.0",
|
"express": "^5.0.0",
|
||||||
|
@@ -200,17 +200,7 @@ export async function checkUriType(Uri: string) {
|
|||||||
}
|
}
|
||||||
// 默认file://
|
// 默认file://
|
||||||
if (uri.startsWith('file:')) {
|
if (uri.startsWith('file:')) {
|
||||||
// 兼容file:///
|
const filePath: string = decodeURIComponent(uri.startsWith('file:///') && process.platform === 'win32' ? uri.slice(8) : uri.slice(7));
|
||||||
// file:///C:/1.jpg
|
|
||||||
if (uri.startsWith('file:///') && process.platform === 'win32') {
|
|
||||||
const filePath: string = uri.slice(8);
|
|
||||||
return { Uri: filePath, Type: FileUriType.Local };
|
|
||||||
}
|
|
||||||
// 处理默认规范
|
|
||||||
// file://C:\1.jpg
|
|
||||||
// file:///test/1.jpg
|
|
||||||
const filePath: string = uri.slice(7);
|
|
||||||
|
|
||||||
return { Uri: filePath, Type: FileUriType.Local };
|
return { Uri: filePath, Type: FileUriType.Local };
|
||||||
}
|
}
|
||||||
if (uri.startsWith('data:')) {
|
if (uri.startsWith('data:')) {
|
||||||
|
@@ -3,7 +3,7 @@ import { truncateString } from '@/common/helper';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import { NTMsgAtType, ChatType, ElementType, MessageElement, RawMessage, SelfInfo } from '@/core';
|
import { NTMsgAtType, ChatType, ElementType, MessageElement, RawMessage, SelfInfo } from '@/core';
|
||||||
|
import EventEmitter from 'node:events';
|
||||||
export enum LogLevel {
|
export enum LogLevel {
|
||||||
DEBUG = 'debug',
|
DEBUG = 'debug',
|
||||||
INFO = 'info',
|
INFO = 'info',
|
||||||
@@ -24,6 +24,36 @@ function getFormattedTimestamp() {
|
|||||||
return `${year}-${month}-${day}_${hours}-${minutes}-${seconds}.${milliseconds}`;
|
return `${year}-${month}-${day}_${hours}-${minutes}-${seconds}.${milliseconds}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const logEmitter = new EventEmitter();
|
||||||
|
export type LogListener = (msg: string) => void;
|
||||||
|
class Subscription {
|
||||||
|
public static MAX_HISTORY = 100;
|
||||||
|
public static history: string[] = [];
|
||||||
|
|
||||||
|
subscribe(listener: LogListener) {
|
||||||
|
for (const history of Subscription.history) {
|
||||||
|
try {
|
||||||
|
listener(history);
|
||||||
|
} catch (_) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logEmitter.on('log', listener);
|
||||||
|
}
|
||||||
|
unsubscribe(listener: LogListener) {
|
||||||
|
logEmitter.off('log', listener);
|
||||||
|
}
|
||||||
|
notify(msg: string) {
|
||||||
|
logEmitter.emit('log', msg);
|
||||||
|
if (Subscription.history.length >= Subscription.MAX_HISTORY) {
|
||||||
|
Subscription.history.shift();
|
||||||
|
}
|
||||||
|
Subscription.history.push(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const logSubscription = new Subscription();
|
||||||
|
|
||||||
export class LogWrapper {
|
export class LogWrapper {
|
||||||
fileLogEnabled = true;
|
fileLogEnabled = true;
|
||||||
consoleLogEnabled = true;
|
consoleLogEnabled = true;
|
||||||
@@ -47,7 +77,7 @@ export class LogWrapper {
|
|||||||
filename: logPath,
|
filename: logPath,
|
||||||
level: 'debug',
|
level: 'debug',
|
||||||
maxsize: 5 * 1024 * 1024, // 5MB
|
maxsize: 5 * 1024 * 1024, // 5MB
|
||||||
maxFiles: 5
|
maxFiles: 5,
|
||||||
}),
|
}),
|
||||||
new transports.Console({
|
new transports.Console({
|
||||||
format: format.combine(
|
format: format.combine(
|
||||||
@@ -56,9 +86,9 @@ export class LogWrapper {
|
|||||||
const userInfo = meta.userInfo ? `${meta.userInfo} | ` : '';
|
const userInfo = meta.userInfo ? `${meta.userInfo} | ` : '';
|
||||||
return `${timestamp} [${level}] ${userInfo}${message}`;
|
return `${timestamp} [${level}] ${userInfo}${message}`;
|
||||||
})
|
})
|
||||||
)
|
),
|
||||||
})
|
}),
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setLogSelfInfo({ nick: '', uid: '' });
|
this.setLogSelfInfo({ nick: '', uid: '' });
|
||||||
@@ -72,7 +102,7 @@ export class LogWrapper {
|
|||||||
this.logger.error('Failed to read log directory', err);
|
this.logger.error('Failed to read log directory', err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
files.forEach(file => {
|
files.forEach((file) => {
|
||||||
const filePath = path.join(logDir, file);
|
const filePath = path.join(logDir, file);
|
||||||
this.deleteOldLogFile(filePath, oneWeekAgo);
|
this.deleteOldLogFile(filePath, oneWeekAgo);
|
||||||
});
|
});
|
||||||
@@ -86,7 +116,7 @@ export class LogWrapper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (stats.mtime.getTime() < oneWeekAgo) {
|
if (stats.mtime.getTime() < oneWeekAgo) {
|
||||||
fs.unlink(filePath, err => {
|
fs.unlink(filePath, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err.code === 'ENOENT') {
|
if (err.code === 'ENOENT') {
|
||||||
this.logger.warn(`File already deleted: ${filePath}`);
|
this.logger.warn(`File already deleted: ${filePath}`);
|
||||||
@@ -111,7 +141,7 @@ export class LogWrapper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setLogSelfInfo(selfInfo: { nick: string, uid: string }) {
|
setLogSelfInfo(selfInfo: { nick: string; uid: string }) {
|
||||||
const userInfo = `${selfInfo.nick}`;
|
const userInfo = `${selfInfo.nick}`;
|
||||||
this.logger.defaultMeta = { userInfo };
|
this.logger.defaultMeta = { userInfo };
|
||||||
}
|
}
|
||||||
@@ -135,14 +165,16 @@ export class LogWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
formatMsg(msg: any[]) {
|
formatMsg(msg: any[]) {
|
||||||
return msg.map(msgItem => {
|
return msg
|
||||||
if (msgItem instanceof Error) {
|
.map((msgItem) => {
|
||||||
return msgItem.stack;
|
if (msgItem instanceof Error) {
|
||||||
} else if (typeof msgItem === 'object') {
|
return msgItem.stack;
|
||||||
return JSON.stringify(truncateString(JSON.parse(JSON.stringify(msgItem, null, 2))));
|
} else if (typeof msgItem === 'object') {
|
||||||
}
|
return JSON.stringify(truncateString(JSON.parse(JSON.stringify(msgItem, null, 2))));
|
||||||
return msgItem;
|
}
|
||||||
}).join(' ');
|
return msgItem;
|
||||||
|
})
|
||||||
|
.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
_log(level: LogLevel, ...args: any[]) {
|
_log(level: LogLevel, ...args: any[]) {
|
||||||
@@ -155,6 +187,7 @@ export class LogWrapper {
|
|||||||
// eslint-disable-next-line no-control-regex
|
// eslint-disable-next-line no-control-regex
|
||||||
this.logger.log(level, message.replace(/\x1B[@-_][0-?]*[ -/]*[@-~]/g, ''));
|
this.logger.log(level, message.replace(/\x1B[@-_][0-?]*[ -/]*[@-~]/g, ''));
|
||||||
}
|
}
|
||||||
|
logSubscription.notify(JSON.stringify({ level, message }));
|
||||||
}
|
}
|
||||||
|
|
||||||
log(...args: any[]) {
|
log(...args: any[]) {
|
||||||
@@ -282,13 +315,10 @@ function textElementToText(textElement: any): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function replyElementToText(replyElement: any, msg: RawMessage, recursiveLevel: number): string {
|
function replyElementToText(replyElement: any, msg: RawMessage, recursiveLevel: number): string {
|
||||||
const recordMsgOrNull = msg.records.find(
|
const recordMsgOrNull = msg.records.find((record) => replyElement.sourceMsgIdInRecords === record.msgId);
|
||||||
record => replyElement.sourceMsgIdInRecords === record.msgId,
|
return `[回复消息 ${
|
||||||
);
|
recordMsgOrNull && recordMsgOrNull.peerUin != '284840486' && recordMsgOrNull.peerUin != '1094950020'
|
||||||
return `[回复消息 ${recordMsgOrNull &&
|
? rawMessageToText(recordMsgOrNull, recursiveLevel + 1)
|
||||||
recordMsgOrNull.peerUin != '284840486' && recordMsgOrNull.peerUin != '1094950020'
|
: `未找到消息记录 (MsgId = ${replyElement.sourceMsgIdInRecords})`
|
||||||
?
|
|
||||||
rawMessageToText(recordMsgOrNull, recursiveLevel + 1) :
|
|
||||||
`未找到消息记录 (MsgId = ${replyElement.sourceMsgIdInRecords})`
|
|
||||||
}]`;
|
}]`;
|
||||||
}
|
}
|
||||||
|
@@ -69,7 +69,7 @@ export class RequestUtil {
|
|||||||
// 'Content-Length': Buffer.byteLength(postData),
|
// 'Content-Length': Buffer.byteLength(postData),
|
||||||
// },
|
// },
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const req = protocol.request(options, (res: any) => {
|
const req = protocol.request(options, (res: http.IncomingMessage) => {
|
||||||
let responseBody = '';
|
let responseBody = '';
|
||||||
res.on('data', (chunk: string | Buffer) => {
|
res.on('data', (chunk: string | Buffer) => {
|
||||||
responseBody += chunk.toString();
|
responseBody += chunk.toString();
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const napCatVersion = '4.2.6';
|
export const napCatVersion = '4.2.9';
|
||||||
|
@@ -163,7 +163,7 @@ export interface NodeIKernelGroupService {
|
|||||||
|
|
||||||
getGroupPortrait(): void;
|
getGroupPortrait(): void;
|
||||||
|
|
||||||
modifyGroupName(groupCode: string, groupName: string, arg: false): void;
|
modifyGroupName(groupCode: string, groupName: string, isNormalMember: boolean): Promise<GeneralCallResult>;
|
||||||
|
|
||||||
modifyGroupRemark(groupCode: string, remark: string): void;
|
modifyGroupRemark(groupCode: string, remark: string): void;
|
||||||
|
|
||||||
|
@@ -42,7 +42,7 @@ export abstract class OneBotAction<PayloadType, ReturnDataType> {
|
|||||||
|
|
||||||
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
||||||
if (this.payloadSchema) {
|
if (this.payloadSchema) {
|
||||||
this.validate = new Ajv({ allowUnionTypes: true }).compile(this.payloadSchema);
|
this.validate = new Ajv({ allowUnionTypes: true, useDefaults: true }).compile(this.payloadSchema);
|
||||||
}
|
}
|
||||||
if (this.validate && !this.validate(payload)) {
|
if (this.validate && !this.validate(payload)) {
|
||||||
const errors = this.validate.errors as ErrorObject[];
|
const errors = this.validate.errors as ErrorObject[];
|
||||||
|
@@ -1,17 +1,13 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Type, Static } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
rawData: Type.String(),
|
||||||
properties: {
|
brief: Type.String(),
|
||||||
rawData: { type: 'string' },
|
});
|
||||||
brief: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['brief', 'rawData'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class CreateCollection extends OneBotAction<Payload, any> {
|
export class CreateCollection extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.CreateCollection;
|
actionName = ActionName.CreateCollection;
|
||||||
@@ -25,4 +21,4 @@ export class CreateCollection extends OneBotAction<Payload, any> {
|
|||||||
payload.brief, payload.rawData,
|
payload.brief, payload.rawData,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,23 +1,19 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Type, Static } from '@sinclair/typebox';
|
||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
count: Type.Union([Type.Number(), Type.String()], { default: 48 }),
|
||||||
properties: {
|
});
|
||||||
count: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class FetchCustomFace extends OneBotAction<Payload, string[]> {
|
export class FetchCustomFace extends OneBotAction<Payload, string[]> {
|
||||||
actionName = ActionName.FetchCustomFace;
|
actionName = ActionName.FetchCustomFace;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
//48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa
|
const ret = await this.core.apis.MsgApi.fetchFavEmojiList(+payload.count);
|
||||||
const ret = await this.core.apis.MsgApi.fetchFavEmojiList(+(payload.count ?? 48));
|
|
||||||
return ret.emojiInfoList.map(e => e.url);
|
return ret.emojiInfoList.map(e => e.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,32 +1,27 @@
|
|||||||
//getMsgEmojiLikesList
|
import { Type, Static } from '@sinclair/typebox';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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 { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
emojiId: Type.Union([Type.Number(), Type.String()]),
|
||||||
user_id: { type: 'string' },
|
emojiType: Type.Union([Type.Number(), Type.String()]),
|
||||||
group_id: { type: 'string' },
|
count: Type.Union([Type.Number(), Type.String()], { default: 20 }),
|
||||||
emojiId: { type: 'string' },
|
});
|
||||||
emojiType: { type: 'string' },
|
|
||||||
message_id: { type: ['string', 'number'] },
|
|
||||||
count: { type: ['string', 'number'] },
|
|
||||||
},
|
|
||||||
required: ['emojiId', 'emojiType', 'message_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class FetchEmojiLike extends OneBotAction<Payload, any> {
|
export class FetchEmojiLike extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.FetchEmojiLike;
|
actionName = ActionName.FetchEmojiLike;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
|
||||||
if (!msgIdPeer) throw new Error('消息不存在');
|
if (!msgIdPeer) throw new Error('消息不存在');
|
||||||
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
||||||
return await this.core.apis.MsgApi.getMsgEmojiLikesList(msgIdPeer.Peer, msg.msgSeq, payload.emojiId, payload.emojiType, +(payload.count ?? 20));
|
return await this.core.apis.MsgApi.getMsgEmojiLikesList(
|
||||||
|
msgIdPeer.Peer, msg.msgSeq, payload.emojiId.toString(), payload.emojiType.toString(), +payload.count
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,17 @@
|
|||||||
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 { Type, Static } from '@sinclair/typebox';
|
||||||
|
|
||||||
export class FetchUserProfileLike extends OneBotAction<{ qq: number }, any> {
|
const SchemaData = Type.Object({
|
||||||
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
|
export class FetchUserProfileLike extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.FetchUserProfileLike;
|
actionName = ActionName.FetchUserProfileLike;
|
||||||
|
|
||||||
async _handle(payload: { qq: number }) {
|
async _handle(payload: Payload) {
|
||||||
if (!payload.qq) throw new Error('qq is required');
|
return await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
return await this.core.apis.UserApi.getUidByUinV2(payload.qq.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
import { AIVoiceChatType } from "@/core/packet/entities/aiChat";
|
import { AIVoiceChatType } from "@/core/packet/entities/aiChat";
|
||||||
|
import { Type, Static } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
chat_type: Type.Union([Type.Union([Type.Number(), Type.String()])], { default: 1 }),
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
chat_type: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
interface GetAiCharactersResponse {
|
interface GetAiCharactersResponse {
|
||||||
type: string;
|
type: string;
|
||||||
@@ -28,7 +24,7 @@ export class GetAiCharacters extends GetPacketStatusDepends<Payload, GetAiCharac
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const rawList = await this.core.apis.PacketApi.pkt.operation.FetchAiVoiceList(+payload.group_id, +(payload.chat_type ?? 1) as AIVoiceChatType);
|
const rawList = await this.core.apis.PacketApi.pkt.operation.FetchAiVoiceList(+payload.group_id, +payload.chat_type as AIVoiceChatType);
|
||||||
return rawList?.map((item) => ({
|
return rawList?.map((item) => ({
|
||||||
type: item.category,
|
type: item.category,
|
||||||
characters: item.voices.map((voice) => ({
|
characters: item.voices.map((voice) => ({
|
||||||
|
@@ -1,23 +1,19 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Type, Static } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
category: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
count: Type.Union([Type.Union([Type.Number(), Type.String()])], { default: 1 }),
|
||||||
category: { type: ['number', 'string'] },
|
});
|
||||||
count: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['category', 'count'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetCollectionList extends OneBotAction<Payload, any> {
|
export class GetCollectionList extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GetCollectionList;
|
actionName = ActionName.GetCollectionList;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
return await this.core.apis.CollectionApi.getAllCollection(parseInt(payload.category.toString()), +(payload.count ?? 1));
|
return await this.core.apis.CollectionApi.getAllCollection(parseInt(payload.category.toString()), +payload.count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,11 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Type, Static } from '@sinclair/typebox';
|
||||||
|
const SchemaData = Type.Object({
|
||||||
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
});
|
||||||
|
|
||||||
const SchemaData = {
|
type Payload = Static<typeof SchemaData>;
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
group_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GetGroupInfoEx extends OneBotAction<Payload, any> {
|
export class GetGroupInfoEx extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GetGroupInfoEx;
|
actionName = ActionName.GetGroupInfoEx;
|
||||||
|
@@ -1,47 +1,37 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
import { MiniAppInfo, MiniAppInfoHelper } from "@/core/packet/utils/helper/miniAppHelper";
|
import { MiniAppInfo, MiniAppInfoHelper } from "@/core/packet/utils/helper/miniAppHelper";
|
||||||
import { MiniAppData, MiniAppRawData, MiniAppReqCustomParams, MiniAppReqParams } from "@/core/packet/entities/miniApp";
|
import { MiniAppData, MiniAppRawData, MiniAppReqCustomParams, MiniAppReqParams } from "@/core/packet/entities/miniApp";
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Union([
|
||||||
type: 'object',
|
Type.Object({
|
||||||
properties: {
|
type: Type.Union([Type.Literal('bili'), Type.Literal('weibo')]),
|
||||||
type: {
|
title: Type.String(),
|
||||||
type: 'string',
|
desc: Type.String(),
|
||||||
enum: ['bili', 'weibo']
|
picUrl: Type.String(),
|
||||||
},
|
jumpUrl: Type.String(),
|
||||||
title: { type: 'string' },
|
rawArkData: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
||||||
desc: { type: 'string' },
|
}),
|
||||||
picUrl: { type: 'string' },
|
Type.Object({
|
||||||
jumpUrl: { type: 'string' },
|
title: Type.String(),
|
||||||
iconUrl: { type: 'string' },
|
desc: Type.String(),
|
||||||
sdkId: { type: 'string' },
|
picUrl: Type.String(),
|
||||||
appId: { type: 'string' },
|
jumpUrl: Type.String(),
|
||||||
scene: { type: ['number', 'string'] },
|
iconUrl: Type.String(),
|
||||||
templateType: { type: ['number', 'string'] },
|
appId: Type.String(),
|
||||||
businessType: { type: ['number', 'string'] },
|
scene: Type.Union([Type.Number(), Type.String()]),
|
||||||
verType: { type: ['number', 'string'] },
|
templateType: Type.Union([Type.Number(), Type.String()]),
|
||||||
shareType: { type: ['number', 'string'] },
|
businessType: Type.Union([Type.Number(), Type.String()]),
|
||||||
versionId: { type: 'string' },
|
verType: Type.Union([Type.Number(), Type.String()]),
|
||||||
withShareTicket: { type: ['number', 'string'] },
|
shareType: Type.Union([Type.Number(), Type.String()]),
|
||||||
rawArkData: { type: ['boolean', 'string'] }
|
versionId: Type.String(),
|
||||||
},
|
sdkId: Type.String(),
|
||||||
oneOf: [
|
withShareTicket: Type.Union([Type.Number(), Type.String()]),
|
||||||
{
|
rawArkData: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
||||||
required: ['type', 'title', 'desc', 'picUrl', 'jumpUrl']
|
})
|
||||||
},
|
]);
|
||||||
{
|
type Payload = Static<typeof SchemaData>;
|
||||||
required: [
|
|
||||||
'title', 'desc', 'picUrl', 'jumpUrl',
|
|
||||||
'iconUrl', 'appId', 'scene', 'templateType', 'businessType',
|
|
||||||
'verType', 'shareType', 'versionId', 'withShareTicket'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GetMiniAppArk extends GetPacketStatusDepends<Payload, {
|
export class GetMiniAppArk extends GetPacketStatusDepends<Payload, {
|
||||||
data: MiniAppData | MiniAppRawData
|
data: MiniAppData | MiniAppRawData
|
||||||
@@ -57,7 +47,7 @@ export class GetMiniAppArk extends GetPacketStatusDepends<Payload, {
|
|||||||
picUrl: payload.picUrl,
|
picUrl: payload.picUrl,
|
||||||
jumpUrl: payload.jumpUrl
|
jumpUrl: payload.jumpUrl
|
||||||
} as MiniAppReqCustomParams;
|
} as MiniAppReqCustomParams;
|
||||||
if (payload.type) {
|
if ('type' in payload) {
|
||||||
reqParam = MiniAppInfoHelper.generateReq(customParams, MiniAppInfo.get(payload.type)!.template);
|
reqParam = MiniAppInfoHelper.generateReq(customParams, MiniAppInfo.get(payload.type)!.template);
|
||||||
} else {
|
} else {
|
||||||
const { appId, scene, iconUrl, templateType, businessType, verType, shareType, versionId, withShareTicket } = payload;
|
const { appId, scene, iconUrl, templateType, businessType, verType, shareType, versionId, withShareTicket } = payload;
|
||||||
|
@@ -1,34 +1,28 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Type, Static } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
properties: {
|
start: Type.Union([Type.Number(), Type.String()], { default: 0 }),
|
||||||
user_id: { type: ['number', 'string'] },
|
count: Type.Union([Type.Number(), Type.String()], { default: 10 }),
|
||||||
start: { type: ['number', 'string'] },
|
type: Type.Union([Type.Number(), Type.String()], { default: 2 }),
|
||||||
count: { type: ['number', 'string'] },
|
});
|
||||||
type: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetProfileLike extends OneBotAction<Payload, any> {
|
export class GetProfileLike extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GetProfileLike;
|
actionName = ActionName.GetProfileLike;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const start = payload.start ? Number(payload.start) : 0;
|
|
||||||
const count = payload.count ? Number(payload.count) : 10;
|
|
||||||
const type = payload.count ? Number(payload.count) : 2;
|
|
||||||
const user_uid =
|
const user_uid =
|
||||||
this.core.selfInfo.uin === payload.user_id || !payload.user_id ?
|
this.core.selfInfo.uin === payload.user_id || !payload.user_id ?
|
||||||
this.core.selfInfo.uid :
|
this.core.selfInfo.uid :
|
||||||
await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
const ret = await this.core.apis.UserApi.getProfileLike(user_uid ?? this.core.selfInfo.uid, start, count, type);
|
const ret = await this.core.apis.UserApi.getProfileLike(user_uid ?? this.core.selfInfo.uid, +payload.start, +payload.count, +payload.type);
|
||||||
const listdata = ret.info.userLikeInfos[0].voteInfo.userInfos;
|
const listdata = ret.info.userLikeInfos[0].voteInfo.userInfos;
|
||||||
for (const item of listdata) {
|
for (const item of listdata) {
|
||||||
item.uin = parseInt((await this.core.apis.UserApi.getUinByUidV2(item.uid)) || '');
|
item.uin = +((await this.core.apis.UserApi.getUinByUidV2(item.uid)) ?? '');
|
||||||
}
|
}
|
||||||
return ret.info.userLikeInfos[0].voteInfo;
|
return ret.info.userLikeInfos[0].voteInfo;
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
|
|
||||||
|
export class GetRkey extends GetPacketStatusDepends<void, Array<any>> {
|
||||||
export class GetRkey extends GetPacketStatusDepends<null, Array<any>> {
|
|
||||||
actionName = ActionName.GetRkey;
|
actionName = ActionName.GetRkey;
|
||||||
|
|
||||||
async _handle() {
|
async _handle() {
|
||||||
|
@@ -4,7 +4,7 @@ import { ActionName } from '@/onebot/action/router';
|
|||||||
export class GetRobotUinRange extends OneBotAction<void, Array<any>> {
|
export class GetRobotUinRange extends OneBotAction<void, Array<any>> {
|
||||||
actionName = ActionName.GetRobotUinRange;
|
actionName = ActionName.GetRobotUinRange;
|
||||||
|
|
||||||
async _handle(payload: void) {
|
async _handle() {
|
||||||
return await this.core.apis.UserApi.getRobotUinRange();
|
return await this.core.apis.UserApi.getRobotUinRange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,12 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
// no_cache get时传字符串
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
const SchemaData = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
user_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['user_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
const SchemaData = Type.Object({
|
||||||
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetUserStatus extends GetPacketStatusDepends<Payload, { status: number; ext_status: number; } | undefined> {
|
export class GetUserStatus extends GetPacketStatusDepends<Payload, { status: number; ext_status: number; } | undefined> {
|
||||||
actionName = ActionName.GetUserStatus;
|
actionName = ActionName.GetUserStatus;
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { checkFileExist, uri2local } from '@/common/file';
|
import { checkFileExist, uri2local } from '@/common/file';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
image: Type.String(),
|
||||||
properties: {
|
});
|
||||||
image: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['image'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class OCRImage extends OneBotAction<Payload, any> {
|
export class OCRImage extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.OCRImage;
|
actionName = ActionName.OCRImage;
|
||||||
@@ -29,12 +25,12 @@ export class OCRImage extends OneBotAction<Payload, any> {
|
|||||||
fs.unlink(path, () => { });
|
fs.unlink(path, () => { });
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
throw new Error(`OCR ${payload.file}失败`);
|
throw new Error(`OCR ${payload.image}失败`);
|
||||||
}
|
}
|
||||||
return ret.result;
|
return ret.result;
|
||||||
}
|
}
|
||||||
fs.unlink(path, () => { });
|
fs.unlink(path, () => { });
|
||||||
throw new Error(`OCR ${payload.file}失败,文件可能不存在`);
|
throw new Error(`OCR ${payload.image}失败,文件可能不存在`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,16 +1,12 @@
|
|||||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
group_id: { type: ['string', 'number'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SetGroupSign extends GetPacketStatusDepends<Payload, any> {
|
export class SetGroupSign extends GetPacketStatusDepends<Payload, any> {
|
||||||
actionName = ActionName.SetGroupSign;
|
actionName = ActionName.SetGroupSign;
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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 { ChatType } from '@/core';
|
import { ChatType } from '@/core';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
event_type: Type.Number(),
|
||||||
event_type: { type: 'number' },
|
});
|
||||||
user_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['event_type', 'user_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SetInputStatus extends OneBotAction<Payload, any> {
|
export class SetInputStatus extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.SetInputStatus;
|
actionName = ActionName.SetInputStatus;
|
||||||
|
@@ -1,16 +1,12 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
longNick: Type.String(),
|
||||||
properties: {
|
});
|
||||||
longNick: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['longNick'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SetLongNick extends OneBotAction<Payload, any> {
|
export class SetLongNick extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.SetLongNick;
|
actionName = ActionName.SetLongNick;
|
||||||
|
@@ -1,19 +1,14 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
// 设置在线状态
|
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
status: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
ext_status: Type.Union([Type.Number(), Type.String()]),
|
||||||
status: { type: ['number', 'string'] },
|
battery_status: Type.Union([Type.Number(), Type.String()]),
|
||||||
ext_status: { type: ['number', 'string'] },
|
});
|
||||||
battery_status: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['status', 'ext_status', 'battery_status'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SetOnlineStatus extends OneBotAction<Payload, null> {
|
export class SetOnlineStatus extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SetOnlineStatus;
|
actionName = ActionName.SetOnlineStatus;
|
||||||
@@ -21,9 +16,9 @@ export class SetOnlineStatus extends OneBotAction<Payload, null> {
|
|||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const ret = await this.core.apis.UserApi.setSelfOnlineStatus(
|
const ret = await this.core.apis.UserApi.setSelfOnlineStatus(
|
||||||
parseInt(payload.status.toString()),
|
+payload.status,
|
||||||
parseInt(payload.ext_status.toString()),
|
+payload.ext_status,
|
||||||
parseInt(payload.battery_status.toString()),
|
+payload.battery_status,
|
||||||
);
|
);
|
||||||
if (ret.result !== 0) {
|
if (ret.result !== 0) {
|
||||||
throw new Error('设置在线状态失败');
|
throw new Error('设置在线状态失败');
|
||||||
|
@@ -1,28 +1,18 @@
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import { checkFileExist, uri2local } from '@/common/file';
|
import { checkFileExist, uri2local } from '@/common/file';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
interface Payload {
|
const SchemaData = Type.Object({
|
||||||
file: string;
|
file: Type.String(),
|
||||||
}
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetAvatar extends OneBotAction<Payload, null> {
|
export default class SetAvatar extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SetQQAvatar;
|
actionName = ActionName.SetQQAvatar;
|
||||||
|
payloadSchema = SchemaData;
|
||||||
// 用不着复杂检测
|
|
||||||
protected async check(payload: Payload): Promise<BaseCheckResult> {
|
|
||||||
if (!payload.file || typeof payload.file != 'string') {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
message: 'file字段不能为空或者类型错误',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
valid: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const { path, success } = (await uri2local(this.core.NapCatTempPath, payload.file));
|
const { path, success } = (await uri2local(this.core.NapCatTempPath, payload.file));
|
||||||
if (!success) {
|
if (!success) {
|
||||||
@@ -45,7 +35,6 @@ export default class SetAvatar extends OneBotAction<Payload, null> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fs.unlink(path, () => { });
|
fs.unlink(path, () => { });
|
||||||
|
|
||||||
throw new Error(`头像${payload.file}设置失败,无法获取头像,文件可能不存在`);
|
throw new Error(`头像${payload.file}设置失败,无法获取头像,文件可能不存在`);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@@ -1,17 +1,14 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
const SchemaData = {
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
group_id: { type: ['number', 'string'] },
|
|
||||||
user_id: { type: ['number', 'string'] },
|
|
||||||
special_title: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'user_id', 'special_title'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
const SchemaData = Type.Object({
|
||||||
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
special_title: Type.String(),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SetSpecialTittle extends GetPacketStatusDepends<Payload, any> {
|
export class SetSpecialTittle extends GetPacketStatusDepends<Payload, any> {
|
||||||
actionName = ActionName.SetSpecialTittle;
|
actionName = ActionName.SetSpecialTittle;
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
properties: {
|
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
user_id: { type: 'string' },
|
phoneNumber: Type.String({ default: '' }),
|
||||||
group_id: { type: 'string' },
|
});
|
||||||
phoneNumber: { type: 'string' },
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SharePeer extends OneBotAction<Payload, any> {
|
export class SharePeer extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.SharePeer;
|
actionName = ActionName.SharePeer;
|
||||||
@@ -20,28 +16,24 @@ export class SharePeer extends OneBotAction<Payload, any> {
|
|||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
if (payload.group_id) {
|
if (payload.group_id) {
|
||||||
return await this.core.apis.GroupApi.getGroupRecommendContactArkJson(payload.group_id);
|
return await this.core.apis.GroupApi.getGroupRecommendContactArkJson(payload.group_id.toString());
|
||||||
} else if (payload.user_id) {
|
} else if (payload.user_id) {
|
||||||
return await this.core.apis.UserApi.getBuddyRecommendContactArkJson(payload.user_id, payload.phoneNumber || '');
|
return await this.core.apis.UserApi.getBuddyRecommendContactArkJson(payload.user_id.toString(), payload.phoneNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const SchemaDataGroupEx = {
|
const SchemaDataGroupEx = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
group_id: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type PayloadGroupEx = FromSchema<typeof SchemaDataGroupEx>;
|
type PayloadGroupEx = Static<typeof SchemaDataGroupEx>;
|
||||||
|
|
||||||
export class ShareGroupEx extends OneBotAction<PayloadGroupEx, any> {
|
export class ShareGroupEx extends OneBotAction<PayloadGroupEx, any> {
|
||||||
actionName = ActionName.ShareGroupEx;
|
actionName = ActionName.ShareGroupEx;
|
||||||
payloadSchema = SchemaDataGroupEx;
|
payloadSchema = SchemaDataGroupEx;
|
||||||
|
|
||||||
async _handle(payload: PayloadGroupEx) {
|
async _handle(payload: PayloadGroupEx) {
|
||||||
return await this.core.apis.GroupApi.getArkJsonGroupShare(payload.group_id);
|
return await this.core.apis.GroupApi.getArkJsonGroupShare(payload.group_id.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,19 +1,12 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
words: Type.Array(Type.String()),
|
||||||
properties: {
|
});
|
||||||
words: {
|
|
||||||
type: 'array',
|
|
||||||
items: { type: 'string' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
required: ['words'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class TranslateEnWordToZn extends OneBotAction<Payload, Array<any> | null> {
|
export class TranslateEnWordToZn extends OneBotAction<Payload, Array<any> | null> {
|
||||||
actionName = ActionName.TranslateEnWordToZn;
|
actionName = ActionName.TranslateEnWordToZn;
|
||||||
|
@@ -2,12 +2,8 @@ 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/helper';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { OB11MessageImage, OB11MessageVideo } from '@/onebot/types';
|
import { OB11MessageImage, OB11MessageVideo } from '@/onebot/types';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
// interface GetFilePayload {
|
|
||||||
// file: string; // 文件名或者fileUuid
|
|
||||||
// }
|
|
||||||
|
|
||||||
export interface GetFileResponse {
|
export interface GetFileResponse {
|
||||||
file?: string; // path
|
file?: string; // path
|
||||||
@@ -16,19 +12,14 @@ export interface GetFileResponse {
|
|||||||
file_name?: string;
|
file_name?: string;
|
||||||
base64?: string;
|
base64?: string;
|
||||||
}
|
}
|
||||||
const GetFileBase_PayloadSchema = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
file: { type: 'string' },
|
|
||||||
file_id: { type: 'string' }
|
|
||||||
},
|
|
||||||
oneOf: [
|
|
||||||
{ required: ['file'] },
|
|
||||||
{ required: ['file_id'] }
|
|
||||||
]
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
export type GetFilePayload = FromSchema<typeof GetFileBase_PayloadSchema>;
|
const GetFileBase_PayloadSchema = Type.Object({
|
||||||
|
file: Type.Optional(Type.String()),
|
||||||
|
file_id: Type.Optional(Type.String())
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export type GetFilePayload = Static<typeof GetFileBase_PayloadSchema>;
|
||||||
|
|
||||||
export class GetFileBase extends OneBotAction<GetFilePayload, GetFileResponse> {
|
export class GetFileBase extends OneBotAction<GetFilePayload, GetFileResponse> {
|
||||||
payloadSchema = GetFileBase_PayloadSchema;
|
payloadSchema = GetFileBase_PayloadSchema;
|
||||||
@@ -50,12 +41,12 @@ export class GetFileBase extends OneBotAction<GetFilePayload, GetFileResponse> {
|
|||||||
let url = '';
|
let url = '';
|
||||||
if (mixElement?.picElement && rawMessage) {
|
if (mixElement?.picElement && rawMessage) {
|
||||||
const tempData =
|
const tempData =
|
||||||
await this.obContext.apis.MsgApi.rawToOb11Converters.picElement?.(mixElement?.picElement, rawMessage, mixElement) as OB11MessageImage | undefined;
|
await this.obContext.apis.MsgApi.rawToOb11Converters.picElement?.(mixElement?.picElement, rawMessage, mixElement, { parseMultMsg: false }) as OB11MessageImage | undefined;
|
||||||
url = tempData?.data.url ?? '';
|
url = tempData?.data.url ?? '';
|
||||||
}
|
}
|
||||||
if (mixElement?.videoElement && rawMessage) {
|
if (mixElement?.videoElement && rawMessage) {
|
||||||
const tempData =
|
const tempData =
|
||||||
await this.obContext.apis.MsgApi.rawToOb11Converters.videoElement?.(mixElement?.videoElement, rawMessage, mixElement) as OB11MessageVideo | undefined;
|
await this.obContext.apis.MsgApi.rawToOb11Converters.videoElement?.(mixElement?.videoElement, rawMessage, mixElement, { parseMultMsg: false }) as OB11MessageVideo | undefined;
|
||||||
url = tempData?.data.url ?? '';
|
url = tempData?.data.url ?? '';
|
||||||
}
|
}
|
||||||
const res: GetFileResponse = {
|
const res: GetFileResponse = {
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { FileNapCatOneBotUUID } from "@/common/helper";
|
import { FileNapCatOneBotUUID } from "@/common/helper";
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
file_id: Type.String(),
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
file_id: { type: ['string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'file_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
interface GetGroupFileUrlResponse {
|
interface GetGroupFileUrlResponse {
|
||||||
url?: string;
|
url?: string;
|
||||||
|
@@ -1,17 +1,13 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
folder_name: Type.String(),
|
||||||
group_id: { type: ['string', 'number'] },
|
});
|
||||||
folder_name: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'folder_name'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class CreateGroupFileFolder extends OneBotAction<Payload, any> {
|
export class CreateGroupFileFolder extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_CreateGroupFileFolder;
|
actionName = ActionName.GoCQHTTP_CreateGroupFileFolder;
|
||||||
|
@@ -1,18 +1,15 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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/helper';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
file_id: Type.String(),
|
||||||
group_id: { type: ['string', 'number'] },
|
});
|
||||||
file_id: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'file_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class DeleteGroupFile extends OneBotAction<Payload, any> {
|
export class DeleteGroupFile extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GOCQHTTP_DeleteGroupFile;
|
actionName = ActionName.GOCQHTTP_DeleteGroupFile;
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
folder_id: Type.Optional(Type.String()),
|
||||||
group_id: { type: ['string', 'number'] },
|
folder: Type.Optional(Type.String()),
|
||||||
folder_id: { type: 'string' },
|
});
|
||||||
folder: { type: 'string' }
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class DeleteGroupFileFolder extends OneBotAction<Payload, any> {
|
export class DeleteGroupFileFolder extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_DeleteGroupFileFolder;
|
actionName = ActionName.GoCQHTTP_DeleteGroupFileFolder;
|
||||||
|
@@ -4,29 +4,20 @@ 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, httpDownload } from '@/common/file';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
interface FileResponse {
|
interface FileResponse {
|
||||||
file: string;
|
file: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
url: Type.Optional(Type.String()),
|
||||||
properties: {
|
base64: Type.Optional(Type.String()),
|
||||||
thread_count: { type: ['number', 'string'] },
|
name: Type.Optional(Type.String()),
|
||||||
url: { type: 'string' },
|
headers: Type.Optional(Type.Union([Type.String(), Type.Array(Type.String())])),
|
||||||
base64: { type: 'string' },
|
});
|
||||||
name: { type: 'string' },
|
|
||||||
headers: {
|
|
||||||
type: ['string', 'array'],
|
|
||||||
items: {
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class GoCQHTTPDownloadFile extends OneBotAction<Payload, FileResponse> {
|
export default class GoCQHTTPDownloadFile extends OneBotAction<Payload, FileResponse> {
|
||||||
actionName = ActionName.GoCQHTTP_DownloadFile;
|
actionName = ActionName.GoCQHTTP_DownloadFile;
|
||||||
|
@@ -1,20 +1,15 @@
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { OB11Message, OB11MessageData, OB11MessageDataType, OB11MessageForward, OB11MessageNodePlain as OB11MessageNode } from '@/onebot';
|
import { OB11Message, OB11MessageData, OB11MessageDataType, OB11MessageForward, OB11MessageNodePlain as OB11MessageNode } from '@/onebot';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
|
const SchemaData = Type.Object({
|
||||||
|
message_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
|
id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
const SchemaData = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
message_id: { type: 'string' },
|
|
||||||
id: { type: 'string' },
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GoCQHTTPGetForwardMsgAction extends OneBotAction<Payload, any> {
|
export class GoCQHTTPGetForwardMsgAction extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_GetForwardMsg;
|
actionName = ActionName.GoCQHTTP_GetForwardMsg;
|
||||||
@@ -60,7 +55,7 @@ export class GoCQHTTPGetForwardMsgAction extends OneBotAction<Payload, any> {
|
|||||||
throw new Error('message_id is required');
|
throw new Error('message_id is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootMsgId = MessageUnique.getShortIdByMsgId(msgId);
|
const rootMsgId = MessageUnique.getShortIdByMsgId(msgId.toString());
|
||||||
const rootMsg = MessageUnique.getMsgIdAndPeerByShortId(rootMsgId ?? +msgId);
|
const rootMsg = MessageUnique.getMsgIdAndPeerByShortId(rootMsgId ?? +msgId);
|
||||||
if (!rootMsg) {
|
if (!rootMsg) {
|
||||||
throw new Error('msg not found');
|
throw new Error('msg not found');
|
||||||
|
@@ -2,26 +2,22 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
|||||||
import { OB11Message } from '@/onebot';
|
import { OB11Message } from '@/onebot';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { ChatType } from '@/core/types';
|
import { ChatType } from '@/core/types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
import { AdapterConfigWrap } from '@/onebot/config/config';
|
import { AdapterConfigWrap } from '@/onebot/config/config';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
messages: OB11Message[];
|
messages: OB11Message[];
|
||||||
}
|
}
|
||||||
|
const SchemaData = Type.Object({
|
||||||
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
message_seq: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
|
count: Type.Union([Type.Number(), Type.String()], { default: 20 }),
|
||||||
|
reverseOrder: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
||||||
|
});
|
||||||
|
|
||||||
const SchemaData = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
user_id: { type: ['number', 'string'] },
|
|
||||||
message_seq: { type: ['number', 'string'] },
|
|
||||||
count: { type: ['number', 'string'] },
|
|
||||||
reverseOrder: { type: ['boolean', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['user_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class GetFriendMsgHistory extends OneBotAction<Payload, Response> {
|
export default class GetFriendMsgHistory extends OneBotAction<Payload, Response> {
|
||||||
actionName = ActionName.GetFriendMsgHistory;
|
actionName = ActionName.GetFriendMsgHistory;
|
||||||
@@ -30,7 +26,7 @@ export default class GetFriendMsgHistory extends OneBotAction<Payload, Response>
|
|||||||
async _handle(payload: Payload, adapter: string): Promise<Response> {
|
async _handle(payload: Payload, adapter: string): Promise<Response> {
|
||||||
//处理参数
|
//处理参数
|
||||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
const MsgCount = +(payload.count ?? 20);
|
|
||||||
const isReverseOrder = typeof payload.reverseOrder === 'string' ? payload.reverseOrder === 'true' : !!payload.reverseOrder;
|
const isReverseOrder = typeof payload.reverseOrder === 'string' ? payload.reverseOrder === 'true' : !!payload.reverseOrder;
|
||||||
if (!uid) throw new Error(`记录${payload.user_id}不存在`);
|
if (!uid) throw new Error(`记录${payload.user_id}不存在`);
|
||||||
const friend = await this.core.apis.FriendApi.isBuddy(uid);
|
const friend = await this.core.apis.FriendApi.isBuddy(uid);
|
||||||
@@ -38,7 +34,7 @@ export default class GetFriendMsgHistory extends OneBotAction<Payload, Response>
|
|||||||
const hasMessageSeq = !payload.message_seq ? !!payload.message_seq : !(payload.message_seq?.toString() === '' || payload.message_seq?.toString() === '0');
|
const hasMessageSeq = !payload.message_seq ? !!payload.message_seq : !(payload.message_seq?.toString() === '' || payload.message_seq?.toString() === '0');
|
||||||
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
|
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
|
||||||
const msgList = hasMessageSeq ?
|
const msgList = hasMessageSeq ?
|
||||||
(await this.core.apis.MsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList : (await this.core.apis.MsgApi.getAioFirstViewLatestMsgs(peer, MsgCount)).msgList;
|
(await this.core.apis.MsgApi.getMsgHistory(peer, startMsgId, +payload.count)).msgList : (await this.core.apis.MsgApi.getAioFirstViewLatestMsgs(peer, +payload.count)).msgList;
|
||||||
if (msgList.length === 0) throw new Error(`消息${payload.message_seq}不存在`);
|
if (msgList.length === 0) throw new Error(`消息${payload.message_seq}不存在`);
|
||||||
//翻转消息
|
//翻转消息
|
||||||
if (isReverseOrder) msgList.reverse();
|
if (isReverseOrder) msgList.reverse();
|
||||||
|
@@ -1,15 +1,12 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()])
|
||||||
properties: {
|
});
|
||||||
group_id: { type: ['number', 'string'] }
|
|
||||||
},
|
type Payload = Static<typeof SchemaData>;
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GoCQHTTPGetGroupAtAllRemain extends OneBotAction<Payload, any> {
|
export class GoCQHTTPGetGroupAtAllRemain extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_GetGroupAtAllRemain;
|
actionName = ActionName.GoCQHTTP_GetGroupAtAllRemain;
|
||||||
|
@@ -1,16 +1,12 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()])
|
||||||
properties: {
|
});
|
||||||
group_id: { type: ['string', 'number'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetGroupFileSystemInfo extends OneBotAction<Payload, {
|
export class GetGroupFileSystemInfo extends OneBotAction<Payload, {
|
||||||
file_count: number,
|
file_count: number,
|
||||||
|
@@ -1,20 +1,17 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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 { OB11Construct } from '@/onebot/helper/data';
|
import { OB11Construct } from '@/onebot/helper/data';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
folder_id: Type.Optional(Type.String()),
|
||||||
group_id: { type: ['string', 'number'] },
|
folder: Type.Optional(Type.String()),
|
||||||
folder_id: { type: 'string' },
|
file_count: Type.Union([Type.Number(), Type.String()], { default: 50 }),
|
||||||
folder: { type: 'string' },
|
});
|
||||||
file_count: { type: ['string', 'number'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetGroupFilesByFolder extends OneBotAction<any, any> {
|
export class GetGroupFilesByFolder extends OneBotAction<any, any> {
|
||||||
actionName = ActionName.GoCQHTTP_GetGroupFilesByFolder;
|
actionName = ActionName.GoCQHTTP_GetGroupFilesByFolder;
|
||||||
@@ -23,7 +20,7 @@ export class GetGroupFilesByFolder extends OneBotAction<any, any> {
|
|||||||
|
|
||||||
const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
|
const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
|
||||||
sortType: 1,
|
sortType: 1,
|
||||||
fileCount: +(payload.file_count ?? 50),
|
fileCount: +payload.file_count,
|
||||||
startIndex: 0,
|
startIndex: 0,
|
||||||
sortOrder: 2,
|
sortOrder: 2,
|
||||||
showOnlinedocFolder: 0,
|
showOnlinedocFolder: 0,
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
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 { WebHonorType } from '@/core/types';
|
import { WebHonorType } from '@/core/types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
type: Type.Optional(Type.Enum(WebHonorType))
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
type: { enum: [WebHonorType.ALL, WebHonorType.EMOTION, WebHonorType.LEGEND, WebHonorType.PERFORMER, WebHonorType.STRONG_NEWBIE, WebHonorType.TALKATIVE] },
|
|
||||||
},
|
type Payload = Static<typeof SchemaData>;
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
// enum是不是有点抽象
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GetGroupHonorInfo extends OneBotAction<Payload, Array<any>> {
|
export class GetGroupHonorInfo extends OneBotAction<Payload, Array<any>> {
|
||||||
actionName = ActionName.GetGroupHonorInfo;
|
actionName = ActionName.GetGroupHonorInfo;
|
||||||
|
@@ -2,26 +2,24 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
|||||||
import { OB11Message } from '@/onebot';
|
import { OB11Message } from '@/onebot';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { ChatType, Peer } from '@/core/types';
|
import { ChatType, Peer } from '@/core/types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
import { AdapterConfigWrap } from '@/onebot/config/config';
|
import { AdapterConfigWrap } from '@/onebot/config/config';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
messages: OB11Message[];
|
messages: OB11Message[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
message_seq: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
group_id: { type: ['number', 'string'] },
|
count: Type.Union([Type.Number(), Type.String()], { default: 20 }),
|
||||||
message_seq: { type: ['number', 'string'] },
|
reverseOrder: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
||||||
count: { type: ['number', 'string'] },
|
});
|
||||||
reverseOrder: { type: ['boolean', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
type Payload = Static<typeof SchemaData>;
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export default class GoCQHTTPGetGroupMsgHistory extends OneBotAction<Payload, Response> {
|
export default class GoCQHTTPGetGroupMsgHistory extends OneBotAction<Payload, Response> {
|
||||||
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
||||||
@@ -30,13 +28,12 @@ export default class GoCQHTTPGetGroupMsgHistory extends OneBotAction<Payload, Re
|
|||||||
async _handle(payload: Payload, adapter: string): Promise<Response> {
|
async _handle(payload: Payload, adapter: string): Promise<Response> {
|
||||||
//处理参数
|
//处理参数
|
||||||
const isReverseOrder = typeof payload.reverseOrder === 'string' ? payload.reverseOrder === 'true' : !!payload.reverseOrder;
|
const isReverseOrder = typeof payload.reverseOrder === 'string' ? payload.reverseOrder === 'true' : !!payload.reverseOrder;
|
||||||
const MsgCount = +(payload.count ?? 20);
|
|
||||||
const peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
|
const peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
|
||||||
const hasMessageSeq = !payload.message_seq ? !!payload.message_seq : !(payload.message_seq?.toString() === '' || payload.message_seq?.toString() === '0');
|
const hasMessageSeq = !payload.message_seq ? !!payload.message_seq : !(payload.message_seq?.toString() === '' || payload.message_seq?.toString() === '0');
|
||||||
//拉取消息
|
//拉取消息
|
||||||
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
|
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
|
||||||
const msgList = hasMessageSeq ?
|
const msgList = hasMessageSeq ?
|
||||||
(await this.core.apis.MsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList : (await this.core.apis.MsgApi.getAioFirstViewLatestMsgs(peer, MsgCount)).msgList;
|
(await this.core.apis.MsgApi.getMsgHistory(peer, startMsgId, +payload.count)).msgList : (await this.core.apis.MsgApi.getAioFirstViewLatestMsgs(peer, +payload.count)).msgList;
|
||||||
if (msgList.length === 0) throw new Error(`消息${payload.message_seq}不存在`);
|
if (msgList.length === 0) throw new Error(`消息${payload.message_seq}不存在`);
|
||||||
//翻转消息
|
//翻转消息
|
||||||
if (isReverseOrder) msgList.reverse();
|
if (isReverseOrder) msgList.reverse();
|
||||||
|
@@ -1,19 +1,16 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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 { OB11GroupFile, OB11GroupFileFolder } from '@/onebot';
|
import { OB11GroupFile, OB11GroupFileFolder } from '@/onebot';
|
||||||
import { OB11Construct } from '@/onebot/helper/data';
|
import { OB11Construct } from '@/onebot/helper/data';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
file_count: Type.Union([Type.Number(), Type.String()], { default: 50 }),
|
||||||
group_id: { type: ['string', 'number'] },
|
});
|
||||||
file_count: { type: ['string', 'number'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetGroupRootFiles extends OneBotAction<Payload, {
|
export class GetGroupRootFiles extends OneBotAction<Payload, {
|
||||||
files: OB11GroupFile[],
|
files: OB11GroupFile[],
|
||||||
@@ -24,7 +21,7 @@ export class GetGroupRootFiles extends OneBotAction<Payload, {
|
|||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
|
const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
|
||||||
sortType: 1,
|
sortType: 1,
|
||||||
fileCount: +(payload.file_count ?? 50),
|
fileCount: +payload.file_count,
|
||||||
startIndex: 0,
|
startIndex: 0,
|
||||||
sortOrder: 2,
|
sortOrder: 2,
|
||||||
showOnlinedocFolder: 0,
|
showOnlinedocFolder: 0,
|
||||||
|
@@ -1,15 +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 { JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { sleep } from '@/common/helper';
|
import { sleep } from '@/common/helper';
|
||||||
|
|
||||||
const SchemaData = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
no_cache: { type: 'boolean' },
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
export class GetOnlineClient extends OneBotAction<void, Array<any>> {
|
export class GetOnlineClient extends OneBotAction<void, Array<any>> {
|
||||||
actionName = ActionName.GetOnlineClient;
|
actionName = ActionName.GetOnlineClient;
|
||||||
|
|
||||||
|
@@ -2,18 +2,14 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
|||||||
import { OB11User, OB11UserSex } from '@/onebot';
|
import { OB11User, OB11UserSex } from '@/onebot';
|
||||||
import { OB11Construct } from '@/onebot/helper/data';
|
import { OB11Construct } from '@/onebot/helper/data';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { calcQQLevel } from '@/common/helper';
|
import { calcQQLevel } from '@/common/helper';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
user_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['user_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
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;
|
||||||
|
@@ -1,15 +1,12 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
url: Type.String(),
|
||||||
properties: {
|
});
|
||||||
url: { type: 'string' },
|
|
||||||
},
|
type Payload = Static<typeof SchemaData>;
|
||||||
required: ['url'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GoCQHTTPCheckUrlSafely extends OneBotAction<Payload, any> {
|
export class GoCQHTTPCheckUrlSafely extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_CheckUrlSafely;
|
actionName = ActionName.GoCQHTTP_CheckUrlSafely;
|
||||||
|
@@ -1,22 +1,15 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
friend_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
|
||||||
properties: {
|
user_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
|
||||||
friend_id: { type: ['string', 'number'] },
|
temp_block: Type.Optional(Type.Boolean()),
|
||||||
user_id: { type: ['string', 'number'] },
|
temp_both_del: Type.Optional(Type.Boolean()),
|
||||||
temp_block: { type: 'boolean' },
|
});
|
||||||
temp_both_del: { type: 'boolean' },
|
|
||||||
},
|
|
||||||
oneOf: [
|
|
||||||
{ required: ['friend_id'] },
|
|
||||||
{ required: ['user_id'] },
|
|
||||||
],
|
|
||||||
|
|
||||||
} as const satisfies JSONSchema;
|
type Payload = Static<typeof SchemaData>;
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GoCQHTTPDeleteFriend extends OneBotAction<Payload, any> {
|
export class GoCQHTTPDeleteFriend extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_DeleteFriend;
|
actionName = ActionName.GoCQHTTP_DeleteFriend;
|
||||||
|
@@ -1,14 +1,12 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
model: Type.String(),
|
||||||
properties: {
|
});
|
||||||
model: { type: 'string' },
|
|
||||||
}
|
type Payload = Static<typeof SchemaData>;
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GoCQHTTPGetModelShow extends OneBotAction<Payload, any> {
|
export class GoCQHTTPGetModelShow extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_GetModelShow;
|
actionName = ActionName.GoCQHTTP_GetModelShow;
|
||||||
|
@@ -1,19 +1,10 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
|
|
||||||
const SchemaData = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
//兼容性代码
|
//兼容性代码
|
||||||
export class GoCQHTTPSetModelShow extends OneBotAction<Payload, any> {
|
export class GoCQHTTPSetModelShow extends OneBotAction<void, any> {
|
||||||
actionName = ActionName.GoCQHTTP_SetModelShow;
|
actionName = ActionName.GoCQHTTP_SetModelShow;
|
||||||
payloadSchema = SchemaData;
|
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: void) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,24 +2,20 @@ import { checkFileExist, uri2local } from '@/common/file';
|
|||||||
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 { unlink } from 'node:fs';
|
import { unlink } from 'node:fs';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
content: Type.String(),
|
||||||
group_id: { type: ['number', 'string'] },
|
image: Type.Optional(Type.String()),
|
||||||
content: { type: 'string' },
|
pinned: Type.Union([Type.Number(), Type.String()], { default: 0 }),
|
||||||
image: { type: 'string' },
|
type: Type.Union([Type.Number(), Type.String()], { default: 1 }),
|
||||||
pinned: { type: ['number', 'string'] },
|
confirm_required: Type.Union([Type.Number(), Type.String()], { default: 1 }),
|
||||||
type: { type: ['number', 'string'] },
|
is_show_edit_card: Type.Union([Type.Number(), Type.String()], { default: 0 }),
|
||||||
confirm_required: { type: ['number', 'string'] },
|
tip_window_type: Type.Union([Type.Number(), Type.String()], { default: 0 })
|
||||||
is_show_edit_card: { type: ['number', 'string'] },
|
});
|
||||||
tip_window_type: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'content'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SendGroupNotice extends OneBotAction<Payload, null> {
|
export class SendGroupNotice extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.GoCQHTTP_SendGroupNotice;
|
actionName = ActionName.GoCQHTTP_SendGroupNotice;
|
||||||
@@ -50,21 +46,14 @@ export class SendGroupNotice extends OneBotAction<Payload, null> {
|
|||||||
|
|
||||||
UploadImage = ImageUploadResult.picInfo;
|
UploadImage = ImageUploadResult.picInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
const noticeType = +(payload.type ?? 1);
|
|
||||||
const noticePinned = +(payload.pinned ?? 0);
|
|
||||||
|
|
||||||
const noticeShowEditCard = +(payload.is_show_edit_card ?? 0);
|
|
||||||
const noticeTipWindowType = +(payload.tip_window_type ?? 0);
|
|
||||||
const noticeConfirmRequired = +(payload.confirm_required ?? 1);
|
|
||||||
const publishGroupBulletinResult = await this.core.apis.WebApi.setGroupNotice(
|
const publishGroupBulletinResult = await this.core.apis.WebApi.setGroupNotice(
|
||||||
payload.group_id.toString(),
|
payload.group_id.toString(),
|
||||||
payload.content,
|
payload.content,
|
||||||
noticePinned,
|
+payload.pinned,
|
||||||
noticeType,
|
+payload.type,
|
||||||
noticeShowEditCard,
|
+payload.is_show_edit_card,
|
||||||
noticeTipWindowType,
|
+payload.tip_window_type,
|
||||||
noticeConfirmRequired,
|
+payload.confirm_required,
|
||||||
UploadImage?.id,
|
UploadImage?.id,
|
||||||
UploadImage?.width,
|
UploadImage?.width,
|
||||||
UploadImage?.height
|
UploadImage?.height
|
||||||
|
@@ -2,28 +2,19 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
|||||||
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import { checkFileExistV2, uri2local } from '@/common/file';
|
import { checkFileExistV2, uri2local } from '@/common/file';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
interface Payload {
|
const SchemaData = Type.Object({
|
||||||
file: string,
|
file: Type.String(),
|
||||||
group_id: number
|
group_id: Type.Union([Type.Number(), Type.String()])
|
||||||
}
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetGroupPortrait extends OneBotAction<Payload, any> {
|
export default class SetGroupPortrait extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.SetGroupPortrait;
|
actionName = ActionName.SetGroupPortrait;
|
||||||
|
payloadSchema = SchemaData;
|
||||||
// 用不着复杂检测
|
|
||||||
protected async check(payload: Payload): Promise<BaseCheckResult> {
|
|
||||||
if (!payload.file || typeof payload.file != 'string' || !payload.group_id || typeof payload.group_id != 'number') {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
message: 'file和group_id字段不能为空或者类型错误',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
valid: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<any> {
|
async _handle(payload: Payload): Promise<any> {
|
||||||
const { path, success } = (await uri2local(this.core.NapCatTempPath, payload.file));
|
const { path, success } = (await uri2local(this.core.NapCatTempPath, payload.file));
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
nickname: Type.String(),
|
||||||
properties: {
|
personal_note: Type.Optional(Type.String()),
|
||||||
nickname: { type: 'string' },
|
sex: Type.Optional(Type.Union([Type.Number(), Type.String()])), // 传Sex值?建议传0
|
||||||
personal_note: { type: 'string' },
|
});
|
||||||
sex: { type: ['number', 'string'] },//传Sex值?建议传0
|
|
||||||
},
|
|
||||||
required: ['nickname'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SetQQProfile extends OneBotAction<Payload, any> {
|
export class SetQQProfile extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.SetQQProfile;
|
actionName = ActionName.SetQQProfile;
|
||||||
|
@@ -3,22 +3,18 @@ import { ActionName } from '@/onebot/action/router';
|
|||||||
import { ChatType, Peer } from '@/core/types';
|
import { ChatType, Peer } from '@/core/types';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { uri2local } from '@/common/file';
|
import { uri2local } from '@/common/file';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { SendMessageContext } from '@/onebot/api';
|
||||||
import { MessageContext } from '@/onebot/api';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
file: Type.String(),
|
||||||
group_id: { type: ['number', 'string'] },
|
name: Type.String(),
|
||||||
file: { type: 'string' },
|
folder: Type.Optional(Type.String()),
|
||||||
name: { type: 'string' },
|
folder_id: Type.Optional(Type.String()),//临时扩展
|
||||||
folder: { type: 'string' },
|
});
|
||||||
folder_id: { type: 'string' },//临时扩展
|
|
||||||
},
|
|
||||||
required: ['group_id', 'file', 'name'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class GoCQHTTPUploadGroupFile extends OneBotAction<Payload, null> {
|
export default class GoCQHTTPUploadGroupFile extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
||||||
@@ -37,7 +33,7 @@ export default class GoCQHTTPUploadGroupFile extends OneBotAction<Payload, null>
|
|||||||
if (!downloadResult.success) {
|
if (!downloadResult.success) {
|
||||||
throw new Error(downloadResult.errMsg);
|
throw new Error(downloadResult.errMsg);
|
||||||
}
|
}
|
||||||
const msgContext: MessageContext = {
|
const msgContext: SendMessageContext = {
|
||||||
peer: peer,
|
peer: peer,
|
||||||
deleteAfterSentFiles: []
|
deleteAfterSentFiles: []
|
||||||
};
|
};
|
||||||
|
@@ -3,21 +3,17 @@ import { ActionName } from '@/onebot/action/router';
|
|||||||
import { ChatType, Peer, SendFileElement } from '@/core/types';
|
import { ChatType, Peer, SendFileElement } from '@/core/types';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { uri2local } from '@/common/file';
|
import { uri2local } from '@/common/file';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { SendMessageContext } from '@/onebot/api';
|
||||||
import { MessageContext } from '@/onebot/api';
|
|
||||||
import { ContextMode, createContext } from '@/onebot/action/msg/SendMsg';
|
import { ContextMode, createContext } from '@/onebot/action/msg/SendMsg';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
file: Type.String(),
|
||||||
user_id: { type: ['number', 'string'] },
|
name: Type.String(),
|
||||||
file: { type: 'string' },
|
});
|
||||||
name: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['user_id', 'file', 'name'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class GoCQHTTPUploadPrivateFile extends OneBotAction<Payload, null> {
|
export default class GoCQHTTPUploadPrivateFile extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.GOCQHTTP_UploadPrivateFile;
|
actionName = ActionName.GOCQHTTP_UploadPrivateFile;
|
||||||
@@ -45,7 +41,7 @@ export default class GoCQHTTPUploadPrivateFile extends OneBotAction<Payload, nul
|
|||||||
throw new Error(downloadResult.errMsg);
|
throw new Error(downloadResult.errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const msgContext: MessageContext = {
|
const msgContext: SendMessageContext = {
|
||||||
peer: await createContext(this.core, {
|
peer: await createContext(this.core, {
|
||||||
user_id: payload.user_id.toString(),
|
user_id: payload.user_id.toString(),
|
||||||
group_id: undefined,
|
group_id: undefined,
|
||||||
|
@@ -1,17 +1,13 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
message_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['message_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class DelEssenceMsg extends OneBotAction<Payload, any> {
|
export default class DelEssenceMsg extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.DelEssenceMsg;
|
actionName = ActionName.DelEssenceMsg;
|
||||||
|
@@ -1,18 +1,13 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
|
const SchemaData = Type.Object({
|
||||||
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
notice_id: Type.String()
|
||||||
|
});
|
||||||
|
|
||||||
const SchemaData = {
|
type Payload = Static<typeof SchemaData>;
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
group_id: { type: ['number', 'string'] },
|
|
||||||
notice_id: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'notice_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class DelGroupNotice extends OneBotAction<Payload, any> {
|
export class DelGroupNotice extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.DelGroupNotice;
|
actionName = ActionName.DelGroupNotice;
|
||||||
|
@@ -1,19 +1,15 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
import { AIVoiceChatType } from "@/core/packet/entities/aiChat";
|
import { AIVoiceChatType } from "@/core/packet/entities/aiChat";
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
character: Type.String(),
|
||||||
properties: {
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
character: { type: ['string'] },
|
text: Type.String(),
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
text: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['character', 'group_id', 'text'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetAiRecord extends GetPacketStatusDepends<Payload, string> {
|
export class GetAiRecord extends GetPacketStatusDepends<Payload, string> {
|
||||||
actionName = ActionName.GetAiRecord;
|
actionName = ActionName.GetAiRecord;
|
||||||
|
@@ -1,20 +1,16 @@
|
|||||||
import { ChatType, Peer } from '@/core';
|
import { ChatType, Peer } from '@/core';
|
||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import { AdapterConfigWrap } from '@/onebot/config/config';
|
import { AdapterConfigWrap } from '@/onebot/config/config';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
group_id: { type: ['number', 'string'] }
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetGroupEssence extends OneBotAction<Payload, any> {
|
export class GetGroupEssence extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
||||||
|
@@ -1,17 +1,6 @@
|
|||||||
import { GroupNotifyMsgStatus } from '@/core';
|
import { GroupNotifyMsgStatus } from '@/core';
|
||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
|
|
||||||
const SchemaData = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
group_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GetGroupIgnoredNotifies extends OneBotAction<void, any> {
|
export class GetGroupIgnoredNotifies extends OneBotAction<void, any> {
|
||||||
actionName = ActionName.GetGroupIgnoredNotifies;
|
actionName = ActionName.GetGroupIgnoredNotifies;
|
||||||
|
|
||||||
|
@@ -2,17 +2,13 @@ import { OB11Group } from '@/onebot';
|
|||||||
import { OB11Construct } from '@/onebot/helper/data';
|
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
group_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
class GetGroupInfo extends OneBotAction<Payload, OB11Group> {
|
class GetGroupInfo extends OneBotAction<Payload, OB11Group> {
|
||||||
actionName = ActionName.GetGroupInfo;
|
actionName = ActionName.GetGroupInfo;
|
||||||
|
@@ -2,16 +2,13 @@ import { OB11Group } from '@/onebot';
|
|||||||
import { OB11Construct } from '@/onebot/helper/data';
|
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
// no_cache get时传字符串
|
|
||||||
const SchemaData = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
no_cache: { type: ['boolean', 'string'] },
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
const SchemaData = Type.Object({
|
||||||
|
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
class GetGroupList extends OneBotAction<Payload, OB11Group[]> {
|
class GetGroupList extends OneBotAction<Payload, OB11Group[]> {
|
||||||
actionName = ActionName.GetGroupList;
|
actionName = ActionName.GetGroupList;
|
||||||
|
@@ -2,19 +2,15 @@ import { OB11GroupMember } from '@/onebot';
|
|||||||
import { OB11Construct } from '@/onebot/helper/data';
|
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
group_id: { type: ['number', 'string'] },
|
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||||
user_id: { type: ['number', 'string'] },
|
});
|
||||||
no_cache: { type: ['boolean', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'user_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
class GetGroupMemberInfo extends OneBotAction<Payload, OB11GroupMember> {
|
class GetGroupMemberInfo extends OneBotAction<Payload, OB11GroupMember> {
|
||||||
actionName = ActionName.GetGroupMemberInfo;
|
actionName = ActionName.GetGroupMemberInfo;
|
||||||
|
@@ -2,18 +2,14 @@ import { OB11GroupMember } from '@/onebot';
|
|||||||
import { OB11Construct } from '@/onebot/helper/data';
|
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
no_cache: { type: ['boolean', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetGroupMemberList extends OneBotAction<Payload, OB11GroupMember[]> {
|
export class GetGroupMemberList extends OneBotAction<Payload, OB11GroupMember[]> {
|
||||||
actionName = ActionName.GetGroupMemberList;
|
actionName = ActionName.GetGroupMemberList;
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
import { WebApiGroupNoticeFeed } from '@/core';
|
import { WebApiGroupNoticeFeed } from '@/core';
|
||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
interface GroupNotice {
|
interface GroupNotice {
|
||||||
sender_id: number;
|
sender_id: number;
|
||||||
publish_time: number;
|
publish_time: number;
|
||||||
@@ -17,15 +16,11 @@ interface GroupNotice {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
group_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed;
|
type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed;
|
||||||
|
|
||||||
|
@@ -1,16 +1,12 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
group_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetGroupShutList extends OneBotAction<Payload, any> {
|
export class GetGroupShutList extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GetGroupShutList;
|
actionName = ActionName.GetGroupShutList;
|
||||||
|
@@ -1,17 +1,13 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
// no_cache get时传字符串
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
const SchemaData = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
group_id: { type: ['number', 'string'] },
|
|
||||||
user_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'user_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
const SchemaData = Type.Object({
|
||||||
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GroupPoke extends GetPacketStatusDepends<Payload, any> {
|
export class GroupPoke extends GetPacketStatusDepends<Payload, any> {
|
||||||
actionName = ActionName.GroupPoke;
|
actionName = ActionName.GroupPoke;
|
||||||
|
@@ -1,21 +1,18 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
import { uri2local } from "@/common/file";
|
import { uri2local } from "@/common/file";
|
||||||
import { ChatType, Peer } from "@/core";
|
import { ChatType, Peer } from "@/core";
|
||||||
import { AIVoiceChatType } from "@/core/packet/entities/aiChat";
|
import { AIVoiceChatType } from "@/core/packet/entities/aiChat";
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
character: Type.String(),
|
||||||
properties: {
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
character: { type: ['string'] },
|
text: Type.String(),
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
text: { type: 'string' },
|
|
||||||
},
|
type Payload = Static<typeof SchemaData>;
|
||||||
required: ['character', 'group_id', 'text'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class SendGroupAiRecord extends GetPacketStatusDepends<Payload, {
|
export class SendGroupAiRecord extends GetPacketStatusDepends<Payload, {
|
||||||
message_id: number
|
message_id: number
|
||||||
|
@@ -1,24 +1,20 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
message_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['message_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetEssenceMsg extends OneBotAction<Payload, any> {
|
export default class SetEssenceMsg extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.SetEssenceMsg;
|
actionName = ActionName.SetEssenceMsg;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<any> {
|
async _handle(payload: Payload): Promise<any> {
|
||||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
throw new Error('msg not found');
|
throw new Error('msg not found');
|
||||||
}
|
}
|
||||||
|
@@ -1,19 +1,15 @@
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { NTGroupRequestOperateTypes } from '@/core/types';
|
import { NTGroupRequestOperateTypes } from '@/core/types';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
flag: Type.String(),
|
||||||
properties: {
|
approve: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||||
flag: { type: 'string' },
|
reason: Type.Union([Type.String({ default: ' ' }), Type.Null()]),
|
||||||
approve: { type: ['string', 'boolean'] },
|
});
|
||||||
reason: { type: 'string', nullable: true },
|
|
||||||
},
|
|
||||||
required: ['flag'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetGroupAddRequest extends OneBotAction<Payload, null> {
|
export default class SetGroupAddRequest extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupAddRequest;
|
actionName = ActionName.SetGroupAddRequest;
|
||||||
|
@@ -1,19 +1,15 @@
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { NTGroupMemberRole } from '@/core/types';
|
import { NTGroupMemberRole } from '@/core/types';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
group_id: { type: ['number', 'string'] },
|
enable: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||||
user_id: { type: ['number', 'string'] },
|
});
|
||||||
enable: { type: ['boolean', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'user_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetGroupAdmin extends OneBotAction<Payload, null> {
|
export default class SetGroupAdmin extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupAdmin;
|
actionName = ActionName.SetGroupAdmin;
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
group_id: { type: ['number', 'string'] },
|
duration: Type.Union([Type.Number(), Type.String()], { default: 0 }),
|
||||||
user_id: { type: ['number', 'string'] },
|
});
|
||||||
duration: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'user_id', 'duration'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetGroupBan extends OneBotAction<Payload, null> {
|
export default class SetGroupBan extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupBan;
|
actionName = ActionName.SetGroupBan;
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
group_id: { type: ['number', 'string'] },
|
card: Type.Optional(Type.String())
|
||||||
user_id: { type: ['number', 'string'] },
|
});
|
||||||
card: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'user_id', 'card'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetGroupCard extends OneBotAction<Payload, null> {
|
export default class SetGroupCard extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupCard;
|
actionName = ActionName.SetGroupCard;
|
||||||
|
@@ -1,19 +1,14 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
|
const SchemaData = Type.Object({
|
||||||
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
reject_add_request: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||||
|
});
|
||||||
|
|
||||||
const SchemaData = {
|
type Payload = Static<typeof SchemaData>;
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
group_id: { type: ['number', 'string'] },
|
|
||||||
user_id: { type: ['number', 'string'] },
|
|
||||||
reject_add_request: { type: ['boolean', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id', 'user_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export default class SetGroupKick extends OneBotAction<Payload, null> {
|
export default class SetGroupKick extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupKick;
|
actionName = ActionName.SetGroupKick;
|
||||||
|
@@ -1,17 +1,14 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
is_dismiss: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
is_dismiss: { type: ['boolean', 'string'] },
|
|
||||||
},
|
type Payload = Static<typeof SchemaData>;
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
export default class SetGroupLeave extends OneBotAction<Payload, any> {
|
export default class SetGroupLeave extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.SetGroupLeave;
|
actionName = ActionName.SetGroupLeave;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
@@ -1,23 +1,24 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
group_name: Type.String(),
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
group_name: { type: 'string' },
|
|
||||||
},
|
type Payload = Static<typeof SchemaData>;
|
||||||
required: ['group_id', 'group_name'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
export default class SetGroupName extends OneBotAction<Payload, null> {
|
export default class SetGroupName extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupName;
|
actionName = ActionName.SetGroupName;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
await this.core.apis.GroupApi.setGroupName(payload.group_id.toString(), payload.group_name);
|
const ret = await this.core.apis.GroupApi.setGroupName(payload.group_id.toString(), payload.group_name);
|
||||||
|
if (ret.result !== 0) {
|
||||||
|
throw new Error(`设置群名称失败 ErrCode: ${ret.result} ErrMsg: ${ret.errMsg}`);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,13 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
enable: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
enable: { type: ['boolean', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['group_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetGroupWholeBan extends OneBotAction<Payload, null> {
|
export default class SetGroupWholeBan extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupWholeBan;
|
actionName = ActionName.SetGroupWholeBan;
|
||||||
|
@@ -1,22 +1,13 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
message_id: {
|
|
||||||
oneOf: [
|
|
||||||
{ type: 'number' },
|
|
||||||
{ type: 'string' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
required: ['message_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
class DeleteMsg extends OneBotAction<Payload, void> {
|
class DeleteMsg extends OneBotAction<Payload, void> {
|
||||||
actionName = ActionName.DeleteMsg;
|
actionName = ActionName.DeleteMsg;
|
||||||
|
@@ -1,20 +1,16 @@
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ChatType, Peer } from '@/core/types';
|
import { ChatType, Peer } from '@/core/types';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
message_id: { type: ['number', 'string'] },
|
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
user_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['message_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
class ForwardSingleMsg extends OneBotAction<Payload, null> {
|
class ForwardSingleMsg extends OneBotAction<Payload, null> {
|
||||||
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
||||||
|
@@ -1,23 +1,18 @@
|
|||||||
import { OB11Message } from '@/onebot';
|
import { OB11Message } from '@/onebot';
|
||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
import { RawMessage } from '@/core';
|
import { RawMessage } from '@/core';
|
||||||
import { AdapterConfigWrap } from '@/onebot/config/config';
|
import { AdapterConfigWrap } from '@/onebot/config/config';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
export type ReturnDataType = OB11Message
|
export type ReturnDataType = OB11Message
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
});
|
||||||
message_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['message_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
class GetMsg extends OneBotAction<Payload, OB11Message> {
|
class GetMsg extends OneBotAction<Payload, OB11Message> {
|
||||||
actionName = ActionName.GetMsg;
|
actionName = ActionName.GetMsg;
|
||||||
|
@@ -1,19 +1,16 @@
|
|||||||
import { ChatType, Peer } from '@/core/types';
|
import { ChatType, Peer } from '@/core/types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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 { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
user_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
|
||||||
properties: {
|
group_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
|
||||||
user_id: { type: ['number', 'string'] },
|
message_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
|
||||||
group_id: { type: ['number', 'string'] },
|
});
|
||||||
message_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type PlayloadType = FromSchema<typeof SchemaData>;
|
type PlayloadType = Static<typeof SchemaData>;
|
||||||
|
|
||||||
class MarkMsgAsRead extends OneBotAction<PlayloadType, null> {
|
class MarkMsgAsRead extends OneBotAction<PlayloadType, null> {
|
||||||
async getPeer(payload: PlayloadType): Promise<Peer> {
|
async getPeer(payload: PlayloadType): Promise<Peer> {
|
||||||
|
@@ -1,19 +1,15 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
properties: {
|
emoji_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
message_id: { type: ['string', 'number'] },
|
set: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
||||||
emoji_id: { type: ['string', 'number'] },
|
});
|
||||||
set: { type: ['boolean', 'string'] }
|
|
||||||
},
|
|
||||||
required: ['message_id', 'emoji_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SetMsgEmojiLike extends OneBotAction<Payload, any> {
|
export class SetMsgEmojiLike extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.SetMsgEmojiLike;
|
actionName = ActionName.SetMsgEmojiLike;
|
||||||
|
@@ -1,21 +1,18 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
cookies: string,
|
cookies: string,
|
||||||
token: number
|
token: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
domain: Type.String()
|
||||||
properties: {
|
});
|
||||||
domain: { type: 'string' },
|
|
||||||
},
|
type Payload = Static<typeof SchemaData>;
|
||||||
required: ['domain'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GetCredentials extends OneBotAction<Payload, Response> {
|
export class GetCredentials extends OneBotAction<Payload, Response> {
|
||||||
actionName = ActionName.GetCredentials;
|
actionName = ActionName.GetCredentials;
|
||||||
|
@@ -1,21 +1,10 @@
|
|||||||
import { GroupNotifyMsgStatus } from '@/core';
|
import { GroupNotifyMsgStatus } from '@/core';
|
||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
|
|
||||||
const SchemaData = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
group_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GetGroupSystemMsg extends OneBotAction<void, any> {
|
export class GetGroupSystemMsg extends OneBotAction<void, any> {
|
||||||
actionName = ActionName.GetGroupSystemMsg;
|
actionName = ActionName.GetGroupSystemMsg;
|
||||||
|
|
||||||
async _handle(payload: void) {
|
async _handle() {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
const NTQQUserApi = this.core.apis.UserApi;
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||||
// 默认10条 该api未完整实现 包括响应数据规范化 类型规范化
|
// 默认10条 该api未完整实现 包括响应数据规范化 类型规范化
|
||||||
|
@@ -1,16 +1,12 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
user_id: Type.Union([Type.Number(), Type.String()])
|
||||||
properties: {
|
});
|
||||||
user_id: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['user_id'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class FriendPoke extends GetPacketStatusDepends<Payload, any> {
|
export class FriendPoke extends GetPacketStatusDepends<Payload, any> {
|
||||||
actionName = ActionName.FriendPoke;
|
actionName = ActionName.FriendPoke;
|
||||||
|
@@ -1,21 +1,16 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
cookies: string,
|
cookies: string,
|
||||||
bkn: string
|
bkn: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
domain: Type.String()
|
||||||
properties: {
|
});
|
||||||
domain: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['domain'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class GetCookies extends OneBotAction<Payload, Response> {
|
export class GetCookies extends OneBotAction<Payload, Response> {
|
||||||
actionName = ActionName.GetCookies;
|
actionName = ActionName.GetCookies;
|
||||||
|
@@ -2,17 +2,14 @@ import { OB11User } from '@/onebot';
|
|||||||
import { OB11Construct } from '@/onebot/helper/data';
|
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
// no_cache get时传字符串
|
const SchemaData = Type.Object({
|
||||||
const SchemaData = {
|
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||||
type: 'object',
|
});
|
||||||
properties: {
|
|
||||||
no_cache: { type: ['boolean', 'string'] },
|
type Payload = Static<typeof SchemaData>;
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
export default class GetFriendList extends OneBotAction<Payload, OB11User[]> {
|
export default class GetFriendList extends OneBotAction<Payload, OB11User[]> {
|
||||||
actionName = ActionName.GetFriendList;
|
actionName = ActionName.GetFriendList;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
@@ -1,23 +1,21 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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 { AdapterConfigWrap } from '@/onebot/config/config';
|
import { AdapterConfigWrap } from '@/onebot/config/config';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
count: Type.Union([Type.Number(), Type.String()], { default: 10 }),
|
||||||
properties: {
|
});
|
||||||
count: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class GetRecentContact extends OneBotAction<Payload, any> {
|
export default class GetRecentContact extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.GetRecentContact;
|
actionName = ActionName.GetRecentContact;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload, adapter: string) {
|
async _handle(payload: Payload, adapter: string) {
|
||||||
const ret = await this.core.apis.UserApi.getRecentContactListSnapShot(+(payload.count || 10));
|
const ret = await this.core.apis.UserApi.getRecentContactListSnapShot(+payload.count);
|
||||||
const network = Object.values(this.obContext.configLoader.configData.network) as Array<AdapterConfigWrap>;
|
const network = Object.values(this.obContext.configLoader.configData.network) as Array<AdapterConfigWrap>;
|
||||||
//烘焙消息
|
//烘焙消息
|
||||||
const msgFormat = network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array';
|
const msgFormat = network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array';
|
||||||
|
@@ -1,17 +1,13 @@
|
|||||||
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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
times: Type.Union([Type.Number(), Type.String()], { default: 1 }),
|
||||||
properties: {
|
user_id: Type.Union([Type.Number(), Type.String()])
|
||||||
user_id: { type: ['number', 'string'] },
|
});
|
||||||
times: { type: ['number', 'string'] },
|
|
||||||
},
|
|
||||||
required: ['user_id', 'times'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SendLike extends OneBotAction<Payload, null> {
|
export default class SendLike extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SendLike;
|
actionName = ActionName.SendLike;
|
||||||
@@ -20,7 +16,7 @@ export default class SendLike extends OneBotAction<Payload, null> {
|
|||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const qq = payload.user_id.toString();
|
const qq = payload.user_id.toString();
|
||||||
const uid: string = await this.core.apis.UserApi.getUidByUinV2(qq) ?? '';
|
const uid: string = await this.core.apis.UserApi.getUidByUinV2(qq) ?? '';
|
||||||
const result = await this.core.apis.UserApi.like(uid, parseInt(payload.times?.toString()) || 1);
|
const result = await this.core.apis.UserApi.like(uid, +payload.times);
|
||||||
if (result.result !== 0) {
|
if (result.result !== 0) {
|
||||||
throw new Error(`点赞失败 ${result.errMsg}`);
|
throw new Error(`点赞失败 ${result.errMsg}`);
|
||||||
}
|
}
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
||||||
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';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = Type.Object({
|
||||||
type: 'object',
|
flag: Type.String(),
|
||||||
properties: {
|
approve: Type.Optional(Type.Union([Type.String(), Type.Boolean()])),
|
||||||
flag: { type: 'string' },
|
remark: Type.Optional(Type.String())
|
||||||
approve: { type: ['string', 'boolean'] },
|
});
|
||||||
remark: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['flag'],
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetFriendAddRequest extends OneBotAction<Payload, null> {
|
export default class SetFriendAddRequest extends OneBotAction<Payload, null> {
|
||||||
actionName = ActionName.SetFriendAddRequest;
|
actionName = ActionName.SetFriendAddRequest;
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import { OneBotFriendApi } from '@/onebot/api/friend';
|
import type { OneBotFriendApi } from '@/onebot/api/friend';
|
||||||
import { OneBotUserApi } from '@/onebot/api/user';
|
import type { OneBotUserApi } from '@/onebot/api/user';
|
||||||
import { OneBotGroupApi } from '@/onebot/api/group';
|
import type { OneBotGroupApi } from '@/onebot/api/group';
|
||||||
import { OneBotMsgApi } from '@/onebot/api/msg';
|
import type { OneBotMsgApi } from '@/onebot/api/msg';
|
||||||
import { OneBotQuickActionApi } from '@/onebot/api/quick-action';
|
import type { OneBotQuickActionApi } from '@/onebot/api/quick-action';
|
||||||
|
|
||||||
export * from './friend';
|
export * from './friend';
|
||||||
export * from './group';
|
export * from './group';
|
||||||
|
@@ -118,7 +118,6 @@ export class OneBotMsgApi {
|
|||||||
return {
|
return {
|
||||||
type: OB11MessageDataType.image,
|
type: OB11MessageDataType.image,
|
||||||
data: {
|
data: {
|
||||||
pic_type: element.picType,
|
|
||||||
summary: element.summary,
|
summary: element.summary,
|
||||||
file: encodedFileId,
|
file: encodedFileId,
|
||||||
sub_type: element.picSubType,
|
sub_type: element.picSubType,
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import {
|
import type {
|
||||||
NapCatOneBot11Adapter,
|
NapCatOneBot11Adapter,
|
||||||
OB11Message,
|
OB11Message,
|
||||||
OB11MessageAt,
|
OB11MessageAt,
|
||||||
@@ -10,17 +10,19 @@ import {
|
|||||||
QuickActionGroupMessage,
|
QuickActionGroupMessage,
|
||||||
QuickActionGroupRequest,
|
QuickActionGroupRequest,
|
||||||
} from '@/onebot';
|
} from '@/onebot';
|
||||||
import { NTGroupRequestOperateTypes, NapCatCore, Peer } from '@/core';
|
import { NTGroupRequestOperateTypes, type NapCatCore, type Peer } from '@/core';
|
||||||
import { OB11FriendRequestEvent } from '@/onebot/event/request/OB11FriendRequest';
|
import type { OB11FriendRequestEvent } from '@/onebot/event/request/OB11FriendRequest';
|
||||||
import { OB11GroupRequestEvent } from '@/onebot/event/request/OB11GroupRequest';
|
import type { OB11GroupRequestEvent } from '@/onebot/event/request/OB11GroupRequest';
|
||||||
|
|
||||||
import { ContextMode, createContext, normalize } from '@/onebot/action/msg/SendMsg';
|
import { ContextMode, createContext, normalize } from '@/onebot/action/msg/SendMsg';
|
||||||
import { isNull } from '@/common/helper';
|
import { isNull } from '@/common/helper';
|
||||||
|
|
||||||
export class OneBotQuickActionApi {
|
export class OneBotQuickActionApi {
|
||||||
constructor(
|
private obContext: NapCatOneBot11Adapter;
|
||||||
public obContext: NapCatOneBot11Adapter,
|
private core: NapCatCore;
|
||||||
public core: NapCatCore,
|
constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
||||||
) {
|
this.obContext = obContext;
|
||||||
|
this.core = core;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleQuickOperation(eventContext: QuickActionEvent, quickAction: QuickAction) {
|
async handleQuickOperation(eventContext: QuickActionEvent, quickAction: QuickAction) {
|
||||||
|
@@ -172,6 +172,7 @@ export function migrateOneBotConfigsV1(config: Partial<v1Config>): OneBotConfig
|
|||||||
if (config.http) {
|
if (config.http) {
|
||||||
mergedConfig.network.httpServers = [
|
mergedConfig.network.httpServers = [
|
||||||
mergeConfigs(httpServerDefaultConfigs, {
|
mergeConfigs(httpServerDefaultConfigs, {
|
||||||
|
name: 'http-server',
|
||||||
enable: config.http.enable,
|
enable: config.http.enable,
|
||||||
port: config.http.port,
|
port: config.http.port,
|
||||||
host: config.http.host,
|
host: config.http.host,
|
||||||
@@ -184,6 +185,7 @@ export function migrateOneBotConfigsV1(config: Partial<v1Config>): OneBotConfig
|
|||||||
if (config.ws) {
|
if (config.ws) {
|
||||||
mergedConfig.network.websocketServers = [
|
mergedConfig.network.websocketServers = [
|
||||||
mergeConfigs(websocketServerDefaultConfigs, {
|
mergeConfigs(websocketServerDefaultConfigs, {
|
||||||
|
name: 'websocket-server',
|
||||||
enable: config.ws.enable,
|
enable: config.ws.enable,
|
||||||
port: config.ws.port,
|
port: config.ws.port,
|
||||||
host: config.ws.host,
|
host: config.ws.host,
|
||||||
@@ -197,6 +199,7 @@ export function migrateOneBotConfigsV1(config: Partial<v1Config>): OneBotConfig
|
|||||||
if (config.reverseWs) {
|
if (config.reverseWs) {
|
||||||
mergedConfig.network.websocketClients = config.reverseWs.urls.map((url) =>
|
mergedConfig.network.websocketClients = config.reverseWs.urls.map((url) =>
|
||||||
mergeConfigs(websocketClientDefaultConfigs, {
|
mergeConfigs(websocketClientDefaultConfigs, {
|
||||||
|
name: 'websocket-client-' + config.reverseWs?.urls.indexOf(url).toString(),
|
||||||
enable: config.reverseWs?.enable,
|
enable: config.reverseWs?.enable,
|
||||||
url: url,
|
url: url,
|
||||||
token: config.token,
|
token: config.token,
|
||||||
|
@@ -58,7 +58,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
readonly context: InstanceContext;
|
readonly context: InstanceContext;
|
||||||
|
|
||||||
configLoader: OB11ConfigLoader;
|
configLoader: OB11ConfigLoader;
|
||||||
apis: StableOneBotApiWrapper;
|
public readonly apis: StableOneBotApiWrapper;
|
||||||
networkManager: OB11NetworkManager;
|
networkManager: OB11NetworkManager;
|
||||||
actions: ActionMap;
|
actions: ActionMap;
|
||||||
private readonly bootTime = Date.now() / 1000;
|
private readonly bootTime = Date.now() / 1000;
|
||||||
@@ -76,7 +76,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
FriendApi: new OneBotFriendApi(this, core),
|
FriendApi: new OneBotFriendApi(this, core),
|
||||||
MsgApi: new OneBotMsgApi(this, core),
|
MsgApi: new OneBotMsgApi(this, core),
|
||||||
QuickActionApi: new OneBotQuickActionApi(this, core),
|
QuickActionApi: new OneBotQuickActionApi(this, core),
|
||||||
};
|
} as const;
|
||||||
this.actions = createActionMap(this, core);
|
this.actions = createActionMap(this, core);
|
||||||
this.networkManager = new OB11NetworkManager();
|
this.networkManager = new OB11NetworkManager();
|
||||||
}
|
}
|
||||||
|
@@ -50,7 +50,7 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
try {
|
try {
|
||||||
this.obContext.apis.QuickActionApi
|
this.obContext.apis.QuickActionApi
|
||||||
.handleQuickOperation(event as QuickActionEvent, resJson)
|
.handleQuickOperation(event as QuickActionEvent, resJson)
|
||||||
.catch(e=>this.logger.logError(e));
|
.catch(e => this.logger.logError(e));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this.logger.logError('[OneBot] [Http Client] 新消息事件HTTP上报返回快速操作失败', e);
|
this.logger.logError('[OneBot] [Http Client] 新消息事件HTTP上报返回快速操作失败', e);
|
||||||
}
|
}
|
||||||
|
366
src/shell/base.ts
Normal file
366
src/shell/base.ts
Normal file
@@ -0,0 +1,366 @@
|
|||||||
|
import type { SelfInfo } from '@/core/types';
|
||||||
|
|
||||||
|
import { LogWrapper } from '@/common/log';
|
||||||
|
import { NodeIKernelLoginListener, NodeIKernelSessionListener } from '@/core/listeners';
|
||||||
|
import { NodeIDependsAdapter, NodeIDispatcherAdapter, NodeIGlobalAdapter } from '@/core/adapters';
|
||||||
|
import { NapCatPathWrapper } from '@/common/path';
|
||||||
|
import {
|
||||||
|
genSessionConfig,
|
||||||
|
InstanceContext,
|
||||||
|
loadQQWrapper,
|
||||||
|
NapCatCore,
|
||||||
|
NapCatCoreWorkingEnv,
|
||||||
|
NodeIQQNTWrapperSession,
|
||||||
|
PlatformType,
|
||||||
|
WrapperNodeApi,
|
||||||
|
} from '@/core';
|
||||||
|
import { QQBasicInfoWrapper } from '@/common/qq-basic-info';
|
||||||
|
import { hostname, systemVersion } from '@/common/system';
|
||||||
|
import { proxiedListenerOf } from '@/common/proxy-handler';
|
||||||
|
|
||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import os from 'os';
|
||||||
|
import { NodeIKernelLoginService } from '@/core/services';
|
||||||
|
import { program } from 'commander';
|
||||||
|
import qrcode from 'qrcode-terminal';
|
||||||
|
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||||
|
import { InitWebUi } from '@/webui';
|
||||||
|
import { WebUiDataRuntime } from '@/webui/src/helper/Data';
|
||||||
|
import { napCatVersion } from '@/common/version';
|
||||||
|
import { NodeIO3MiscListener } from '@/core/listeners/NodeIO3MiscListener';
|
||||||
|
// NapCat Shell App ES 入口文件
|
||||||
|
async function handleUncaughtExceptions(logger: LogWrapper) {
|
||||||
|
process.on('uncaughtException', (err) => {
|
||||||
|
logger.logError('[NapCat] [Error] Unhandled Exception:', err.message);
|
||||||
|
});
|
||||||
|
process.on('unhandledRejection', (reason, promise) => {
|
||||||
|
logger.logError('[NapCat] [Error] unhandledRejection:', reason);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDataPaths(wrapper: WrapperNodeApi): [string, string] {
|
||||||
|
if (os.platform() === 'darwin') {
|
||||||
|
const userPath = os.homedir();
|
||||||
|
const appDataPath = path.resolve(userPath, './Library/Application Support/QQ');
|
||||||
|
return [appDataPath, path.join(appDataPath, 'global')];
|
||||||
|
}
|
||||||
|
let dataPath = wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig();
|
||||||
|
if (!dataPath) {
|
||||||
|
dataPath = path.resolve(os.homedir(), './.config/QQ');
|
||||||
|
fs.mkdirSync(dataPath, { recursive: true });
|
||||||
|
}
|
||||||
|
const dataPathGlobal = path.resolve(dataPath, './nt_qq/global');
|
||||||
|
return [dataPath, dataPathGlobal];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPlatformType(): PlatformType {
|
||||||
|
const platformMapping: Partial<Record<NodeJS.Platform, PlatformType>> = {
|
||||||
|
win32: PlatformType.KWINDOWS,
|
||||||
|
darwin: PlatformType.KMAC,
|
||||||
|
linux: PlatformType.KLINUX,
|
||||||
|
};
|
||||||
|
return platformMapping[os.platform()] ?? PlatformType.KWINDOWS;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function initializeEngine(
|
||||||
|
engine: any,
|
||||||
|
basicInfoWrapper: QQBasicInfoWrapper,
|
||||||
|
dataPathGlobal: string,
|
||||||
|
systemPlatform: PlatformType,
|
||||||
|
systemVersion: string
|
||||||
|
) {
|
||||||
|
engine.initWithDeskTopConfig(
|
||||||
|
{
|
||||||
|
base_path_prefix: '',
|
||||||
|
platform_type: systemPlatform,
|
||||||
|
app_type: 4,
|
||||||
|
app_version: basicInfoWrapper.getFullQQVesion(),
|
||||||
|
os_version: systemVersion,
|
||||||
|
use_xlog: false,
|
||||||
|
qua: basicInfoWrapper.QQVersionQua,
|
||||||
|
global_path_config: {
|
||||||
|
desktopGlobalPath: dataPathGlobal,
|
||||||
|
},
|
||||||
|
thumb_config: { maxSide: 324, minSide: 48, longLimit: 6, density: 2 },
|
||||||
|
},
|
||||||
|
new NodeIGlobalAdapter(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function initializeLoginService(
|
||||||
|
loginService: NodeIKernelLoginService,
|
||||||
|
basicInfoWrapper: QQBasicInfoWrapper,
|
||||||
|
dataPathGlobal: string,
|
||||||
|
systemVersion: string,
|
||||||
|
hostname: string
|
||||||
|
) {
|
||||||
|
loginService.initConfig({
|
||||||
|
machineId: '',
|
||||||
|
appid: basicInfoWrapper.QQVersionAppid ?? '',
|
||||||
|
platVer: systemVersion,
|
||||||
|
commonPath: dataPathGlobal,
|
||||||
|
clientVer: basicInfoWrapper.getFullQQVesion(),
|
||||||
|
hostName: hostname,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleLogin(
|
||||||
|
loginService: NodeIKernelLoginService,
|
||||||
|
logger: LogWrapper,
|
||||||
|
pathWrapper: NapCatPathWrapper,
|
||||||
|
quickLoginUin: string | undefined,
|
||||||
|
historyLoginList: any[]
|
||||||
|
): Promise<SelfInfo> {
|
||||||
|
return new Promise<SelfInfo>((resolve) => {
|
||||||
|
const loginListener = new NodeIKernelLoginListener();
|
||||||
|
let isLogined = false;
|
||||||
|
|
||||||
|
loginListener.onUserLoggedIn = (userid: string) => {
|
||||||
|
logger.logError(`当前账号(${userid})已登录,无法重复登录`);
|
||||||
|
};
|
||||||
|
|
||||||
|
loginListener.onQRCodeLoginSucceed = async (loginResult) => {
|
||||||
|
isLogined = true;
|
||||||
|
resolve({
|
||||||
|
uid: loginResult.uid,
|
||||||
|
uin: loginResult.uin,
|
||||||
|
nick: '',
|
||||||
|
online: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
loginListener.onQRCodeGetPicture = ({ pngBase64QrcodeData, qrcodeUrl }) => {
|
||||||
|
WebUiDataRuntime.setQQLoginQrcodeURL(qrcodeUrl);
|
||||||
|
|
||||||
|
const realBase64 = pngBase64QrcodeData.replace(/^data:image\/\w+;base64,/, '');
|
||||||
|
const buffer = Buffer.from(realBase64, 'base64');
|
||||||
|
logger.logWarn('请扫描下面的二维码,然后在手Q上授权登录:');
|
||||||
|
const qrcodePath = path.join(pathWrapper.cachePath, 'qrcode.png');
|
||||||
|
qrcode.generate(qrcodeUrl, { small: true }, (res) => {
|
||||||
|
logger.logWarn([
|
||||||
|
'\n',
|
||||||
|
res,
|
||||||
|
'二维码解码URL: ' + qrcodeUrl,
|
||||||
|
'如果控制台二维码无法扫码,可以复制解码url到二维码生成网站生成二维码再扫码,也可以打开下方的二维码路径图片进行扫码。',
|
||||||
|
].join('\n'));
|
||||||
|
fs.writeFile(qrcodePath, buffer, {}, () => {
|
||||||
|
logger.logWarn('二维码已保存到', qrcodePath);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
loginListener.onQRCodeSessionFailed = (errType: number, errCode: number, errMsg: string) => {
|
||||||
|
if (!isLogined) {
|
||||||
|
logger.logError('[Core] [Login] Login Error,ErrCode: ', errCode, ' ErrMsg:', errMsg);
|
||||||
|
if (errType == 1 && errCode == 3) {
|
||||||
|
// 二维码过期刷新
|
||||||
|
}
|
||||||
|
loginService.getQRCodePicture();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loginListener.onLoginFailed = (args) => {
|
||||||
|
logger.logError('[Core] [Login] Login Error , ErrInfo: ', args);
|
||||||
|
};
|
||||||
|
|
||||||
|
loginService.addKernelLoginListener(proxiedListenerOf(loginListener, logger));
|
||||||
|
const isConnect = loginService.connect();
|
||||||
|
if (!isConnect) {
|
||||||
|
logger.logError('核心登录服务连接失败!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.log('核心登录服务连接成功!');
|
||||||
|
|
||||||
|
loginService.getLoginList().then((res) => {
|
||||||
|
// 遍历 res.LocalLoginInfoList[x].isQuickLogin是否可以 res.LocalLoginInfoList[x].uin 转为string 加入string[] 最后遍历完成调用WebUiDataRuntime.setQQQuickLoginList
|
||||||
|
WebUiDataRuntime.setQQQuickLoginList(res.LocalLoginInfoList.filter((item) => item.isQuickLogin).map((item) => item.uin.toString()));
|
||||||
|
});
|
||||||
|
|
||||||
|
WebUiDataRuntime.setQuickLoginCall(async (uin: string) => {
|
||||||
|
return await new Promise((resolve) => {
|
||||||
|
if (uin) {
|
||||||
|
logger.log('正在快速登录 ', uin);
|
||||||
|
loginService.quickLoginWithUin(uin).then(res => {
|
||||||
|
if (res.loginErrorInfo.errMsg) {
|
||||||
|
resolve({ result: false, message: res.loginErrorInfo.errMsg });
|
||||||
|
}
|
||||||
|
resolve({ result: true, message: '' });
|
||||||
|
}).catch((e) => {
|
||||||
|
logger.logError(e);
|
||||||
|
resolve({ result: false, message: '快速登录发生错误' });
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve({ result: false, message: '快速登录失败' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (quickLoginUin) {
|
||||||
|
if (historyLoginList.some(u => u.uin === quickLoginUin)) {
|
||||||
|
logger.log('正在快速登录 ', quickLoginUin);
|
||||||
|
setTimeout(() => {
|
||||||
|
loginService.quickLoginWithUin(quickLoginUin)
|
||||||
|
.then(result => {
|
||||||
|
if (result.loginErrorInfo.errMsg) {
|
||||||
|
logger.logError('快速登录错误:', result.loginErrorInfo.errMsg);
|
||||||
|
if (!isLogined) loginService.getQRCodePicture();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch();
|
||||||
|
}, 1000);
|
||||||
|
} else {
|
||||||
|
logger.logError('快速登录失败,未找到该 QQ 历史登录记录,将使用二维码登录方式');
|
||||||
|
if (!isLogined) loginService.getQRCodePicture();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.log('没有 -q 指令指定快速登录,将使用二维码登录方式');
|
||||||
|
if (historyLoginList.length > 0) {
|
||||||
|
logger.log(`可用于快速登录的 QQ:\n${historyLoginList
|
||||||
|
.map((u, index) => `${index + 1}. ${u.uin} ${u.nickName}`)
|
||||||
|
.join('\n')
|
||||||
|
}`);
|
||||||
|
}
|
||||||
|
loginService.getQRCodePicture();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function initializeSession(
|
||||||
|
session: NodeIQQNTWrapperSession,
|
||||||
|
sessionConfig: any,
|
||||||
|
logger: LogWrapper
|
||||||
|
) {
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
const sessionListener = new NodeIKernelSessionListener();
|
||||||
|
sessionListener.onSessionInitComplete = (r: unknown) => {
|
||||||
|
if (r === 0) {
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
reject(new Error('登录异常' + r?.toString()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
session.init(
|
||||||
|
sessionConfig,
|
||||||
|
new NodeIDependsAdapter(),
|
||||||
|
new NodeIDispatcherAdapter(),
|
||||||
|
sessionListener,
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
session.startNT(0);
|
||||||
|
} catch (_) {
|
||||||
|
try {
|
||||||
|
session.startNT();
|
||||||
|
} catch (e: unknown) {
|
||||||
|
reject(new Error('init failed ' + (e as Error).message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function NCoreInitShell() {
|
||||||
|
console.log('NapCat Shell App Loading...');
|
||||||
|
const pathWrapper = new NapCatPathWrapper();
|
||||||
|
const logger = new LogWrapper(pathWrapper.logsPath);
|
||||||
|
handleUncaughtExceptions(logger);
|
||||||
|
|
||||||
|
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
||||||
|
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
||||||
|
|
||||||
|
const o3Service = wrapper.NodeIO3MiscService.get();
|
||||||
|
o3Service.addO3MiscListener(new NodeIO3MiscListener());
|
||||||
|
|
||||||
|
logger.log(`[NapCat] [Core] NapCat.Core Version: ` + napCatVersion);
|
||||||
|
InitWebUi(logger, pathWrapper).then().catch(e => logger.logError(e));
|
||||||
|
|
||||||
|
const engine = wrapper.NodeIQQNTWrapperEngine.get();
|
||||||
|
const loginService = wrapper.NodeIKernelLoginService.get();
|
||||||
|
const session = wrapper.NodeIQQNTWrapperSession.create();
|
||||||
|
|
||||||
|
const [dataPath, dataPathGlobal] = getDataPaths(wrapper);
|
||||||
|
const systemPlatform = getPlatformType();
|
||||||
|
|
||||||
|
if (!basicInfoWrapper.QQVersionAppid || !basicInfoWrapper.QQVersionQua) throw new Error('QQVersionAppid or QQVersionQua is not defined');
|
||||||
|
|
||||||
|
await initializeEngine(engine, basicInfoWrapper, dataPathGlobal, systemPlatform, systemVersion);
|
||||||
|
await initializeLoginService(loginService, basicInfoWrapper, dataPathGlobal, systemVersion, hostname);
|
||||||
|
|
||||||
|
program.option('-q, --qq [number]', 'QQ号').parse(process.argv);
|
||||||
|
const cmdOptions = program.opts();
|
||||||
|
const quickLoginUin = cmdOptions.qq;
|
||||||
|
const historyLoginList = (await loginService.getLoginList()).LocalLoginInfoList;
|
||||||
|
|
||||||
|
const dataTimestape = new Date().getTime().toString();
|
||||||
|
o3Service.reportAmgomWeather('login', 'a1', [dataTimestape, '0', '0']);
|
||||||
|
|
||||||
|
const selfInfo = await handleLogin(loginService, logger, pathWrapper, quickLoginUin, historyLoginList);
|
||||||
|
|
||||||
|
const amgomDataPiece = 'eb1fd6ac257461580dc7438eb099f23aae04ca679f4d88f53072dc56e3bb1129';
|
||||||
|
o3Service.setAmgomDataPiece(basicInfoWrapper.QQVersionAppid, new Uint8Array(Buffer.from(amgomDataPiece, 'hex')));
|
||||||
|
|
||||||
|
let guid = loginService.getMachineGuid();
|
||||||
|
guid = guid.slice(0, 8) + '-' + guid.slice(8, 12) + '-' + guid.slice(12, 16) + '-' + guid.slice(16, 20) + '-' + guid.slice(20);
|
||||||
|
o3Service.reportAmgomWeather('login', 'a6', [dataTimestape, '184', '329']);
|
||||||
|
|
||||||
|
const sessionConfig = await genSessionConfig(
|
||||||
|
guid,
|
||||||
|
basicInfoWrapper.QQVersionAppid,
|
||||||
|
basicInfoWrapper.getFullQQVesion(),
|
||||||
|
selfInfo.uin,
|
||||||
|
selfInfo.uid,
|
||||||
|
dataPath,
|
||||||
|
);
|
||||||
|
|
||||||
|
await initializeSession(session, sessionConfig, logger);
|
||||||
|
|
||||||
|
const accountDataPath = path.resolve(dataPath, './NapCat/data');
|
||||||
|
fs.mkdirSync(dataPath, { recursive: true });
|
||||||
|
logger.logDebug('本账号数据/缓存目录:', accountDataPath);
|
||||||
|
|
||||||
|
await new NapCatShell(
|
||||||
|
wrapper,
|
||||||
|
session,
|
||||||
|
logger,
|
||||||
|
loginService,
|
||||||
|
selfInfo,
|
||||||
|
basicInfoWrapper,
|
||||||
|
pathWrapper,
|
||||||
|
).InitNapCat();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class NapCatShell {
|
||||||
|
readonly core: NapCatCore;
|
||||||
|
readonly context: InstanceContext;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
wrapper: WrapperNodeApi,
|
||||||
|
session: NodeIQQNTWrapperSession,
|
||||||
|
logger: LogWrapper,
|
||||||
|
loginService: NodeIKernelLoginService,
|
||||||
|
selfInfo: SelfInfo,
|
||||||
|
basicInfoWrapper: QQBasicInfoWrapper,
|
||||||
|
pathWrapper: NapCatPathWrapper,
|
||||||
|
) {
|
||||||
|
this.context = {
|
||||||
|
workingEnv: NapCatCoreWorkingEnv.Shell,
|
||||||
|
wrapper,
|
||||||
|
session,
|
||||||
|
logger,
|
||||||
|
loginService,
|
||||||
|
basicInfoWrapper,
|
||||||
|
pathWrapper,
|
||||||
|
};
|
||||||
|
this.core = new NapCatCore(this.context, selfInfo);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
async InitNapCat() {
|
||||||
|
await this.core.initCore();
|
||||||
|
new NapCatOneBot11Adapter(this.core, this.context, this.context.pathWrapper).InitOneBot()
|
||||||
|
.catch(e => this.context.logger.logError('初始化OneBot失败', e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -1,369 +1,3 @@
|
|||||||
import type { SelfInfo } from '@/core/types';
|
import { NCoreInitShell } from "./base";
|
||||||
|
|
||||||
import { LogWrapper } from '@/common/log';
|
|
||||||
import { NodeIKernelLoginListener, NodeIKernelSessionListener } from '@/core/listeners';
|
|
||||||
import { NodeIDependsAdapter, NodeIDispatcherAdapter, NodeIGlobalAdapter } from '@/core/adapters';
|
|
||||||
import { NapCatPathWrapper } from '@/common/path';
|
|
||||||
import {
|
|
||||||
genSessionConfig,
|
|
||||||
InstanceContext,
|
|
||||||
loadQQWrapper,
|
|
||||||
NapCatCore,
|
|
||||||
NapCatCoreWorkingEnv,
|
|
||||||
NodeIQQNTWrapperSession,
|
|
||||||
PlatformType,
|
|
||||||
WrapperNodeApi,
|
|
||||||
} from '@/core';
|
|
||||||
import { QQBasicInfoWrapper } from '@/common/qq-basic-info';
|
|
||||||
import { hostname, systemVersion } from '@/common/system';
|
|
||||||
import { proxiedListenerOf } from '@/common/proxy-handler';
|
|
||||||
|
|
||||||
import path from 'path';
|
|
||||||
import fs from 'fs';
|
|
||||||
import os from 'os';
|
|
||||||
import { NodeIKernelLoginService } from '@/core/services';
|
|
||||||
import { program } from 'commander';
|
|
||||||
import qrcode from 'qrcode-terminal';
|
|
||||||
import { NapCatOneBot11Adapter } from '@/onebot';
|
|
||||||
import { InitWebUi } from '@/webui';
|
|
||||||
import { WebUiDataRuntime } from '@/webui/src/helper/Data';
|
|
||||||
import { napCatVersion } from '@/common/version';
|
|
||||||
import { NodeIO3MiscListener } from '@/core/listeners/NodeIO3MiscListener';
|
|
||||||
|
|
||||||
program.option('-q, --qq [number]', 'QQ号').parse(process.argv);
|
|
||||||
const cmdOptions = program.opts();
|
|
||||||
|
|
||||||
// NapCat Shell App ES 入口文件
|
|
||||||
async function handleUncaughtExceptions(logger: LogWrapper) {
|
|
||||||
process.on('uncaughtException', (err) => {
|
|
||||||
logger.logError('[NapCat] [Error] Unhandled Exception:', err.message);
|
|
||||||
});
|
|
||||||
process.on('unhandledRejection', (reason, promise) => {
|
|
||||||
logger.logError('[NapCat] [Error] unhandledRejection:', reason);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDataPaths(wrapper: WrapperNodeApi): [string, string] {
|
|
||||||
if (os.platform() === 'darwin') {
|
|
||||||
const userPath = os.homedir();
|
|
||||||
const appDataPath = path.resolve(userPath, './Library/Application Support/QQ');
|
|
||||||
return [appDataPath, path.join(appDataPath, 'global')];
|
|
||||||
}
|
|
||||||
let dataPath = wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig();
|
|
||||||
if (!dataPath) {
|
|
||||||
dataPath = path.resolve(os.homedir(), './.config/QQ');
|
|
||||||
fs.mkdirSync(dataPath, { recursive: true });
|
|
||||||
}
|
|
||||||
const dataPathGlobal = path.resolve(dataPath, './nt_qq/global');
|
|
||||||
return [dataPath, dataPathGlobal];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPlatformType(): PlatformType {
|
|
||||||
const platformMapping: Partial<Record<NodeJS.Platform, PlatformType>> = {
|
|
||||||
win32: PlatformType.KWINDOWS,
|
|
||||||
darwin: PlatformType.KMAC,
|
|
||||||
linux: PlatformType.KLINUX,
|
|
||||||
};
|
|
||||||
return platformMapping[os.platform()] ?? PlatformType.KWINDOWS;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function initializeEngine(
|
|
||||||
engine: any,
|
|
||||||
basicInfoWrapper: QQBasicInfoWrapper,
|
|
||||||
dataPathGlobal: string,
|
|
||||||
systemPlatform: PlatformType,
|
|
||||||
systemVersion: string
|
|
||||||
) {
|
|
||||||
engine.initWithDeskTopConfig(
|
|
||||||
{
|
|
||||||
base_path_prefix: '',
|
|
||||||
platform_type: systemPlatform,
|
|
||||||
app_type: 4,
|
|
||||||
app_version: basicInfoWrapper.getFullQQVesion(),
|
|
||||||
os_version: systemVersion,
|
|
||||||
use_xlog: false,
|
|
||||||
qua: basicInfoWrapper.QQVersionQua,
|
|
||||||
global_path_config: {
|
|
||||||
desktopGlobalPath: dataPathGlobal,
|
|
||||||
},
|
|
||||||
thumb_config: { maxSide: 324, minSide: 48, longLimit: 6, density: 2 },
|
|
||||||
},
|
|
||||||
new NodeIGlobalAdapter(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function initializeLoginService(
|
|
||||||
loginService: NodeIKernelLoginService,
|
|
||||||
basicInfoWrapper: QQBasicInfoWrapper,
|
|
||||||
dataPathGlobal: string,
|
|
||||||
systemVersion: string,
|
|
||||||
hostname: string
|
|
||||||
) {
|
|
||||||
loginService.initConfig({
|
|
||||||
machineId: '',
|
|
||||||
appid: basicInfoWrapper.QQVersionAppid ?? '',
|
|
||||||
platVer: systemVersion,
|
|
||||||
commonPath: dataPathGlobal,
|
|
||||||
clientVer: basicInfoWrapper.getFullQQVesion(),
|
|
||||||
hostName: hostname,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleLogin(
|
|
||||||
loginService: NodeIKernelLoginService,
|
|
||||||
logger: LogWrapper,
|
|
||||||
pathWrapper: NapCatPathWrapper,
|
|
||||||
quickLoginUin: string | undefined,
|
|
||||||
historyLoginList: any[]
|
|
||||||
): Promise<SelfInfo> {
|
|
||||||
return new Promise<SelfInfo>((resolve) => {
|
|
||||||
const loginListener = new NodeIKernelLoginListener();
|
|
||||||
let isLogined = false;
|
|
||||||
|
|
||||||
loginListener.onUserLoggedIn = (userid: string) => {
|
|
||||||
logger.logError(`当前账号(${userid})已登录,无法重复登录`);
|
|
||||||
};
|
|
||||||
|
|
||||||
loginListener.onQRCodeLoginSucceed = async (loginResult) => {
|
|
||||||
isLogined = true;
|
|
||||||
resolve({
|
|
||||||
uid: loginResult.uid,
|
|
||||||
uin: loginResult.uin,
|
|
||||||
nick: '',
|
|
||||||
online: true,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
loginListener.onQRCodeGetPicture = ({ pngBase64QrcodeData, qrcodeUrl }) => {
|
|
||||||
WebUiDataRuntime.setQQLoginQrcodeURL(qrcodeUrl);
|
|
||||||
|
|
||||||
const realBase64 = pngBase64QrcodeData.replace(/^data:image\/\w+;base64,/, '');
|
|
||||||
const buffer = Buffer.from(realBase64, 'base64');
|
|
||||||
logger.logWarn('请扫描下面的二维码,然后在手Q上授权登录:');
|
|
||||||
const qrcodePath = path.join(pathWrapper.cachePath, 'qrcode.png');
|
|
||||||
qrcode.generate(qrcodeUrl, { small: true }, (res) => {
|
|
||||||
logger.logWarn([
|
|
||||||
'\n',
|
|
||||||
res,
|
|
||||||
'二维码解码URL: ' + qrcodeUrl,
|
|
||||||
'如果控制台二维码无法扫码,可以复制解码url到二维码生成网站生成二维码再扫码,也可以打开下方的二维码路径图片进行扫码。',
|
|
||||||
].join('\n'));
|
|
||||||
fs.writeFile(qrcodePath, buffer, {}, () => {
|
|
||||||
logger.logWarn('二维码已保存到', qrcodePath);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
loginListener.onQRCodeSessionFailed = (errType: number, errCode: number, errMsg: string) => {
|
|
||||||
if (!isLogined) {
|
|
||||||
logger.logError('[Core] [Login] Login Error,ErrCode: ', errCode, ' ErrMsg:', errMsg);
|
|
||||||
if (errType == 1 && errCode == 3) {
|
|
||||||
// 二维码过期刷新
|
|
||||||
}
|
|
||||||
loginService.getQRCodePicture();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
loginListener.onLoginFailed = (args) => {
|
|
||||||
logger.logError('[Core] [Login] Login Error , ErrInfo: ', args);
|
|
||||||
};
|
|
||||||
|
|
||||||
loginService.addKernelLoginListener(proxiedListenerOf(loginListener, logger));
|
|
||||||
const isConnect = loginService.connect();
|
|
||||||
if (!isConnect) {
|
|
||||||
logger.logError('核心登录服务连接失败!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.log('核心登录服务连接成功!');
|
|
||||||
|
|
||||||
loginService.getLoginList().then((res) => {
|
|
||||||
// 遍历 res.LocalLoginInfoList[x].isQuickLogin是否可以 res.LocalLoginInfoList[x].uin 转为string 加入string[] 最后遍历完成调用WebUiDataRuntime.setQQQuickLoginList
|
|
||||||
WebUiDataRuntime.setQQQuickLoginList(res.LocalLoginInfoList.filter((item) => item.isQuickLogin).map((item) => item.uin.toString()));
|
|
||||||
});
|
|
||||||
|
|
||||||
WebUiDataRuntime.setQuickLoginCall(async (uin: string) => {
|
|
||||||
return await new Promise((resolve) => {
|
|
||||||
if (uin) {
|
|
||||||
logger.log('正在快速登录 ', uin);
|
|
||||||
loginService.quickLoginWithUin(uin).then(res => {
|
|
||||||
if (res.loginErrorInfo.errMsg) {
|
|
||||||
resolve({ result: false, message: res.loginErrorInfo.errMsg });
|
|
||||||
}
|
|
||||||
resolve({ result: true, message: '' });
|
|
||||||
}).catch((e) => {
|
|
||||||
logger.logError(e);
|
|
||||||
resolve({ result: false, message: '快速登录发生错误' });
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
resolve({ result: false, message: '快速登录失败' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (quickLoginUin) {
|
|
||||||
if (historyLoginList.some(u => u.uin === quickLoginUin)) {
|
|
||||||
logger.log('正在快速登录 ', quickLoginUin);
|
|
||||||
setTimeout(() => {
|
|
||||||
loginService.quickLoginWithUin(quickLoginUin)
|
|
||||||
.then(result => {
|
|
||||||
if (result.loginErrorInfo.errMsg) {
|
|
||||||
logger.logError('快速登录错误:', result.loginErrorInfo.errMsg);
|
|
||||||
if (!isLogined) loginService.getQRCodePicture();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch();
|
|
||||||
}, 1000);
|
|
||||||
} else {
|
|
||||||
logger.logError('快速登录失败,未找到该 QQ 历史登录记录,将使用二维码登录方式');
|
|
||||||
if (!isLogined) loginService.getQRCodePicture();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.log('没有 -q 指令指定快速登录,将使用二维码登录方式');
|
|
||||||
if (historyLoginList.length > 0) {
|
|
||||||
logger.log(`可用于快速登录的 QQ:\n${historyLoginList
|
|
||||||
.map((u, index) => `${index + 1}. ${u.uin} ${u.nickName}`)
|
|
||||||
.join('\n')
|
|
||||||
}`);
|
|
||||||
}
|
|
||||||
loginService.getQRCodePicture();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function initializeSession(
|
|
||||||
session: NodeIQQNTWrapperSession,
|
|
||||||
sessionConfig: any,
|
|
||||||
logger: LogWrapper
|
|
||||||
) {
|
|
||||||
return new Promise<void>((resolve, reject) => {
|
|
||||||
const sessionListener = new NodeIKernelSessionListener();
|
|
||||||
sessionListener.onSessionInitComplete = (r: unknown) => {
|
|
||||||
if (r === 0) {
|
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
reject(new Error('登录异常' + r?.toString()));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
session.init(
|
|
||||||
sessionConfig,
|
|
||||||
new NodeIDependsAdapter(),
|
|
||||||
new NodeIDispatcherAdapter(),
|
|
||||||
sessionListener,
|
|
||||||
);
|
|
||||||
try {
|
|
||||||
session.startNT(0);
|
|
||||||
} catch (_) {
|
|
||||||
try {
|
|
||||||
session.startNT();
|
|
||||||
} catch (e: unknown) {
|
|
||||||
reject(new Error('init failed ' + (e as Error).message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function NCoreInitShell() {
|
|
||||||
console.log('NapCat Shell App Loading...');
|
|
||||||
const pathWrapper = new NapCatPathWrapper();
|
|
||||||
const logger = new LogWrapper(pathWrapper.logsPath);
|
|
||||||
handleUncaughtExceptions(logger);
|
|
||||||
|
|
||||||
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
|
||||||
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
|
||||||
|
|
||||||
const o3Service = wrapper.NodeIO3MiscService.get();
|
|
||||||
o3Service.addO3MiscListener(new NodeIO3MiscListener());
|
|
||||||
|
|
||||||
logger.log(`[NapCat] [Core] NapCat.Core Version: ` + napCatVersion);
|
|
||||||
InitWebUi(logger, pathWrapper).then().catch(e => logger.logError(e));
|
|
||||||
|
|
||||||
const engine = wrapper.NodeIQQNTWrapperEngine.get();
|
|
||||||
const loginService = wrapper.NodeIKernelLoginService.get();
|
|
||||||
const session = wrapper.NodeIQQNTWrapperSession.create();
|
|
||||||
|
|
||||||
const [dataPath, dataPathGlobal] = getDataPaths(wrapper);
|
|
||||||
const systemPlatform = getPlatformType();
|
|
||||||
|
|
||||||
if (!basicInfoWrapper.QQVersionAppid || !basicInfoWrapper.QQVersionQua) throw new Error('QQVersionAppid or QQVersionQua is not defined');
|
|
||||||
|
|
||||||
await initializeEngine(engine, basicInfoWrapper, dataPathGlobal, systemPlatform, systemVersion);
|
|
||||||
await initializeLoginService(loginService, basicInfoWrapper, dataPathGlobal, systemVersion, hostname);
|
|
||||||
|
|
||||||
const quickLoginUin = cmdOptions.qq;
|
|
||||||
const historyLoginList = (await loginService.getLoginList()).LocalLoginInfoList;
|
|
||||||
|
|
||||||
const dataTimestape = new Date().getTime().toString();
|
|
||||||
o3Service.reportAmgomWeather('login', 'a1', [dataTimestape, '0', '0']);
|
|
||||||
|
|
||||||
const selfInfo = await handleLogin(loginService, logger, pathWrapper, quickLoginUin, historyLoginList);
|
|
||||||
|
|
||||||
const amgomDataPiece = 'eb1fd6ac257461580dc7438eb099f23aae04ca679f4d88f53072dc56e3bb1129';
|
|
||||||
o3Service.setAmgomDataPiece(basicInfoWrapper.QQVersionAppid, new Uint8Array(Buffer.from(amgomDataPiece, 'hex')));
|
|
||||||
|
|
||||||
let guid = loginService.getMachineGuid();
|
|
||||||
guid = guid.slice(0, 8) + '-' + guid.slice(8, 12) + '-' + guid.slice(12, 16) + '-' + guid.slice(16, 20) + '-' + guid.slice(20);
|
|
||||||
o3Service.reportAmgomWeather('login', 'a6', [dataTimestape, '184', '329']);
|
|
||||||
|
|
||||||
const sessionConfig = await genSessionConfig(
|
|
||||||
guid,
|
|
||||||
basicInfoWrapper.QQVersionAppid,
|
|
||||||
basicInfoWrapper.getFullQQVesion(),
|
|
||||||
selfInfo.uin,
|
|
||||||
selfInfo.uid,
|
|
||||||
dataPath,
|
|
||||||
);
|
|
||||||
|
|
||||||
await initializeSession(session, sessionConfig, logger);
|
|
||||||
|
|
||||||
const accountDataPath = path.resolve(dataPath, './NapCat/data');
|
|
||||||
fs.mkdirSync(dataPath, { recursive: true });
|
|
||||||
logger.logDebug('本账号数据/缓存目录:', accountDataPath);
|
|
||||||
|
|
||||||
await new NapCatShell(
|
|
||||||
wrapper,
|
|
||||||
session,
|
|
||||||
logger,
|
|
||||||
loginService,
|
|
||||||
selfInfo,
|
|
||||||
basicInfoWrapper,
|
|
||||||
pathWrapper,
|
|
||||||
).InitNapCat();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export class NapCatShell {
|
|
||||||
readonly core: NapCatCore;
|
|
||||||
readonly context: InstanceContext;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
wrapper: WrapperNodeApi,
|
|
||||||
session: NodeIQQNTWrapperSession,
|
|
||||||
logger: LogWrapper,
|
|
||||||
loginService: NodeIKernelLoginService,
|
|
||||||
selfInfo: SelfInfo,
|
|
||||||
basicInfoWrapper: QQBasicInfoWrapper,
|
|
||||||
pathWrapper: NapCatPathWrapper,
|
|
||||||
) {
|
|
||||||
this.context = {
|
|
||||||
workingEnv: NapCatCoreWorkingEnv.Shell,
|
|
||||||
wrapper,
|
|
||||||
session,
|
|
||||||
logger,
|
|
||||||
loginService,
|
|
||||||
basicInfoWrapper,
|
|
||||||
pathWrapper,
|
|
||||||
};
|
|
||||||
this.core = new NapCatCore(this.context, selfInfo);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
async InitNapCat() {
|
|
||||||
await this.core.initCore();
|
|
||||||
new NapCatOneBot11Adapter(this.core, this.context, this.context.pathWrapper).InitOneBot()
|
|
||||||
.catch(e => this.context.logger.logError('初始化OneBot失败', e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NCoreInitShell();
|
NCoreInitShell();
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user