node-karin 0.12.0 → 0.12.2-5.pr.206.027f2f2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1029 -0
- package/default/comment/config.json +34 -0
- package/default/comment/friendDirect.json +10 -0
- package/default/comment/groupGuild.json +11 -0
- package/default/comment/server.json +17 -0
- package/default/config/adapter.json +28 -0
- package/default/config/config.json +47 -0
- package/default/config/groups.json +47 -0
- package/default/config/groups.yaml +70 -0
- package/default/config/pm2.json +16 -0
- package/default/config/privates.json +23 -0
- package/default/config/privates.yaml +31 -0
- package/default/config/redis.json +10 -0
- package/default/config/render.json +19 -0
- package/default/view/group.yaml +73 -0
- package/dist/index.d.ts +9869 -0
- package/dist/index.js +12643 -0
- package/dist/module/art-template.cjs +11 -0
- package/dist/module/art-template.d.ts +1 -0
- package/dist/module/axios.cjs +22 -0
- package/dist/module/axios.d.ts +2 -0
- package/dist/module/chalk.cjs +22 -0
- package/dist/module/chalk.d.ts +2 -0
- package/dist/module/chokidar.cjs +22 -0
- package/dist/module/chokidar.d.ts +2 -0
- package/dist/module/commander.cjs +35 -0
- package/dist/module/commander.d.ts +3 -0
- package/dist/module/commander.js +3 -0
- package/dist/module/dotenv.cjs +22 -0
- package/dist/module/dotenv.d.ts +2 -0
- package/dist/module/dotenv.js +2 -0
- package/dist/module/express.cjs +112 -0
- package/dist/module/express.d.ts +1 -0
- package/dist/module/express.js +1 -0
- package/dist/module/level.cjs +22 -0
- package/dist/module/level.d.ts +2 -0
- package/dist/module/lodash.cjs +11 -0
- package/dist/module/lodash.d.ts +1 -0
- package/dist/module/log4js.cjs +22 -0
- package/dist/module/log4js.d.ts +2 -0
- package/dist/module/moment.cjs +11 -0
- package/dist/module/moment.d.ts +1 -0
- package/dist/module/node-schedule.cjs +22 -0
- package/dist/module/node-schedule.d.ts +2 -0
- package/dist/module/redis.cjs +22 -0
- package/dist/module/redis.d.ts +2 -0
- package/dist/module/ws.cjs +28 -0
- package/dist/module/ws.d.ts +1 -0
- package/dist/module/ws.js +1 -0
- package/dist/module/yaml.cjs +22 -0
- package/dist/module/yaml.d.ts +2 -0
- package/dist/root.d.ts +40 -0
- package/dist/root.js +44 -0
- package/package.json +142 -128
- package/LICENSE +0 -674
- package/README.md +0 -56
- package/config/defSet/App.yaml +0 -42
- package/config/defSet/config.yaml +0 -65
- package/config/defSet/group.yaml +0 -56
- package/config/defSet/pm2.yaml +0 -21
- package/config/defSet/redis.yaml +0 -18
- package/config/defSet/server.yaml +0 -42
- package/config/view/group.yaml +0 -92
- package/lib/adapter/index.d.ts +0 -2
- package/lib/adapter/index.js +0 -2
- package/lib/adapter/input/index.d.ts +0 -78
- package/lib/adapter/input/index.js +0 -205
- package/lib/adapter/onebot/11/convert.d.ts +0 -12
- package/lib/adapter/onebot/11/convert.js +0 -167
- package/lib/adapter/onebot/11/event.d.ts +0 -25
- package/lib/adapter/onebot/11/event.js +0 -442
- package/lib/adapter/onebot/11/index.d.ts +0 -508
- package/lib/adapter/onebot/11/index.js +0 -1047
- package/lib/cli/index.d.ts +0 -92
- package/lib/cli/index.js +0 -307
- package/lib/cli/init.d.ts +0 -2
- package/lib/cli/init.js +0 -22
- package/lib/cli/karin.d.ts +0 -2
- package/lib/cli/karin.js +0 -16
- package/lib/cli/pkg.d.ts +0 -4
- package/lib/cli/pkg.js +0 -14
- package/lib/cli/start.d.ts +0 -1
- package/lib/cli/start.js +0 -8
- package/lib/core/index.d.ts +0 -10
- package/lib/core/index.js +0 -10
- package/lib/core/init/config.d.ts +0 -43
- package/lib/core/init/config.js +0 -201
- package/lib/core/init/dir.d.ts +0 -4
- package/lib/core/init/dir.js +0 -7
- package/lib/core/init/init.d.ts +0 -1
- package/lib/core/init/init.js +0 -47
- package/lib/core/karin/karin.d.ts +0 -198
- package/lib/core/karin/karin.js +0 -226
- package/lib/core/listener/listener.d.ts +0 -145
- package/lib/core/listener/listener.js +0 -235
- package/lib/core/plugin/base.d.ts +0 -156
- package/lib/core/plugin/base.js +0 -131
- package/lib/core/plugin/loader.d.ts +0 -141
- package/lib/core/plugin/loader.js +0 -618
- package/lib/core/process/process.d.ts +0 -18
- package/lib/core/process/process.js +0 -96
- package/lib/core/server/server.d.ts +0 -25
- package/lib/core/server/server.js +0 -295
- package/lib/db/index.d.ts +0 -2
- package/lib/db/index.js +0 -2
- package/lib/db/level/level.d.ts +0 -19
- package/lib/db/level/level.js +0 -36
- package/lib/db/redis/redis.d.ts +0 -2
- package/lib/db/redis/redis.js +0 -135
- package/lib/db/redis/redis_level.d.ts +0 -112
- package/lib/db/redis/redis_level.js +0 -281
- package/lib/event/handler/base.d.ts +0 -42
- package/lib/event/handler/base.js +0 -200
- package/lib/event/handler/message.d.ts +0 -29
- package/lib/event/handler/message.js +0 -307
- package/lib/event/handler/notice.d.ts +0 -18
- package/lib/event/handler/notice.js +0 -214
- package/lib/event/handler/request.d.ts +0 -18
- package/lib/event/handler/request.js +0 -115
- package/lib/event/handler/review.d.ts +0 -55
- package/lib/event/handler/review.js +0 -386
- package/lib/event/index.d.ts +0 -5
- package/lib/event/index.js +0 -5
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -8
- package/lib/modules/art-template.d.ts +0 -1
- package/lib/modules/axios.d.ts +0 -2
- package/lib/modules/chalk.d.ts +0 -2
- package/lib/modules/chokidar.d.ts +0 -2
- package/lib/modules/commander.d.ts +0 -2
- package/lib/modules/commander.js +0 -2
- package/lib/modules/express.d.ts +0 -3
- package/lib/modules/express.js +0 -3
- package/lib/modules/level.d.ts +0 -2
- package/lib/modules/lodash.d.ts +0 -1
- package/lib/modules/log4js.d.ts +0 -2
- package/lib/modules/moment.d.ts +0 -1
- package/lib/modules/node-schedule.d.ts +0 -2
- package/lib/modules/redis.d.ts +0 -2
- package/lib/modules/ws.d.ts +0 -3
- package/lib/modules/ws.js +0 -3
- package/lib/modules/yaml.d.ts +0 -2
- package/lib/modules.d.ts +0 -15
- package/lib/modules.js +0 -15
- package/lib/render/app.d.ts +0 -56
- package/lib/render/app.js +0 -120
- package/lib/render/base.d.ts +0 -30
- package/lib/render/base.js +0 -69
- package/lib/render/client.d.ts +0 -41
- package/lib/render/client.js +0 -238
- package/lib/render/http.d.ts +0 -19
- package/lib/render/http.js +0 -50
- package/lib/render/index.d.ts +0 -6
- package/lib/render/index.js +0 -6
- package/lib/render/server.d.ts +0 -25
- package/lib/render/server.js +0 -101
- package/lib/render/wormhole.d.ts +0 -1
- package/lib/render/wormhole.js +0 -156
- package/lib/types/adapter/api.d.ts +0 -399
- package/lib/types/adapter/api.js +0 -1
- package/lib/types/adapter/base.d.ts +0 -560
- package/lib/types/adapter/base.js +0 -1
- package/lib/types/config/config.d.ts +0 -379
- package/lib/types/config/config.js +0 -1
- package/lib/types/element/element.d.ts +0 -565
- package/lib/types/element/element.js +0 -1
- package/lib/types/element/qqbot.d.ts +0 -123
- package/lib/types/element/qqbot.js +0 -1
- package/lib/types/event/contact.d.ts +0 -28
- package/lib/types/event/contact.js +0 -1
- package/lib/types/event/event.d.ts +0 -305
- package/lib/types/event/event.js +0 -1
- package/lib/types/event/index.d.ts +0 -12
- package/lib/types/event/index.js +0 -7
- package/lib/types/event/message.d.ts +0 -109
- package/lib/types/event/message.js +0 -74
- package/lib/types/event/notice.d.ts +0 -513
- package/lib/types/event/notice.js +0 -52
- package/lib/types/event/reply.d.ts +0 -50
- package/lib/types/event/reply.js +0 -1
- package/lib/types/event/request.d.ts +0 -126
- package/lib/types/event/request.js +0 -52
- package/lib/types/event/sender.d.ts +0 -44
- package/lib/types/event/sender.js +0 -1
- package/lib/types/index.d.ts +0 -13
- package/lib/types/index.js +0 -13
- package/lib/types/logger/logger.d.ts +0 -110
- package/lib/types/logger/logger.js +0 -1
- package/lib/types/onebot11/api.d.ts +0 -53
- package/lib/types/onebot11/api.js +0 -1
- package/lib/types/onebot11/event.d.ts +0 -619
- package/lib/types/onebot11/event.js +0 -2
- package/lib/types/onebot11/index.d.ts +0 -6
- package/lib/types/onebot11/index.js +0 -6
- package/lib/types/onebot11/params.d.ts +0 -609
- package/lib/types/onebot11/params.js +0 -1
- package/lib/types/onebot11/response.d.ts +0 -516
- package/lib/types/onebot11/response.js +0 -1
- package/lib/types/onebot11/segment.d.ts +0 -269
- package/lib/types/onebot11/segment.js +0 -1
- package/lib/types/onebot11/sender.d.ts +0 -59
- package/lib/types/onebot11/sender.js +0 -1
- package/lib/types/plugin/app.d.ts +0 -71
- package/lib/types/plugin/app.js +0 -1
- package/lib/types/plugin/plugin.d.ts +0 -473
- package/lib/types/plugin/plugin.js +0 -1
- package/lib/types/render/render.d.ts +0 -118
- package/lib/types/render/render.js +0 -1
- package/lib/types/type/global.d.ts +0 -25
- package/lib/types/type/global.js +0 -1
- package/lib/utils/common/common.d.ts +0 -236
- package/lib/utils/common/common.js +0 -708
- package/lib/utils/config/config.d.ts +0 -193
- package/lib/utils/config/config.js +0 -328
- package/lib/utils/config/updateVersion.d.ts +0 -33
- package/lib/utils/config/updateVersion.js +0 -145
- package/lib/utils/config/yamlEditor.d.ts +0 -101
- package/lib/utils/config/yamlEditor.js +0 -330
- package/lib/utils/core/handler.d.ts +0 -18
- package/lib/utils/core/handler.js +0 -46
- package/lib/utils/core/logger.d.ts +0 -3
- package/lib/utils/core/logger.js +0 -105
- package/lib/utils/core/segment.d.ts +0 -279
- package/lib/utils/core/segment.js +0 -451
- package/lib/utils/index.d.ts +0 -13
- package/lib/utils/index.js +0 -13
- package/lib/utils/tools/button.d.ts +0 -2
- package/lib/utils/tools/button.js +0 -27
- package/lib/utils/tools/exec.d.ts +0 -20
- package/lib/utils/tools/exec.js +0 -54
- package/lib/utils/tools/ffmpeg.d.ts +0 -12
- package/lib/utils/tools/ffmpeg.js +0 -25
- package/lib/utils/tools/restart.d.ts +0 -15
- package/lib/utils/tools/restart.js +0 -39
- package/lib/utils/tools/stop.d.ts +0 -7
- package/lib/utils/tools/stop.js +0 -13
- package/lib/utils/tools/update.d.ts +0 -67
- package/lib/utils/tools/update.js +0 -151
- /package/{config → default}/view/App.yaml +0 -0
- /package/{config → default}/view/config.yaml +0 -0
- /package/{config → default}/view/pm2.yaml +0 -0
- /package/{config → default}/view/redis.yaml +0 -0
- /package/{config → default}/view/server.yaml +0 -0
- /package/{lib/modules → dist/module}/art-template.js +0 -0
- /package/{lib/modules → dist/module}/axios.js +0 -0
- /package/{lib/modules → dist/module}/chalk.js +0 -0
- /package/{lib/modules → dist/module}/chokidar.js +0 -0
- /package/{lib/modules → dist/module}/level.js +0 -0
- /package/{lib/modules → dist/module}/lodash.js +0 -0
- /package/{lib/modules → dist/module}/log4js.js +0 -0
- /package/{lib/modules → dist/module}/moment.js +0 -0
- /package/{lib/modules → dist/module}/node-schedule.js +0 -0
- /package/{lib/modules → dist/module}/redis.js +0 -0
- /package/{lib/modules → dist/module}/yaml.js +0 -0
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { Contact, KarinElement, KarinAdapter, KarinMessage, KarinNoticeType, KarinRequestType, KarinMessageType } from '../../types/index.js';
|
|
3
|
-
type AdapterType = KarinAdapter['adapter']['type'];
|
|
4
|
-
type onAdapter = {
|
|
5
|
-
type: AdapterType;
|
|
6
|
-
adapter: new () => KarinAdapter;
|
|
7
|
-
path?: string;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* 产生事件映射
|
|
11
|
-
*/
|
|
12
|
-
export interface EmittEventMap {
|
|
13
|
-
'karin:count:send': number;
|
|
14
|
-
'karin:count:fnc': string;
|
|
15
|
-
error: any;
|
|
16
|
-
adapter: onAdapter;
|
|
17
|
-
'adapter.message': KarinMessageType;
|
|
18
|
-
'adapter.notice': KarinNoticeType;
|
|
19
|
-
'adapter.request': KarinRequestType;
|
|
20
|
-
message: KarinMessageType;
|
|
21
|
-
notice: KarinNoticeType;
|
|
22
|
-
request: KarinRequestType;
|
|
23
|
-
'plugin.watch': undefined;
|
|
24
|
-
'restart.grpc': undefined;
|
|
25
|
-
'restart.http': undefined;
|
|
26
|
-
}
|
|
27
|
-
/** 上下文 */
|
|
28
|
-
type ContextEvents = {
|
|
29
|
-
[K in `ctx:${string}`]: (e: KarinMessage) => void;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* 监听事件映射
|
|
33
|
-
*/
|
|
34
|
-
export interface OnEventMap extends ContextEvents {
|
|
35
|
-
'karin:count:send': (count: number) => void;
|
|
36
|
-
'karin:count:fnc': (fnc: string) => void;
|
|
37
|
-
error: (error: any) => void;
|
|
38
|
-
adapter: (data: onAdapter) => void;
|
|
39
|
-
'adapter.message': (data: KarinMessageType) => void;
|
|
40
|
-
'adapter.notice': (data: KarinNoticeType) => void;
|
|
41
|
-
'adapter.request': (data: KarinRequestType) => void;
|
|
42
|
-
message: (data: KarinMessageType) => void;
|
|
43
|
-
notice: (data: KarinNoticeType) => void;
|
|
44
|
-
request: (data: KarinRequestType) => void;
|
|
45
|
-
'plugin.watch': undefined;
|
|
46
|
-
'restart.grpc': undefined;
|
|
47
|
-
'restart.http': undefined;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* 监听器实例
|
|
51
|
-
*/
|
|
52
|
-
export declare class Listeners extends EventEmitter {
|
|
53
|
-
#private;
|
|
54
|
-
/** 框架名称 */
|
|
55
|
-
name: string;
|
|
56
|
-
/** Bot列表 */
|
|
57
|
-
list: Array<{
|
|
58
|
-
index: number;
|
|
59
|
-
type: AdapterType;
|
|
60
|
-
bot: KarinAdapter;
|
|
61
|
-
}>;
|
|
62
|
-
/** 适配器列表 */
|
|
63
|
-
adapter: Array<{
|
|
64
|
-
type: AdapterType;
|
|
65
|
-
adapter: new () => KarinAdapter;
|
|
66
|
-
path: string;
|
|
67
|
-
}>;
|
|
68
|
-
constructor();
|
|
69
|
-
on<K extends keyof OnEventMap>(event: K, listener: OnEventMap[K]): this;
|
|
70
|
-
on(event: string, listener: (...args: any[]) => void): this;
|
|
71
|
-
emit<K extends keyof EmittEventMap>(event: K, ...args: Parameters<EmittEventMap[K]>): boolean;
|
|
72
|
-
emit(event: string | symbol, ...args: any[]): boolean;
|
|
73
|
-
/**
|
|
74
|
-
* 注册Bot 返回索引id
|
|
75
|
-
*/
|
|
76
|
-
addBot(data: {
|
|
77
|
-
bot: KarinAdapter;
|
|
78
|
-
type: AdapterType;
|
|
79
|
-
}): number | false;
|
|
80
|
-
/**
|
|
81
|
-
* 卸载Bot
|
|
82
|
-
* @param index - Bot的索引id
|
|
83
|
-
*/
|
|
84
|
-
delBot(index: number): void;
|
|
85
|
-
/**
|
|
86
|
-
* 通过Bot uid 获取Bot
|
|
87
|
-
* @param uid - Bot的uid 未传入则返回第一个Bot
|
|
88
|
-
*/
|
|
89
|
-
getBot(uid?: string): KarinAdapter | undefined;
|
|
90
|
-
/**
|
|
91
|
-
* 根据索引获取Bot
|
|
92
|
-
* @param index - Bot的索引id
|
|
93
|
-
*/
|
|
94
|
-
getBotByIndex(index: number): KarinAdapter;
|
|
95
|
-
/**
|
|
96
|
-
* 获取当前已注册Bot数量
|
|
97
|
-
*/
|
|
98
|
-
getBotCount(): number;
|
|
99
|
-
/**
|
|
100
|
-
* 获取所有Bot列表
|
|
101
|
-
* @param isIndex - 是否返回包含的索引列表 默认返回Bot实例列表
|
|
102
|
-
*/
|
|
103
|
-
getBotAll(isIndex?: boolean): KarinAdapter[] | {
|
|
104
|
-
index: number;
|
|
105
|
-
bot: KarinAdapter;
|
|
106
|
-
}[];
|
|
107
|
-
/**
|
|
108
|
-
* 注册适配器
|
|
109
|
-
* @param data - 适配器信息
|
|
110
|
-
* @param data.type - 适配器类型
|
|
111
|
-
* @param data.adapter - 适配器实例
|
|
112
|
-
* @param data.path - 适配器路径
|
|
113
|
-
*/
|
|
114
|
-
addAdapter(data: onAdapter): void;
|
|
115
|
-
/**
|
|
116
|
-
* 通过path获取适配器 仅适用于反向WS适配器
|
|
117
|
-
* @param path - 适配器路径
|
|
118
|
-
*/
|
|
119
|
-
getAdapter(path?: string): (new () => KarinAdapter) | undefined;
|
|
120
|
-
/**
|
|
121
|
-
* 获取适配器列表
|
|
122
|
-
* @param isType - 是否返回包含的类型列表 默认返回适配器实例列表
|
|
123
|
-
*/
|
|
124
|
-
getAdapterAll(isType?: boolean): {
|
|
125
|
-
type: AdapterType;
|
|
126
|
-
adapter: new () => KarinAdapter;
|
|
127
|
-
path: string;
|
|
128
|
-
}[] | (new () => KarinAdapter)[];
|
|
129
|
-
/**
|
|
130
|
-
* 发送主动消息
|
|
131
|
-
* @param uid - Bot的uid
|
|
132
|
-
* @param contact - 目标信息
|
|
133
|
-
* @param elements - 消息内容
|
|
134
|
-
* @param options - 消息选项
|
|
135
|
-
* @param options.recallMsg - 发送成功后撤回消息时间
|
|
136
|
-
* @param options.retry_count - 重试次数
|
|
137
|
-
*/
|
|
138
|
-
sendMsg(uid: string, contact: Contact, elements: Array<KarinElement>, options?: {
|
|
139
|
-
recallMsg?: number;
|
|
140
|
-
retry_count?: number;
|
|
141
|
-
}): Promise<{
|
|
142
|
-
message_id: string;
|
|
143
|
-
}>;
|
|
144
|
-
}
|
|
145
|
-
export {};
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { level } from '../../db/index.js';
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
|
-
import { pluginLoader } from '../plugin/loader.js';
|
|
4
|
-
import { common, logger, config, segment } from '../../utils/index.js';
|
|
5
|
-
import { MessageHandler, NoticeHandler, RequestHandler } from '../../event/index.js';
|
|
6
|
-
/**
|
|
7
|
-
* 监听器实例
|
|
8
|
-
*/
|
|
9
|
-
export class Listeners extends EventEmitter {
|
|
10
|
-
/** 框架名称 */
|
|
11
|
-
name;
|
|
12
|
-
/** Bot列表 */
|
|
13
|
-
list;
|
|
14
|
-
/** 适配器列表 */
|
|
15
|
-
adapter;
|
|
16
|
-
/** Bot自增索引 */
|
|
17
|
-
#index;
|
|
18
|
-
/** 是否启动 */
|
|
19
|
-
#start;
|
|
20
|
-
constructor() {
|
|
21
|
-
super();
|
|
22
|
-
this.#index = 0;
|
|
23
|
-
this.name = 'Karin';
|
|
24
|
-
this.list = [];
|
|
25
|
-
this.adapter = [];
|
|
26
|
-
this.on('error', data => logger.error(data));
|
|
27
|
-
this.on('adapter', data => this.addAdapter(data));
|
|
28
|
-
this.on('adapter.message', data => new MessageHandler(data));
|
|
29
|
-
this.on('adapter.notice', data => new NoticeHandler(data));
|
|
30
|
-
this.on('adapter.request', data => new RequestHandler(data));
|
|
31
|
-
this.#start = false;
|
|
32
|
-
}
|
|
33
|
-
on(event, listener) {
|
|
34
|
-
return super.on(event, listener);
|
|
35
|
-
}
|
|
36
|
-
emit(event, ...args) {
|
|
37
|
-
return super.emit(event, ...args);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 注册Bot 返回索引id
|
|
41
|
-
*/
|
|
42
|
-
addBot(data) {
|
|
43
|
-
this.#index++;
|
|
44
|
-
const index = this.#index;
|
|
45
|
-
if (!data.bot) {
|
|
46
|
-
logger.error('[Bot管理][注册] 注册失败: Bot实例不能为空', JSON.stringify(data));
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
this.list.push({ index, type: data.type, bot: data.bot });
|
|
50
|
-
logger.info(`[机器人][注册][${data.type}] ` + logger.green(`[account:${data.bot.account.uid || data.bot.account.uin}(${data.bot.account.name})]`));
|
|
51
|
-
this.#online(data.bot.account.uid || data.bot.account.uin);
|
|
52
|
-
logger.debug('注册', this.list);
|
|
53
|
-
return index;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* 发送上线通知
|
|
57
|
-
*/
|
|
58
|
-
async #online(uid) {
|
|
59
|
-
/** 重启 */
|
|
60
|
-
const key = `karin:restart:${uid}`;
|
|
61
|
-
const options = await level.get(key);
|
|
62
|
-
if (!options)
|
|
63
|
-
return;
|
|
64
|
-
const { id, contact, time, message_id } = options;
|
|
65
|
-
/** 重启花费时间 保留2位小数 */
|
|
66
|
-
const restartTime = ((Date.now() - time) / 1000).toFixed(2);
|
|
67
|
-
/** 超过2分钟不发 */
|
|
68
|
-
if (Number(restartTime) > 120) {
|
|
69
|
-
await level.del(key);
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
const element = [
|
|
73
|
-
segment.reply(message_id),
|
|
74
|
-
segment.text(`\nKarin 重启成功:${restartTime}秒`),
|
|
75
|
-
];
|
|
76
|
-
await this.sendMsg(id, contact, element);
|
|
77
|
-
await level.del(key);
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 卸载Bot
|
|
82
|
-
* @param index - Bot的索引id
|
|
83
|
-
*/
|
|
84
|
-
delBot(index) {
|
|
85
|
-
this.list = this.list.filter(item => item.index !== index);
|
|
86
|
-
logger.debug('[机器人][卸载] ', this.list);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* 通过Bot uid 获取Bot
|
|
90
|
-
* @param uid - Bot的uid 未传入则返回第一个Bot
|
|
91
|
-
*/
|
|
92
|
-
getBot(uid = '') {
|
|
93
|
-
uid = String(uid);
|
|
94
|
-
if (this.list.length === 0) {
|
|
95
|
-
logger.error('[Bot管理][UID] 当前Bot列表为空');
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
if (!uid)
|
|
99
|
-
return this.list[0].bot;
|
|
100
|
-
const index = this.list.findIndex(item => String(item.bot.account.uid) === uid);
|
|
101
|
-
if (index === -1) {
|
|
102
|
-
logger.error('[Bot管理][UID] 无法找到对应的 Bot 实例');
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
return this.list[index].bot;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* 根据索引获取Bot
|
|
109
|
-
* @param index - Bot的索引id
|
|
110
|
-
*/
|
|
111
|
-
getBotByIndex(index) {
|
|
112
|
-
index = this.list.findIndex(item => item.index === index);
|
|
113
|
-
if (index === -1) {
|
|
114
|
-
throw new Error('[Bot管理][索引] 无法找到对应的 Bot 实例');
|
|
115
|
-
}
|
|
116
|
-
return this.list[index].bot;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* 获取当前已注册Bot数量
|
|
120
|
-
*/
|
|
121
|
-
getBotCount() {
|
|
122
|
-
return this.list.length;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* 获取所有Bot列表
|
|
126
|
-
* @param isIndex - 是否返回包含的索引列表 默认返回Bot实例列表
|
|
127
|
-
*/
|
|
128
|
-
getBotAll(isIndex = false) {
|
|
129
|
-
if (isIndex)
|
|
130
|
-
return this.list;
|
|
131
|
-
return this.list.map(item => item.bot);
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* 注册适配器
|
|
135
|
-
* @param data - 适配器信息
|
|
136
|
-
* @param data.type - 适配器类型
|
|
137
|
-
* @param data.adapter - 适配器实例
|
|
138
|
-
* @param data.path - 适配器路径
|
|
139
|
-
*/
|
|
140
|
-
addAdapter(data) {
|
|
141
|
-
let path = data.path || '无';
|
|
142
|
-
if (path && data.type !== 'grpc')
|
|
143
|
-
path = `ws://127.0.0.1:${config.Server.http.port}${data.path}`;
|
|
144
|
-
path = logger.green(path);
|
|
145
|
-
logger.info(`[适配器][注册][${data.type}]: ` + path);
|
|
146
|
-
const adapter = { type: data.type, adapter: data.adapter, path: '' };
|
|
147
|
-
if (data.path)
|
|
148
|
-
adapter.path = data.path;
|
|
149
|
-
this.adapter.push(adapter);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* 通过path获取适配器 仅适用于反向WS适配器
|
|
153
|
-
* @param path - 适配器路径
|
|
154
|
-
*/
|
|
155
|
-
getAdapter(path = '') {
|
|
156
|
-
const index = this.adapter.findIndex(item => item?.path === path);
|
|
157
|
-
if (index === -1) {
|
|
158
|
-
logger.error('[适配器管理] 无法找到对应的适配器实例');
|
|
159
|
-
return undefined;
|
|
160
|
-
}
|
|
161
|
-
return this.adapter[index].adapter;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* 获取适配器列表
|
|
165
|
-
* @param isType - 是否返回包含的类型列表 默认返回适配器实例列表
|
|
166
|
-
*/
|
|
167
|
-
getAdapterAll(isType = false) {
|
|
168
|
-
if (isType)
|
|
169
|
-
return this.adapter;
|
|
170
|
-
return this.adapter.map(item => item.adapter);
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* 发送主动消息
|
|
174
|
-
* @param uid - Bot的uid
|
|
175
|
-
* @param contact - 目标信息
|
|
176
|
-
* @param elements - 消息内容
|
|
177
|
-
* @param options - 消息选项
|
|
178
|
-
* @param options.recallMsg - 发送成功后撤回消息时间
|
|
179
|
-
* @param options.retry_count - 重试次数
|
|
180
|
-
*/
|
|
181
|
-
async sendMsg(uid, contact, elements, options = { recallMsg: 0, retry_count: 1 }) {
|
|
182
|
-
/** 结果 */
|
|
183
|
-
let result = {};
|
|
184
|
-
/** 先调用中间件 */
|
|
185
|
-
for (const info of pluginLoader.use.sendMsg) {
|
|
186
|
-
try {
|
|
187
|
-
let next = false;
|
|
188
|
-
let exit = false;
|
|
189
|
-
const nextFn = () => { next = true; };
|
|
190
|
-
const exitFn = () => { exit = true; };
|
|
191
|
-
await info.fn(uid, contact, elements, nextFn, exitFn);
|
|
192
|
-
if (exit) {
|
|
193
|
-
const plugin = pluginLoader.plugin.get(info.key);
|
|
194
|
-
logger.debug(`[消息中间件][${plugin.plugin}][${plugin.file}] 主动操作退出`);
|
|
195
|
-
return result;
|
|
196
|
-
}
|
|
197
|
-
if (!next)
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
catch (e) {
|
|
201
|
-
logger.error('[消息中间件] 调用失败,已跳过');
|
|
202
|
-
logger.error(e);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
const bot = this.getBot(uid);
|
|
206
|
-
if (!bot)
|
|
207
|
-
throw new Error('发送消息失败: 未找到对应Bot实例');
|
|
208
|
-
const { recallMsg, retry_count } = options;
|
|
209
|
-
/** 标准化 */
|
|
210
|
-
const NewElements = common.makeMessage(elements);
|
|
211
|
-
const reply_log = common.makeMessageLog(NewElements);
|
|
212
|
-
const self_id = bot.account.uid || bot.account.uin;
|
|
213
|
-
if (contact.scene === 'group') {
|
|
214
|
-
logger.bot('info', self_id, `${logger.green('Send Proactive Group')} ${contact.peer}: ${reply_log}`);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
logger.bot('info', self_id, `${logger.green('Send Proactive private')} ${contact.peer}: ${reply_log}`);
|
|
218
|
-
}
|
|
219
|
-
try {
|
|
220
|
-
this.emit('karin:count:send', 1);
|
|
221
|
-
/** 取结果 */
|
|
222
|
-
result = await bot.SendMessage(contact, NewElements, retry_count);
|
|
223
|
-
logger.bot('debug', self_id, `主动消息结果:${JSON.stringify(result, null, 2)}`);
|
|
224
|
-
}
|
|
225
|
-
catch (error) {
|
|
226
|
-
logger.bot('error', self_id, `主动消息发送失败:${reply_log}`);
|
|
227
|
-
logger.bot('error', self_id, error);
|
|
228
|
-
}
|
|
229
|
-
/** 快速撤回 */
|
|
230
|
-
if (recallMsg && bot.RecallMessage && recallMsg > 0 && result?.message_id) {
|
|
231
|
-
setTimeout(() => bot.RecallMessage(contact, result.message_id), recallMsg * 1000);
|
|
232
|
-
}
|
|
233
|
-
return result;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { PluginType, KarinElement, NodeElement, stateArrType, KarinNoticeType, KarinRequestType, ReplyReturn, EType } from '../../types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* 插件基类
|
|
4
|
-
*/
|
|
5
|
-
export declare class Plugin implements PluginType {
|
|
6
|
-
/**
|
|
7
|
-
* @param name - 插件名称
|
|
8
|
-
*/
|
|
9
|
-
name: PluginType['name'];
|
|
10
|
-
/**
|
|
11
|
-
* @param desc - 插件描述
|
|
12
|
-
*/
|
|
13
|
-
desc: PluginType['desc'];
|
|
14
|
-
/**
|
|
15
|
-
* @param event - 监听事件 仅支持消息事件 其他事件请使用accept
|
|
16
|
-
*/
|
|
17
|
-
event: PluginType['event'];
|
|
18
|
-
/**
|
|
19
|
-
* @param priority - 优先级 默认10000
|
|
20
|
-
*/
|
|
21
|
-
priority: PluginType['priority'];
|
|
22
|
-
/**
|
|
23
|
-
* @param task - 定时任务 即将废弃 请使用karin.task
|
|
24
|
-
* @deprecated
|
|
25
|
-
*/
|
|
26
|
-
task: PluginType['task'];
|
|
27
|
-
/**
|
|
28
|
-
* @param rule - 命令规则
|
|
29
|
-
*/
|
|
30
|
-
rule: PluginType['rule'];
|
|
31
|
-
/**
|
|
32
|
-
* @param handler - handler 已废弃 请使用karin.handler
|
|
33
|
-
* @deprecated
|
|
34
|
-
*/
|
|
35
|
-
handler: PluginType['handler'];
|
|
36
|
-
/**
|
|
37
|
-
* @param userId - 用户ID 一般上下文使用
|
|
38
|
-
*/
|
|
39
|
-
userId?: PluginType['userId'];
|
|
40
|
-
/**
|
|
41
|
-
* @param timeout - 上下文超时
|
|
42
|
-
*/
|
|
43
|
-
timeout: PluginType['timeout'];
|
|
44
|
-
constructor({ name, desc, event, priority, task, rule, handler, }: {
|
|
45
|
-
/**
|
|
46
|
-
* - 插件名称
|
|
47
|
-
*/
|
|
48
|
-
name: string;
|
|
49
|
-
/**
|
|
50
|
-
* - 插件描述 没有则默认为插件名称
|
|
51
|
-
*/
|
|
52
|
-
desc?: string;
|
|
53
|
-
/**
|
|
54
|
-
* - 监听事件 默认为message
|
|
55
|
-
*/
|
|
56
|
-
event?: PluginType['event'];
|
|
57
|
-
/**
|
|
58
|
-
* - 优先级 默认为10000
|
|
59
|
-
*/
|
|
60
|
-
priority?: PluginType['priority'];
|
|
61
|
-
/**
|
|
62
|
-
* - 定时任务 即将废弃 请使用karin.task
|
|
63
|
-
* @deprecated
|
|
64
|
-
*/
|
|
65
|
-
task?: PluginType['task'];
|
|
66
|
-
/**
|
|
67
|
-
* - 命令规则
|
|
68
|
-
*/
|
|
69
|
-
rule?: PluginType['rule'];
|
|
70
|
-
/**
|
|
71
|
-
* - handler 已废弃 请使用karin.handler
|
|
72
|
-
* @deprecated
|
|
73
|
-
*/
|
|
74
|
-
handler?: PluginType['handler'];
|
|
75
|
-
});
|
|
76
|
-
/**
|
|
77
|
-
* - 快速回复
|
|
78
|
-
*/
|
|
79
|
-
reply(msg?: string | KarinElement | Array<KarinElement | string>, options?: {
|
|
80
|
-
/**
|
|
81
|
-
* @param at - 是否at用户
|
|
82
|
-
* @default false
|
|
83
|
-
*/
|
|
84
|
-
at?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* @param reply - 是否引用回复
|
|
87
|
-
* @default false
|
|
88
|
-
*/
|
|
89
|
-
reply?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* @param recallMsg - 群聊是否撤回消息,0-120秒,0不撤回
|
|
92
|
-
* @default 0
|
|
93
|
-
*/
|
|
94
|
-
recallMsg?: number;
|
|
95
|
-
/**
|
|
96
|
-
* @param button - 是否使用按钮
|
|
97
|
-
* @default false
|
|
98
|
-
*/
|
|
99
|
-
button?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* @param retry_count - 重试次数
|
|
102
|
-
* @default 1
|
|
103
|
-
*/
|
|
104
|
-
retry_count?: number;
|
|
105
|
-
}): Promise<ReplyReturn>;
|
|
106
|
-
/**
|
|
107
|
-
* - 快速回复合并转发
|
|
108
|
-
*/
|
|
109
|
-
replyForward(msg: NodeElement[]): Promise<{
|
|
110
|
-
message_id: string;
|
|
111
|
-
}>;
|
|
112
|
-
/**
|
|
113
|
-
* - 构建上下文键
|
|
114
|
-
*/
|
|
115
|
-
conKey(): string;
|
|
116
|
-
/**
|
|
117
|
-
* 设置上下文状态
|
|
118
|
-
*/
|
|
119
|
-
setContext(
|
|
120
|
-
/**
|
|
121
|
-
* @param fnc - 执行方法
|
|
122
|
-
*/
|
|
123
|
-
fnc: string | Function,
|
|
124
|
-
/**
|
|
125
|
-
* @param reply - 超时后是否回复
|
|
126
|
-
*/
|
|
127
|
-
reply?: boolean,
|
|
128
|
-
/**
|
|
129
|
-
* @param time - 超时时间,默认120秒
|
|
130
|
-
*/
|
|
131
|
-
time?: number): void;
|
|
132
|
-
/**
|
|
133
|
-
* 获取上下文状态
|
|
134
|
-
*/
|
|
135
|
-
getContext(): stateArrType[string];
|
|
136
|
-
/**
|
|
137
|
-
* 清除上下文状态
|
|
138
|
-
*/
|
|
139
|
-
finish(): void;
|
|
140
|
-
e: EType<this>;
|
|
141
|
-
replyCallback: PluginType['replyCallback'];
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* 上下文状态
|
|
145
|
-
*/
|
|
146
|
-
export declare const stateArr: stateArrType;
|
|
147
|
-
/**
|
|
148
|
-
* 通知事件 插件类型
|
|
149
|
-
*/
|
|
150
|
-
export interface ExtendedPlugin extends Plugin {
|
|
151
|
-
accept: (e: KarinNoticeType | KarinRequestType) => Promise<void>;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* @description 即将废弃,请使用 `Plugin`
|
|
155
|
-
*/
|
|
156
|
-
export declare const plugin: typeof Plugin;
|
package/lib/core/plugin/base.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 插件基类
|
|
3
|
-
*/
|
|
4
|
-
export class Plugin {
|
|
5
|
-
/**
|
|
6
|
-
* @param name - 插件名称
|
|
7
|
-
*/
|
|
8
|
-
name;
|
|
9
|
-
/**
|
|
10
|
-
* @param desc - 插件描述
|
|
11
|
-
*/
|
|
12
|
-
desc;
|
|
13
|
-
/**
|
|
14
|
-
* @param event - 监听事件 仅支持消息事件 其他事件请使用accept
|
|
15
|
-
*/
|
|
16
|
-
event;
|
|
17
|
-
/**
|
|
18
|
-
* @param priority - 优先级 默认10000
|
|
19
|
-
*/
|
|
20
|
-
priority;
|
|
21
|
-
/**
|
|
22
|
-
* @param task - 定时任务 即将废弃 请使用karin.task
|
|
23
|
-
* @deprecated
|
|
24
|
-
*/
|
|
25
|
-
task;
|
|
26
|
-
/**
|
|
27
|
-
* @param rule - 命令规则
|
|
28
|
-
*/
|
|
29
|
-
rule;
|
|
30
|
-
/**
|
|
31
|
-
* @param handler - handler 已废弃 请使用karin.handler
|
|
32
|
-
* @deprecated
|
|
33
|
-
*/
|
|
34
|
-
handler;
|
|
35
|
-
/**
|
|
36
|
-
* @param userId - 用户ID 一般上下文使用
|
|
37
|
-
*/
|
|
38
|
-
userId;
|
|
39
|
-
/**
|
|
40
|
-
* @param timeout - 上下文超时
|
|
41
|
-
*/
|
|
42
|
-
timeout;
|
|
43
|
-
constructor({ name, desc = name, event = "message" /* EventType.Message */, priority = 10000, task = [], rule = [], handler = [], }) {
|
|
44
|
-
this.name = name;
|
|
45
|
-
this.desc = desc;
|
|
46
|
-
this.event = event;
|
|
47
|
-
this.priority = priority;
|
|
48
|
-
this.task = task;
|
|
49
|
-
this.rule = rule;
|
|
50
|
-
this.handler = handler;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* - 快速回复
|
|
54
|
-
*/
|
|
55
|
-
reply(msg = '', options = { reply: false, recallMsg: 0, at: false, button: false, retry_count: 1 }) {
|
|
56
|
-
return this.e.reply(msg, options);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* - 快速回复合并转发
|
|
60
|
-
*/
|
|
61
|
-
async replyForward(msg) {
|
|
62
|
-
const result = await this.e.bot.sendForwardMessage(this.e.contact, msg);
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* - 构建上下文键
|
|
67
|
-
*/
|
|
68
|
-
conKey() {
|
|
69
|
-
return `${this.e.isGroup ? `${this.e.group_id}.` : ''}` + (this.userId || this.e.user_id);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* 设置上下文状态
|
|
73
|
-
*/
|
|
74
|
-
setContext(
|
|
75
|
-
/**
|
|
76
|
-
* @param fnc - 执行方法
|
|
77
|
-
*/
|
|
78
|
-
fnc,
|
|
79
|
-
/**
|
|
80
|
-
* @param reply - 超时后是否回复
|
|
81
|
-
*/
|
|
82
|
-
reply = true,
|
|
83
|
-
/**
|
|
84
|
-
* @param time - 超时时间,默认120秒
|
|
85
|
-
*/
|
|
86
|
-
time = 120) {
|
|
87
|
-
const key = this.conKey();
|
|
88
|
-
if (typeof fnc === 'string') {
|
|
89
|
-
stateArr[key] = { type: 'class', fnc: this, name: fnc };
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
stateArr[key] = { type: 'fnc', fnc };
|
|
93
|
-
}
|
|
94
|
-
/** 操作时间 */
|
|
95
|
-
this.timeout = setTimeout(() => {
|
|
96
|
-
if (stateArr[key]) {
|
|
97
|
-
delete stateArr[key];
|
|
98
|
-
if (reply)
|
|
99
|
-
this.e.reply('操作超时已取消', { at: true });
|
|
100
|
-
}
|
|
101
|
-
}, time * 1000);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* 获取上下文状态
|
|
105
|
-
*/
|
|
106
|
-
getContext() {
|
|
107
|
-
const key = this.conKey();
|
|
108
|
-
return stateArr[key];
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* 清除上下文状态
|
|
112
|
-
*/
|
|
113
|
-
finish() {
|
|
114
|
-
const key = this.conKey();
|
|
115
|
-
if (stateArr[key] && stateArr[key]) {
|
|
116
|
-
/** 清除定时器 */
|
|
117
|
-
clearTimeout(this.timeout);
|
|
118
|
-
delete stateArr[key];
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
e;
|
|
122
|
-
replyCallback;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* 上下文状态
|
|
126
|
-
*/
|
|
127
|
-
export const stateArr = {};
|
|
128
|
-
/**
|
|
129
|
-
* @description 即将废弃,请使用 `Plugin`
|
|
130
|
-
*/
|
|
131
|
-
export const plugin = Plugin;
|