node-karin 0.6.14 → 0.6.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 +2 -2
- package/lib/adapter/input/index.js +1 -1
- package/lib/adapter/kritor/grpc.js +1 -1
- package/lib/adapter/onebot/onebot11.d.ts +4 -4
- package/lib/adapter/onebot/onebot11.js +3 -3
- package/lib/core/plugin.d.ts +2 -4
- package/lib/core/plugin.js +3 -5
- package/lib/core/plugin.loader.d.ts +4 -1
- package/lib/core/plugin.loader.js +13 -9
- package/lib/event/message.d.ts +2 -2
- package/lib/event/message.js +1 -1
- package/lib/types/adapter.d.ts +2 -1
- package/lib/types/api.d.ts +1 -1
- package/lib/types/event.d.ts +1 -1
- package/lib/types/logger.d.ts +3 -2
- package/lib/types/plugin.d.ts +1 -0
- package/lib/utils/ffmpeg.d.ts +1 -1
- package/lib/utils/ffmpeg.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KarinAdapter } from '../../types/adapter.js';
|
|
2
|
-
import { contact, KarinElement } from '../../types/index.js';
|
|
2
|
+
import { contact, KarinElement, LoggerLevel } from '../../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* - 标准输入输出适配器
|
|
5
5
|
*/
|
|
@@ -14,7 +14,7 @@ export declare class AdapterInput implements KarinAdapter {
|
|
|
14
14
|
get self_id(): string;
|
|
15
15
|
stdin(): this;
|
|
16
16
|
init(): void;
|
|
17
|
-
logger(level:
|
|
17
|
+
logger(level: LoggerLevel, ...args: any[]): void;
|
|
18
18
|
GetVersion(): Promise<{
|
|
19
19
|
name: string;
|
|
20
20
|
app_name: string;
|
|
@@ -80,7 +80,7 @@ export class KritorGrpc {
|
|
|
80
80
|
user_id: sender.uid + '',
|
|
81
81
|
time: kritorData.time,
|
|
82
82
|
message_id: kritorData.message_id + '',
|
|
83
|
-
message_seq: kritorData.message_seq
|
|
83
|
+
message_seq: Number(kritorData.message_seq),
|
|
84
84
|
sender: {
|
|
85
85
|
...sender,
|
|
86
86
|
uid: sender.uid + '',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
2
|
import { IncomingMessage } from 'http';
|
|
3
|
-
import { KarinAdapter } from '../../types/index.js';
|
|
3
|
+
import { KarinAdapter, LoggerLevel } from '../../types/index.js';
|
|
4
4
|
import { contact, OneBot11Api, KarinElement, OneBot11Segment, CustomNodeSegment, OneBot11ApiParamsType, GroupInfo, KarinNodeElement } from '../../types/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* @class OneBot11
|
|
@@ -44,7 +44,7 @@ export declare class AdapterOneBot11 implements KarinAdapter {
|
|
|
44
44
|
/**
|
|
45
45
|
* 专属当前Bot的日志打印方法
|
|
46
46
|
*/
|
|
47
|
-
logger(level:
|
|
47
|
+
logger(level: LoggerLevel, ...args: any[]): void;
|
|
48
48
|
/**
|
|
49
49
|
* 获取头像url
|
|
50
50
|
* @param 头像大小,默认`0`
|
|
@@ -277,14 +277,14 @@ export declare class AdapterOneBot11 implements KarinAdapter {
|
|
|
277
277
|
* @param name - 文件名称 必须提供
|
|
278
278
|
* @param folder - 父目录ID 不提供则上传到根目录
|
|
279
279
|
*/
|
|
280
|
-
|
|
280
|
+
UploadGroupFile(group_id: string, file: string, name: string, folder?: string): Promise<any>;
|
|
281
281
|
/**
|
|
282
282
|
* 上传私聊文件
|
|
283
283
|
* @param user_id - 用户ID
|
|
284
284
|
* @param file - 本地文件绝对路径
|
|
285
285
|
* @param name - 文件名称 必须提供
|
|
286
286
|
*/
|
|
287
|
-
|
|
287
|
+
UploadPrivateFile(user_id: string, file: string, name: string): Promise<any>;
|
|
288
288
|
SetEssenceMessage(): Promise<void>;
|
|
289
289
|
DeleteEssenceMessage(): Promise<void>;
|
|
290
290
|
SetFriendApplyResult(): Promise<void>;
|
|
@@ -157,7 +157,7 @@ export class AdapterOneBot11 {
|
|
|
157
157
|
user_id: data.sender.user_id + '',
|
|
158
158
|
time: data.time,
|
|
159
159
|
message_id: data.message_id + '',
|
|
160
|
-
message_seq: data.message_id
|
|
160
|
+
message_seq: data.message_id,
|
|
161
161
|
sender: {
|
|
162
162
|
...data.sender,
|
|
163
163
|
uid: data.sender.user_id + '',
|
|
@@ -1223,7 +1223,7 @@ export class AdapterOneBot11 {
|
|
|
1223
1223
|
* @param name - 文件名称 必须提供
|
|
1224
1224
|
* @param folder - 父目录ID 不提供则上传到根目录
|
|
1225
1225
|
*/
|
|
1226
|
-
async
|
|
1226
|
+
async UploadGroupFile(group_id, file, name, folder) {
|
|
1227
1227
|
return await this.SendApi('upload_group_file', { group_id, file, name, folder });
|
|
1228
1228
|
}
|
|
1229
1229
|
/**
|
|
@@ -1232,7 +1232,7 @@ export class AdapterOneBot11 {
|
|
|
1232
1232
|
* @param file - 本地文件绝对路径
|
|
1233
1233
|
* @param name - 文件名称 必须提供
|
|
1234
1234
|
*/
|
|
1235
|
-
async
|
|
1235
|
+
async UploadPrivateFile(user_id, file, name) {
|
|
1236
1236
|
return await this.SendApi('upload_private_file', { user_id, file, name });
|
|
1237
1237
|
}
|
|
1238
1238
|
async SetEssenceMessage() { }
|
package/lib/core/plugin.d.ts
CHANGED
|
@@ -3,10 +3,6 @@ import { PluginType, KarinElement, KarinNodeElement, EventType, KarinNoticeEvent
|
|
|
3
3
|
* 插件基类
|
|
4
4
|
*/
|
|
5
5
|
export declare class Plugin implements PluginType {
|
|
6
|
-
e: EventType<this>;
|
|
7
|
-
init?: () => Promise<any>;
|
|
8
|
-
accept?: (e: any) => Promise<any>;
|
|
9
|
-
replyCallback: PluginType['replyCallback'];
|
|
10
6
|
/**
|
|
11
7
|
* @param name - 插件名称
|
|
12
8
|
*/
|
|
@@ -159,6 +155,8 @@ export declare class Plugin implements PluginType {
|
|
|
159
155
|
* 清除上下文状态
|
|
160
156
|
*/
|
|
161
157
|
finish(): void;
|
|
158
|
+
e: EventType<this>;
|
|
159
|
+
replyCallback: PluginType['replyCallback'];
|
|
162
160
|
}
|
|
163
161
|
/**
|
|
164
162
|
* 上下文状态
|
package/lib/core/plugin.js
CHANGED
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
* 插件基类
|
|
3
3
|
*/
|
|
4
4
|
export class Plugin {
|
|
5
|
-
// 类型 需要根据e中的event类型来确定
|
|
6
|
-
e
|
|
7
|
-
init
|
|
8
|
-
accept
|
|
9
|
-
replyCallback
|
|
10
5
|
/**
|
|
11
6
|
* @param name - 插件名称
|
|
12
7
|
*/
|
|
@@ -136,6 +131,9 @@ export class Plugin {
|
|
|
136
131
|
delete stateArr[key]
|
|
137
132
|
}
|
|
138
133
|
}
|
|
134
|
+
|
|
135
|
+
e
|
|
136
|
+
replyCallback
|
|
139
137
|
}
|
|
140
138
|
/**
|
|
141
139
|
* 上下文状态
|
|
@@ -85,7 +85,10 @@ declare class PluginLoader {
|
|
|
85
85
|
* @param path - 插件路径
|
|
86
86
|
* @param lang - 语言环境
|
|
87
87
|
*/
|
|
88
|
-
getIndex(path: string, lang: 'js' | 'ts'):
|
|
88
|
+
getIndex(path: string, dir: dirName, lang: 'js' | 'ts'): {
|
|
89
|
+
dir: dirName;
|
|
90
|
+
name: fileName;
|
|
91
|
+
} | false;
|
|
89
92
|
/**
|
|
90
93
|
* 获取指定文件夹下的所有插件
|
|
91
94
|
* @param dir - 插件包名称
|
|
@@ -126,10 +126,10 @@ class PluginLoader {
|
|
|
126
126
|
/** package */
|
|
127
127
|
const pack = common.readJson(`${PluginPath}/package.json`)
|
|
128
128
|
/** 旧版本入口文件 */
|
|
129
|
-
const index = this.getIndex(PluginPath, process.env.karin_app_lang)
|
|
129
|
+
const index = this.getIndex(PluginPath, dir, process.env.karin_app_lang)
|
|
130
130
|
if (index) {
|
|
131
|
-
this.FileList.push({ dir, name: index })
|
|
132
|
-
this.isDev && this.watchList.push({ dir, name: index })
|
|
131
|
+
this.FileList.push({ dir: index.dir, name: index.name })
|
|
132
|
+
this.isDev && this.watchList.push({ dir: index.dir, name: index.name })
|
|
133
133
|
}
|
|
134
134
|
/** 新版本入口 */
|
|
135
135
|
if (pack.main) {
|
|
@@ -175,11 +175,15 @@ class PluginLoader {
|
|
|
175
175
|
* @param path - 插件路径
|
|
176
176
|
* @param lang - 语言环境
|
|
177
177
|
*/
|
|
178
|
-
getIndex (path, lang) {
|
|
178
|
+
getIndex (path, dir, lang) {
|
|
179
179
|
const isJS = common.exists(`${path}/index.js`)
|
|
180
|
-
if (isJS && lang === 'js') {
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
if (isJS && lang === 'js') {
|
|
181
|
+
return { dir, name: 'index.js' }
|
|
182
|
+
}
|
|
183
|
+
const isTS = common.exists(`${path}/src/index.ts`)
|
|
184
|
+
if (isTS && lang === 'ts') {
|
|
185
|
+
return { dir: `${dir}/src`, name: 'index.ts' }
|
|
186
|
+
}
|
|
183
187
|
return false
|
|
184
188
|
}
|
|
185
189
|
|
|
@@ -386,7 +390,7 @@ class PluginLoader {
|
|
|
386
390
|
* 新增accept、handler
|
|
387
391
|
*/
|
|
388
392
|
async addAccept (index, Class) {
|
|
389
|
-
if (
|
|
393
|
+
if ('accept' in Class && typeof Class.accept === 'function') {
|
|
390
394
|
this.PluginList[index].accept = true
|
|
391
395
|
this.acceptIds.push(index)
|
|
392
396
|
}
|
|
@@ -410,7 +414,7 @@ class PluginLoader {
|
|
|
410
414
|
* 执行初始化
|
|
411
415
|
*/
|
|
412
416
|
async addInit (Class) {
|
|
413
|
-
Class.init && await Class.init()
|
|
417
|
+
'init' in Class && typeof Class.init === 'function' && await Class.init()
|
|
414
418
|
}
|
|
415
419
|
|
|
416
420
|
/**
|
package/lib/event/message.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class KarinMessage extends KarinEvent {
|
|
|
32
32
|
/**
|
|
33
33
|
* - 消息序列号
|
|
34
34
|
*/
|
|
35
|
-
message_seq?:
|
|
35
|
+
message_seq?: number;
|
|
36
36
|
/**
|
|
37
37
|
* - 原始消息文本
|
|
38
38
|
*/
|
|
@@ -61,7 +61,7 @@ export declare class KarinMessage extends KarinEvent {
|
|
|
61
61
|
/**
|
|
62
62
|
* - 消息序列号
|
|
63
63
|
*/
|
|
64
|
-
message_seq?:
|
|
64
|
+
message_seq?: number;
|
|
65
65
|
/**
|
|
66
66
|
* - 原始消息文本
|
|
67
67
|
*/
|
package/lib/event/message.js
CHANGED
|
@@ -3,7 +3,7 @@ import { KarinEvent } from './event.js'
|
|
|
3
3
|
* - 消息事件基类
|
|
4
4
|
*/
|
|
5
5
|
export class KarinMessage extends KarinEvent {
|
|
6
|
-
constructor ({ event = 'message', event_id, self_id, user_id, time, message_id, message_seq =
|
|
6
|
+
constructor ({ event = 'message', event_id, self_id, user_id, time, message_id, message_seq = 0, raw_message = '', contact, sender, elements, group_id = '' }) {
|
|
7
7
|
super({ event, event_id: event_id || message_id, self_id, user_id, group_id, time, contact, sender, sub_event: contact.scene === 'group' ? 'group_message' : 'private_message' })
|
|
8
8
|
this.message_id = message_id
|
|
9
9
|
this.message_seq = message_seq
|
package/lib/types/adapter.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { IncomingMessage } from 'http';
|
|
|
3
3
|
import { contact } from './event.js';
|
|
4
4
|
import { KarinElement, KarinNodeElement } from './element.js';
|
|
5
5
|
import { PushMessageBody, EssenceMessageBody, FriendInfo, GroupInfo, GroupMemberInfo, GroupHonorInfo } from './api.js';
|
|
6
|
+
import { LoggerLevel } from './logger.js';
|
|
6
7
|
export interface KarinAdapter {
|
|
7
8
|
/**
|
|
8
9
|
* - 适配器版本信息
|
|
@@ -82,7 +83,7 @@ export interface KarinAdapter {
|
|
|
82
83
|
* @param level - 日志等级
|
|
83
84
|
* @param args - 日志内容
|
|
84
85
|
*/
|
|
85
|
-
logger(level:
|
|
86
|
+
logger(level: LoggerLevel, ...args: any[]): void;
|
|
86
87
|
/**
|
|
87
88
|
* - 可选方法 仅ws有效 在注册适配器后 如果有符合的path则会调用此方法
|
|
88
89
|
* - @param socket - WebSocket实例
|
package/lib/types/api.d.ts
CHANGED
package/lib/types/event.d.ts
CHANGED
package/lib/types/logger.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
+
export type LoggerLevel = 'trace' | 'debug' | 'mark' | 'info' | 'mark' | 'warn' | 'error' | 'fatal';
|
|
2
3
|
export interface Logger {
|
|
3
4
|
/**
|
|
4
5
|
* 颜色模块
|
|
@@ -50,7 +51,7 @@ export interface Logger {
|
|
|
50
51
|
* @param id 机器人ID
|
|
51
52
|
* @param args 参数
|
|
52
53
|
*/
|
|
53
|
-
bot: (level:
|
|
54
|
+
bot: (level: LoggerLevel, id: string, ...args: string[]) => void;
|
|
54
55
|
}
|
|
55
56
|
declare module 'log4js' {
|
|
56
57
|
interface Logger {
|
|
@@ -104,6 +105,6 @@ declare module 'log4js' {
|
|
|
104
105
|
* @param id 机器人ID
|
|
105
106
|
* @param args 参数
|
|
106
107
|
*/
|
|
107
|
-
bot: (level:
|
|
108
|
+
bot: (level: LoggerLevel, id: string, ...args: string[]) => void;
|
|
108
109
|
}
|
|
109
110
|
}
|
package/lib/types/plugin.d.ts
CHANGED
package/lib/utils/ffmpeg.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 执行 ffmpeg 命令
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export declare function ffmpeg(): Promise<false | ((cmd: string, log?: boolean, options?: {
|
|
5
5
|
cwd: string;
|
|
6
6
|
encoding: string;
|
|
7
7
|
}) => Promise<{
|
package/lib/utils/ffmpeg.js
CHANGED