node-karin 0.2.0 → 0.2.1
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/config/defSet/config.yaml +3 -0
- package/lib/adapter/onebot/onebot11.d.ts +4 -6
- package/lib/adapter/onebot/onebot11.js +3 -8
- package/lib/core/index.d.ts +9 -0
- package/lib/core/index.js +9 -0
- package/lib/core/init.d.ts +1 -0
- package/lib/core/init.js +20 -2
- package/lib/core/karin.d.ts +2 -4
- package/lib/core/karin.js +2 -2
- package/lib/core/listener.d.ts +2 -5
- package/lib/core/listener.js +9 -11
- package/lib/core/plugin.app.d.ts +1 -1
- package/lib/core/plugin.d.ts +2 -4
- package/lib/core/plugin.js +1 -1
- package/lib/core/plugin.loader.d.ts +6 -7
- package/lib/core/plugin.loader.js +13 -16
- package/lib/core/process.d.ts +18 -0
- package/lib/core/process.js +98 -0
- package/lib/core/server.d.ts +4 -5
- package/lib/core/server.js +11 -13
- package/lib/db/index.d.ts +4 -0
- package/lib/db/index.js +4 -0
- package/lib/db/level.d.ts +1 -3
- package/lib/db/level.js +1 -3
- package/lib/db/redis.js +1 -2
- package/lib/event/event.d.ts +1 -3
- package/lib/event/event.handler.d.ts +1 -2
- package/lib/event/event.handler.js +13 -16
- package/lib/event/index.d.ts +7 -0
- package/lib/event/index.js +9 -0
- package/lib/event/message.d.ts +1 -2
- package/lib/event/message.handler.d.ts +1 -1
- package/lib/event/message.handler.js +12 -15
- package/lib/event/notice.d.ts +1 -1
- package/lib/event/request.d.ts +1 -1
- package/lib/event/review.handler.d.ts +12 -15
- package/lib/event/review.handler.js +6 -7
- package/lib/index.d.ts +152 -26
- package/lib/index.js +24 -37
- package/lib/modules.d.ts +14 -0
- package/lib/modules.js +14 -0
- package/lib/renderer/app.d.ts +14 -21
- package/lib/renderer/app.js +12 -11
- package/lib/renderer/base.d.ts +1 -1
- package/lib/renderer/base.js +2 -3
- package/lib/renderer/client.d.ts +2 -2
- package/lib/renderer/client.js +7 -8
- package/lib/renderer/http.d.ts +2 -2
- package/lib/renderer/http.js +2 -2
- package/lib/renderer/index.d.ts +6 -0
- package/lib/renderer/index.js +6 -0
- package/lib/renderer/server.d.ts +4 -4
- package/lib/renderer/server.js +7 -7
- package/lib/renderer/wormhole.d.ts +1 -1
- package/lib/renderer/wormhole.js +7 -7
- package/lib/types/adapter.d.ts +1 -1
- package/lib/types/config.d.ts +9 -3
- package/lib/types/{types.d.ts → event.d.ts} +1 -3
- package/lib/types/index.d.ts +3 -2
- package/lib/types/index.js +3 -2
- package/lib/types/plugin.d.ts +6 -6
- package/lib/utils/button.d.ts +8 -9
- package/lib/utils/button.js +1 -1
- package/lib/utils/common.d.ts +10 -5
- package/lib/utils/common.js +20 -8
- package/lib/utils/config.d.ts +6 -5
- package/lib/utils/config.js +6 -6
- package/lib/utils/ffmpeg.js +2 -2
- package/lib/utils/handler.d.ts +3 -4
- package/lib/utils/handler.js +1 -1
- package/lib/utils/index.d.ts +11 -0
- package/lib/utils/index.js +11 -0
- package/lib/utils/logger.d.ts +1 -1
- package/lib/utils/logger.js +4 -4
- package/lib/utils/segment.d.ts +2 -3
- package/lib/utils/segment.js +1 -1
- package/lib/utils/update.d.ts +1 -2
- package/lib/utils/update.js +1 -1
- package/package.json +2 -2
- /package/lib/types/{types.js → event.js} +0 -0
- /package/lib/utils/{YamlEditor.d.ts → yamlEditor.d.ts} +0 -0
- /package/lib/utils/{YamlEditor.js → yamlEditor.js} +0 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { GroupCfg } from '../types/config.js';
|
|
2
1
|
import { KarinMessage } from './message.js';
|
|
3
2
|
import { KarinNotice } from './notice.js';
|
|
4
3
|
import { KarinRequest } from './request.js';
|
|
5
|
-
import { Event, Permission, SubEvent } from '../types/
|
|
4
|
+
import { Event, Permission, SubEvent, GroupCfg } from '../types/index.js';
|
|
6
5
|
export default class EventHandler {
|
|
7
6
|
e: KarinMessage | KarinNotice | KarinRequest;
|
|
8
7
|
config: GroupCfg | {};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import logger from '../utils/
|
|
4
|
-
import Common from '../utils/common.js'
|
|
5
|
-
import Segment from '../utils/segment.js'
|
|
6
|
-
import Listeners from '../core/listener.js'
|
|
1
|
+
import { review } from './review.handler.js'
|
|
2
|
+
import { listener } from '../core/index.js'
|
|
3
|
+
import { segment, common, logger, config } from '../utils/index.js'
|
|
7
4
|
export default class EventHandler {
|
|
8
5
|
e
|
|
9
6
|
config
|
|
@@ -14,7 +11,7 @@ export default class EventHandler {
|
|
|
14
11
|
this.e = e
|
|
15
12
|
this.config = {}
|
|
16
13
|
/** 加入e.bot */
|
|
17
|
-
Object.defineProperty(this.e, 'bot', { value:
|
|
14
|
+
Object.defineProperty(this.e, 'bot', { value: listener.getBot(this.e.self_id) })
|
|
18
15
|
if (this.e.group_id) { this.config = config.group(this.e.group_id) }
|
|
19
16
|
}
|
|
20
17
|
|
|
@@ -23,17 +20,17 @@ export default class EventHandler {
|
|
|
23
20
|
*/
|
|
24
21
|
review () {
|
|
25
22
|
/** 检查CD */
|
|
26
|
-
if (!
|
|
23
|
+
if (!review.CD(this.e, this.config)) {
|
|
27
24
|
logger.debug('[消息拦截] 正在冷却中')
|
|
28
25
|
return true
|
|
29
26
|
}
|
|
30
27
|
/** 检查群聊黑白名单 */
|
|
31
|
-
if (!
|
|
28
|
+
if (!review.GroupEnable(this.e)) {
|
|
32
29
|
logger.debug('[消息拦截] 未通过群聊黑白名单检查')
|
|
33
30
|
return true
|
|
34
31
|
}
|
|
35
32
|
/** 检查用户黑白名单 */
|
|
36
|
-
if (!
|
|
33
|
+
if (!review.UserEnable(this.e)) {
|
|
37
34
|
logger.debug('[消息拦截] 未通过用户黑白名单检查')
|
|
38
35
|
return true
|
|
39
36
|
}
|
|
@@ -106,23 +103,23 @@ export default class EventHandler {
|
|
|
106
103
|
* @param options 回复选项
|
|
107
104
|
*/
|
|
108
105
|
this.e.reply = async (elements = '', options = { reply: false, recallMsg: 0, at: false, retry_count: 1 }) => {
|
|
109
|
-
const message =
|
|
106
|
+
const message = common.makeMessage(elements)
|
|
110
107
|
const { reply = false, recallMsg = 0, at, retry_count = 1 } = options
|
|
111
108
|
/** 加入at */
|
|
112
|
-
if (at && this.e.isGroup) { message.unshift(
|
|
109
|
+
if (at && this.e.isGroup) { message.unshift(segment.at(this.e.user_id)) }
|
|
113
110
|
/** 加入引用回复 */
|
|
114
|
-
if (reply && 'message_id' in this.e) { message.unshift(
|
|
111
|
+
if (reply && 'message_id' in this.e) { message.unshift(segment.reply(this.e.message_id)) }
|
|
115
112
|
/** 先发 提升速度 */
|
|
116
113
|
const result = this.e.replyCallback(message, retry_count)
|
|
117
|
-
const ReplyLog =
|
|
114
|
+
const ReplyLog = common.makeMessageLog(message)
|
|
118
115
|
if (this.e.isGroup) {
|
|
119
|
-
|
|
116
|
+
review.GroupMsgPrint(this.e) && logger.bot('info', this.e.self_id, `${logger.green(`Send Group ${this.e.group_id}: `)}${ReplyLog}`)
|
|
120
117
|
} else {
|
|
121
118
|
logger.bot('info', this.e.self_id, `${logger.green(`Send private ${this.e.user_id}: `)}${ReplyLog}`)
|
|
122
119
|
}
|
|
123
120
|
let message_id = ''
|
|
124
121
|
try {
|
|
125
|
-
|
|
122
|
+
listener.emit('karin:count:send', 1)
|
|
126
123
|
/** 取结果 */
|
|
127
124
|
const Res = await result
|
|
128
125
|
message_id = Res.message_id || ''
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './event.js'
|
|
2
|
+
export * from './event.handler.js'
|
|
3
|
+
export * from './message.js'
|
|
4
|
+
export * from './message.handler.js'
|
|
5
|
+
export * from './notice.js'
|
|
6
|
+
// export * from './notice.handler'
|
|
7
|
+
export * from './request.js'
|
|
8
|
+
// export * from './request.handler'
|
|
9
|
+
export * from './review.handler.js'
|
package/lib/event/message.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import lodash from 'lodash'
|
|
2
|
-
import
|
|
3
|
-
import logger from '../utils/logger.js'
|
|
4
|
-
import Review from './review.handler.js'
|
|
5
|
-
import Listener from '../core/listener.js'
|
|
6
|
-
import { stateArr } from '../core/plugin.js'
|
|
2
|
+
import { review } from './review.handler.js'
|
|
7
3
|
import EventHandler from './event.handler.js'
|
|
8
|
-
import
|
|
4
|
+
import { logger, config } from '../utils/index.js'
|
|
5
|
+
import { listener, stateArr, PluginLoader } from '../core/index.js'
|
|
9
6
|
/**
|
|
10
7
|
* 消息事件
|
|
11
8
|
*/
|
|
12
|
-
export
|
|
9
|
+
export class MessageHandler extends EventHandler {
|
|
13
10
|
e
|
|
14
11
|
/**
|
|
15
12
|
* - 是否打印群消息日志
|
|
@@ -18,13 +15,13 @@ export default class Message extends EventHandler {
|
|
|
18
15
|
constructor (e) {
|
|
19
16
|
super(e)
|
|
20
17
|
this.e = e
|
|
21
|
-
|
|
18
|
+
listener.emit('karin:count:recv', 1)
|
|
22
19
|
/** 处理消息 保证日志的打印 */
|
|
23
20
|
this.dealMsg()
|
|
24
21
|
/** 事件处理 */
|
|
25
22
|
if (this.review()) { return }
|
|
26
23
|
/** 响应模式 */
|
|
27
|
-
if (this.e.group_id && 'mode' in this.config && this.config.mode && !
|
|
24
|
+
if (this.e.group_id && 'mode' in this.config && this.config.mode && !review.mode(this.e, this.config)) {
|
|
28
25
|
logger.debug('[消息拦截] 响应模式不匹配')
|
|
29
26
|
return
|
|
30
27
|
}
|
|
@@ -52,7 +49,7 @@ export default class Message extends EventHandler {
|
|
|
52
49
|
v.reg.lastIndex = 0
|
|
53
50
|
if (v.reg.test(this.e.msg)) {
|
|
54
51
|
/** 检查黑白名单插件 */
|
|
55
|
-
if ('GroupCD' in this.config && !
|
|
52
|
+
if ('GroupCD' in this.config && !review.PluginEnable(app, this.config)) { continue }
|
|
56
53
|
/** 判断子事件 */
|
|
57
54
|
if (v.event && !this.filtEvent(v.event)) { continue }
|
|
58
55
|
this.e.logFnc = `[${app.file.dir}][${app.name}][${v.fnc}]`
|
|
@@ -71,7 +68,7 @@ export default class Message extends EventHandler {
|
|
|
71
68
|
}
|
|
72
69
|
/** 计算插件处理时间 */
|
|
73
70
|
const start = Date.now()
|
|
74
|
-
|
|
71
|
+
listener.emit('karin:count:fnc', this.e.logFnc)
|
|
75
72
|
res = await res
|
|
76
73
|
this.GroupMsgPrint && typeof v.log === 'function' && v.log(this.e.self_id, `${logFnc} ${lodash.truncate(this.e.msg, { length: 80 })} 处理完成 ${logger.green(Date.now() - start + 'ms')}`)
|
|
77
74
|
if (res !== false) { break a }
|
|
@@ -194,13 +191,13 @@ export default class Message extends EventHandler {
|
|
|
194
191
|
}
|
|
195
192
|
this.e.raw_message = logs.join('')
|
|
196
193
|
/** 前缀处理 */
|
|
197
|
-
this.e.group_id && 'GroupCD' in this.config &&
|
|
194
|
+
this.e.group_id && 'GroupCD' in this.config && review.alias(this.e, this.config)
|
|
198
195
|
/** 主人 这里强制是因为yaml在自动保存QQ号的时候会强制化为数字 */
|
|
199
196
|
const masterId = (Number(this.e.user_id) || String(this.e.user_id))
|
|
200
|
-
if (
|
|
197
|
+
if (config.master.includes(masterId)) {
|
|
201
198
|
this.e.isMaster = true
|
|
202
199
|
this.e.isAdmin = true
|
|
203
|
-
} else if (
|
|
200
|
+
} else if (config.admin.includes(masterId)) {
|
|
204
201
|
/** 管理员 */
|
|
205
202
|
this.e.isAdmin = true
|
|
206
203
|
}
|
|
@@ -212,7 +209,7 @@ export default class Message extends EventHandler {
|
|
|
212
209
|
} else if (this.e.contact.scene === 'group') {
|
|
213
210
|
this.e.isGroup = true
|
|
214
211
|
this.e.logText = `[Group:${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})]`
|
|
215
|
-
this.GroupMsgPrint =
|
|
212
|
+
this.GroupMsgPrint = review.GroupMsgPrint(this.e)
|
|
216
213
|
this.GroupMsgPrint && logger.bot('info', this.e.self_id, `群消息:[${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`)
|
|
217
214
|
} else {
|
|
218
215
|
logger.bot('info', this.e.self_id, `未知消息:${JSON.stringify(this.e)}`)
|
package/lib/event/notice.d.ts
CHANGED
package/lib/event/request.d.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PluginApps } from '../types/
|
|
3
|
-
import { GroupCfg } from '../types/config.js';
|
|
4
|
-
import { KarinMessage } from '../event/message.js';
|
|
1
|
+
import { KarinMessage } from '../event/index.js';
|
|
2
|
+
import { E, PluginApps, GroupCfg } from '../types/index.js';
|
|
5
3
|
/**
|
|
6
4
|
* 事件拦截器
|
|
7
5
|
* 利用可执行函数的特性,热更新所有拦截器
|
|
8
6
|
* 所有拦截器返回的都是布尔值 为true说明通过 为false则未通过
|
|
9
7
|
*/
|
|
10
|
-
declare const
|
|
8
|
+
export declare const review: {
|
|
11
9
|
GroupCD: {
|
|
12
10
|
[key: string]: boolean;
|
|
13
11
|
};
|
|
14
12
|
GroupUserCD: {
|
|
15
13
|
[key: string]: boolean;
|
|
16
14
|
};
|
|
17
|
-
App: import("../types/
|
|
18
|
-
Config: import("../types/
|
|
15
|
+
App: import("../types/index.js").App;
|
|
16
|
+
Config: import("../types/index.js").Config;
|
|
19
17
|
CD: (e: E, config: GroupCfg) => boolean;
|
|
20
18
|
mode: (e: KarinMessage, config: GroupCfg) => boolean;
|
|
21
19
|
alias: (e: KarinMessage, config: GroupCfg) => boolean;
|
|
@@ -27,28 +25,27 @@ declare const _default: {
|
|
|
27
25
|
/**
|
|
28
26
|
* 群聊黑白名单 允许哪个群触发事件
|
|
29
27
|
*/
|
|
30
|
-
"__#
|
|
28
|
+
"__#1@#GroupEnable"(): true | undefined;
|
|
31
29
|
/**
|
|
32
30
|
* 用户黑白名单 允许那个用户触发事件
|
|
33
31
|
*/
|
|
34
|
-
"__#
|
|
32
|
+
"__#1@#UserEnable"(): true | undefined;
|
|
35
33
|
/**
|
|
36
34
|
* 群聊事件日志 是否打印
|
|
37
35
|
*/
|
|
38
|
-
"__#
|
|
36
|
+
"__#1@#GroupMsgPrint"(): true | undefined;
|
|
39
37
|
/**
|
|
40
38
|
* 黑白名单插件 哪个插件可以被触发
|
|
41
39
|
*/
|
|
42
|
-
"__#
|
|
40
|
+
"__#1@#PluginEnable"(): boolean;
|
|
43
41
|
/** 群聊cd */
|
|
44
|
-
"__#
|
|
42
|
+
"__#1@#CD"(): true | undefined;
|
|
45
43
|
/**
|
|
46
44
|
* 响应模式
|
|
47
45
|
*/
|
|
48
|
-
"__#
|
|
46
|
+
"__#1@#mode"(): true | undefined;
|
|
49
47
|
/**
|
|
50
48
|
* 前缀、别名
|
|
51
49
|
*/
|
|
52
|
-
"__#
|
|
50
|
+
"__#1@#alias"(): true | undefined;
|
|
53
51
|
};
|
|
54
|
-
export default _default;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import logger from '../utils/logger.js'
|
|
1
|
+
import { logger, config } from '../utils/index.js'
|
|
3
2
|
/**
|
|
4
3
|
* 事件拦截器
|
|
5
4
|
* 利用可执行函数的特性,热更新所有拦截器
|
|
6
5
|
* 所有拦截器返回的都是布尔值 为true说明通过 为false则未通过
|
|
7
6
|
*/
|
|
8
|
-
export
|
|
7
|
+
export const review = new (class Handler {
|
|
9
8
|
GroupCD
|
|
10
9
|
GroupUserCD
|
|
11
|
-
App =
|
|
12
|
-
Config =
|
|
10
|
+
App = config['App']
|
|
11
|
+
Config = config['Config']
|
|
13
12
|
CD
|
|
14
13
|
mode
|
|
15
14
|
alias
|
|
@@ -43,8 +42,8 @@ export default new (class Review {
|
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
main () {
|
|
46
|
-
this.App =
|
|
47
|
-
this.Config =
|
|
45
|
+
this.App = config.App
|
|
46
|
+
this.Config = config.Config
|
|
48
47
|
this.#CD()
|
|
49
48
|
this.#mode()
|
|
50
49
|
this.#alias()
|
package/lib/index.d.ts
CHANGED
|
@@ -1,27 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
export * from 'kritor-proto';
|
|
4
|
+
export * from './core/index.js';
|
|
5
|
+
export * from './event/index.js';
|
|
6
|
+
export * from './db/index.js';
|
|
7
|
+
export * from './renderer/index.js';
|
|
8
|
+
export * from './utils/index.js';
|
|
9
|
+
export * from './types/index.js';
|
|
10
|
+
import { Karin, Plugin } from './core/index.js';
|
|
11
|
+
/**
|
|
12
|
+
* @description 即将废弃,请使用 `Plugin`
|
|
13
|
+
*/
|
|
14
|
+
export declare const plugin: typeof Plugin;
|
|
15
|
+
/**
|
|
16
|
+
* @description 即将废弃,请使用 `render`
|
|
17
|
+
*/
|
|
18
|
+
export declare const Renderer: {
|
|
19
|
+
index: number;
|
|
20
|
+
Apps: import("./types/index.js").KarinRenderApp[];
|
|
21
|
+
app(data: {
|
|
22
|
+
id: string;
|
|
23
|
+
type?: string | undefined;
|
|
24
|
+
render: (options: import("./types/index.js").KarinRenderType) => Promise<string | string[]>;
|
|
25
|
+
}): number;
|
|
26
|
+
unapp(index: number): boolean;
|
|
27
|
+
App(id?: string): import("./types/index.js").KarinRenderApp;
|
|
28
|
+
render(options: import("./types/index.js").KarinRenderType, id: string): Promise<string | string[]>;
|
|
29
|
+
renderHtml(data: string): Promise<string | string[]>;
|
|
30
|
+
};
|
|
31
|
+
export declare const Cfg: {
|
|
32
|
+
dir: string;
|
|
33
|
+
_path: string;
|
|
34
|
+
_pathDef: string;
|
|
35
|
+
change: Map<string, any>;
|
|
36
|
+
watcher: Map<string, any>;
|
|
37
|
+
review: boolean;
|
|
38
|
+
loggger: import("log4js").Logger;
|
|
39
|
+
initCfg(): Promise<void>;
|
|
40
|
+
getPlugins(): string[];
|
|
41
|
+
dirPath(name: string, plugins: string[]): Promise<void>;
|
|
42
|
+
timeout(type?: "grpc" | "ws"): number;
|
|
43
|
+
readonly redis: import("./types/index.js").Redis;
|
|
44
|
+
readonly master: string[];
|
|
45
|
+
readonly admin: string[];
|
|
46
|
+
readonly App: import("./types/index.js").App;
|
|
47
|
+
readonly Config: import("./types/index.js").Config;
|
|
48
|
+
readonly Server: import("./types/index.js").Server;
|
|
49
|
+
readonly package: import("./types/index.js").Package;
|
|
50
|
+
group(group_id?: string): import("./types/index.js").GroupCfg;
|
|
51
|
+
getYaml(type: "defSet" | "config", name: string, isWatch?: boolean): any;
|
|
52
|
+
watch(type: "defSet" | "config", name: string, file: string): Promise<true | undefined>;
|
|
53
|
+
change_App(): Promise<void>;
|
|
54
|
+
change_config(): Promise<void>;
|
|
55
|
+
change_group(): Promise<void>;
|
|
56
|
+
"__#2@#review"(): Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
export declare const Bot: {
|
|
59
|
+
index: number;
|
|
60
|
+
name: string;
|
|
61
|
+
list: {
|
|
62
|
+
index: number;
|
|
63
|
+
type: "internal" | "http" | "grpc" | "ws" | "render";
|
|
64
|
+
bot: import("./types/index.js").KarinAdapter;
|
|
65
|
+
}[];
|
|
66
|
+
adapter: {
|
|
67
|
+
type: "internal" | "http" | "grpc" | "ws" | "render";
|
|
68
|
+
adapter: new () => import("./types/index.js").KarinAdapter;
|
|
69
|
+
/**
|
|
70
|
+
* @description 即将废弃,请使用 `Plugin`
|
|
71
|
+
*/
|
|
72
|
+
path: string;
|
|
73
|
+
}[];
|
|
74
|
+
addBot(data: {
|
|
75
|
+
bot: import("./types/index.js").KarinAdapter;
|
|
76
|
+
type: "internal" | "http" | "grpc" | "ws" | "render";
|
|
77
|
+
}): number | false;
|
|
78
|
+
delBot(index: number): void;
|
|
79
|
+
getBot(uid?: string): import("./types/index.js").KarinAdapter | undefined;
|
|
80
|
+
getBotByIndex(index: number): import("./types/index.js").KarinAdapter;
|
|
81
|
+
getBotCount(): number;
|
|
82
|
+
getBotAll(isIndex?: boolean): import("./types/index.js").KarinAdapter[] | {
|
|
83
|
+
index: number;
|
|
84
|
+
bot: import("./types/index.js").KarinAdapter;
|
|
85
|
+
}[];
|
|
86
|
+
addAdapter(data: {
|
|
87
|
+
type: "internal" | "http" | "grpc" | "ws" | "render";
|
|
88
|
+
adapter: new () => import("./types/index.js").KarinAdapter;
|
|
89
|
+
path?: string | undefined;
|
|
90
|
+
}): void;
|
|
91
|
+
getAdapter(path?: string): (new () => import("./types/index.js").KarinAdapter) | undefined;
|
|
92
|
+
getAdapterAll(isType?: boolean): {
|
|
93
|
+
type: "internal" | "http" | "grpc" | "ws" | "render";
|
|
94
|
+
adapter: new () => import("./types/index.js").KarinAdapter;
|
|
95
|
+
/**
|
|
96
|
+
* @description 即将废弃,请使用 `Plugin`
|
|
97
|
+
*/
|
|
98
|
+
path: string;
|
|
99
|
+
}[] | (new () => import("./types/index.js").KarinAdapter)[];
|
|
100
|
+
sendMsg(uid: string, contact: import("./types/index.js").contact, elements: import("./types/index.js").KarinElement, options?: {
|
|
101
|
+
recallMsg: number;
|
|
102
|
+
retry_count: number;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
message_id: string;
|
|
105
|
+
}>;
|
|
106
|
+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
|
|
107
|
+
addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
108
|
+
on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
109
|
+
once<K_3>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
110
|
+
removeListener<K_4>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
111
|
+
off<K_5>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
112
|
+
removeAllListeners(eventName?: string | symbol | undefined): any;
|
|
113
|
+
setMaxListeners(n: number): any;
|
|
114
|
+
getMaxListeners(): number;
|
|
115
|
+
listeners<K_6>(eventName: string | symbol): Function[];
|
|
116
|
+
rawListeners<K_7>(eventName: string | symbol): Function[];
|
|
117
|
+
emit<K_8>(eventName: string | symbol, ...args: any[]): boolean;
|
|
118
|
+
listenerCount<K_9>(eventName: string | symbol, listener?: Function | undefined): number;
|
|
119
|
+
prependListener<K_10>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
120
|
+
prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
121
|
+
eventNames(): (string | symbol)[];
|
|
122
|
+
};
|
|
123
|
+
export declare const Update: {
|
|
124
|
+
dir: string;
|
|
125
|
+
getPlugins(): string[];
|
|
126
|
+
update(path: string, cmd?: string, time?: number): Promise<{
|
|
127
|
+
status: string;
|
|
128
|
+
data: string;
|
|
129
|
+
}>;
|
|
130
|
+
getTime(path: string): Promise<string>;
|
|
131
|
+
getHash(path: string, short?: boolean): Promise<string>;
|
|
132
|
+
getCommit(options: {
|
|
133
|
+
path: any;
|
|
134
|
+
count?: any;
|
|
135
|
+
hash?: any;
|
|
136
|
+
branch?: any;
|
|
137
|
+
}): Promise<string>;
|
|
138
|
+
checkUpdate(path: import("fs").PathLike, time?: number): Promise<{
|
|
139
|
+
status: string;
|
|
140
|
+
data: string | undefined;
|
|
141
|
+
count?: undefined;
|
|
142
|
+
} | {
|
|
143
|
+
status: string;
|
|
144
|
+
data: boolean;
|
|
145
|
+
count?: undefined;
|
|
146
|
+
} | {
|
|
147
|
+
status: string;
|
|
148
|
+
data: string;
|
|
149
|
+
count: string | number;
|
|
150
|
+
}>;
|
|
151
|
+
};
|
|
152
|
+
export declare const karin: Karin;
|
|
27
153
|
export default karin;
|
package/lib/index.js
CHANGED
|
@@ -1,44 +1,31 @@
|
|
|
1
1
|
// 基本模块
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
import common from './utils/common.js';
|
|
13
|
-
import segment from './utils/segment.js';
|
|
14
|
-
import handler from './utils/handler.js';
|
|
15
|
-
import ffmpeg from './utils/ffmpeg.js';
|
|
16
|
-
import exec from './utils/exec.js';
|
|
17
|
-
import button from './utils/button.js';
|
|
18
|
-
import update from './utils/update.js';
|
|
19
|
-
import YamlEditor from './utils/YamlEditor.js';
|
|
20
|
-
import render from './renderer/app.js';
|
|
21
|
-
import { KarinMessage } from './event/message.js';
|
|
22
|
-
import Karin from './core/karin.js';
|
|
23
|
-
// 适配器
|
|
24
|
-
import Puppeteer from './renderer/server.js';
|
|
2
|
+
export * from 'kritor-proto';
|
|
3
|
+
export * from './core/index.js';
|
|
4
|
+
export * from './event/index.js';
|
|
5
|
+
export * from './db/index.js';
|
|
6
|
+
export * from './renderer/index.js';
|
|
7
|
+
export * from './utils/index.js';
|
|
8
|
+
export * from './types/index.js';
|
|
9
|
+
import { config, update } from './utils/index.js';
|
|
10
|
+
import { render } from './renderer/index.js';
|
|
11
|
+
import { RenderServer } from './renderer/index.js';
|
|
25
12
|
import OneBot11 from './adapter/onebot/onebot11.js';
|
|
26
|
-
|
|
27
|
-
import level from './db/level.js';
|
|
28
|
-
import Redis from './db/redis.js';
|
|
29
|
-
// proto
|
|
30
|
-
import { kritor } from 'kritor-proto';
|
|
31
|
-
export * as types from './types/index.js';
|
|
13
|
+
import { server, Karin, PluginLoader, listener, Plugin } from './core/index.js';
|
|
32
14
|
// 初始化
|
|
33
15
|
server.init();
|
|
34
|
-
const redis = (await new Redis().start());
|
|
35
16
|
PluginLoader.load();
|
|
36
|
-
listener.emit('adapter',
|
|
17
|
+
listener.emit('adapter', RenderServer);
|
|
37
18
|
listener.emit('adapter', OneBot11);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @description 即将废弃,请使用 `Plugin`
|
|
21
|
+
*/
|
|
22
|
+
export const plugin = Plugin;
|
|
23
|
+
/**
|
|
24
|
+
* @description 即将废弃,请使用 `render`
|
|
25
|
+
*/
|
|
26
|
+
export const Renderer = render;
|
|
27
|
+
export const Cfg = config;
|
|
28
|
+
export const Bot = listener;
|
|
29
|
+
export const Update = update;
|
|
30
|
+
export const karin = new Karin();
|
|
44
31
|
export default karin;
|
package/lib/modules.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import ws from 'ws';
|
|
4
|
+
import moment from 'moment';
|
|
5
|
+
import lodash from 'lodash';
|
|
6
|
+
import express from 'express';
|
|
7
|
+
import axios from 'axios';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
import chokidar from 'chokidar';
|
|
10
|
+
import { Level as level } from 'level';
|
|
11
|
+
import schedule from 'node-schedule';
|
|
12
|
+
import yaml from 'yaml';
|
|
13
|
+
import log4js from 'log4js';
|
|
14
|
+
export { fs, ws, path, axios, lodash, moment, express, chalk, chokidar, level, schedule, yaml, log4js, };
|
package/lib/modules.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import ws from 'ws';
|
|
4
|
+
import moment from 'moment';
|
|
5
|
+
import lodash from 'lodash';
|
|
6
|
+
import express from 'express';
|
|
7
|
+
import axios from 'axios';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
import chokidar from 'chokidar';
|
|
10
|
+
import { Level as level } from 'level';
|
|
11
|
+
import schedule from 'node-schedule';
|
|
12
|
+
import yaml from 'yaml';
|
|
13
|
+
import log4js from 'log4js';
|
|
14
|
+
export { fs, ws, path, axios, lodash, moment, express, chalk, chokidar, level, schedule, yaml, log4js, };
|
package/lib/renderer/app.d.ts
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
import { KarinRender, KarinRenderApp, KarinRenderType } from '../types/
|
|
2
|
-
|
|
3
|
-
* 渲染器管理器
|
|
4
|
-
*/
|
|
5
|
-
declare const _default: {
|
|
1
|
+
import { KarinRender, KarinRenderApp, KarinRenderType } from '../types/index.js';
|
|
2
|
+
declare class Renderer {
|
|
6
3
|
index: number;
|
|
7
4
|
Apps: Array<KarinRenderApp>;
|
|
5
|
+
constructor();
|
|
8
6
|
/**
|
|
9
7
|
* 注册渲染器
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @returns
|
|
8
|
+
* @param data 渲染器数据
|
|
9
|
+
* @param data.id 渲染器ID
|
|
10
|
+
* @param data.type 渲染器类型
|
|
11
|
+
* @param ata.render 渲染器标准方法
|
|
12
|
+
* @returns 渲染器索引
|
|
15
13
|
*/
|
|
16
14
|
app(data: {
|
|
17
|
-
/**
|
|
18
|
-
* 渲染器ID
|
|
19
|
-
*/
|
|
20
15
|
id: string;
|
|
21
|
-
/**
|
|
22
|
-
* 渲染器类型
|
|
23
|
-
*/
|
|
24
16
|
type?: 'image' | string;
|
|
25
|
-
/**
|
|
26
|
-
* 渲染器标准方法
|
|
27
|
-
*/
|
|
28
17
|
render: KarinRender['render'];
|
|
29
18
|
}): number;
|
|
30
19
|
/**
|
|
@@ -49,5 +38,9 @@ declare const _default: {
|
|
|
49
38
|
* @returns 返回图片base64或数组
|
|
50
39
|
*/
|
|
51
40
|
renderHtml(data: string): Promise<string | string[]>;
|
|
52
|
-
}
|
|
53
|
-
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 渲染器管理器
|
|
44
|
+
*/
|
|
45
|
+
export declare const render: Renderer;
|
|
46
|
+
export {};
|