node-karin 0.3.7 → 0.3.9

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.
@@ -1,5 +1,3 @@
1
- /// <reference types="@types/ws" />
2
- /// <reference types="node" />
3
1
  import WebSocket from 'ws';
4
2
  import { IncomingMessage } from 'http';
5
3
  import { KarinAdapter } from '../../types/adapter.js';
@@ -131,10 +129,10 @@ export declare class OneBot11 implements KarinAdapter {
131
129
  data: {
132
130
  content: string;
133
131
  custom_template_id: string;
134
- params: {
132
+ params: Array<{
135
133
  key: string;
136
- values: string[];
137
- }[];
134
+ values: Array<string>;
135
+ }>;
138
136
  text?: undefined;
139
137
  id?: undefined;
140
138
  qq?: undefined;
@@ -1,10 +1,9 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
2
  import { KarinAdapter, contact, KarinElement } from '../types/index.js';
4
3
  /**
5
4
  * 监听器管理
6
5
  */
7
- export declare const listener: {
6
+ declare class Listeners extends EventEmitter {
8
7
  /**
9
8
  * Bot索引
10
9
  * @type - Bot索引
@@ -24,6 +23,7 @@ export declare const listener: {
24
23
  adapter: new () => KarinAdapter;
25
24
  path: string;
26
25
  }>;
26
+ constructor();
27
27
  /**
28
28
  * 注册Bot 返回索引id
29
29
  */
@@ -80,7 +80,7 @@ export declare const listener: {
80
80
  * @param isType - 是否返回包含的类型列表 默认返回适配器实例列表
81
81
  */
82
82
  getAdapterAll(isType?: boolean): {
83
- type: KarinAdapter['adapter']['type'];
83
+ type: KarinAdapter["adapter"]["type"];
84
84
  adapter: new () => KarinAdapter;
85
85
  path: string;
86
86
  }[] | (new () => KarinAdapter)[];
@@ -99,20 +99,7 @@ export declare const listener: {
99
99
  }): Promise<{
100
100
  message_id: string;
101
101
  }>;
102
- [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
103
- addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
104
- on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
105
- once<K_3>(eventName: string | symbol, listener: (...args: any[]) => void): any;
106
- removeListener<K_4>(eventName: string | symbol, listener: (...args: any[]) => void): any;
107
- off<K_5>(eventName: string | symbol, listener: (...args: any[]) => void): any;
108
- removeAllListeners(eventName?: string | symbol | undefined): any;
109
- setMaxListeners(n: number): any;
110
- getMaxListeners(): number;
111
- listeners<K_6>(eventName: string | symbol): Function[];
112
- rawListeners<K_7>(eventName: string | symbol): Function[];
113
- emit<K_8>(eventName: string | symbol, ...args: any[]): boolean;
114
- listenerCount<K_9>(eventName: string | symbol, listener?: Function | undefined): number;
115
- prependListener<K_10>(eventName: string | symbol, listener: (...args: any[]) => void): any;
116
- prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
117
- eventNames(): (string | symbol)[];
118
- };
102
+ }
103
+ export declare const listener: Listeners;
104
+ export declare const Bot: Listeners;
105
+ export {};
@@ -5,7 +5,7 @@ import { MessageHandler } from '../event/message.handler.js'
5
5
  /**
6
6
  * 监听器管理
7
7
  */
8
- export const listener = new (class Listeners extends EventEmitter {
8
+ class Listeners extends EventEmitter {
9
9
  /**
10
10
  * Bot索引
11
11
  * @type - Bot索引
@@ -183,4 +183,6 @@ export const listener = new (class Listeners extends EventEmitter {
183
183
  }
184
184
  return result
185
185
  }
186
- })()
186
+ }
187
+ export const listener = new Listeners()
188
+ export const Bot = listener
@@ -6,7 +6,7 @@ import { PluginApps, PluginTask, dirName, fileName, AppInfo } from '../types/ind
6
6
  * 加载插件
7
7
  */
8
8
  export declare const pluginLoader: {
9
- dir: './plugins';
9
+ dir: "./plugins";
10
10
  dirPath: string;
11
11
  /**
12
12
  * - 插件索引ID
@@ -21,11 +21,11 @@ export declare const pluginLoader: {
21
21
  * - handler
22
22
  */
23
23
  handlerIds: {
24
- [key: string]: {
24
+ [key: string]: Array<{
25
25
  index: string;
26
26
  fnc: string | Function;
27
27
  priority: number;
28
- }[];
28
+ }>;
29
29
  };
30
30
  /**
31
31
  * - 插件列表
@@ -76,7 +76,7 @@ export declare const pluginLoader: {
76
76
  * @param path - 插件路径
77
77
  * @param lang - 语言环境
78
78
  */
79
- getIndex(path: string, lang: 'js' | 'ts'): string | boolean;
79
+ getIndex(path: string, lang: "js" | "ts"): string | boolean;
80
80
  /**
81
81
  * 获取指定文件夹下的所有插件
82
82
  * @param dir - 插件包名称
package/lib/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  export * from 'kritor-proto';
4
2
  export * from './core/index.js';
5
3
  export * from './event/index.js';
@@ -17,15 +15,15 @@ export declare const plugin: typeof Plugin;
17
15
  */
18
16
  export declare const Renderer: {
19
17
  index: number;
20
- Apps: import("./types/index.js").KarinRenderApp[];
18
+ Apps: Array<import("./types/index.js").KarinRenderApp>;
21
19
  app(data: {
22
20
  id: string;
23
- type?: string | undefined;
24
- render: (options: import("./types/index.js").KarinRenderType) => Promise<string | string[]>;
21
+ type?: "image" | string;
22
+ render: import("./types/index.js").KarinRender["render"];
25
23
  }): number;
26
24
  unapp(index: number): boolean;
27
25
  App(id?: string): import("./types/index.js").KarinRenderApp;
28
- render(options: import("./types/index.js").KarinRenderType, id?: string | undefined): Promise<string | string[]>;
26
+ render(options: import("./types/index.js").KarinRenderType, id?: string): Promise<string | string[]>;
29
27
  renderHtml(data: string): Promise<string | string[]>;
30
28
  };
31
29
  export declare const Cfg: {
@@ -39,7 +37,7 @@ export declare const Cfg: {
39
37
  initCfg(): Promise<void>;
40
38
  getPlugins(): string[];
41
39
  dirPath(name: string, plugins: string[]): Promise<void>;
42
- timeout(type?: "grpc" | "ws"): number;
40
+ timeout(type?: "ws" | "grpc"): number;
43
41
  readonly redis: import("./types/index.js").Redis;
44
42
  readonly master: string[];
45
43
  readonly admin: string[];
@@ -55,65 +53,6 @@ export declare const Cfg: {
55
53
  change_group(): Promise<void>;
56
54
  "__#2@#review"(): Promise<void>;
57
55
  };
58
- export declare const Bot: {
59
- index: number;
60
- name: string;
61
- list: {
62
- index: number;
63
- type: "internal" | "http" | "grpc" | "ws" | "render";
64
- bot: import("./types/index.js").KarinAdapter;
65
- }[];
66
- adapter: {
67
- type: "internal" | "http" | "grpc" | "ws" | "render";
68
- adapter: new () => import("./types/index.js").KarinAdapter;
69
- path: string;
70
- }[];
71
- addBot(data: {
72
- bot: import("./types/index.js").KarinAdapter;
73
- type: "internal" | "http" | "grpc" | "ws" | "render";
74
- }): number | false;
75
- delBot(index: number): void;
76
- getBot(uid?: string): import("./types/index.js").KarinAdapter | undefined;
77
- getBotByIndex(index: number): import("./types/index.js").KarinAdapter;
78
- getBotCount(): number;
79
- getBotAll(isIndex?: boolean): import("./types/index.js").KarinAdapter[] | {
80
- index: number;
81
- bot: import("./types/index.js").KarinAdapter;
82
- }[];
83
- addAdapter(data: {
84
- type: "internal" | "http" | "grpc" | "ws" | "render";
85
- adapter: new () => import("./types/index.js").KarinAdapter;
86
- path?: string | undefined;
87
- }): void;
88
- getAdapter(path?: string): (new () => import("./types/index.js").KarinAdapter) | undefined;
89
- getAdapterAll(isType?: boolean): {
90
- type: "internal" | "http" | "grpc" | "ws" | "render";
91
- adapter: new () => import("./types/index.js").KarinAdapter;
92
- path: string;
93
- }[] | (new () => import("./types/index.js").KarinAdapter)[];
94
- sendMsg(uid: string, contact: import("./types/index.js").contact, elements: import("./types/index.js").KarinElement, options?: {
95
- recallMsg?: number | undefined;
96
- retry_count?: number | undefined;
97
- }): Promise<{
98
- message_id: string;
99
- }>;
100
- [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
101
- addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
102
- on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
103
- once<K_3>(eventName: string | symbol, listener: (...args: any[]) => void): any;
104
- removeListener<K_4>(eventName: string | symbol, listener: (...args: any[]) => void): any;
105
- off<K_5>(eventName: string | symbol, listener: (...args: any[]) => void): any;
106
- removeAllListeners(eventName?: string | symbol | undefined): any;
107
- setMaxListeners(n: number): any;
108
- getMaxListeners(): number;
109
- listeners<K_6>(eventName: string | symbol): Function[];
110
- rawListeners<K_7>(eventName: string | symbol): Function[];
111
- emit<K_8>(eventName: string | symbol, ...args: any[]): boolean;
112
- listenerCount<K_9>(eventName: string | symbol, listener?: Function | undefined): number;
113
- prependListener<K_10>(eventName: string | symbol, listener: (...args: any[]) => void): any;
114
- prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
115
- eventNames(): (string | symbol)[];
116
- };
117
56
  export declare const Update: {
118
57
  dir: string;
119
58
  getPlugins(): string[];
package/lib/index.js CHANGED
@@ -30,7 +30,6 @@ export const plugin = Plugin;
30
30
  */
31
31
  export const Renderer = render;
32
32
  export const Cfg = config;
33
- export const Bot = listener;
34
33
  export const Update = update;
35
34
  export const karin = new Karin();
36
35
  export default karin;
@@ -1,4 +1,3 @@
1
- /// <reference types="@types/ws" />
2
1
  import WebSocket from 'ws';
3
2
  import { RenderBase } from './base.js';
4
3
  import { KarinRenderType } from '../types/render.js';
@@ -1,5 +1,3 @@
1
- /// <reference types="@types/ws" />
2
- /// <reference types="node" />
3
1
  import WebSocket from 'ws';
4
2
  import { RenderBase } from './base.js';
5
3
  import { IncomingMessage } from 'http';
@@ -1,5 +1,3 @@
1
- /// <reference types="@types/ws" />
2
- /// <reference types="node" />
3
1
  import { WebSocket } from 'ws';
4
2
  import { IncomingMessage } from 'http';
5
3
  import { KarinElement, KarinNodeElement } from './element.js';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import schedule from 'node-schedule';
3
2
  import { KarinNodeElement } from './element.js';
4
3
  import { Reply, replyCallback } from './reply.js';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { AxiosRequestConfig } from 'axios';
3
2
  import { Readable } from 'stream';
4
3
  import { fs } from '../modules.js';
@@ -26,7 +25,7 @@ export declare const common: {
26
25
  * @param type 请求类型
27
26
  * @param param axios参数
28
27
  */
29
- axios(url: string, type?: 'get' | 'post', param?: AxiosRequestConfig): Promise<any | null>;
28
+ axios(url: string, type?: "get" | "post", param?: AxiosRequestConfig): Promise<any | null>;
30
29
  /**
31
30
  * 递归创建目录
32
31
  * @param dirname - 要创建的文件夹路径
@@ -21,7 +21,7 @@ export declare const config: {
21
21
  /**
22
22
  * 超时时间
23
23
  */
24
- timeout(type?: 'ws' | 'grpc'): number;
24
+ timeout(type?: "ws" | "grpc"): number;
25
25
  /**
26
26
  * Redis 配置
27
27
  * 采用实时读取优化性能
@@ -58,14 +58,14 @@ export declare const config: {
58
58
  /**
59
59
  * 获取配置yaml
60
60
  */
61
- getYaml(type: 'defSet' | 'config', name: string, isWatch?: boolean): any;
61
+ getYaml(type: "defSet" | "config", name: string, isWatch?: boolean): any;
62
62
  /**
63
63
  * 监听配置文件
64
64
  * @param {'defSet'|'config'} type 类型
65
65
  * @param {string} name 文件名称 不带后缀
66
66
  * @param {string} file 文件路径
67
67
  */
68
- watch(type: 'defSet' | 'config', name: string, file: string): Promise<true | undefined>;
68
+ watch(type: "defSet" | "config", name: string, file: string): Promise<true | undefined>;
69
69
  change_App(): Promise<void>;
70
70
  change_config(): Promise<void>;
71
71
  change_group(): Promise<void>;
@@ -11,12 +11,12 @@ export declare const exec: (cmd: string, log?: boolean, options?: {
11
11
  /**
12
12
  * - 执行状态
13
13
  */
14
- status: 'ok' | 'failed';
14
+ status: "ok" | "failed";
15
15
  /**
16
16
  * - 错误信息
17
17
  */
18
18
  error: Error | null;
19
- stdout: string | '';
20
- stderr: string | '';
19
+ stdout: string | "";
20
+ stderr: string | "";
21
21
  }>;
22
22
  export default exec;
@@ -5,8 +5,8 @@ export default function ffmpeg(): Promise<false | ((cmd: string, log?: boolean,
5
5
  cwd: string;
6
6
  encoding: string;
7
7
  }) => Promise<{
8
- status: "failed" | "ok";
8
+ status: "ok" | "failed";
9
9
  error: Error | null;
10
- stdout: string;
11
- stderr: string;
10
+ stdout: string | "";
11
+ stderr: string | "";
12
12
  }>)>;
@@ -17,11 +17,11 @@ export declare const handler: {
17
17
  /**
18
18
  * 插件索引
19
19
  */
20
- index: string | '';
20
+ index: string | "";
21
21
  /**
22
22
  * 事件键
23
23
  */
24
- key: string | '';
24
+ key: string | "";
25
25
  }): boolean;
26
26
  /**
27
27
  * 调用事件处理器
@@ -30,7 +30,7 @@ export declare const handler: {
30
30
  */
31
31
  call(key: string, args: {
32
32
  [key: string]: any;
33
- e?: import("../index.js").KarinMessage | undefined;
33
+ e?: EventType<unknown>;
34
34
  }): Promise<any>;
35
35
  /**
36
36
  * 检查是否存在指定键的事件处理器
@@ -45,7 +45,7 @@ export declare const segment: {
45
45
  /**
46
46
  * - 图片类型,show: 展示图片,flash: 闪照,original: 原图
47
47
  */
48
- file_type?: 'show' | 'flash' | 'original';
48
+ file_type?: "show" | "flash" | "original";
49
49
  /**
50
50
  * - 图片名称
51
51
  */
@@ -136,7 +136,7 @@ export declare const segment: {
136
136
  * @param id - 音乐ID
137
137
  * @returns {MusicElement} 音乐元素
138
138
  */
139
- music(platform: 'QQ' | 'netease' | 'custom', id: string): MusicElement;
139
+ music(platform: "QQ" | "netease" | "custom", id: string): MusicElement;
140
140
  /**
141
141
  * 天气
142
142
  * @param city - 城市名称
@@ -190,7 +190,7 @@ export declare const segment: {
190
190
  * @param peer - 被推荐人的QQ号或者被推荐群的群号
191
191
  * @returns {ContactElement} 分享名片元素
192
192
  */
193
- contact(scene: 'group' | 'friend', peer: string): ContactElement;
193
+ contact(scene: "group" | "friend", peer: string): ContactElement;
194
194
  /**
195
195
  * JSON
196
196
  * @param data - JSON序列化过的字符串
@@ -260,9 +260,9 @@ export declare const segment: {
260
260
  * @param data - 按钮数据
261
261
  * @returns {ButtonElement} 按钮元素
262
262
  */
263
- button(data: ButtonElement['data']): ButtonElement;
264
- rows(data: Array<ButtonElement['data']>): {
265
- type: 'rows';
263
+ button(data: ButtonElement["data"]): ButtonElement;
264
+ rows(data: Array<ButtonElement["data"]>): {
265
+ type: "rows";
266
266
  rows: Array<ButtonElement>;
267
267
  };
268
268
  /**
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",
7
- "types": "./lib/index.d.ts",
8
7
  "bugs": {
9
8
  "url": "https://github.com/KarinJS/Karin/issues"
10
9
  },
@@ -19,6 +18,7 @@
19
18
  "#Karin": "./lib/index.js"
20
19
  },
21
20
  "main": "./lib/index.js",
21
+ "types": "./lib/index.d.ts",
22
22
  "bin": {
23
23
  "init": "./lib/tools/init.js"
24
24
  },
@@ -41,12 +41,12 @@
41
41
  "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && npm run fix && npm run cp",
42
42
  "cp": "cp ./lib/modules.d.ts ./modules.d.ts && cp ./lib/modules.js ./modules.js && cp ./src/utils/kritor-proto.d.ts ./lib/utils/kritor-proto.d.ts",
43
43
  "delete": "pm2 delete ./config/config/pm2.yaml",
44
+ "dev": "tsx ./lib/index.js --dev",
44
45
  "fix": "eslint lib/**/*.js --fix",
45
46
  "fix:all": "eslint lib/**/*.js --fix && eslint src/**/*.ts --fix",
46
47
  "init": "node lib/tools/install.js",
47
48
  "init:dev": "node lib/tools/install.js",
48
49
  "init:pack": "node lib/tools/install.js",
49
- "dev": "tsx ./lib/index.js --dev",
50
50
  "log": "node lib/tools/pm2Log.js",
51
51
  "monit": "pm2 monit",
52
52
  "pub": "npm publish --access public",
@@ -54,8 +54,7 @@
54
54
  "sort:pack": "npx sort-package-json",
55
55
  "start": "pm2 start ./config/config/pm2.yaml && pm2 monit",
56
56
  "stop": "pm2 delete ./config/config/pm2.yaml",
57
- "uninstall": "node lib/tools/uninstall.js",
58
- "ver": "node lib/tools/updateVersion.js"
57
+ "uninstall": "node lib/tools/uninstall.js"
59
58
  },
60
59
  "dependencies": {
61
60
  "@grpc/grpc-js": "1.10.10",
@@ -65,7 +64,7 @@
65
64
  "chalk": "5.3.0",
66
65
  "chokidar": "3.6.0",
67
66
  "express": "4.19.2",
68
- "kritor-proto": "^0.0.6",
67
+ "kritor-proto": "^1.0.1",
69
68
  "level": "8.0.1",
70
69
  "lodash": "4.17.21",
71
70
  "log4js": "6.9.1",
@@ -76,18 +75,25 @@
76
75
  "yaml": "2.4.1"
77
76
  },
78
77
  "devDependencies": {
79
- "@types/express": "^4.17.21",
80
- "@types/lodash": "^4.17.5",
81
- "@types/node": "^20.14.8",
82
- "@types/node-schedule": "^2.1.7",
83
- "@types/ws": "8.5.10",
84
- "eslint": "9.5.0",
85
- "neostandard": "^0.9.0",
86
- "sort-package-json": "^2.10.0",
87
- "tsc-alias": "^1.8.10",
88
- "tsx": "^4.15.7",
89
- "typescript": "^4.9.5"
78
+ "@types/express": "latest",
79
+ "@types/lodash": "latest",
80
+ "@types/node": "latest",
81
+ "@types/node-schedule": "latest",
82
+ "@types/ws": "latest",
83
+ "eslint": "latest",
84
+ "neostandard": "latest",
85
+ "sort-package-json": "latest",
86
+ "tsc-alias": "latest",
87
+ "tsx": "latest",
88
+ "typescript": "latest"
90
89
  },
90
+ "bundledDependencies": [
91
+ "@types/express",
92
+ "@types/lodash",
93
+ "@types/node",
94
+ "@types/node-schedule",
95
+ "@types/ws"
96
+ ],
91
97
  "engines": {
92
98
  "node": ">=18"
93
99
  },