node-karin 0.10.0 → 0.10.2
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/group.yaml +40 -2
- package/lib/adapter/onebot/11/index.js +1 -1
- package/lib/cli/init.js +1 -1
- package/lib/cli/karin.js +1 -1
- package/lib/core/index.d.ts +9 -9
- package/lib/core/index.js +9 -9
- package/lib/core/init/dir.js +7 -0
- package/lib/core/init/init.js +46 -0
- package/lib/core/{karin.d.ts → karin/karin.d.ts} +1 -1
- package/lib/core/karin/karin.js +194 -0
- package/lib/core/{listener.d.ts → listener/listener.d.ts} +1 -1
- package/lib/core/listener/listener.js +213 -0
- package/lib/core/{plugin.app.d.ts → plugin/app.d.ts} +1 -1
- package/lib/core/plugin/app.js +19 -0
- package/lib/core/{plugin.d.ts → plugin/base.d.ts} +1 -1
- package/lib/core/plugin/base.js +140 -0
- package/lib/core/{plugin.loader.d.ts → plugin/loader.d.ts} +3 -3
- package/lib/core/plugin/loader.js +579 -0
- package/lib/core/process/process.js +100 -0
- package/lib/core/server/server.js +283 -0
- package/lib/db/index.d.ts +2 -2
- package/lib/db/index.js +2 -2
- package/lib/db/level/level.js +36 -0
- package/lib/db/redis/redis.js +135 -0
- package/lib/db/redis/redis_level.js +287 -0
- package/lib/event/{event.handler.d.ts → handler/base.d.ts} +2 -2
- package/lib/event/handler/base.js +173 -0
- package/lib/event/{message.handler.d.ts → handler/message.d.ts} +3 -3
- package/lib/event/handler/message.js +270 -0
- package/lib/event/{notice.handler.d.ts → handler/notice.d.ts} +3 -3
- package/lib/event/handler/notice.js +212 -0
- package/lib/event/{request.handler.d.ts → handler/request.d.ts} +3 -3
- package/lib/event/handler/request.js +118 -0
- package/lib/event/{review.handler.d.ts → handler/review.d.ts} +3 -3
- package/lib/event/handler/review.js +391 -0
- package/lib/event/index.d.ts +5 -5
- package/lib/event/index.js +5 -5
- package/lib/render/base.d.ts +1 -1
- package/lib/render/client.d.ts +1 -1
- package/lib/render/client.js +2 -12
- package/lib/render/client_even.d.ts +1 -1
- package/lib/render/client_even.js +2 -12
- package/lib/render/http.d.ts +1 -1
- package/lib/render/http.js +1 -1
- package/lib/render/server.js +1 -1
- package/lib/types/adapter/{adapter.d.ts → base.d.ts} +2 -2
- package/lib/types/config/config.js +1 -0
- package/lib/types/element/element.js +1 -0
- package/lib/types/event/message.d.ts +1 -1
- package/lib/types/event/reply.d.ts +1 -1
- package/lib/types/index.d.ts +6 -6
- package/lib/types/index.js +6 -6
- package/lib/types/logger/logger.js +1 -0
- package/lib/types/{plugin.d.ts → plugin/plugin.d.ts} +3 -3
- package/lib/types/plugin/plugin.js +1 -0
- package/lib/types/render/render.js +1 -0
- package/lib/utils/{common.d.ts → common/common.d.ts} +1 -1
- package/lib/utils/common/common.js +591 -0
- package/lib/utils/{config.d.ts → config/config.d.ts} +37 -19
- package/lib/utils/config/config.js +328 -0
- package/lib/utils/config/updateVersion.js +145 -0
- package/lib/utils/config/yamlEditor.js +292 -0
- package/lib/utils/{handler.d.ts → core/handler.d.ts} +1 -1
- package/lib/utils/core/handler.js +115 -0
- package/lib/utils/core/init.js +213 -0
- package/lib/utils/core/logger.js +105 -0
- package/lib/utils/{segment.d.ts → core/segment.d.ts} +1 -1
- package/lib/utils/core/segment.js +441 -0
- package/lib/utils/index.d.ts +11 -11
- package/lib/utils/index.js +11 -11
- package/lib/utils/{button.d.ts → tools/button.d.ts} +1 -1
- package/lib/utils/tools/button.js +38 -0
- package/lib/utils/tools/exec.js +37 -0
- package/lib/utils/tools/ffmpeg.js +25 -0
- package/lib/utils/tools/update.js +139 -0
- package/package.json +1 -1
- package/lib/core/dir.js +0 -7
- package/lib/core/init.js +0 -42
- package/lib/core/karin.js +0 -194
- package/lib/core/listener.js +0 -217
- package/lib/core/plugin.app.js +0 -19
- package/lib/core/plugin.js +0 -145
- package/lib/core/plugin.loader.js +0 -561
- package/lib/core/process.js +0 -98
- package/lib/core/server.js +0 -269
- package/lib/db/level.js +0 -37
- package/lib/db/redis.js +0 -134
- package/lib/db/redis_level.js +0 -293
- package/lib/event/event.handler.js +0 -167
- package/lib/event/message.handler.js +0 -254
- package/lib/event/notice.handler.js +0 -204
- package/lib/event/request.handler.js +0 -110
- package/lib/event/review.handler.js +0 -387
- package/lib/types/config.js +0 -1
- package/lib/types/element.js +0 -1
- package/lib/types/logger.js +0 -1
- package/lib/types/plugin.js +0 -1
- package/lib/types/render.js +0 -1
- package/lib/utils/button.js +0 -34
- package/lib/utils/common.js +0 -572
- package/lib/utils/config.js +0 -318
- package/lib/utils/exec.js +0 -36
- package/lib/utils/ffmpeg.js +0 -25
- package/lib/utils/handler.js +0 -109
- package/lib/utils/init.js +0 -208
- package/lib/utils/logger.js +0 -104
- package/lib/utils/segment.js +0 -470
- package/lib/utils/update.js +0 -135
- package/lib/utils/updateVersion.js +0 -145
- package/lib/utils/yamlEditor.js +0 -279
- /package/lib/core/{dir.d.ts → init/dir.d.ts} +0 -0
- /package/lib/core/{init.d.ts → init/init.d.ts} +0 -0
- /package/lib/core/{process.d.ts → process/process.d.ts} +0 -0
- /package/lib/core/{server.d.ts → server/server.d.ts} +0 -0
- /package/lib/db/{level.d.ts → level/level.d.ts} +0 -0
- /package/lib/db/{redis.d.ts → redis/redis.d.ts} +0 -0
- /package/lib/db/{redis_level.d.ts → redis/redis_level.d.ts} +0 -0
- /package/lib/types/adapter/{adapter.js → base.js} +0 -0
- /package/lib/types/{config.d.ts → config/config.d.ts} +0 -0
- /package/lib/types/{element.d.ts → element/element.d.ts} +0 -0
- /package/lib/types/{logger.d.ts → logger/logger.d.ts} +0 -0
- /package/lib/types/{render.d.ts → render/render.d.ts} +0 -0
- /package/lib/utils/{updateVersion.d.ts → config/updateVersion.d.ts} +0 -0
- /package/lib/utils/{yamlEditor.d.ts → config/yamlEditor.d.ts} +0 -0
- /package/lib/utils/{init.d.ts → core/init.d.ts} +0 -0
- /package/lib/utils/{logger.d.ts → core/logger.d.ts} +0 -0
- /package/lib/utils/{exec.d.ts → tools/exec.d.ts} +0 -0
- /package/lib/utils/{ffmpeg.d.ts → tools/ffmpeg.d.ts} +0 -0
- /package/lib/utils/{update.d.ts → tools/update.d.ts} +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import log4js from 'log4js';
|
|
4
|
+
import { config } from '../config/config.js';
|
|
5
|
+
const logsDir = './logs';
|
|
6
|
+
if (!fs.existsSync(logsDir))
|
|
7
|
+
fs.mkdirSync(logsDir);
|
|
8
|
+
const { log_level, log_days_Keep, log4jsCfg } = config.Config;
|
|
9
|
+
const level = log_level || log4jsCfg.level || 'info';
|
|
10
|
+
const daysToKeep = log_days_Keep || log4jsCfg.daysToKeep || 7;
|
|
11
|
+
const { overall, fragments, maxLogSize } = log4jsCfg;
|
|
12
|
+
const defaultOptions = { appenders: ['console'], level, enableCallStack: process.env.KarinMode === 'dev' };
|
|
13
|
+
const options = {
|
|
14
|
+
appenders: {
|
|
15
|
+
console: {
|
|
16
|
+
type: 'console',
|
|
17
|
+
layout: {
|
|
18
|
+
type: 'pattern',
|
|
19
|
+
pattern: `%[[Karin][%d{hh:mm:ss.SSS}][%4.4p]%] ${process.env.KarinMode === 'dev' ? '[%f{3}:%l] ' : ''}%m`,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
categories: { default: defaultOptions },
|
|
24
|
+
};
|
|
25
|
+
if (overall) {
|
|
26
|
+
defaultOptions.appenders.unshift('overall');
|
|
27
|
+
options.appenders.overall = {
|
|
28
|
+
/** 输出到文件 */
|
|
29
|
+
type: 'file',
|
|
30
|
+
filename: 'logs/logger',
|
|
31
|
+
pattern: 'yyyy-MM-dd.log',
|
|
32
|
+
/** 日期后缀 */
|
|
33
|
+
keepFileExt: true,
|
|
34
|
+
/** 日志文件名中包含日期模式 */
|
|
35
|
+
alwaysIncludePattern: true,
|
|
36
|
+
/** 日志文件保留天数 */
|
|
37
|
+
daysToKeep,
|
|
38
|
+
/** 日志输出格式 */
|
|
39
|
+
layout: {
|
|
40
|
+
type: 'pattern',
|
|
41
|
+
pattern: '[%d{hh:mm:ss.SSS}][%4.4p] %m',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (fragments) {
|
|
46
|
+
defaultOptions.appenders.unshift('fragments');
|
|
47
|
+
options.appenders.fragments = {
|
|
48
|
+
type: 'file',
|
|
49
|
+
filename: 'logs/app.log',
|
|
50
|
+
pattern: 'MM-dd.log',
|
|
51
|
+
keepFileExt: true,
|
|
52
|
+
alwaysIncludePattern: true,
|
|
53
|
+
daysToKeep,
|
|
54
|
+
maxLogSize: (maxLogSize || 30) * 1024 * 1024,
|
|
55
|
+
/** 最大文件数 */
|
|
56
|
+
numBackups: 9999999,
|
|
57
|
+
/** 日志输出格式 */
|
|
58
|
+
layout: {
|
|
59
|
+
type: 'pattern',
|
|
60
|
+
pattern: '[%d{hh:mm:ss.SSS}][%4.4p] %m',
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
log4js.configure(options);
|
|
65
|
+
export const logger = log4js.getLogger('default');
|
|
66
|
+
logger.chalk = chalk;
|
|
67
|
+
logger.red = chalk.red;
|
|
68
|
+
logger.green = chalk.green;
|
|
69
|
+
logger.yellow = chalk.yellow;
|
|
70
|
+
logger.blue = chalk.blue;
|
|
71
|
+
logger.magenta = chalk.magenta;
|
|
72
|
+
logger.cyan = chalk.cyan;
|
|
73
|
+
logger.white = chalk.white;
|
|
74
|
+
logger.gray = chalk.gray;
|
|
75
|
+
logger.violet = chalk.hex('#868ECC');
|
|
76
|
+
logger.fnc = chalk.hex(config.Config.log_color || '#FFFF00');
|
|
77
|
+
logger.bot = (level, id, ...args) => {
|
|
78
|
+
switch (level) {
|
|
79
|
+
case 'trace':
|
|
80
|
+
logger.trace(logger.violet(`[Bot:${id}]`), ...args);
|
|
81
|
+
break;
|
|
82
|
+
case 'debug':
|
|
83
|
+
logger.debug(logger.violet(`[Bot:${id}]`), ...args);
|
|
84
|
+
break;
|
|
85
|
+
case 'mark':
|
|
86
|
+
logger.mark(logger.violet(`[Bot:${id}]`), ...args);
|
|
87
|
+
break;
|
|
88
|
+
case 'info':
|
|
89
|
+
logger.info(logger.violet(`[Bot:${id}]`), ...args);
|
|
90
|
+
break;
|
|
91
|
+
case 'warn':
|
|
92
|
+
logger.warn(logger.violet(`[Bot:${id}]`), ...args);
|
|
93
|
+
break;
|
|
94
|
+
case 'error':
|
|
95
|
+
logger.error(logger.violet(`[Bot:${id}]`), ...args);
|
|
96
|
+
break;
|
|
97
|
+
case 'fatal':
|
|
98
|
+
logger.fatal(logger.violet(`[Bot:${id}]`), ...args);
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
logger.info(logger.violet(`[Bot:${id}]`), ...args);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
global.logger = logger;
|
|
105
|
+
export default logger;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextElement, AtElement, ImageElement, FaceElement, BubbleFaceElement, ReplyElement, VideoElement, BasketballElement, DiceElement, RpsElement, PokeElement, MusicElement, WeatherElement, LocationElement, ShareElement, GiftElement, MarketFaceElement, ForwardElement, ContactElement, JsonElement, XmlElement, FileElement, ButtonElement, CustomMusicElemen, TplMarkdownElement, RawMarkdownElement, NodeElement, KarinElement, LongMsgElement, RecordElement } from '
|
|
1
|
+
import { TextElement, AtElement, ImageElement, FaceElement, BubbleFaceElement, ReplyElement, VideoElement, BasketballElement, DiceElement, RpsElement, PokeElement, MusicElement, WeatherElement, LocationElement, ShareElement, GiftElement, MarketFaceElement, ForwardElement, ContactElement, JsonElement, XmlElement, FileElement, ButtonElement, CustomMusicElemen, TplMarkdownElement, RawMarkdownElement, NodeElement, KarinElement, LongMsgElement, RecordElement } from '../../types/index.js';
|
|
2
2
|
export declare const segment: {
|
|
3
3
|
/**
|
|
4
4
|
* 纯文本
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
export const segment = new (class Segment {
|
|
2
|
+
/**
|
|
3
|
+
* 纯文本
|
|
4
|
+
* @param text - 文本内容
|
|
5
|
+
* @returns {TextElement} 纯文本元素
|
|
6
|
+
*/
|
|
7
|
+
text(text) {
|
|
8
|
+
return {
|
|
9
|
+
type: 'text',
|
|
10
|
+
text: text + '',
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 提及
|
|
15
|
+
* 提供一个uid即可
|
|
16
|
+
* @param uid - uid
|
|
17
|
+
* @param uin - uin
|
|
18
|
+
* @param name - 名称
|
|
19
|
+
* @returns {AtElement} 提及元素
|
|
20
|
+
*/
|
|
21
|
+
at(uid, uin, name) {
|
|
22
|
+
return {
|
|
23
|
+
type: 'at',
|
|
24
|
+
uid: uid + '',
|
|
25
|
+
uin: (uin || '') + '',
|
|
26
|
+
name,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 表情
|
|
31
|
+
* @param id - 表情ID
|
|
32
|
+
* @param is_big - 是否大表情,默认不是
|
|
33
|
+
* @returns {FaceElement} 表情元素
|
|
34
|
+
*/
|
|
35
|
+
face(id, is_big = false) {
|
|
36
|
+
return {
|
|
37
|
+
type: 'face',
|
|
38
|
+
id: Number(id),
|
|
39
|
+
is_big,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 弹射表情
|
|
44
|
+
* @param id - 表情ID
|
|
45
|
+
* @param count - 数量
|
|
46
|
+
* @returns {BubbleFaceElement} 弹射表情元素
|
|
47
|
+
*/
|
|
48
|
+
bubble_face(id, count = 1) {
|
|
49
|
+
return {
|
|
50
|
+
type: 'bubble_face',
|
|
51
|
+
id: Number(id),
|
|
52
|
+
count: Number(count),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 引用回复
|
|
57
|
+
* @param message_id - 消息ID
|
|
58
|
+
* @returns {ReplyElement} 引用回复元素
|
|
59
|
+
*/
|
|
60
|
+
reply(message_id) {
|
|
61
|
+
return {
|
|
62
|
+
type: 'reply',
|
|
63
|
+
message_id: message_id + '',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 图片
|
|
68
|
+
* - 一般情况提供一个file参数即可,其他参数一般为收到的消息中的参数
|
|
69
|
+
* @param file - 图片URL或路径、Base64
|
|
70
|
+
* @param options - 图片类型、名称、MD5、子类型、宽度、高度
|
|
71
|
+
* @returns {ImageElement} 图片元素
|
|
72
|
+
*/
|
|
73
|
+
image(file, options = {}) {
|
|
74
|
+
const file_type = options.file_type || 'original';
|
|
75
|
+
const name = options.name || '';
|
|
76
|
+
const md5 = options.md5 || '';
|
|
77
|
+
const sub_type = options.sub_type || '';
|
|
78
|
+
const width = options.width || 0;
|
|
79
|
+
const height = options.height || 0;
|
|
80
|
+
return {
|
|
81
|
+
type: 'image',
|
|
82
|
+
file,
|
|
83
|
+
file_type,
|
|
84
|
+
name,
|
|
85
|
+
md5,
|
|
86
|
+
sub_type,
|
|
87
|
+
width,
|
|
88
|
+
height,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 语音
|
|
93
|
+
* @description 即将废弃,请使用voice
|
|
94
|
+
* @param file - 语音URL或路径、Base64
|
|
95
|
+
* @param magic - 是否魔法语音,默认为 false
|
|
96
|
+
* @param md5 - 语音md5
|
|
97
|
+
* @param name - 语音名称
|
|
98
|
+
* @returns {VoiceElement} 语音元素
|
|
99
|
+
*/
|
|
100
|
+
record(file, magic = false, md5 = '', name = '') {
|
|
101
|
+
return {
|
|
102
|
+
type: 'record',
|
|
103
|
+
file,
|
|
104
|
+
magic,
|
|
105
|
+
md5,
|
|
106
|
+
name,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 语音 即将废弃 请使用segment.record
|
|
111
|
+
* @param file - 语音URL或路径、Base64
|
|
112
|
+
* @param magic - 是否魔法语音,默认为 false
|
|
113
|
+
* @param md5 - 语音md5
|
|
114
|
+
* @param name - 语音名称
|
|
115
|
+
* @returns {VoiceElement} 语音元素
|
|
116
|
+
* @deprecated 即将废弃 请使用segment.record
|
|
117
|
+
*/
|
|
118
|
+
voice(file, magic = false, md5 = '', name = '') {
|
|
119
|
+
return {
|
|
120
|
+
type: 'record',
|
|
121
|
+
file,
|
|
122
|
+
magic,
|
|
123
|
+
md5,
|
|
124
|
+
name,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 视频
|
|
129
|
+
* @param file - 视频URL或路径、Base64
|
|
130
|
+
* @param md5 - 视频md5
|
|
131
|
+
* @param name - 视频名称
|
|
132
|
+
* @returns {VideoElement} 视频元素
|
|
133
|
+
*/
|
|
134
|
+
video(file, md5 = '', name = '') {
|
|
135
|
+
return {
|
|
136
|
+
type: 'video',
|
|
137
|
+
file,
|
|
138
|
+
md5,
|
|
139
|
+
name,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 篮球
|
|
144
|
+
* @param id - 篮球ID
|
|
145
|
+
* @returns {BasketballElement} 篮球元素
|
|
146
|
+
*/
|
|
147
|
+
basketball(id) {
|
|
148
|
+
return {
|
|
149
|
+
type: 'basketball',
|
|
150
|
+
id,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 骰子
|
|
155
|
+
* @param id - 骰子ID
|
|
156
|
+
* @returns {DiceElement} 骰子元素
|
|
157
|
+
*/
|
|
158
|
+
dice(id) {
|
|
159
|
+
return {
|
|
160
|
+
type: 'dice',
|
|
161
|
+
id,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 石头剪刀布
|
|
166
|
+
* @param id - 石头剪刀布ID
|
|
167
|
+
* @returns {RpsElement} 石头剪刀布元素
|
|
168
|
+
*/
|
|
169
|
+
rps(id) {
|
|
170
|
+
return {
|
|
171
|
+
type: 'rps',
|
|
172
|
+
id,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 戳一戳
|
|
177
|
+
* @param id - 戳一戳ID
|
|
178
|
+
* @param poke_type - 戳一戳类型
|
|
179
|
+
* @param strength - 戳一戳强度(1-5 默认1)
|
|
180
|
+
* @returns {PokeElement} 戳一戳元素
|
|
181
|
+
*/
|
|
182
|
+
poke(id, poke_type, strength = 1) {
|
|
183
|
+
return {
|
|
184
|
+
type: 'poke',
|
|
185
|
+
id,
|
|
186
|
+
poke_type,
|
|
187
|
+
strength,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 自定义音乐
|
|
192
|
+
* @param url - 跳转链接
|
|
193
|
+
* @param audio - 音乐音频链接
|
|
194
|
+
* @param title - 标题
|
|
195
|
+
* @param author - 歌手
|
|
196
|
+
* @param pic - 封面
|
|
197
|
+
* @returns {CustomMusicElemen} 自定义音乐元素
|
|
198
|
+
*/
|
|
199
|
+
customMusic(url, audio, title, author, pic, id) {
|
|
200
|
+
return {
|
|
201
|
+
type: 'music',
|
|
202
|
+
platform: 'custom',
|
|
203
|
+
url,
|
|
204
|
+
audio,
|
|
205
|
+
title,
|
|
206
|
+
author,
|
|
207
|
+
pic,
|
|
208
|
+
id,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* 音乐
|
|
213
|
+
* @param platform - 音乐平台
|
|
214
|
+
* @param id - 音乐ID
|
|
215
|
+
* @returns {MusicElement} 音乐元素
|
|
216
|
+
*/
|
|
217
|
+
music(platform, id) {
|
|
218
|
+
return {
|
|
219
|
+
type: 'music',
|
|
220
|
+
platform,
|
|
221
|
+
id,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 天气
|
|
226
|
+
* @param city - 城市名称
|
|
227
|
+
* @param code - 城市代码
|
|
228
|
+
* @returns {WeatherElement} 天气元素
|
|
229
|
+
*/
|
|
230
|
+
weather(city, code) {
|
|
231
|
+
return {
|
|
232
|
+
type: 'weather',
|
|
233
|
+
city,
|
|
234
|
+
code,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* 位置
|
|
239
|
+
* @param lat - 纬度
|
|
240
|
+
* @param lon - 经度
|
|
241
|
+
* @param title - 标题
|
|
242
|
+
* @param address - 地址
|
|
243
|
+
* @returns {LocationElement} 位置元素
|
|
244
|
+
*/
|
|
245
|
+
location(lat, lon, title, address) {
|
|
246
|
+
return {
|
|
247
|
+
type: 'location',
|
|
248
|
+
lat,
|
|
249
|
+
lon,
|
|
250
|
+
title,
|
|
251
|
+
address,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 分享
|
|
256
|
+
* @param url - 分享链接
|
|
257
|
+
* @param title - 分享标题
|
|
258
|
+
* @param content - 分享内容
|
|
259
|
+
* @param image - 分享图片
|
|
260
|
+
* @returns {ShareElement} 分享元素
|
|
261
|
+
*/
|
|
262
|
+
share(url, title, content, image) {
|
|
263
|
+
return {
|
|
264
|
+
type: 'share',
|
|
265
|
+
url,
|
|
266
|
+
title,
|
|
267
|
+
content,
|
|
268
|
+
image,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* 礼物
|
|
273
|
+
* @param qq - QQ 号
|
|
274
|
+
* @param id - 礼物ID
|
|
275
|
+
* @returns {GiftElement} 礼物元素
|
|
276
|
+
*/
|
|
277
|
+
gift(qq, id) {
|
|
278
|
+
return {
|
|
279
|
+
type: 'gift',
|
|
280
|
+
qq,
|
|
281
|
+
id,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* 商城表情
|
|
286
|
+
* @param id - 表情ID
|
|
287
|
+
* @returns {MarketFaceElement} 商城表情元素
|
|
288
|
+
*/
|
|
289
|
+
marketFace(id) {
|
|
290
|
+
return {
|
|
291
|
+
type: 'market_face',
|
|
292
|
+
id,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* 转发
|
|
297
|
+
* @param res_id - 资源ID
|
|
298
|
+
* @param uniseq - 序列号(可能不对?)
|
|
299
|
+
* @param summary - 摘要
|
|
300
|
+
* @param description - 描述
|
|
301
|
+
* @returns {ForwardElement} 转发元素
|
|
302
|
+
*/
|
|
303
|
+
forward(res_id, uniseq, summary, description) {
|
|
304
|
+
return {
|
|
305
|
+
type: 'forward',
|
|
306
|
+
res_id,
|
|
307
|
+
uniseq: uniseq || '',
|
|
308
|
+
summary: summary || '',
|
|
309
|
+
description: description || '',
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* 分享名片
|
|
314
|
+
* @param scene - 分享类型
|
|
315
|
+
* @param peer - 被推荐人的QQ号或者被推荐群的群号
|
|
316
|
+
* @returns {ContactElement} 分享名片元素
|
|
317
|
+
*/
|
|
318
|
+
contact(scene, peer) {
|
|
319
|
+
return {
|
|
320
|
+
type: 'contact',
|
|
321
|
+
scene,
|
|
322
|
+
peer,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* JSON
|
|
327
|
+
* @param data - JSON序列化过的字符串
|
|
328
|
+
* @returns {JsonElement} JSON元素
|
|
329
|
+
*/
|
|
330
|
+
json(data) {
|
|
331
|
+
return {
|
|
332
|
+
type: 'json',
|
|
333
|
+
data,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* XML
|
|
338
|
+
* @param data - XML字符串
|
|
339
|
+
* @returns {XmlElement} XML元素
|
|
340
|
+
*/
|
|
341
|
+
xml(data) {
|
|
342
|
+
return {
|
|
343
|
+
type: 'xml',
|
|
344
|
+
data,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* 文件
|
|
349
|
+
*/
|
|
350
|
+
file(options) {
|
|
351
|
+
return {
|
|
352
|
+
type: 'file',
|
|
353
|
+
file: options.url,
|
|
354
|
+
name: options.name || '',
|
|
355
|
+
size: options.size || 0,
|
|
356
|
+
expire_time: options.expire_time || 0,
|
|
357
|
+
id: options.id || '',
|
|
358
|
+
url: options.url,
|
|
359
|
+
biz: options.biz || 0,
|
|
360
|
+
sub_id: options.sub_id || '',
|
|
361
|
+
md5: options.md5 || '',
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* 长消息
|
|
366
|
+
* @param id - ID
|
|
367
|
+
*/
|
|
368
|
+
long_msg(id) {
|
|
369
|
+
return {
|
|
370
|
+
type: 'long_msg',
|
|
371
|
+
id,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Markdown
|
|
376
|
+
* @param content - 原生markdown内容
|
|
377
|
+
* @param config - 未知的参数
|
|
378
|
+
*/
|
|
379
|
+
markdown(content, config) {
|
|
380
|
+
return {
|
|
381
|
+
type: 'markdown',
|
|
382
|
+
content,
|
|
383
|
+
config,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* 构建模板Markdown
|
|
388
|
+
* @param custom_template_id - 模板ID
|
|
389
|
+
* @param params - 模板markdown参数
|
|
390
|
+
*/
|
|
391
|
+
markdown_tpl(
|
|
392
|
+
/**
|
|
393
|
+
* - 模板ID
|
|
394
|
+
*/
|
|
395
|
+
custom_template_id,
|
|
396
|
+
/**
|
|
397
|
+
* - 模板markdown参数
|
|
398
|
+
*/
|
|
399
|
+
params) {
|
|
400
|
+
return {
|
|
401
|
+
type: 'markdown_tpl',
|
|
402
|
+
custom_template_id,
|
|
403
|
+
params,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* 按钮
|
|
408
|
+
* @param data - 按钮数据
|
|
409
|
+
* @returns {ButtonElement} 按钮元素
|
|
410
|
+
*/
|
|
411
|
+
button(data) {
|
|
412
|
+
return {
|
|
413
|
+
type: 'button',
|
|
414
|
+
data,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
rows(data) {
|
|
418
|
+
const rows = [];
|
|
419
|
+
if (!Array.isArray(data))
|
|
420
|
+
data = [data];
|
|
421
|
+
for (const i of data) {
|
|
422
|
+
rows.push(this.button(i));
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
return { type: 'rows', rows };
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* 转发自定义节点
|
|
429
|
+
* @param user_id - 用户ID
|
|
430
|
+
* @param nickname - 用户昵称
|
|
431
|
+
* @param content - 节点内容
|
|
432
|
+
*/
|
|
433
|
+
node(user_id, nickname, content) {
|
|
434
|
+
return {
|
|
435
|
+
type: 'node',
|
|
436
|
+
user_id,
|
|
437
|
+
nickname,
|
|
438
|
+
content,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
})();
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from './button.js';
|
|
2
|
-
export * from './common.js';
|
|
3
|
-
export * from './config.js';
|
|
4
|
-
export * from './ffmpeg.js';
|
|
5
|
-
export * from './handler.js';
|
|
6
|
-
export * from './exec.js';
|
|
7
|
-
export * from './segment.js';
|
|
8
|
-
export * from './update.js';
|
|
9
|
-
export * from './yamlEditor.js';
|
|
10
|
-
export * from './logger.js';
|
|
11
|
-
export * from './updateVersion.js';
|
|
1
|
+
export * from './tools/button.js';
|
|
2
|
+
export * from './common/common.js';
|
|
3
|
+
export * from './config/config.js';
|
|
4
|
+
export * from './tools/ffmpeg.js';
|
|
5
|
+
export * from './core/handler.js';
|
|
6
|
+
export * from './tools/exec.js';
|
|
7
|
+
export * from './core/segment.js';
|
|
8
|
+
export * from './tools/update.js';
|
|
9
|
+
export * from './config/yamlEditor.js';
|
|
10
|
+
export * from './core/logger.js';
|
|
11
|
+
export * from './config/updateVersion.js';
|
package/lib/utils/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from './button.js'
|
|
2
|
-
export * from './common.js'
|
|
3
|
-
export * from './config.js'
|
|
4
|
-
export * from './ffmpeg.js'
|
|
5
|
-
export * from './handler.js'
|
|
6
|
-
export * from './exec.js'
|
|
7
|
-
export * from './segment.js'
|
|
8
|
-
export * from './update.js'
|
|
9
|
-
export * from './yamlEditor.js'
|
|
10
|
-
export * from './logger.js'
|
|
11
|
-
export * from './updateVersion.js'
|
|
1
|
+
export * from './tools/button.js'
|
|
2
|
+
export * from './common/common.js'
|
|
3
|
+
export * from './config/config.js'
|
|
4
|
+
export * from './tools/ffmpeg.js'
|
|
5
|
+
export * from './core/handler.js'
|
|
6
|
+
export * from './tools/exec.js'
|
|
7
|
+
export * from './core/segment.js'
|
|
8
|
+
export * from './tools/update.js'
|
|
9
|
+
export * from './config/yamlEditor.js'
|
|
10
|
+
export * from './core/logger.js'
|
|
11
|
+
export * from './config/updateVersion.js'
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { KarinMessageType } from '
|
|
1
|
+
import { KarinMessageType } from '../../types/index.js';
|
|
2
2
|
export declare const button: (e: KarinMessageType) => Promise<any>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import logger from '../core/logger.js';
|
|
2
|
+
import { pluginLoader as loader } from '../../core/index.js';
|
|
3
|
+
export const button = async (e) => {
|
|
4
|
+
const button = [];
|
|
5
|
+
for (const v of loader.buttonIds) {
|
|
6
|
+
const info = loader.PluginList[v];
|
|
7
|
+
for (const v of info.button) {
|
|
8
|
+
const reg = v.reg;
|
|
9
|
+
if (reg.test(e.msg)) {
|
|
10
|
+
try {
|
|
11
|
+
let res;
|
|
12
|
+
let done = true;
|
|
13
|
+
/**
|
|
14
|
+
* 标记函数 如果调用则继续执行 循环下一个按钮插件处理
|
|
15
|
+
*/
|
|
16
|
+
const reject = () => { done = false; };
|
|
17
|
+
if (typeof v.fnc === 'function') {
|
|
18
|
+
res = await v.fnc(e, reject);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const cla = new info.file.Fnc();
|
|
22
|
+
cla.e = e;
|
|
23
|
+
res = await cla[v.fnc](e, reject);
|
|
24
|
+
}
|
|
25
|
+
if (res)
|
|
26
|
+
button.push(res);
|
|
27
|
+
if (done)
|
|
28
|
+
return res;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
logger.error(error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** 理论上不会走到这里,但是还是要稳一手,不排除有所有插件都false... */
|
|
37
|
+
return button;
|
|
38
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import logger from '../core/logger.js';
|
|
2
|
+
import { exec as execCmd } from 'child_process';
|
|
3
|
+
/**
|
|
4
|
+
* 执行 shell 命令
|
|
5
|
+
* @param cmd 命令
|
|
6
|
+
* @param log 是否打印日志
|
|
7
|
+
* @param options 选项
|
|
8
|
+
*/
|
|
9
|
+
export const exec = (cmd, log = true, options = { cwd: process.cwd(), encoding: 'utf-8' }) => {
|
|
10
|
+
return new Promise(resolve => {
|
|
11
|
+
const logMessage = (level, message) => {
|
|
12
|
+
if (log)
|
|
13
|
+
logger[level](message);
|
|
14
|
+
};
|
|
15
|
+
const logType = (status) => {
|
|
16
|
+
switch (status) {
|
|
17
|
+
case '开始执行':
|
|
18
|
+
return logger.yellow('[exec][开始执行]');
|
|
19
|
+
case 'ok':
|
|
20
|
+
return logger.green('[exec][执行成功]');
|
|
21
|
+
case 'failed':
|
|
22
|
+
return logger.red('[exec][执行失败]');
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const formatMessage = (status, details) => [logType(status), `cmd: ${cmd}`, `cwd: ${options.cwd || process.cwd()}`, details, '--------'].join('\n');
|
|
26
|
+
logMessage('info', formatMessage('开始执行', ''));
|
|
27
|
+
execCmd(cmd, options, (error, stdout, stderr) => {
|
|
28
|
+
if (error) {
|
|
29
|
+
logMessage('error', formatMessage('failed', `Error: ${error.message || error.stack || error.toString()}`));
|
|
30
|
+
return resolve({ status: 'failed', error, stdout, stderr });
|
|
31
|
+
}
|
|
32
|
+
logMessage('mark', formatMessage('ok', `stdout: ${stdout}\nstderr: ${stderr}`));
|
|
33
|
+
resolve({ status: 'ok', error, stdout, stderr });
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
export default exec;
|