node-karin 0.12.13 → 0.12.15
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/lib/adapter/input/index.d.ts +1 -1
- package/lib/adapter/input/index.js +1 -1
- package/lib/adapter/onebot/11/event.js +90 -84
- package/lib/adapter/onebot/11/index.d.ts +89 -127
- package/lib/adapter/onebot/11/index.js +192 -254
- package/lib/cli/index.js +2 -2
- package/lib/core/init/config.js +1 -1
- package/lib/core/karin/karin.d.ts +21 -30
- package/lib/core/karin/karin.js +7 -9
- package/lib/core/listener/listener.js +11 -11
- package/lib/core/plugin/base.d.ts +7 -21
- package/lib/core/plugin/base.js +2 -6
- package/lib/core/plugin/loader.d.ts +5 -15
- package/lib/core/plugin/loader.js +5 -15
- package/lib/core/server/server.js +4 -4
- package/lib/event/handler/base.d.ts +1 -3
- package/lib/event/handler/base.js +1 -3
- package/lib/event/handler/message.js +9 -3
- package/lib/event/handler/notice.js +38 -32
- package/lib/event/handler/request.js +6 -6
- package/lib/index.d.ts +6 -0
- package/lib/index.js +6 -0
- package/lib/modules.d.ts +2 -2
- package/lib/modules.js +3 -2
- package/lib/types/adapter/accept.d.ts +24 -0
- package/lib/types/adapter/accept.js +1 -0
- package/lib/types/adapter/api.d.ts +88 -264
- package/lib/types/adapter/base.d.ts +3 -3
- package/lib/types/config/config.d.ts +4 -12
- package/lib/types/element/element.d.ts +119 -349
- package/lib/types/element/qqbot.d.ts +4 -12
- package/lib/types/event/contact.d.ts +6 -12
- package/lib/types/event/event.d.ts +59 -163
- package/lib/types/event/message.d.ts +11 -31
- package/lib/types/event/message.js +10 -12
- package/lib/types/event/notice.d.ts +118 -325
- package/lib/types/event/notice.js +8 -10
- package/lib/types/event/request.d.ts +29 -66
- package/lib/types/event/request.js +8 -10
- package/lib/types/event/sender.d.ts +7 -21
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/onebot11/api.d.ts +49 -49
- package/lib/types/onebot11/event.d.ts +131 -347
- package/lib/types/onebot11/params.d.ts +184 -456
- package/lib/types/onebot11/response.d.ts +159 -381
- package/lib/types/onebot11/segment.d.ts +25 -75
- package/lib/types/onebot11/sender.d.ts +13 -39
- package/lib/types/plugin/app.d.ts +7 -11
- package/lib/types/plugin/plugin.d.ts +55 -165
- package/lib/types/render/render.d.ts +16 -48
- package/lib/utils/common/common.js +4 -2
- package/lib/utils/config/config.js +1 -1
- package/lib/utils/core/logger.js +3 -3
- package/lib/utils/core/segment.d.ts +28 -59
- package/lib/utils/core/segment.js +26 -30
- package/lib/utils/tools/restart.d.ts +3 -3
- package/lib/utils/tools/restart.js +5 -5
- package/package.json +1 -2
package/lib/cli/index.js
CHANGED
|
@@ -41,7 +41,7 @@ export class KarinCli {
|
|
|
41
41
|
getConfigPath(name) {
|
|
42
42
|
const filePath = `./config/config/${name}.yaml`;
|
|
43
43
|
if (!fs.existsSync(filePath))
|
|
44
|
-
return `${this.karinDir}/config/
|
|
44
|
+
return `${this.karinDir}/config/defSet/${name}.yaml`;
|
|
45
45
|
return filePath;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
@@ -131,7 +131,7 @@ export class KarinCli {
|
|
|
131
131
|
fs.writeFileSync(filePath, yaml.stringify(data));
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
const cmd = `pm2 start ${filePath}
|
|
134
|
+
const cmd = `pm2 start ${filePath}`;
|
|
135
135
|
await this.exec(cmd);
|
|
136
136
|
console.log('pm2服务已启动 可执行 【npx karin log】 查看日志');
|
|
137
137
|
process.exit(0);
|
package/lib/core/init/config.js
CHANGED
|
@@ -177,7 +177,7 @@ export class KarinCfgInit {
|
|
|
177
177
|
}
|
|
178
178
|
/** 检查是否为官方源 如果不是则生成.npmrc */
|
|
179
179
|
const registry = await this.shell('npm config get registry');
|
|
180
|
-
if (registry
|
|
180
|
+
if (!registry || !registry?.includes('registry.npmjs.org')) {
|
|
181
181
|
const text = `node_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/sqlite3
|
|
182
182
|
better_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3
|
|
183
183
|
sass_binary_site=https://registry.npmmirror.com/-/binary/node-sass
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { Contact, KarinElement, KarinMessage, KarinRenderType, RenderResult, AllMessageSubType, CommandInfo, TaskInfo, HandlerInfo,
|
|
1
|
+
import { Contact, KarinElement, KarinMessage, KarinRenderType, RenderResult, AllMessageSubType, CommandInfo, TaskInfo, HandlerInfo, UseInfo, UseMapType, AppType, ButtonInfo, Permission, AcceptDict } from '../../types/index.js';
|
|
2
2
|
import { Listeners } from '../listener/listener.js';
|
|
3
3
|
export type FncFunction = (e: KarinMessage) => Promise<boolean>;
|
|
4
4
|
export type FncElement = string | KarinElement | Array<KarinElement>;
|
|
5
5
|
export type UseFnType<K extends keyof UseMapType> = UseMapType[K];
|
|
6
6
|
export interface Options {
|
|
7
|
-
/**
|
|
8
|
-
* - 插件名称 不传则使用 插件名称:函数名
|
|
9
|
-
*/
|
|
7
|
+
/** 插件名称 不传则使用 插件名称:函数名 */
|
|
10
8
|
name?: string;
|
|
11
9
|
/**
|
|
12
10
|
* - 插件优先级 数字越小优先级越高
|
|
@@ -20,9 +18,7 @@ export interface Options {
|
|
|
20
18
|
log?: boolean | Function;
|
|
21
19
|
}
|
|
22
20
|
export interface OptionsCommand extends Options {
|
|
23
|
-
/**
|
|
24
|
-
* - 监听事件
|
|
25
|
-
*/
|
|
21
|
+
/** 监听事件 */
|
|
26
22
|
event?: `${AllMessageSubType}`;
|
|
27
23
|
/**
|
|
28
24
|
* - 权限
|
|
@@ -41,9 +37,7 @@ export interface OptionsElement extends OptionsCommand {
|
|
|
41
37
|
* @default false
|
|
42
38
|
*/
|
|
43
39
|
reply?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* - 延迟回复 单位毫秒
|
|
46
|
-
*/
|
|
40
|
+
/** 延迟回复 单位毫秒 */
|
|
47
41
|
delay?: number;
|
|
48
42
|
/**
|
|
49
43
|
* - 发送是否撤回消息 单位秒
|
|
@@ -92,9 +86,9 @@ export declare class Karin extends Listeners {
|
|
|
92
86
|
* 构建contact
|
|
93
87
|
* @param scene - 场景
|
|
94
88
|
* @param peer - 群号或者用户id
|
|
95
|
-
* @param
|
|
89
|
+
* @param subPeer - 子id
|
|
96
90
|
*/
|
|
97
|
-
contact(scene: Contact['scene'], peer: Contact['peer'],
|
|
91
|
+
contact(scene: Contact['scene'], peer: Contact['peer'], subPeer?: Contact['sub_peer']): Contact;
|
|
98
92
|
/**
|
|
99
93
|
* 构建group_contact
|
|
100
94
|
* @param peer - 群号
|
|
@@ -108,9 +102,9 @@ export declare class Karin extends Listeners {
|
|
|
108
102
|
/**
|
|
109
103
|
* 构建guild_contact
|
|
110
104
|
* @param peer - 频道id
|
|
111
|
-
* @param
|
|
105
|
+
* @param subPeer - 子频道id
|
|
112
106
|
*/
|
|
113
|
-
contactGuild(peer: Contact['peer'],
|
|
107
|
+
contactGuild(peer: Contact['peer'], subPeer: string): Contact;
|
|
114
108
|
/**
|
|
115
109
|
* 快速渲染
|
|
116
110
|
* @param file - 文件路径、http地址
|
|
@@ -132,21 +126,13 @@ export declare class Karin extends Listeners {
|
|
|
132
126
|
* @param options - 上下文选项
|
|
133
127
|
*/
|
|
134
128
|
ctx(e: KarinMessage, options?: {
|
|
135
|
-
/**
|
|
136
|
-
* - 指定用户id触发下文 不指定则使用默认e.user_id
|
|
137
|
-
*/
|
|
129
|
+
/** 指定用户id触发下文 不指定则使用默认e.user_id */
|
|
138
130
|
userId?: string;
|
|
139
|
-
/**
|
|
140
|
-
* - 超时时间 默认120秒
|
|
141
|
-
*/
|
|
131
|
+
/** 超时时间 默认120秒 */
|
|
142
132
|
time?: number;
|
|
143
|
-
/**
|
|
144
|
-
* - 超时后是否回复
|
|
145
|
-
*/
|
|
133
|
+
/** 超时后是否回复 */
|
|
146
134
|
reply?: boolean;
|
|
147
|
-
/**
|
|
148
|
-
* - 超时回复文本 默认为'操作超时已取消'
|
|
149
|
-
*/
|
|
135
|
+
/** 超时回复文本 默认为'操作超时已取消' */
|
|
150
136
|
replyMsg?: string;
|
|
151
137
|
}): Promise<KarinMessage>;
|
|
152
138
|
/**
|
|
@@ -154,7 +140,14 @@ export declare class Karin extends Listeners {
|
|
|
154
140
|
* @param event - 监听事件
|
|
155
141
|
* @param fn - 实现函数
|
|
156
142
|
*/
|
|
157
|
-
accept(event:
|
|
143
|
+
accept<T extends keyof AcceptDict>(event: T, fn: (e: AcceptDict[T]) => boolean, options?: Options): {
|
|
144
|
+
event: T;
|
|
145
|
+
fn: (e: AcceptDict[T]) => boolean;
|
|
146
|
+
log: (id: string, text: string) => void;
|
|
147
|
+
name: string;
|
|
148
|
+
rank: number;
|
|
149
|
+
type: AppType;
|
|
150
|
+
};
|
|
158
151
|
/**
|
|
159
152
|
* 中间件
|
|
160
153
|
* @param type 中间件类型
|
|
@@ -168,9 +161,7 @@ export declare class Karin extends Listeners {
|
|
|
168
161
|
* @param fn - 函数
|
|
169
162
|
*/
|
|
170
163
|
button(reg: RegExp | string, fn: ButtonInfo['fn'], options?: Omit<Options, 'log'>): ButtonInfo;
|
|
171
|
-
/**
|
|
172
|
-
* - 启动
|
|
173
|
-
*/
|
|
164
|
+
/** 启动 */
|
|
174
165
|
run(): Promise<void>;
|
|
175
166
|
}
|
|
176
167
|
export declare const karin: Karin;
|
package/lib/core/karin/karin.js
CHANGED
|
@@ -102,10 +102,10 @@ export class Karin extends Listeners {
|
|
|
102
102
|
* 构建contact
|
|
103
103
|
* @param scene - 场景
|
|
104
104
|
* @param peer - 群号或者用户id
|
|
105
|
-
* @param
|
|
105
|
+
* @param subPeer - 子id
|
|
106
106
|
*/
|
|
107
|
-
contact(scene, peer,
|
|
108
|
-
return { scene, peer, sub_peer };
|
|
107
|
+
contact(scene, peer, subPeer) {
|
|
108
|
+
return { scene, peer, sub_peer: subPeer };
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
111
|
* 构建group_contact
|
|
@@ -124,10 +124,10 @@ export class Karin extends Listeners {
|
|
|
124
124
|
/**
|
|
125
125
|
* 构建guild_contact
|
|
126
126
|
* @param peer - 频道id
|
|
127
|
-
* @param
|
|
127
|
+
* @param subPeer - 子频道id
|
|
128
128
|
*/
|
|
129
|
-
contactGuild(peer,
|
|
130
|
-
return { scene: "guild" /* Scene.Guild */, peer, sub_peer };
|
|
129
|
+
contactGuild(peer, subPeer) {
|
|
130
|
+
return { scene: "guild" /* Scene.Guild */, peer, sub_peer: subPeer };
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
133
|
* - 渲染
|
|
@@ -216,9 +216,7 @@ export class Karin extends Listeners {
|
|
|
216
216
|
type: "button" /* AppType.Button */,
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
|
-
/**
|
|
220
|
-
* - 启动
|
|
221
|
-
*/
|
|
219
|
+
/** 启动 */
|
|
222
220
|
async run() {
|
|
223
221
|
if (this.#start)
|
|
224
222
|
return;
|
|
@@ -87,7 +87,7 @@ export class Listeners extends EventEmitter {
|
|
|
87
87
|
const options = await level.get(key);
|
|
88
88
|
if (!options)
|
|
89
89
|
return;
|
|
90
|
-
const { id, contact, time, message_id } = options;
|
|
90
|
+
const { id, contact, time, message_id: messageId } = options;
|
|
91
91
|
/** 重启花费时间 保留2位小数 */
|
|
92
92
|
const restartTime = ((Date.now() - time) / 1000).toFixed(2);
|
|
93
93
|
/** 超过2分钟不发 */
|
|
@@ -96,7 +96,7 @@ export class Listeners extends EventEmitter {
|
|
|
96
96
|
return false;
|
|
97
97
|
}
|
|
98
98
|
const element = [
|
|
99
|
-
segment.reply(
|
|
99
|
+
segment.reply(messageId),
|
|
100
100
|
segment.text(`\nKarin 重启成功:${restartTime}秒`),
|
|
101
101
|
];
|
|
102
102
|
await this.sendMsg(id, contact, element);
|
|
@@ -231,26 +231,26 @@ export class Listeners extends EventEmitter {
|
|
|
231
231
|
const bot = this.getBot(uid);
|
|
232
232
|
if (!bot)
|
|
233
233
|
throw new Error('发送消息失败: 未找到对应Bot实例');
|
|
234
|
-
const { recallMsg, retry_count } = options;
|
|
234
|
+
const { recallMsg, retry_count: retryCount } = options;
|
|
235
235
|
/** 标准化 */
|
|
236
236
|
const NewElements = common.makeMessage(elements);
|
|
237
|
-
const
|
|
238
|
-
const
|
|
237
|
+
const replyLog = common.makeMessageLog(NewElements);
|
|
238
|
+
const selfId = bot.account.uid || bot.account.uin;
|
|
239
239
|
if (contact.scene === 'group') {
|
|
240
|
-
logger.bot('info',
|
|
240
|
+
logger.bot('info', selfId, `${logger.green('Send Proactive Group')} ${contact.peer}: ${replyLog}`);
|
|
241
241
|
}
|
|
242
242
|
else {
|
|
243
|
-
logger.bot('info',
|
|
243
|
+
logger.bot('info', selfId, `${logger.green('Send Proactive private')} ${contact.peer}: ${replyLog}`);
|
|
244
244
|
}
|
|
245
245
|
try {
|
|
246
246
|
this.emit('karin:count:send', 1);
|
|
247
247
|
/** 取结果 */
|
|
248
|
-
result = await bot.SendMessage(contact, NewElements,
|
|
249
|
-
logger.bot('debug',
|
|
248
|
+
result = await bot.SendMessage(contact, NewElements, retryCount);
|
|
249
|
+
logger.bot('debug', selfId, `主动消息结果:${JSON.stringify(result, null, 2)}`);
|
|
250
250
|
}
|
|
251
251
|
catch (error) {
|
|
252
|
-
logger.bot('error',
|
|
253
|
-
logger.bot('error',
|
|
252
|
+
logger.bot('error', selfId, `主动消息发送失败:${replyLog}`);
|
|
253
|
+
logger.bot('error', selfId, error);
|
|
254
254
|
}
|
|
255
255
|
/** 快速撤回 */
|
|
256
256
|
if (recallMsg && bot.RecallMessage && recallMsg > 0 && result?.message_id) {
|
|
@@ -42,30 +42,20 @@ export declare class Plugin implements PluginType {
|
|
|
42
42
|
*/
|
|
43
43
|
timeout: PluginType['timeout'];
|
|
44
44
|
constructor({ name, desc, event, priority, task, rule, handler, }: {
|
|
45
|
-
/**
|
|
46
|
-
* - 插件名称
|
|
47
|
-
*/
|
|
45
|
+
/** 插件名称 */
|
|
48
46
|
name: string;
|
|
49
|
-
/**
|
|
50
|
-
* - 插件描述 没有则默认为插件名称
|
|
51
|
-
*/
|
|
47
|
+
/** 插件描述 没有则默认为插件名称 */
|
|
52
48
|
desc?: string;
|
|
53
|
-
/**
|
|
54
|
-
* - 监听事件 默认为message
|
|
55
|
-
*/
|
|
49
|
+
/** 监听事件 默认为message */
|
|
56
50
|
event?: PluginType['event'];
|
|
57
|
-
/**
|
|
58
|
-
* - 优先级 默认为10000
|
|
59
|
-
*/
|
|
51
|
+
/** 优先级 默认为10000 */
|
|
60
52
|
priority?: PluginType['priority'];
|
|
61
53
|
/**
|
|
62
54
|
* - 定时任务 即将废弃 请使用karin.task
|
|
63
55
|
* @deprecated
|
|
64
56
|
*/
|
|
65
57
|
task?: PluginType['task'];
|
|
66
|
-
/**
|
|
67
|
-
* - 命令规则
|
|
68
|
-
*/
|
|
58
|
+
/** 命令规则 */
|
|
69
59
|
rule?: PluginType['rule'];
|
|
70
60
|
/**
|
|
71
61
|
* - handler 已废弃 请使用karin.handler
|
|
@@ -73,9 +63,7 @@ export declare class Plugin implements PluginType {
|
|
|
73
63
|
*/
|
|
74
64
|
handler?: PluginType['handler'];
|
|
75
65
|
});
|
|
76
|
-
/**
|
|
77
|
-
* - 快速回复
|
|
78
|
-
*/
|
|
66
|
+
/** 快速回复 */
|
|
79
67
|
reply(msg?: string | KarinElement | Array<KarinElement | string>, options?: {
|
|
80
68
|
/**
|
|
81
69
|
* @param at - 是否at用户
|
|
@@ -103,9 +91,7 @@ export declare class Plugin implements PluginType {
|
|
|
103
91
|
*/
|
|
104
92
|
retry_count?: number;
|
|
105
93
|
}): Promise<ReplyReturn>;
|
|
106
|
-
/**
|
|
107
|
-
* - 快速回复合并转发
|
|
108
|
-
*/
|
|
94
|
+
/** 快速回复合并转发 */
|
|
109
95
|
replyForward(msg: NodeElement[]): Promise<{
|
|
110
96
|
message_id: string;
|
|
111
97
|
}>;
|
package/lib/core/plugin/base.js
CHANGED
|
@@ -49,15 +49,11 @@ export class Plugin {
|
|
|
49
49
|
this.rule = rule;
|
|
50
50
|
this.handler = handler;
|
|
51
51
|
}
|
|
52
|
-
/**
|
|
53
|
-
* - 快速回复
|
|
54
|
-
*/
|
|
52
|
+
/** 快速回复 */
|
|
55
53
|
reply(msg = '', options = { reply: false, recallMsg: 0, at: false, button: false, retry_count: 1 }) {
|
|
56
54
|
return this.e.reply(msg, options);
|
|
57
55
|
}
|
|
58
|
-
/**
|
|
59
|
-
* - 快速回复合并转发
|
|
60
|
-
*/
|
|
56
|
+
/** 快速回复合并转发 */
|
|
61
57
|
async replyForward(msg) {
|
|
62
58
|
const result = await this.e.bot.sendForwardMessage(this.e.contact, msg);
|
|
63
59
|
return result;
|
|
@@ -15,27 +15,17 @@ export interface AppFile {
|
|
|
15
15
|
}
|
|
16
16
|
declare class PluginLoader {
|
|
17
17
|
dir: './plugins';
|
|
18
|
-
/**
|
|
19
|
-
* - 插件索引ID
|
|
20
|
-
*/
|
|
18
|
+
/** 插件索引ID */
|
|
21
19
|
index: number;
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
/**
|
|
26
|
-
* - 监听器
|
|
27
|
-
*/
|
|
20
|
+
/** 定时任务 */
|
|
21
|
+
/** 监听器 */
|
|
28
22
|
watcher: Map<string, chokidar.FSWatcher>;
|
|
29
|
-
/**
|
|
30
|
-
* - 热更新列表
|
|
31
|
-
*/
|
|
23
|
+
/** 热更新列表 */
|
|
32
24
|
watchList: Array<{
|
|
33
25
|
plugin: string;
|
|
34
26
|
path: string;
|
|
35
27
|
}>;
|
|
36
|
-
/**
|
|
37
|
-
* - 依赖缺失收集
|
|
38
|
-
*/
|
|
28
|
+
/** 依赖缺失收集 */
|
|
39
29
|
dependErr: {
|
|
40
30
|
[key: string]: {
|
|
41
31
|
plugin: string;
|
|
@@ -8,25 +8,15 @@ import { karin } from '../karin/karin.js';
|
|
|
8
8
|
import { common, logger } from '../../utils/index.js';
|
|
9
9
|
class PluginLoader {
|
|
10
10
|
dir;
|
|
11
|
-
/**
|
|
12
|
-
* - 插件索引ID
|
|
13
|
-
*/
|
|
11
|
+
/** 插件索引ID */
|
|
14
12
|
index;
|
|
15
|
-
/**
|
|
16
|
-
* - 定时任务
|
|
17
|
-
*/
|
|
13
|
+
/** 定时任务 */
|
|
18
14
|
// task: Array<PluginTask & { App: NewMessagePlugin, schedule?: schedule.Job, file: { dir: dirName, name: fileName } }>
|
|
19
|
-
/**
|
|
20
|
-
* - 监听器
|
|
21
|
-
*/
|
|
15
|
+
/** 监听器 */
|
|
22
16
|
watcher;
|
|
23
|
-
/**
|
|
24
|
-
* - 热更新列表
|
|
25
|
-
*/
|
|
17
|
+
/** 热更新列表 */
|
|
26
18
|
watchList;
|
|
27
|
-
/**
|
|
28
|
-
* - 依赖缺失收集
|
|
29
|
-
*/
|
|
19
|
+
/** 依赖缺失收集 */
|
|
30
20
|
dependErr;
|
|
31
21
|
/** accept */
|
|
32
22
|
accept;
|
|
@@ -176,12 +176,12 @@ export const server = new (class Server {
|
|
|
176
176
|
.replace(/^\.\//, '');
|
|
177
177
|
/** 判断是否为html文件且路径存在 */
|
|
178
178
|
if (!html.endsWith('.html') || !fs.existsSync(html)) {
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
181
|
-
return res.redirect(
|
|
179
|
+
const notFound = config.Server.HttpRender.not_found;
|
|
180
|
+
if (notFound.startsWith('http')) {
|
|
181
|
+
return res.redirect(notFound);
|
|
182
182
|
}
|
|
183
183
|
else {
|
|
184
|
-
return res.status(404).send(JSON.stringify({ code: 404, msg:
|
|
184
|
+
return res.status(404).send(JSON.stringify({ code: 404, msg: notFound || '?' }));
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
let content = fs.readFileSync(html, 'utf-8');
|
|
@@ -163,12 +163,12 @@ export class MessageHandler extends EventBaseHandler {
|
|
|
163
163
|
/** 管理员 */
|
|
164
164
|
this.e.isAdmin = true;
|
|
165
165
|
}
|
|
166
|
-
if (this.e.contact.scene ===
|
|
166
|
+
if (this.e.contact.scene === "friend" /* Scene.Private */) {
|
|
167
167
|
this.e.isPrivate = true;
|
|
168
168
|
this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]`;
|
|
169
169
|
logger.bot('info', this.e.self_id, `私聊:[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
|
|
170
170
|
}
|
|
171
|
-
else if (this.e.contact.scene ===
|
|
171
|
+
else if (this.e.contact.scene === "group" /* Scene.Group */) {
|
|
172
172
|
this.e.isGroup = true;
|
|
173
173
|
this.e.logText = `[Group:${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})]`;
|
|
174
174
|
this.GroupMsgPrint = review.GroupMsgPrint(this.e);
|
|
@@ -176,11 +176,17 @@ export class MessageHandler extends EventBaseHandler {
|
|
|
176
176
|
this.e.group_id && review.alias(this.e, this.config);
|
|
177
177
|
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}`);
|
|
178
178
|
}
|
|
179
|
-
else if (this.e.contact.scene ===
|
|
179
|
+
else if (this.e.contact.scene === "guild" /* Scene.Guild */) {
|
|
180
180
|
this.e.isGuild = true;
|
|
181
181
|
this.e.logText = `[Guild:${this.e.contact.peer}-${this.e.contact.sub_peer}-${this.e.user_id}(${this.e.sender.nick || ''})]`;
|
|
182
182
|
logger.bot('info', this.e.self_id, `频道消息:[${this.e.contact.peer}-${this.e.contact.sub_peer}-${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
|
|
183
183
|
}
|
|
184
|
+
else if (this.e.contact.scene === "guild_direct" /* Scene.GuildDirect */) {
|
|
185
|
+
this.e.isGuild = true;
|
|
186
|
+
this.e.isPrivate = true;
|
|
187
|
+
this.e.logText = `[GuildDirect:${this.e.contact.peer}-${this.e.contact.sub_peer}-${this.e.user_id}(${this.e.sender.nick || ''})]`;
|
|
188
|
+
logger.bot('info', this.e.self_id, `频道私信:[${this.e.contact.peer}-${this.e.contact.sub_peer}-${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
|
|
189
|
+
}
|
|
184
190
|
else {
|
|
185
191
|
logger.bot('info', this.e.self_id, `未知消息:${JSON.stringify(this.e)}`);
|
|
186
192
|
}
|
|
@@ -108,52 +108,52 @@ export class NoticeHandler extends EventBaseHandler {
|
|
|
108
108
|
/** 私聊文件上传 */
|
|
109
109
|
case "private_file_uploaded" /* NoticeSubType.PrivateFileUploaded */: {
|
|
110
110
|
const content = this.e.content;
|
|
111
|
-
const { file_url } = content;
|
|
112
|
-
this.e.raw_message = `[私聊文件上传]: ${
|
|
111
|
+
const { file_url: fileUrl } = content;
|
|
112
|
+
this.e.raw_message = `[私聊文件上传]: ${fileUrl}`;
|
|
113
113
|
break;
|
|
114
114
|
}
|
|
115
115
|
/** 群头像戳一戳 */
|
|
116
116
|
case "group_poke" /* NoticeSubType.GroupPoke */: {
|
|
117
|
-
const { operator_uid, operator_uin, target_uid, target_uin } = this.e.content;
|
|
118
|
-
this.e.raw_message = `[群戳一戳]: ${
|
|
117
|
+
const { operator_uid: operatorUid, operator_uin: operatorUin, target_uid: targetUid, target_uin: targetUin } = this.e.content;
|
|
118
|
+
this.e.raw_message = `[群戳一戳]: ${operatorUid || operatorUin} 戳了戳 ${targetUid || targetUin}`;
|
|
119
119
|
break;
|
|
120
120
|
}
|
|
121
121
|
/** 群消息撤回 */
|
|
122
122
|
case "group_recall" /* NoticeSubType.GroupRecall */: {
|
|
123
|
-
const { operator_uid, operator_uin, message_id } = this.e.content;
|
|
124
|
-
this.e.raw_message = `[群消息撤回]: ${
|
|
123
|
+
const { operator_uid: operatorUid, operator_uin: operatorUin, message_id: messageId } = this.e.content;
|
|
124
|
+
this.e.raw_message = `[群消息撤回]: ${operatorUid || operatorUin} 撤回了一条消息 ${messageId}`;
|
|
125
125
|
break;
|
|
126
126
|
}
|
|
127
127
|
/** 群文件上传 */
|
|
128
128
|
case "group_file_uploaded" /* NoticeSubType.GroupFileUploaded */: {
|
|
129
|
-
const { file_url, operator_uid, operator_uin } = this.e.content;
|
|
130
|
-
this.e.raw_message = `[群文件上传]: ${
|
|
129
|
+
const { file_url: fileUrl, operator_uid: operatorUid, operator_uin: operatorUin } = this.e.content;
|
|
130
|
+
this.e.raw_message = `[群文件上传]: ${operatorUid || operatorUin} 上传了 ${fileUrl}`;
|
|
131
131
|
break;
|
|
132
132
|
}
|
|
133
133
|
/** 群成员增加 */
|
|
134
134
|
case "group_member_increase" /* NoticeSubType.GroupMemberIncrease */: {
|
|
135
|
-
const { operator_uid, operator_uin, target_uid, target_uin, type } = this.e.content;
|
|
136
|
-
this.e.raw_message = `[群成员新增]: ${
|
|
135
|
+
const { operator_uid: operatorUid, operator_uin: operatorUin, target_uid: targetUid, target_uin: targetUin, type } = this.e.content;
|
|
136
|
+
this.e.raw_message = `[群成员新增]: ${operatorUid || operatorUin} ${type === 'invite' ? '邀请' : '同意'} ${targetUid || targetUin} 加入群聊`;
|
|
137
137
|
break;
|
|
138
138
|
}
|
|
139
139
|
/** 群成员减少 */
|
|
140
140
|
case "group_member_decrease" /* NoticeSubType.GroupMemberDecrease */: {
|
|
141
141
|
switch (this.e.content.type) {
|
|
142
142
|
case 'leave': {
|
|
143
|
-
const { target_uid, target_uin } = this.e.content;
|
|
144
|
-
this.e.raw_message = `[群成员减少]: ${
|
|
143
|
+
const { target_uid: targetUid, target_uin: targetUin } = this.e.content;
|
|
144
|
+
this.e.raw_message = `[群成员减少]: ${targetUid || targetUin} 主动退出群聊`;
|
|
145
145
|
break;
|
|
146
146
|
}
|
|
147
147
|
// 群成员被踢
|
|
148
148
|
case 'kick': {
|
|
149
|
-
const { operator_uid, operator_uin, target_uid, target_uin } = this.e.content;
|
|
150
|
-
this.e.raw_message = `[群成员减少]: ${
|
|
149
|
+
const { operator_uid: operatorUid, operator_uin: operatorUin, target_uid: targetUid, target_uin: targetUin } = this.e.content;
|
|
150
|
+
this.e.raw_message = `[群成员减少]: ${operatorUid || operatorUin} 将 ${targetUid || targetUin} 踢出群聊`;
|
|
151
151
|
break;
|
|
152
152
|
}
|
|
153
153
|
// bot被踢
|
|
154
154
|
case 'kick_me': {
|
|
155
|
-
const { operator_uid, operator_uin } = this.e.content;
|
|
156
|
-
this.e.raw_message = `[群成员减少]: 机器人被移除群聊,操作人:${
|
|
155
|
+
const { operator_uid: operatorUid, operator_uin: operatorUin } = this.e.content;
|
|
156
|
+
this.e.raw_message = `[群成员减少]: 机器人被移除群聊,操作人:${operatorUid || operatorUin}`;
|
|
157
157
|
break;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -161,50 +161,56 @@ export class NoticeHandler extends EventBaseHandler {
|
|
|
161
161
|
}
|
|
162
162
|
/** 群管理员变动 */
|
|
163
163
|
case "group_admin_changed" /* NoticeSubType.GroupAdminChanged */: {
|
|
164
|
-
const { target_uid, target_uin, is_admin } = this.e.content;
|
|
165
|
-
this.e.raw_message = `[群管理员变动]: ${
|
|
164
|
+
const { target_uid: targetUid, target_uin: targetUin, is_admin: isAdmin } = this.e.content;
|
|
165
|
+
this.e.raw_message = `[群管理员变动]: ${targetUid || targetUin} 被${isAdmin ? '设置' : '取消'}群管理员`;
|
|
166
166
|
break;
|
|
167
167
|
}
|
|
168
168
|
/** 群成员被禁言 */
|
|
169
169
|
case "group_member_ban" /* NoticeSubType.GroupMemberBan */: {
|
|
170
|
-
const { operator_uid, operator_uin, target_uid, target_uin, type } = this.e.content;
|
|
171
|
-
this.e.raw_message = `[群成员禁言]: ${
|
|
170
|
+
const { operator_uid: operatorUid, operator_uin: operatorUin, target_uid: targetUid, target_uin: targetUin, type } = this.e.content;
|
|
171
|
+
this.e.raw_message = `[群成员禁言]: ${operatorUid || operatorUin} ${type === 'ban' ? '禁言' : '解禁'}了 ${targetUid || targetUin}`;
|
|
172
172
|
break;
|
|
173
173
|
}
|
|
174
174
|
/** 群签到 */
|
|
175
175
|
case "group_sign_in" /* NoticeSubType.GroupSignIn */: {
|
|
176
|
-
const { target_uid, target_uin } = this.e.content;
|
|
177
|
-
this.e.raw_message = `[群签到]: ${
|
|
176
|
+
const { target_uid: targetUid, target_uin: targetUin } = this.e.content;
|
|
177
|
+
this.e.raw_message = `[群签到]: ${targetUid || targetUin}`;
|
|
178
178
|
break;
|
|
179
179
|
}
|
|
180
180
|
/** 群全员禁言 */
|
|
181
181
|
case "group_whole_ban" /* NoticeSubType.GroupWholeBan */: {
|
|
182
|
-
const { operator_uid, operator_uin, is_ban } = this.e.content;
|
|
183
|
-
this.e.raw_message = `[群全员禁言]: ${
|
|
182
|
+
const { operator_uid: operatorUid, operator_uin: operatorUin, is_ban: isBan } = this.e.content;
|
|
183
|
+
this.e.raw_message = `[群全员禁言]: ${operatorUid || operatorUin} ${isBan ? '开启全员禁言' : '解除全员禁言'}`;
|
|
184
184
|
break;
|
|
185
185
|
}
|
|
186
186
|
/** 群名片改变 */
|
|
187
187
|
case "group_card_changed" /* NoticeSubType.GroupCardChanged */: {
|
|
188
|
-
const { operator_uid, operator_uin, target_uid, target_uin, new_card } = this.e.content;
|
|
189
|
-
this.e.raw_message = `[群名片改变]: ${
|
|
188
|
+
const { operator_uid: operatorUid, operator_uin: operatorUin, target_uid: targetUid, target_uin: targetUin, new_card: newCard } = this.e.content;
|
|
189
|
+
this.e.raw_message = `[群名片改变]: ${operatorUid || operatorUin} 修改了 ${targetUid || targetUin} 的名片为 ${newCard}`;
|
|
190
190
|
break;
|
|
191
191
|
}
|
|
192
192
|
/** 群成员专属头衔改变 */
|
|
193
193
|
case "group_member_unique_title_changed" /* NoticeSubType.GroupMemberUniqueTitleChanged */: {
|
|
194
|
-
const { target_uid, target_uin, title } = this.e.content;
|
|
195
|
-
this.e.raw_message = `[群头衔更改]: ${
|
|
194
|
+
const { target_uid: targetUid, target_uin: targetUin, title } = this.e.content;
|
|
195
|
+
this.e.raw_message = `[群头衔更改]: ${targetUid || targetUin} 的专属头衔改变为 ${title}`;
|
|
196
196
|
break;
|
|
197
197
|
}
|
|
198
198
|
/** 群精华消息改变 */
|
|
199
199
|
case "group_essence_changed" /* NoticeSubType.GroupEssenceChanged */: {
|
|
200
|
-
const { operator_uid, operator_uin, target_uid, target_uin, message_id, is_set } = this.e.content;
|
|
201
|
-
this.e.raw_message = `[群精华消息]: ${
|
|
200
|
+
const { operator_uid: operatorUid, operator_uin: operatorUin, target_uid: targetUid, target_uin: targetUin, message_id: messageId, is_set: isSet } = this.e.content;
|
|
201
|
+
this.e.raw_message = `[群精华消息]: ${operatorUid || operatorUin} ${isSet ? `将${targetUid || targetUin}的消息${messageId}设置为精华消息` : `取消了${targetUid || targetUin}精华消息 ${messageId}`}`;
|
|
202
202
|
break;
|
|
203
203
|
}
|
|
204
204
|
/** 群表情回应 */
|
|
205
205
|
case "group_message_reaction" /* NoticeSubType.GroupMessageReaction */: {
|
|
206
|
-
const { message_id, face_id } = this.e.content;
|
|
207
|
-
this.e.raw_message = `[群表情回应]: ${this.e.user_id} 给消息 ${
|
|
206
|
+
const { message_id: messageId, face_id: faceId } = this.e.content;
|
|
207
|
+
this.e.raw_message = `[群表情回应]: ${this.e.user_id} 给消息 ${messageId} 回应了一个${faceId}的表情`;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
/** 好友新增 */
|
|
211
|
+
case "friend_increase" /* NoticeSubType.FriendIncrease */: {
|
|
212
|
+
const { target_uid: targetUid, target_uin: targetUin } = this.e.content;
|
|
213
|
+
this.e.raw_message = `[新增好友]: ${targetUid || targetUin}`;
|
|
208
214
|
break;
|
|
209
215
|
}
|
|
210
216
|
default: {
|
|
@@ -92,20 +92,20 @@ export class RequestHandler extends EventBaseHandler {
|
|
|
92
92
|
switch (this.e.sub_event) {
|
|
93
93
|
/** 好友申请 */
|
|
94
94
|
case "private_apply" /* RequestSubType.PrivateApply */: {
|
|
95
|
-
const { applier_uid, applier_uin, message } = this.e.content;
|
|
96
|
-
this.e.raw_message = `[好友申请]: ${
|
|
95
|
+
const { applier_uid: applierUid, applier_uin: applierUin, message } = this.e.content;
|
|
96
|
+
this.e.raw_message = `[好友申请]: ${applierUid || applierUin} 申请理由: ${message}`;
|
|
97
97
|
break;
|
|
98
98
|
}
|
|
99
99
|
/** 群申请 */
|
|
100
100
|
case "group_apply" /* RequestSubType.GroupApply */: {
|
|
101
|
-
const { group_id, applier_uid, applier_uin, inviter_uid, inviter_uin, reason } = this.e.content;
|
|
102
|
-
this.e.raw_message = `[群申请]: ${
|
|
101
|
+
const { group_id: groupId, applier_uid: applierUid, applier_uin: applierUin, inviter_uid: inviterUid, inviter_uin: inviterUin, reason } = this.e.content;
|
|
102
|
+
this.e.raw_message = `[群申请]: ${groupId} 申请人: ${applierUid || applierUin} 邀请人: ${inviterUid || inviterUin} 理由: ${reason}`;
|
|
103
103
|
break;
|
|
104
104
|
}
|
|
105
105
|
/** 邀请入群 */
|
|
106
106
|
case "invited_group" /* RequestSubType.InvitedGroup */: {
|
|
107
|
-
const { group_id, inviter_uid, inviter_uin } = this.e.content;
|
|
108
|
-
this.e.raw_message = `[邀请入群]: ${
|
|
107
|
+
const { group_id: groupId, inviter_uid: inviterUid, inviter_uin: inviterUin } = this.e.content;
|
|
108
|
+
this.e.raw_message = `[邀请入群]: ${groupId} 邀请人: ${inviterUid || inviterUin}`;
|
|
109
109
|
break;
|
|
110
110
|
}
|
|
111
111
|
default: {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import yaml from 'yaml';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
import lodash from 'lodash';
|
|
5
|
+
import express from 'express';
|
|
1
6
|
export * from './core/index.js';
|
|
2
7
|
export * from './event/index.js';
|
|
3
8
|
export * from './db/index.js';
|
|
@@ -6,3 +11,4 @@ export * from './utils/index.js';
|
|
|
6
11
|
export * from './types/index.js';
|
|
7
12
|
export * from './adapter/index.js';
|
|
8
13
|
export { karin as default } from './core/index.js';
|
|
14
|
+
export { axios, moment, lodash, express, yaml };
|