mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
13 Commits
esm-wrappe
...
feat-new-c
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3a1d1f2e59 | ||
![]() |
e9a048721d | ||
![]() |
68f0c7ff1a | ||
![]() |
2875fe94ea | ||
![]() |
1870427c0f | ||
![]() |
636568fd30 | ||
![]() |
bbc2391bf8 | ||
![]() |
401684542a | ||
![]() |
870edb2513 | ||
![]() |
7ad09169ea | ||
![]() |
c1a0f8915b | ||
![]() |
dcdab8e5a1 | ||
![]() |
eb3278fdab |
@@ -53,6 +53,8 @@ _Modern protocol-side framework implemented based on NTQQ._
|
|||||||
|
|
||||||
+ [AstrBot](https://github.com/AstrBotDevs/AstrBot) 是完美适配本项目的LLM Bot框架 在此推荐一下
|
+ [AstrBot](https://github.com/AstrBotDevs/AstrBot) 是完美适配本项目的LLM Bot框架 在此推荐一下
|
||||||
|
|
||||||
|
+ [MaiBot](https://github.com/MaiM-with-u/MaiBot) 一只赛博群友 麦麦 Bot框架 在此推荐一下
|
||||||
|
|
||||||
+ 不过最最重要的 还是需要感谢屏幕前的你哦~
|
+ 不过最最重要的 还是需要感谢屏幕前的你哦~
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "4.7.62",
|
"version": "4.7.63",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
16
package.json
16
package.json
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "4.7.62",
|
"version": "4.7.63",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
||||||
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
||||||
@@ -41,31 +41,29 @@
|
|||||||
"ajv": "^8.13.0",
|
"ajv": "^8.13.0",
|
||||||
"async-mutex": "^0.5.0",
|
"async-mutex": "^0.5.0",
|
||||||
"commander": "^13.0.0",
|
"commander": "^13.0.0",
|
||||||
"compressing": "^1.10.1",
|
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"esbuild": "0.25.4",
|
"esbuild": "0.25.4",
|
||||||
"eslint": "^9.14.0",
|
"eslint": "^9.14.0",
|
||||||
"eslint-import-resolver-typescript": "^4.0.0",
|
"eslint-import-resolver-typescript": "^4.0.0",
|
||||||
"eslint-plugin-import": "^2.29.1",
|
"eslint-plugin-import": "^2.29.1",
|
||||||
"express": "npm:@karinjs/express@1.0.3",
|
"express-rate-limit": "^7.5.0",
|
||||||
"fast-xml-parser": "^4.3.6",
|
"fast-xml-parser": "^4.3.6",
|
||||||
"file-type": "^20.0.0",
|
"file-type": "^20.0.0",
|
||||||
"globals": "^16.0.0",
|
"globals": "^16.0.0",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"napcat.protobuf": "^1.1.4",
|
|
||||||
"on-finished": "^2.4.1",
|
|
||||||
"silk-wasm": "^3.6.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": "^6.0.0",
|
"vite-plugin-cp": "^6.0.0",
|
||||||
"vite-plugin-wasm": "^3.4.1",
|
|
||||||
"vite-tsconfig-paths": "^5.1.0",
|
"vite-tsconfig-paths": "^5.1.0",
|
||||||
|
"napcat.protobuf": "^1.1.4",
|
||||||
"winston": "^3.17.0",
|
"winston": "^3.17.0",
|
||||||
"ws": "npm:@karinjs/ws@1.2.0"
|
"compressing": "^1.10.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"type-is": "^2.0.1"
|
"express": "^5.0.0",
|
||||||
|
"silk-wasm": "^3.6.1",
|
||||||
|
"ws": "^8.18.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const napCatVersion = '4.7.62';
|
export const napCatVersion = '4.7.63';
|
||||||
|
8
src/core/external/appid.json
vendored
8
src/core/external/appid.json
vendored
@@ -286,5 +286,13 @@
|
|||||||
"9.9.19-34958": {
|
"9.9.19-34958": {
|
||||||
"appid": 537290742,
|
"appid": 537290742,
|
||||||
"qua": "V1_WIN_NQ_9.9.19_34958_GW_B"
|
"qua": "V1_WIN_NQ_9.9.19_34958_GW_B"
|
||||||
|
},
|
||||||
|
"3.2.17-35184": {
|
||||||
|
"appid": 537291084,
|
||||||
|
"qua": "V1_LNX_NQ_3.2.17_35184_GW_B"
|
||||||
|
},
|
||||||
|
"9.9.19-35184": {
|
||||||
|
"appid": 537291048,
|
||||||
|
"qua": "V1_WIN_NQ_9.9.19_35184_GW_B"
|
||||||
}
|
}
|
||||||
}
|
}
|
12
src/core/external/offset.json
vendored
12
src/core/external/offset.json
vendored
@@ -366,5 +366,17 @@
|
|||||||
"9.9.19-34958-x64": {
|
"9.9.19-34958-x64": {
|
||||||
"send": "3BDD8D0",
|
"send": "3BDD8D0",
|
||||||
"recv": "3BE20D0"
|
"recv": "3BE20D0"
|
||||||
|
},
|
||||||
|
"3.2.17-35184-x64": {
|
||||||
|
"send": "AE0DDE0",
|
||||||
|
"recv": "AE11800"
|
||||||
|
},
|
||||||
|
"3.2.17-35184-arm64": {
|
||||||
|
"send": "7776028",
|
||||||
|
"recv": "7779958"
|
||||||
|
},
|
||||||
|
"9.9.19-35184-x64": {
|
||||||
|
"send": "3BE5A10",
|
||||||
|
"recv": "3BEA210"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,372 +0,0 @@
|
|||||||
/*!
|
|
||||||
* on-finished
|
|
||||||
* Copyright(c) 2013 Jonathan Ong
|
|
||||||
* Copyright(c) 2014 Douglas Christopher Wilson
|
|
||||||
* MIT Licensed
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义消息对象接口
|
|
||||||
*/
|
|
||||||
interface Message {
|
|
||||||
socket?: Socket;
|
|
||||||
finished?: boolean;
|
|
||||||
complete?: boolean;
|
|
||||||
readable?: boolean;
|
|
||||||
upgrade?: boolean;
|
|
||||||
__onFinished?: Listener;
|
|
||||||
on?: (event: string, callback: (socket: Socket) => void) => void;
|
|
||||||
removeListener?: (event: string, callback: Function) => void;
|
|
||||||
assignSocket?: (socket: Socket) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定义Socket接口
|
|
||||||
*/
|
|
||||||
interface Socket {
|
|
||||||
writable: boolean;
|
|
||||||
readable: boolean;
|
|
||||||
on?: (event: string, callback: Function) => void;
|
|
||||||
removeListener?: (event: string, callback: Function) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 事件处理器类型
|
|
||||||
*/
|
|
||||||
type EventHandler = (err?: Error) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 事件元组: [对象, ...事件名称]
|
|
||||||
*/
|
|
||||||
type EventTuple = [unknown, ...string[]];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消函数类型
|
|
||||||
*/
|
|
||||||
interface CancelableListener {
|
|
||||||
cancel: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 监听器函数类型
|
|
||||||
*/
|
|
||||||
type ListenerCallback = (err: Error | null, msg: Message) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改监听器接口,使其参数类型更通用
|
|
||||||
*/
|
|
||||||
interface Listener {
|
|
||||||
(err: Error | null | undefined): void;
|
|
||||||
queue: ListenerCallback[] | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 模块导出
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export { onFinished as default, isFinished };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 模块依赖
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const asyncHooks = tryRequireAsyncHooks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 变量
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const defer = function(fn: ListenerCallback, err: Error | null, msg: Message): void {
|
|
||||||
setImmediate(fn, err, msg);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 实现 ee-first 功能:监听多个事件,当第一个事件触发时执行回调并移除所有监听器
|
|
||||||
* @param {Array<EventTuple>} stuff - 事件元组数组
|
|
||||||
* @param {EventHandler} done - 完成时的回调
|
|
||||||
* @returns {CancelableListener} 可取消的监听器对象
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function first(stuff: EventTuple[], done: EventHandler): CancelableListener {
|
|
||||||
if (!Array.isArray(stuff)) {
|
|
||||||
throw new TypeError('参数 "stuff" 必须是数组');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof done !== 'function') {
|
|
||||||
throw new TypeError('参数 "done" 必须是函数');
|
|
||||||
}
|
|
||||||
|
|
||||||
const cleanups: Function[] = [];
|
|
||||||
let finished = false;
|
|
||||||
|
|
||||||
// 处理所有传入的对象和事件
|
|
||||||
for (const tuple of stuff) {
|
|
||||||
if (!Array.isArray(tuple) || tuple.length < 2) {
|
|
||||||
throw new TypeError('每个事件元组必须是长度大于等于2的数组');
|
|
||||||
}
|
|
||||||
|
|
||||||
const obj = tuple[0];
|
|
||||||
|
|
||||||
if (!obj || typeof obj !== 'object') {
|
|
||||||
throw new TypeError('监听目标必须是对象');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用类型断言确保obj有on和removeListener方法
|
|
||||||
const target = obj as {
|
|
||||||
on: (event: string, callback: Function) => void;
|
|
||||||
removeListener: (event: string, callback: Function) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (typeof target.on !== 'function' || typeof target.removeListener !== 'function') {
|
|
||||||
throw new TypeError('监听目标必须支持 on/removeListener 方法');
|
|
||||||
}
|
|
||||||
|
|
||||||
const events = tuple.slice(1);
|
|
||||||
|
|
||||||
// 为每个事件创建一个监听器
|
|
||||||
for (const event of events) {
|
|
||||||
if (typeof event !== 'string') {
|
|
||||||
throw new TypeError('事件名称必须是字符串');
|
|
||||||
}
|
|
||||||
|
|
||||||
const listener = createEventListener(target, event, cleanup);
|
|
||||||
cleanups.push(listener.cleanup);
|
|
||||||
target.on(event, listener.callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建可取消的监听器对象
|
|
||||||
return {
|
|
||||||
cancel: cleanup
|
|
||||||
};
|
|
||||||
|
|
||||||
// 清理函数
|
|
||||||
function cleanup(): void {
|
|
||||||
if (finished) return;
|
|
||||||
finished = true;
|
|
||||||
|
|
||||||
// 执行所有清理函数
|
|
||||||
for (const cleanup of cleanups) {
|
|
||||||
try {
|
|
||||||
cleanup();
|
|
||||||
} catch (err) {
|
|
||||||
console.error('清理事件监听器时出错:', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建单个事件监听器
|
|
||||||
function createEventListener(
|
|
||||||
obj: { on: Function; removeListener: Function },
|
|
||||||
event: string,
|
|
||||||
cleanup: Function
|
|
||||||
): {
|
|
||||||
callback: (arg?: unknown) => void;
|
|
||||||
cleanup: () => void;
|
|
||||||
} {
|
|
||||||
const callback = (arg?: unknown): void => {
|
|
||||||
cleanup();
|
|
||||||
done(arg instanceof Error ? arg : undefined);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
callback,
|
|
||||||
cleanup: () => {
|
|
||||||
obj.removeListener(event, callback);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当响应结束时调用回调,用于资源清理
|
|
||||||
*
|
|
||||||
* @param {Message} msg
|
|
||||||
* @param {ListenerCallback} listener
|
|
||||||
* @return {Message}
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
function onFinished(msg: Message, listener: ListenerCallback): Message {
|
|
||||||
if (!msg || typeof msg !== 'object') {
|
|
||||||
throw new TypeError('参数 "msg" 必须是对象');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof listener !== 'function') {
|
|
||||||
throw new TypeError('参数 "listener" 必须是函数');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isFinished(msg) !== false) {
|
|
||||||
defer(listener, null, msg);
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将监听器附加到消息
|
|
||||||
attachListener(msg, wrap(listener));
|
|
||||||
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 确定消息是否已完成
|
|
||||||
*
|
|
||||||
* @param {Message} msg
|
|
||||||
* @return {boolean | undefined}
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
function isFinished(msg: Message): boolean | undefined {
|
|
||||||
if (!msg || typeof msg !== 'object') {
|
|
||||||
throw new TypeError('参数 "msg" 必须是对象');
|
|
||||||
}
|
|
||||||
|
|
||||||
const socket = msg.socket;
|
|
||||||
|
|
||||||
if (typeof msg.finished === 'boolean') {
|
|
||||||
// OutgoingMessage
|
|
||||||
return Boolean(msg.finished || (socket && !socket.writable));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof msg.complete === 'boolean') {
|
|
||||||
// IncomingMessage
|
|
||||||
return Boolean(msg.upgrade || !socket || !socket.readable || (msg.complete && !msg.readable));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 不确定状态
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将完成监听器附加到消息
|
|
||||||
*
|
|
||||||
* @param {Message} msg
|
|
||||||
* @param {Function} callback
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function attachFinishedListener(msg: Message, callback: (error?: Error) => void): void {
|
|
||||||
let eeMsg: CancelableListener;
|
|
||||||
let eeSocket: CancelableListener;
|
|
||||||
let finished = false;
|
|
||||||
|
|
||||||
function onFinish(error?: Error): void {
|
|
||||||
if (!eeMsg || !eeSocket) {
|
|
||||||
return; // 防御性检查
|
|
||||||
}
|
|
||||||
|
|
||||||
eeMsg.cancel();
|
|
||||||
eeSocket.cancel();
|
|
||||||
|
|
||||||
finished = true;
|
|
||||||
callback(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在第一个消息事件上完成
|
|
||||||
eeMsg = eeSocket = first([[msg, 'end', 'finish']], onFinish);
|
|
||||||
|
|
||||||
function onSocket(socket: Socket): void {
|
|
||||||
// 移除监听器
|
|
||||||
if (msg.removeListener && typeof msg.removeListener === 'function') {
|
|
||||||
msg.removeListener('socket', onSocket);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (finished) return;
|
|
||||||
if (eeMsg !== eeSocket) return;
|
|
||||||
|
|
||||||
if (!socket || typeof socket !== 'object') {
|
|
||||||
return; // 防御性检查
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在第一个socket事件上完成
|
|
||||||
eeSocket = first([[socket, 'error', 'close']], onFinish);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.socket) {
|
|
||||||
// socket已分配
|
|
||||||
onSocket(msg.socket);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 等待socket分配
|
|
||||||
if (msg.on && typeof msg.on === 'function') {
|
|
||||||
msg.on('socket', onSocket);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将监听器附加到消息
|
|
||||||
*
|
|
||||||
* @param {Message} msg
|
|
||||||
* @param {ListenerCallback} listener
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function attachListener(msg: Message, listener: ListenerCallback): void {
|
|
||||||
let attached = msg.__onFinished;
|
|
||||||
|
|
||||||
// 创建私有单一监听器和队列
|
|
||||||
if (!attached || !attached.queue) {
|
|
||||||
attached = msg.__onFinished = createListener(msg);
|
|
||||||
attachFinishedListener(msg, attached);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attached.queue) {
|
|
||||||
attached.queue.push(listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在消息上创建监听器
|
|
||||||
*
|
|
||||||
* @param {Message} msg
|
|
||||||
* @return {Listener}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function createListener(msg: Message): Listener {
|
|
||||||
const listener: Listener = function listener(err: Error | null | undefined): void {
|
|
||||||
if (msg.__onFinished === listener) msg.__onFinished = undefined;
|
|
||||||
if (!listener.queue) return;
|
|
||||||
|
|
||||||
const queue = listener.queue;
|
|
||||||
listener.queue = null;
|
|
||||||
|
|
||||||
for (let i = 0; i < queue.length; i++) {
|
|
||||||
queue[i]?.(err || null, msg);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
listener.queue = [];
|
|
||||||
|
|
||||||
return listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 尝试引入async_hooks
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function tryRequireAsyncHooks(): { AsyncResource?: typeof import('async_hooks').AsyncResource } {
|
|
||||||
try {
|
|
||||||
return require('async_hooks');
|
|
||||||
} catch (e) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果可能,用async resource包装函数
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function wrap(fn: ListenerCallback): ListenerCallback {
|
|
||||||
if (typeof fn !== 'function') {
|
|
||||||
throw new TypeError('参数必须是函数');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Node.js 16+ 总是有 AsyncResource
|
|
||||||
if (!asyncHooks.AsyncResource) {
|
|
||||||
return fn;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建匿名资源
|
|
||||||
const res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn');
|
|
||||||
|
|
||||||
// 返回绑定函数
|
|
||||||
return (res.runInAsyncScope.bind(res, fn, null) as ListenerCallback);
|
|
||||||
}
|
|
@@ -1,4 +1,4 @@
|
|||||||
import { normalize, SendMsgBase } from '@/onebot/action/msg/SendMsg';
|
import { ContextMode, normalize, ReturnDataType, SendMsgBase } from '@/onebot/action/msg/SendMsg';
|
||||||
import { OB11PostSendMsg } from '@/onebot/types';
|
import { OB11PostSendMsg } from '@/onebot/types';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
|
||||||
@@ -19,8 +19,14 @@ export class GoCQHTTPSendForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
|||||||
}
|
}
|
||||||
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
||||||
override actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
|
override actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
|
||||||
|
override async _handle(payload: OB11PostSendMsg): Promise<ReturnDataType> {
|
||||||
|
return this.base_handle(payload, ContextMode.Private);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
||||||
override actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
override actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||||
|
override async _handle(payload: OB11PostSendMsg): Promise<ReturnDataType> {
|
||||||
|
return this.base_handle(payload, ContextMode.Group);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,19 @@
|
|||||||
import { ContextMode, SendMsgBase } from '@/onebot/action/msg/SendMsg';
|
import { ContextMode, ReturnDataType, SendMsgBase } from '@/onebot/action/msg/SendMsg';
|
||||||
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
||||||
import { OB11PostSendMsg } from '@/onebot/types';
|
import { OB11PostSendMsg } from '@/onebot/types';
|
||||||
|
|
||||||
// 未检测参数
|
// 未检测参数
|
||||||
class SendGroupMsg extends SendMsgBase {
|
class SendGroupMsg extends SendMsgBase {
|
||||||
override actionName = ActionName.SendGroupMsg;
|
override actionName = ActionName.SendGroupMsg;
|
||||||
override contextMode: ContextMode = ContextMode.Group;
|
|
||||||
|
|
||||||
protected override async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
protected override async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||||
delete payload.user_id;
|
delete payload.user_id;
|
||||||
payload.message_type = 'group';
|
payload.message_type = 'group';
|
||||||
return super.check(payload);
|
return super.check(payload);
|
||||||
}
|
}
|
||||||
|
override async _handle(payload: OB11PostSendMsg): Promise<ReturnDataType> {
|
||||||
|
return this.base_handle(payload, ContextMode.Group);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SendGroupMsg;
|
export default SendGroupMsg;
|
||||||
|
@@ -104,8 +104,6 @@ function getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
|
export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
|
||||||
contextMode = ContextMode.Normal;
|
|
||||||
|
|
||||||
protected override async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
protected override async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||||
const messages = normalize(payload.message);
|
const messages = normalize(payload.message);
|
||||||
const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node);
|
const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node);
|
||||||
@@ -117,12 +115,13 @@ export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
return { valid: true };
|
return { valid: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
async _handle(payload: OB11PostSendMsg): Promise<ReturnDataType> {
|
async _handle(payload: OB11PostSendMsg): Promise<ReturnDataType> {
|
||||||
this.contextMode = ContextMode.Normal;
|
return this.base_handle(payload);
|
||||||
if (payload.message_type === 'group') this.contextMode = ContextMode.Group;
|
}
|
||||||
if (payload.message_type === 'private') this.contextMode = ContextMode.Private;
|
async base_handle(payload: OB11PostSendMsg, contextMode: ContextMode = ContextMode.Normal): Promise<ReturnDataType> {
|
||||||
const peer = await createContext(this.core, payload, this.contextMode);
|
if (payload.message_type === 'group') contextMode = ContextMode.Group;
|
||||||
|
if (payload.message_type === 'private') contextMode = ContextMode.Private;
|
||||||
|
const peer = await createContext(this.core, payload, contextMode);
|
||||||
|
|
||||||
const messages = normalize(
|
const messages = normalize(
|
||||||
payload.message,
|
payload.message,
|
||||||
|
@@ -1,16 +1,18 @@
|
|||||||
import { ContextMode, SendMsgBase } from './SendMsg';
|
import { ContextMode, ReturnDataType, SendMsgBase } from './SendMsg';
|
||||||
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
||||||
import { OB11PostSendMsg } from '@/onebot/types';
|
import { OB11PostSendMsg } from '@/onebot/types';
|
||||||
|
|
||||||
// 未检测参数
|
// 未检测参数
|
||||||
class SendPrivateMsg extends SendMsgBase {
|
class SendPrivateMsg extends SendMsgBase {
|
||||||
override actionName = ActionName.SendPrivateMsg;
|
override actionName = ActionName.SendPrivateMsg;
|
||||||
override contextMode: ContextMode = ContextMode.Private;
|
|
||||||
|
|
||||||
protected override async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
protected override async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||||
payload.message_type = 'private';
|
payload.message_type = 'private';
|
||||||
return super.check(payload);
|
return super.check(payload);
|
||||||
}
|
}
|
||||||
|
override async _handle(payload: OB11PostSendMsg): Promise<ReturnDataType> {
|
||||||
|
return this.base_handle(payload, ContextMode.Private);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SendPrivateMsg;
|
export default SendPrivateMsg;
|
||||||
|
@@ -2,4 +2,5 @@ import { EventType, OneBotEvent } from '@/onebot/event/OneBotEvent';
|
|||||||
|
|
||||||
export abstract class OB11BaseNoticeEvent extends OneBotEvent {
|
export abstract class OB11BaseNoticeEvent extends OneBotEvent {
|
||||||
post_type = EventType.NOTICE;
|
post_type = EventType.NOTICE;
|
||||||
|
abstract notice_type: string;
|
||||||
}
|
}
|
6
src/onebot/event/request/OB11BaseRequestEvent.ts
Normal file
6
src/onebot/event/request/OB11BaseRequestEvent.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { EventType, OneBotEvent } from '@/onebot/event/OneBotEvent';
|
||||||
|
|
||||||
|
export abstract class OB11BaseRequestEvent extends OneBotEvent {
|
||||||
|
readonly post_type = EventType.REQUEST;
|
||||||
|
abstract request_type: string;
|
||||||
|
}
|
@@ -1,10 +1,8 @@
|
|||||||
import { OB11BaseNoticeEvent } from '@/onebot/event/notice/OB11BaseNoticeEvent';
|
|
||||||
import { EventType } from '@/onebot/event/OneBotEvent';
|
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
|
import { OB11BaseRequestEvent } from './OB11BaseRequestEvent';
|
||||||
|
|
||||||
export class OB11FriendRequestEvent extends OB11BaseNoticeEvent {
|
export class OB11FriendRequestEvent extends OB11BaseRequestEvent {
|
||||||
override post_type = EventType.REQUEST;
|
override request_type = 'friend';
|
||||||
request_type = 'friend';
|
|
||||||
|
|
||||||
user_id: number;
|
user_id: number;
|
||||||
comment: string;
|
comment: string;
|
||||||
|
@@ -1,18 +1,18 @@
|
|||||||
import { OB11GroupNoticeEvent } from '@/onebot/event/notice/OB11GroupNoticeEvent';
|
|
||||||
import { EventType } from '@/onebot/event/OneBotEvent';
|
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
|
import { OB11BaseRequestEvent } from './OB11BaseRequestEvent';
|
||||||
|
|
||||||
export class OB11GroupRequestEvent extends OB11GroupNoticeEvent {
|
export class OB11GroupRequestEvent extends OB11BaseRequestEvent {
|
||||||
override post_type = EventType.REQUEST;
|
override readonly request_type = 'group' as const;
|
||||||
request_type = 'group';
|
|
||||||
|
|
||||||
override user_id: number;
|
group_id: number;
|
||||||
|
user_id: number;
|
||||||
comment: string;
|
comment: string;
|
||||||
flag: string;
|
flag: string;
|
||||||
sub_type: string;
|
sub_type: string;
|
||||||
|
|
||||||
constructor(core: NapCatCore, groupId: number, userId: number, sub_type: string, comment: string, flag: string) {
|
constructor(core: NapCatCore, groupId: number, userId: number, sub_type: string, comment: string, flag: string) {
|
||||||
super(core, groupId, userId);
|
super(core);
|
||||||
|
this.group_id = groupId;
|
||||||
this.user_id = userId;
|
this.user_id = userId;
|
||||||
this.sub_type = sub_type;
|
this.sub_type = sub_type;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
|
import rateLimit from 'express-rate-limit';
|
||||||
import {
|
import {
|
||||||
ListFilesHandler,
|
ListFilesHandler,
|
||||||
CreateDirHandler,
|
CreateDirHandler,
|
||||||
@@ -19,15 +20,15 @@ import {
|
|||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// const apiLimiter = rateLimit({
|
const apiLimiter = rateLimit({
|
||||||
// windowMs: 1 * 60 * 1000, // 1分钟内
|
windowMs: 1 * 60 * 1000, // 1分钟内
|
||||||
// max: 60, // 最大60个请求
|
max: 60, // 最大60个请求
|
||||||
// validate: {
|
validate: {
|
||||||
// xForwardedForHeader: false,
|
xForwardedForHeader: false,
|
||||||
// },
|
},
|
||||||
// });
|
});
|
||||||
|
|
||||||
// router.use(apiLimiter);
|
router.use(apiLimiter);
|
||||||
|
|
||||||
router.get('/list', ListFilesHandler);
|
router.get('/list', ListFilesHandler);
|
||||||
router.post('/mkdir', CreateDirHandler);
|
router.post('/mkdir', CreateDirHandler);
|
||||||
|
@@ -3,7 +3,6 @@ import { defineConfig, PluginOption, UserConfig } from 'vite';
|
|||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import nodeResolve from '@rollup/plugin-node-resolve';
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
||||||
import { builtinModules } from 'module';
|
import { builtinModules } from 'module';
|
||||||
import wasm from 'vite-plugin-wasm';
|
|
||||||
//依赖排除
|
//依赖排除
|
||||||
const external = [
|
const external = [
|
||||||
'silk-wasm',
|
'silk-wasm',
|
||||||
@@ -22,7 +21,6 @@ if (process.env.NAPCAT_BUILDSYS == 'linux') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const UniversalBaseConfigPlugin: PluginOption[] = [
|
const UniversalBaseConfigPlugin: PluginOption[] = [
|
||||||
wasm(),
|
|
||||||
cp({
|
cp({
|
||||||
targets: [
|
targets: [
|
||||||
{ src: './manifest.json', dest: 'dist' },
|
{ src: './manifest.json', dest: 'dist' },
|
||||||
@@ -46,7 +44,6 @@ const UniversalBaseConfigPlugin: PluginOption[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const FrameworkBaseConfigPlugin: PluginOption[] = [
|
const FrameworkBaseConfigPlugin: PluginOption[] = [
|
||||||
wasm(),
|
|
||||||
cp({
|
cp({
|
||||||
targets: [
|
targets: [
|
||||||
{ src: './manifest.json', dest: 'dist' },
|
{ src: './manifest.json', dest: 'dist' },
|
||||||
@@ -66,7 +63,6 @@ const FrameworkBaseConfigPlugin: PluginOption[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const ShellBaseConfigPlugin: PluginOption[] = [
|
const ShellBaseConfigPlugin: PluginOption[] = [
|
||||||
wasm(),
|
|
||||||
cp({
|
cp({
|
||||||
targets: [
|
targets: [
|
||||||
{ src: './src/native/packet', dest: 'dist/moehoo', flatten: false },
|
{ src: './src/native/packet', dest: 'dist/moehoo', flatten: false },
|
||||||
|
Reference in New Issue
Block a user