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,112 +0,0 @@
|
|
|
1
|
-
import { Level } from 'level';
|
|
2
|
-
export default class RedisLevel {
|
|
3
|
-
#private;
|
|
4
|
-
level: Level<string, string>;
|
|
5
|
-
/** 唯一标识符 用于区分不同的数据库 */
|
|
6
|
-
id: string;
|
|
7
|
-
constructor();
|
|
8
|
-
/**
|
|
9
|
-
* get 获取数据
|
|
10
|
-
* @param {string} key 键
|
|
11
|
-
* @returns {Promise<string>|Error} 数据
|
|
12
|
-
*/
|
|
13
|
-
get(key: string): Promise<string | null>;
|
|
14
|
-
/**
|
|
15
|
-
* set 设置数据
|
|
16
|
-
* @param key 键
|
|
17
|
-
* @param value 值
|
|
18
|
-
* @param options 选项
|
|
19
|
-
*/
|
|
20
|
-
set(key: string, value: string, options?: {
|
|
21
|
-
EX: number;
|
|
22
|
-
} | undefined): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* del 删除数据
|
|
25
|
-
* @param key 键
|
|
26
|
-
*/
|
|
27
|
-
del(key: string): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* keys 获取所有键
|
|
30
|
-
* @param prefix 前缀
|
|
31
|
-
*/
|
|
32
|
-
keys(prefix?: string): Promise<string[]>;
|
|
33
|
-
/**
|
|
34
|
-
* incr 递增数据
|
|
35
|
-
* @param {string} key 键
|
|
36
|
-
* @returns {Promise<number>|Error}
|
|
37
|
-
*/
|
|
38
|
-
incr(key: string): Promise<number>;
|
|
39
|
-
/**
|
|
40
|
-
* decr 递减数据
|
|
41
|
-
* @param {string} key 键
|
|
42
|
-
* @returns {Promise<number>|Error}
|
|
43
|
-
*/
|
|
44
|
-
decr(key: string): Promise<number>;
|
|
45
|
-
/**
|
|
46
|
-
* expire 设置过期时间
|
|
47
|
-
* @param {string} key 键
|
|
48
|
-
* @param seconds 过期时间 单位秒
|
|
49
|
-
* @returns {Promise<number>|Error}
|
|
50
|
-
*/
|
|
51
|
-
expire(key: string, seconds: number): Promise<number>;
|
|
52
|
-
/**
|
|
53
|
-
* ttl 获取过期时间
|
|
54
|
-
* @param {string} key 键
|
|
55
|
-
* @returns {Promise<number>|Error}
|
|
56
|
-
*/
|
|
57
|
-
ttl(key: string): Promise<number>;
|
|
58
|
-
/**
|
|
59
|
-
* setEx 设置数据并设置过期时间
|
|
60
|
-
* @param {string} key 键
|
|
61
|
-
* @param seconds 过期时间 单位秒
|
|
62
|
-
* @param {string} value 值
|
|
63
|
-
* @returns {Promise<void>|Error}
|
|
64
|
-
*/
|
|
65
|
-
setEx(key: string, seconds: number, value: string): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* exists 判断键是否存在
|
|
68
|
-
* @param {string} key 键
|
|
69
|
-
* @returns {Promise<number>|Error}
|
|
70
|
-
*/
|
|
71
|
-
exists(key: string): Promise<number>;
|
|
72
|
-
/**
|
|
73
|
-
* zAdd 有序集合添加元素
|
|
74
|
-
* @param {string} key 键
|
|
75
|
-
* @param {object} data 数据
|
|
76
|
-
* @param data.score 分数
|
|
77
|
-
* @param {string} data.value 值
|
|
78
|
-
*/
|
|
79
|
-
zAdd(key: string, { score, value }: {
|
|
80
|
-
score: number;
|
|
81
|
-
value: string;
|
|
82
|
-
}): Promise<void>;
|
|
83
|
-
/**
|
|
84
|
-
* zRem 有序集合删除元素
|
|
85
|
-
* @param {string} key 键
|
|
86
|
-
* @param {string} value 值
|
|
87
|
-
*/
|
|
88
|
-
zRem(key: string, value: string): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* zIncrBy 有序集合分数递增
|
|
91
|
-
* @param {string} key 键
|
|
92
|
-
* @param increment 递增值
|
|
93
|
-
* @param {string} value 值
|
|
94
|
-
* @returns {Promise<number>|Error}
|
|
95
|
-
*/
|
|
96
|
-
zIncrBy(key: string, increment: number, value: string): Promise<number>;
|
|
97
|
-
/**
|
|
98
|
-
* zRangeByScore 有序集合根据分数范围获取元素
|
|
99
|
-
* @param {string} key 键
|
|
100
|
-
* @param min 最小分数
|
|
101
|
-
* @param max 最大分数
|
|
102
|
-
* @returns {Promise<string[]>|Error}
|
|
103
|
-
*/
|
|
104
|
-
zRangeByScore(key: string, min: number, max: number): Promise<any[]>;
|
|
105
|
-
/**
|
|
106
|
-
* zScore 有序集合获取元素分数
|
|
107
|
-
* @param {string} key 键
|
|
108
|
-
* @param {string} value 值
|
|
109
|
-
* @returns {Promise<number>|Error}
|
|
110
|
-
*/
|
|
111
|
-
zScore(key: string, value: string): Promise<number | null>;
|
|
112
|
-
}
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import { Level } from 'level';
|
|
2
|
-
export default class RedisLevel {
|
|
3
|
-
level;
|
|
4
|
-
/** 过期时间映射表 */
|
|
5
|
-
#expireMap;
|
|
6
|
-
/** 唯一标识符 用于区分不同的数据库 */
|
|
7
|
-
id;
|
|
8
|
-
constructor() {
|
|
9
|
-
const path = process.cwd() + '/data/db/RedisLevel';
|
|
10
|
-
this.level = new Level(path, { valueEncoding: 'json' });
|
|
11
|
-
this.id = 'RedisLevel';
|
|
12
|
-
this.#expireMap = new Map();
|
|
13
|
-
this.#expireHandle();
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* 过期时间处理 每分钟检查一次
|
|
17
|
-
*/
|
|
18
|
-
async #expireHandle() {
|
|
19
|
-
setInterval(async () => {
|
|
20
|
-
const now = Date.now();
|
|
21
|
-
// 获取代理对象的键值对数组
|
|
22
|
-
const entries = Array.from(this.#expireMap.entries());
|
|
23
|
-
for (const [key, expire] of entries) {
|
|
24
|
-
if (expire < now) {
|
|
25
|
-
await this.level.del(key);
|
|
26
|
-
this.#expireMap.delete(key); // 通过代理的方式删除键值对
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}, 60000);
|
|
30
|
-
/**
|
|
31
|
-
* 对expireMap进行代理 实现持久化 每次触发都保存到数据库
|
|
32
|
-
*/
|
|
33
|
-
const handler = {
|
|
34
|
-
get: function (target, prop, receiver) {
|
|
35
|
-
if (prop === 'get' || prop === 'entries') {
|
|
36
|
-
return function (...args) {
|
|
37
|
-
const reflect = Reflect.get(target, prop).apply(target, args);
|
|
38
|
-
return typeof reflect === 'function' ? reflect.bind(target) : reflect;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const reflect = Reflect.get(target, prop, receiver);
|
|
42
|
-
return typeof reflect === 'function' ? reflect.bind(target) : reflect;
|
|
43
|
-
},
|
|
44
|
-
set: function (target, key, value) {
|
|
45
|
-
target.set(key, value);
|
|
46
|
-
// 修改后持久化到数据库
|
|
47
|
-
const reflect = Reflect.set(target, key, value);
|
|
48
|
-
return typeof reflect === 'function' ? reflect.bind(target) : reflect;
|
|
49
|
-
},
|
|
50
|
-
deleteProperty: function (target, key) {
|
|
51
|
-
Reflect.deleteProperty(target, key);
|
|
52
|
-
// 删除后持久化到数据库
|
|
53
|
-
const reflect = Reflect.deleteProperty(target, key);
|
|
54
|
-
return typeof reflect === 'function' ? reflect.bind(target) : reflect;
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
this.#expireMap = new Proxy(this.#expireMap, handler);
|
|
58
|
-
/** 延迟2秒执行 */
|
|
59
|
-
setTimeout(async () => this.level.open(), 2000);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* get 获取数据
|
|
63
|
-
* @param {string} key 键
|
|
64
|
-
* @returns {Promise<string>|Error} 数据
|
|
65
|
-
*/
|
|
66
|
-
async get(key) {
|
|
67
|
-
try {
|
|
68
|
-
/** 先查过期时间 */
|
|
69
|
-
const expire = this.#expireMap.get(key);
|
|
70
|
-
if (expire && expire < Date.now()) {
|
|
71
|
-
await this.level.del(key);
|
|
72
|
-
this.#expireMap.delete(key);
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
return await this.level.get(key);
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
if (error.notFound)
|
|
79
|
-
return null;
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* set 设置数据
|
|
85
|
-
* @param key 键
|
|
86
|
-
* @param value 值
|
|
87
|
-
* @param options 选项
|
|
88
|
-
*/
|
|
89
|
-
async set(key, value, options) {
|
|
90
|
-
if (options && options.EX) {
|
|
91
|
-
this.#expireMap.set(key, Date.now() + options.EX * 1000);
|
|
92
|
-
}
|
|
93
|
-
return await this.level.put(key, value);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* del 删除数据
|
|
97
|
-
* @param key 键
|
|
98
|
-
*/
|
|
99
|
-
async del(key) {
|
|
100
|
-
this.#expireMap.delete(key);
|
|
101
|
-
return await this.level.del(key);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* keys 获取所有键
|
|
105
|
-
* @param prefix 前缀
|
|
106
|
-
*/
|
|
107
|
-
async keys(prefix = '') {
|
|
108
|
-
/** 去掉末尾的* */
|
|
109
|
-
prefix = prefix.replace(/\*$/, '');
|
|
110
|
-
const list = await this.level.keys({ gte: prefix, lt: `${prefix}\xFF` }).all();
|
|
111
|
-
this.#checkKeys(list);
|
|
112
|
-
return list;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* 给一个kyes 检查是否过期
|
|
116
|
-
* @param keys 键数组
|
|
117
|
-
*/
|
|
118
|
-
async #checkKeys(keys) {
|
|
119
|
-
for (const key of keys) {
|
|
120
|
-
const expire = this.#expireMap.get(key);
|
|
121
|
-
if (expire && expire < Date.now()) {
|
|
122
|
-
await this.level.del(key);
|
|
123
|
-
this.#expireMap.delete(key);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* incr 递增数据
|
|
129
|
-
* @param {string} key 键
|
|
130
|
-
* @returns {Promise<number>|Error}
|
|
131
|
-
*/
|
|
132
|
-
async incr(key) {
|
|
133
|
-
let value = Number(await this.get(key));
|
|
134
|
-
if (value === null) {
|
|
135
|
-
value = 0;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
value = Number(value);
|
|
139
|
-
if (isNaN(value))
|
|
140
|
-
throw new Error('Value is not a number');
|
|
141
|
-
}
|
|
142
|
-
value += 1;
|
|
143
|
-
await this.set(key, value.toString());
|
|
144
|
-
return value;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* decr 递减数据
|
|
148
|
-
* @param {string} key 键
|
|
149
|
-
* @returns {Promise<number>|Error}
|
|
150
|
-
*/
|
|
151
|
-
async decr(key) {
|
|
152
|
-
let value = Number(await this.get(key));
|
|
153
|
-
if (value === null) {
|
|
154
|
-
value = 0;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
value = Number(value);
|
|
158
|
-
if (isNaN(value))
|
|
159
|
-
throw new Error('Value is not a number');
|
|
160
|
-
}
|
|
161
|
-
value -= 1;
|
|
162
|
-
await this.set(key, value.toString());
|
|
163
|
-
return value;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* expire 设置过期时间
|
|
167
|
-
* @param {string} key 键
|
|
168
|
-
* @param seconds 过期时间 单位秒
|
|
169
|
-
* @returns {Promise<number>|Error}
|
|
170
|
-
*/
|
|
171
|
-
async expire(key, seconds) {
|
|
172
|
-
this.#expireMap.set(key, Date.now() + seconds * 1000);
|
|
173
|
-
return seconds;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* ttl 获取过期时间
|
|
177
|
-
* @param {string} key 键
|
|
178
|
-
* @returns {Promise<number>|Error}
|
|
179
|
-
*/
|
|
180
|
-
async ttl(key) {
|
|
181
|
-
const expire = this.#expireMap.get(key);
|
|
182
|
-
if (expire) {
|
|
183
|
-
return Math.ceil((expire - Date.now()) / 1000);
|
|
184
|
-
}
|
|
185
|
-
return -2;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* setEx 设置数据并设置过期时间
|
|
189
|
-
* @param {string} key 键
|
|
190
|
-
* @param seconds 过期时间 单位秒
|
|
191
|
-
* @param {string} value 值
|
|
192
|
-
* @returns {Promise<void>|Error}
|
|
193
|
-
*/
|
|
194
|
-
async setEx(key, seconds, value) {
|
|
195
|
-
this.#expireMap.set(key, Date.now() + seconds * 1000);
|
|
196
|
-
return await this.level.put(key, value);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* exists 判断键是否存在
|
|
200
|
-
* @param {string} key 键
|
|
201
|
-
* @returns {Promise<number>|Error}
|
|
202
|
-
*/
|
|
203
|
-
async exists(key) {
|
|
204
|
-
const value = await this.get(key);
|
|
205
|
-
return value === null ? 0 : 1;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* zAdd 有序集合添加元素
|
|
209
|
-
* @param {string} key 键
|
|
210
|
-
* @param {object} data 数据
|
|
211
|
-
* @param data.score 分数
|
|
212
|
-
* @param {string} data.value 值
|
|
213
|
-
*/
|
|
214
|
-
async zAdd(key, { score, value }) {
|
|
215
|
-
const set = await this.get(key);
|
|
216
|
-
const arr = (set ? JSON.parse(set) : []);
|
|
217
|
-
arr.push({ score, value });
|
|
218
|
-
arr.sort((a, b) => a.score - b.score);
|
|
219
|
-
await this.set(key, JSON.stringify(arr));
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* zRem 有序集合删除元素
|
|
223
|
-
* @param {string} key 键
|
|
224
|
-
* @param {string} value 值
|
|
225
|
-
*/
|
|
226
|
-
async zRem(key, value) {
|
|
227
|
-
const set = await this.get(key);
|
|
228
|
-
if (set === null)
|
|
229
|
-
return;
|
|
230
|
-
let arr = JSON.parse(set);
|
|
231
|
-
arr = arr.filter((item) => item.value !== value);
|
|
232
|
-
await this.set(key, JSON.stringify(arr));
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* zIncrBy 有序集合分数递增
|
|
236
|
-
* @param {string} key 键
|
|
237
|
-
* @param increment 递增值
|
|
238
|
-
* @param {string} value 值
|
|
239
|
-
* @returns {Promise<number>|Error}
|
|
240
|
-
*/
|
|
241
|
-
async zIncrBy(key, increment, value) {
|
|
242
|
-
const set = await this.get(key);
|
|
243
|
-
if (set === null)
|
|
244
|
-
throw new Error('Set does not exist');
|
|
245
|
-
const arr = JSON.parse(set);
|
|
246
|
-
const item = arr.find((item) => item.value === value);
|
|
247
|
-
if (item)
|
|
248
|
-
item.score += increment;
|
|
249
|
-
arr.sort((a, b) => a.score - b.score);
|
|
250
|
-
await this.set(key, JSON.stringify(arr));
|
|
251
|
-
return item.score;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* zRangeByScore 有序集合根据分数范围获取元素
|
|
255
|
-
* @param {string} key 键
|
|
256
|
-
* @param min 最小分数
|
|
257
|
-
* @param max 最大分数
|
|
258
|
-
* @returns {Promise<string[]>|Error}
|
|
259
|
-
*/
|
|
260
|
-
async zRangeByScore(key, min, max) {
|
|
261
|
-
const set = await this.get(key);
|
|
262
|
-
if (set === null)
|
|
263
|
-
return [];
|
|
264
|
-
const arr = JSON.parse(set);
|
|
265
|
-
return arr.filter((item) => item.score >= min && item.score <= max).map((item) => item.value);
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* zScore 有序集合获取元素分数
|
|
269
|
-
* @param {string} key 键
|
|
270
|
-
* @param {string} value 值
|
|
271
|
-
* @returns {Promise<number>|Error}
|
|
272
|
-
*/
|
|
273
|
-
async zScore(key, value) {
|
|
274
|
-
const set = await this.get(key);
|
|
275
|
-
if (set === null)
|
|
276
|
-
return null;
|
|
277
|
-
const arr = JSON.parse(set);
|
|
278
|
-
const item = arr.find((item) => item.value === value);
|
|
279
|
-
return item ? item.score : null;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { GroupCfg, KarinEventTypes, AllListenEvent, PluginRule } from '../../types/index.js';
|
|
2
|
-
export declare class EventBaseHandler {
|
|
3
|
-
e: KarinEventTypes;
|
|
4
|
-
/** 仅在群聊下存在 */
|
|
5
|
-
config: GroupCfg;
|
|
6
|
-
/**
|
|
7
|
-
* - 是否打印群消息日志
|
|
8
|
-
*/
|
|
9
|
-
GroupMsgPrint: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* 处理事件,加入自定义字段
|
|
12
|
-
*/
|
|
13
|
-
constructor(e: KarinEventTypes);
|
|
14
|
-
/**
|
|
15
|
-
* cd检查 返回false表示在cd中
|
|
16
|
-
*/
|
|
17
|
-
getCd(): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* 群聊黑白名单检查 返回false表示未通过
|
|
20
|
-
*/
|
|
21
|
-
getGroupEnable(): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* 用户黑白名单检查 返回false表示未通过
|
|
24
|
-
*/
|
|
25
|
-
getUserEnable(): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* 处理私聊功能 功能开启返回true
|
|
28
|
-
*/
|
|
29
|
-
private(): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* 根据事件类型过滤事件 返回false表示未通过
|
|
32
|
-
*/
|
|
33
|
-
filtEvent(event: AllListenEvent): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* 判断权限
|
|
36
|
-
*/
|
|
37
|
-
filterPermission(permission?: PluginRule['permission']): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* 快速回复
|
|
40
|
-
*/
|
|
41
|
-
reply(): void;
|
|
42
|
-
}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { listener, pluginLoader } from '../../core/index.js';
|
|
2
|
-
import { review } from './review.js';
|
|
3
|
-
import { segment, common, logger, config } from '../../utils/index.js';
|
|
4
|
-
export class EventBaseHandler {
|
|
5
|
-
e;
|
|
6
|
-
/** 仅在群聊下存在 */
|
|
7
|
-
config;
|
|
8
|
-
/**
|
|
9
|
-
* - 是否打印群消息日志
|
|
10
|
-
*/
|
|
11
|
-
GroupMsgPrint;
|
|
12
|
-
/**
|
|
13
|
-
* 处理事件,加入自定义字段
|
|
14
|
-
*/
|
|
15
|
-
constructor(e) {
|
|
16
|
-
this.e = e;
|
|
17
|
-
this.GroupMsgPrint = true;
|
|
18
|
-
/** 加入e.bot */
|
|
19
|
-
!this.e.bot && Object.defineProperty(this.e, 'bot', { value: listener.getBot(this.e.self_id) });
|
|
20
|
-
if (this.e.group_id)
|
|
21
|
-
this.config = config.group(this.e.group_id, this.e);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* cd检查 返回false表示在cd中
|
|
25
|
-
*/
|
|
26
|
-
getCd() {
|
|
27
|
-
if (review.CD(this.e, this.config))
|
|
28
|
-
return true;
|
|
29
|
-
logger.debug(`[消息拦截][${this.e.group_id}][${this.e.user_id}] 正在冷却中`);
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 群聊黑白名单检查 返回false表示未通过
|
|
34
|
-
*/
|
|
35
|
-
getGroupEnable() {
|
|
36
|
-
if (review.GroupEnable(this.e))
|
|
37
|
-
return true;
|
|
38
|
-
logger.debug(`[消息拦截][${this.e.group_id}][${this.e.user_id}] 未通过群聊黑白名单检查`);
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* 用户黑白名单检查 返回false表示未通过
|
|
43
|
-
*/
|
|
44
|
-
getUserEnable() {
|
|
45
|
-
if (review.UserEnable(this.e))
|
|
46
|
-
return true;
|
|
47
|
-
logger.debug(`[消息拦截][${this.e.group_id}][${this.e.user_id}] 未通过用户黑白名单检查`);
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* 处理私聊功能 功能开启返回true
|
|
52
|
-
*/
|
|
53
|
-
private() {
|
|
54
|
-
/** 检查私聊是否开启 */
|
|
55
|
-
if (this.e.user_id !== 'input' && this.e.isPrivate && !review.Private()) {
|
|
56
|
-
/** 用户处于白名单 */
|
|
57
|
-
if (config.Config?.private?.white_list?.includes(String(this.e.user_id)))
|
|
58
|
-
return true;
|
|
59
|
-
/** 不处于白名单 检查是否存在提示词 */
|
|
60
|
-
if (config.Config?.private?.tips)
|
|
61
|
-
this.e.reply(config.Config.private.tips);
|
|
62
|
-
logger.debug(`[消息拦截][${this.e.user_id}] 私聊功能未开启`);
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 根据事件类型过滤事件 返回false表示未通过
|
|
69
|
-
*/
|
|
70
|
-
filtEvent(event) {
|
|
71
|
-
/** 事件映射表 */
|
|
72
|
-
const eventMap = {
|
|
73
|
-
message: () => `message.${this.e.sub_event}`,
|
|
74
|
-
message_sent: () => `message_sent.${this.e.sub_event}`,
|
|
75
|
-
meta_event: () => `message.${this.e.sub_event}`,
|
|
76
|
-
notice: () => `notice.${this.e.sub_event}`,
|
|
77
|
-
request: () => `request.${this.e.sub_event}`,
|
|
78
|
-
};
|
|
79
|
-
const eventType = eventMap[this.e.event]();
|
|
80
|
-
return eventType.includes(event);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* 判断权限
|
|
84
|
-
*/
|
|
85
|
-
filterPermission(permission) {
|
|
86
|
-
if (!permission || permission === 'all')
|
|
87
|
-
return true;
|
|
88
|
-
if (permission === 'master') {
|
|
89
|
-
if (!this.e.isMaster) {
|
|
90
|
-
this.e.reply('暂无权限,只有主人才能操作');
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
if (permission === 'admin') {
|
|
96
|
-
if (!this.e.isMaster && !this.e.isAdmin) {
|
|
97
|
-
this.e.reply('暂无权限,只有管理员才能操作');
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
if (this.e.isGroup) {
|
|
103
|
-
const list = {
|
|
104
|
-
'group.owner': {
|
|
105
|
-
role: 'owner',
|
|
106
|
-
name: '群主',
|
|
107
|
-
},
|
|
108
|
-
'group.admin': {
|
|
109
|
-
role: 'admin',
|
|
110
|
-
name: '群管理员',
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
const role = list[permission];
|
|
114
|
-
if (!role)
|
|
115
|
-
return true;
|
|
116
|
-
if (role.role === 'owner' && this.e.sender?.role === 'owner')
|
|
117
|
-
return true;
|
|
118
|
-
if (role.role === 'admin' && (this.e.sender?.role === 'owner' || this.e.sender?.role === 'admin'))
|
|
119
|
-
return true;
|
|
120
|
-
this.e.reply(`暂无权限,只有${role.name}才能操作`);
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* 快速回复
|
|
127
|
-
*/
|
|
128
|
-
reply() {
|
|
129
|
-
/**
|
|
130
|
-
* 快速回复
|
|
131
|
-
* @param elements 回复内容
|
|
132
|
-
* @param options 回复选项
|
|
133
|
-
*/
|
|
134
|
-
this.e.reply = async (elements = '', options = { reply: false, recallMsg: 0, at: false, retry_count: 1 }) => {
|
|
135
|
-
const request = {
|
|
136
|
-
message_id: '',
|
|
137
|
-
message_time: 0,
|
|
138
|
-
raw_data: undefined,
|
|
139
|
-
};
|
|
140
|
-
const message = common.makeMessage(elements);
|
|
141
|
-
/** 先调用中间件 */
|
|
142
|
-
for (const info of pluginLoader.use.replyMsg) {
|
|
143
|
-
try {
|
|
144
|
-
let next = false;
|
|
145
|
-
let exit = false;
|
|
146
|
-
const nextFn = () => { next = true; };
|
|
147
|
-
const exitFn = () => { exit = true; };
|
|
148
|
-
await info.fn(this.e, message, nextFn, exitFn);
|
|
149
|
-
if (exit) {
|
|
150
|
-
const plugin = pluginLoader.plugin.get(info.key);
|
|
151
|
-
logger.debug(`[消息中间件][${plugin.plugin}][${plugin.file}] 主动操作退出`);
|
|
152
|
-
return request;
|
|
153
|
-
}
|
|
154
|
-
if (!next)
|
|
155
|
-
break;
|
|
156
|
-
if (!next)
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
logger.error('[消息中间件] 调用失败,已跳过');
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
const { reply = false, recallMsg = 0, at, retry_count = 1 } = options;
|
|
164
|
-
/** 加入at */
|
|
165
|
-
if (at && this.e.isGroup)
|
|
166
|
-
message.unshift(segment.at(this.e.user_id));
|
|
167
|
-
/** 加入引用回复 */
|
|
168
|
-
if (reply && 'message_id' in this.e)
|
|
169
|
-
message.unshift(segment.reply(this.e.message_id));
|
|
170
|
-
/** 先发 提升速度 */
|
|
171
|
-
const result = this.e.replyCallback(message, retry_count);
|
|
172
|
-
const ReplyLog = common.makeMessageLog(message);
|
|
173
|
-
if (this.e.isGroup) {
|
|
174
|
-
review.GroupMsgPrint(this.e) && logger.bot('info', this.e.self_id, `${logger.green(`Send Group ${this.e.group_id}: `)}${ReplyLog.replace(/\n/g, '\\n')}`);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
this.e.self_id !== 'input' && logger.bot('info', this.e.self_id, `${logger.green(`Send private ${this.e.user_id}: `)}${ReplyLog.replace(/\n/g, '\\n')}`);
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
listener.emit('karin:count:send', 1);
|
|
181
|
-
/** 取结果 */
|
|
182
|
-
const Res = await result;
|
|
183
|
-
request.message_id = Res.message_id || '';
|
|
184
|
-
request.message_time = Res.message_time || Date.now();
|
|
185
|
-
request.raw_data = Res.raw_data || undefined;
|
|
186
|
-
logger.bot('debug', this.e.self_id, `回复消息结果:${JSON.stringify(request)}`);
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
logger.bot('error', this.e.self_id, `回复消息失败:${ReplyLog.replace(/\n/g, '\\n')}`);
|
|
190
|
-
logger.bot('error', this.e.self_id, error.stack || error.message || JSON.stringify(error));
|
|
191
|
-
}
|
|
192
|
-
/** 快速撤回 */
|
|
193
|
-
if (recallMsg > 0 && request.message_id) {
|
|
194
|
-
setTimeout(() => this.e.bot.RecallMessage(this.e.contact, request.message_id), recallMsg * 1000);
|
|
195
|
-
}
|
|
196
|
-
return request;
|
|
197
|
-
};
|
|
198
|
-
Object.freeze(this.e.reply);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { EventBaseHandler } from './base.js';
|
|
2
|
-
import { KarinMessageType } from '../../types/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* 消息事件
|
|
5
|
-
*/
|
|
6
|
-
export declare class MessageHandler extends EventBaseHandler {
|
|
7
|
-
e: KarinMessageType;
|
|
8
|
-
constructor(e: KarinMessageType);
|
|
9
|
-
/**
|
|
10
|
-
* 先对消息事件进行初始化
|
|
11
|
-
*/
|
|
12
|
-
init(): void;
|
|
13
|
-
/**
|
|
14
|
-
* 响应模式检查 返回false表示未通过
|
|
15
|
-
*/
|
|
16
|
-
getMode(): boolean;
|
|
17
|
-
/**
|
|
18
|
-
* 打印
|
|
19
|
-
*/
|
|
20
|
-
print(): void;
|
|
21
|
-
/**
|
|
22
|
-
* 处理消息
|
|
23
|
-
*/
|
|
24
|
-
deal(): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* 处理上下文
|
|
27
|
-
*/
|
|
28
|
-
context(): Promise<boolean>;
|
|
29
|
-
}
|