node-karin 0.6.1 → 0.6.3
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.js +1 -1
- package/lib/adapter/kritor/grpc.js +5 -5
- package/lib/adapter/onebot/onebot11.d.ts +0 -1
- package/lib/adapter/onebot/onebot11.js +4 -5
- package/lib/core/dir.d.ts +3 -0
- package/lib/core/dir.js +3 -0
- package/lib/core/karin.d.ts +13 -1
- package/lib/core/karin.js +30 -0
- package/lib/event/message.handler.js +1 -1
- package/lib/event/notice.handler.js +1 -1
- package/lib/event/request.handler.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/tools/init.js +8 -10
- package/lib/types/event.d.ts +1 -1
- package/lib/utils/config.d.ts +3 -2
- package/lib/utils/config.js +11 -6
- package/package.json +1 -4
|
@@ -124,7 +124,7 @@ export class KritorGrpc {
|
|
|
124
124
|
const uid = data.operator_uid;
|
|
125
125
|
const uin = data.operator_uin;
|
|
126
126
|
const contact = {
|
|
127
|
-
scene: '
|
|
127
|
+
scene: 'friend',
|
|
128
128
|
peer: uid,
|
|
129
129
|
sub_peer: '',
|
|
130
130
|
};
|
|
@@ -162,7 +162,7 @@ export class KritorGrpc {
|
|
|
162
162
|
const uid = data.operator_uid;
|
|
163
163
|
const uin = data.operator_uin;
|
|
164
164
|
const contact = {
|
|
165
|
-
scene: '
|
|
165
|
+
scene: 'friend',
|
|
166
166
|
peer: uid,
|
|
167
167
|
sub_peer: '',
|
|
168
168
|
};
|
|
@@ -196,7 +196,7 @@ export class KritorGrpc {
|
|
|
196
196
|
const uid = data.operator_uid;
|
|
197
197
|
const uin = data.operator_uin;
|
|
198
198
|
const contact = {
|
|
199
|
-
scene: '
|
|
199
|
+
scene: 'friend',
|
|
200
200
|
peer: uid,
|
|
201
201
|
sub_peer: '',
|
|
202
202
|
};
|
|
@@ -772,7 +772,7 @@ export class KritorGrpc {
|
|
|
772
772
|
/** scene映射表 */
|
|
773
773
|
const sceneMap = {
|
|
774
774
|
[kritor.common.Scene.GROUP]: 'group',
|
|
775
|
-
[kritor.common.Scene.FRIEND]: '
|
|
775
|
+
[kritor.common.Scene.FRIEND]: 'friend',
|
|
776
776
|
[kritor.common.Scene.GUILD]: 'guild',
|
|
777
777
|
[kritor.common.Scene.NEARBY]: 'nearby',
|
|
778
778
|
[kritor.common.Scene.STRANGER]: 'stranger',
|
|
@@ -786,7 +786,7 @@ export class KritorGrpc {
|
|
|
786
786
|
};
|
|
787
787
|
/*
|
|
788
788
|
0=群聊 1=私聊 2=频道 5=附近的人 6=陌生人 10=群临时会话
|
|
789
|
-
0=group 1=
|
|
789
|
+
0=group 1=friend 2=guild 5=nearby 6=stranger 10=stranger_from_group
|
|
790
790
|
*/
|
|
791
791
|
const scene = sceneMap[contact.scene];
|
|
792
792
|
const role = roleMap[sender.role];
|
|
@@ -112,7 +112,6 @@ export declare class AdapterOneBot11 implements KarinAdapter {
|
|
|
112
112
|
* 获取消息
|
|
113
113
|
* @param _contact - ob11无需提供contact参数
|
|
114
114
|
* @param message_id - 消息ID
|
|
115
|
-
* @returns {Promise<object>} - 消息内容
|
|
116
115
|
*/
|
|
117
116
|
GetMessage(_contact: contact, message_id: string): Promise<any>;
|
|
118
117
|
/**
|
|
@@ -188,7 +188,7 @@ export class AdapterOneBot11 {
|
|
|
188
188
|
},
|
|
189
189
|
elements: this.AdapterConvertKarin(data.message),
|
|
190
190
|
contact: {
|
|
191
|
-
scene: (data.message_type === 'private' ? '
|
|
191
|
+
scene: (data.message_type === 'private' ? 'friend' : 'group'),
|
|
192
192
|
peer: data.message_type === 'private' ? data.sender.user_id : data.group_id,
|
|
193
193
|
sub_peer: '',
|
|
194
194
|
},
|
|
@@ -237,7 +237,7 @@ export class AdapterOneBot11 {
|
|
|
237
237
|
role: '',
|
|
238
238
|
};
|
|
239
239
|
const contact = {
|
|
240
|
-
scene: ('group_id' in data ? 'group' : '
|
|
240
|
+
scene: ('group_id' in data ? 'group' : 'friend'),
|
|
241
241
|
peer: 'group_id' in data ? data.group_id : data.user_id,
|
|
242
242
|
sub_peer: '',
|
|
243
243
|
};
|
|
@@ -478,7 +478,7 @@ export class AdapterOneBot11 {
|
|
|
478
478
|
user_id: data.user_id + '',
|
|
479
479
|
time: data.time,
|
|
480
480
|
contact: {
|
|
481
|
-
scene: '
|
|
481
|
+
scene: 'friend',
|
|
482
482
|
peer: data.user_id + '',
|
|
483
483
|
sub_peer: '',
|
|
484
484
|
},
|
|
@@ -811,7 +811,6 @@ export class AdapterOneBot11 {
|
|
|
811
811
|
* 获取消息
|
|
812
812
|
* @param _contact - ob11无需提供contact参数
|
|
813
813
|
* @param message_id - 消息ID
|
|
814
|
-
* @returns {Promise<object>} - 消息内容
|
|
815
814
|
*/
|
|
816
815
|
async GetMessage(_contact, message_id) {
|
|
817
816
|
let res = await this.SendApi('get_msg', { message_id });
|
|
@@ -820,7 +819,7 @@ export class AdapterOneBot11 {
|
|
|
820
819
|
message_id: res.message_id,
|
|
821
820
|
message_seq: res.message_id,
|
|
822
821
|
contact: {
|
|
823
|
-
scene: res.message_type === 'group' ? 'group' : '
|
|
822
|
+
scene: res.message_type === 'group' ? 'group' : 'friend',
|
|
824
823
|
peer: res.sender.user_id, // 拿不到group_id...
|
|
825
824
|
},
|
|
826
825
|
sender: {
|
package/lib/core/dir.d.ts
CHANGED
package/lib/core/dir.js
CHANGED
package/lib/core/karin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KarinMessage } from '../event/message.js';
|
|
2
|
-
import { Permission, PluginApps, KarinElement } from '../types/index.js';
|
|
2
|
+
import { Permission, PluginApps, KarinElement, contact, KarinRenderType } from '../types/index.js';
|
|
3
3
|
type FncFunction = (e: KarinMessage) => Promise<boolean>;
|
|
4
4
|
type FncElement = string | KarinElement | Array<KarinElement>;
|
|
5
5
|
export interface OptionsCommand {
|
|
@@ -107,5 +107,17 @@ export declare class Karin {
|
|
|
107
107
|
*/
|
|
108
108
|
priority?: number;
|
|
109
109
|
}): PluginApps;
|
|
110
|
+
/**
|
|
111
|
+
* 构建contact
|
|
112
|
+
* @param peer - 群号或者id
|
|
113
|
+
* @param isGroup - 是否是群聊
|
|
114
|
+
* @param sub_peer - 子id
|
|
115
|
+
*/
|
|
116
|
+
contact(peer: string, isGroup?: boolean, sub_peer?: string): contact;
|
|
117
|
+
/**
|
|
118
|
+
* - 渲染
|
|
119
|
+
* @param options - 渲染参数
|
|
120
|
+
*/
|
|
121
|
+
render(options: KarinRenderType): Promise<string | string[]>;
|
|
110
122
|
}
|
|
111
123
|
export {};
|
package/lib/core/karin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import PluginApp from './plugin.app.js'
|
|
2
2
|
import { common } from '../utils/index.js'
|
|
3
|
+
import { render } from '../render/index.js'
|
|
3
4
|
export class Karin {
|
|
4
5
|
/**
|
|
5
6
|
* - 快速构建命令
|
|
@@ -99,4 +100,33 @@ export class Karin {
|
|
|
99
100
|
}
|
|
100
101
|
return PluginApp(data)
|
|
101
102
|
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 构建contact
|
|
106
|
+
* @param peer - 群号或者id
|
|
107
|
+
* @param isGroup - 是否是群聊
|
|
108
|
+
* @param sub_peer - 子id
|
|
109
|
+
*/
|
|
110
|
+
contact (peer, isGroup = true, sub_peer) {
|
|
111
|
+
if (isGroup) {
|
|
112
|
+
return {
|
|
113
|
+
scene: 'group',
|
|
114
|
+
peer,
|
|
115
|
+
sub_peer: sub_peer || '',
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
scene: 'friend',
|
|
120
|
+
peer,
|
|
121
|
+
sub_peer: sub_peer || '',
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* - 渲染
|
|
127
|
+
* @param options - 渲染参数
|
|
128
|
+
*/
|
|
129
|
+
render (options) {
|
|
130
|
+
return render.render(options)
|
|
131
|
+
}
|
|
102
132
|
}
|
|
@@ -198,7 +198,7 @@ export class MessageHandler extends EventHandler {
|
|
|
198
198
|
/** 管理员 */
|
|
199
199
|
this.e.isAdmin = true
|
|
200
200
|
}
|
|
201
|
-
if (this.e.contact.scene === '
|
|
201
|
+
if (this.e.contact.scene === 'friend') {
|
|
202
202
|
this.e.isPrivate = true
|
|
203
203
|
this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]`
|
|
204
204
|
logger.bot('info', this.e.self_id, `私聊:[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`)
|
|
@@ -32,7 +32,7 @@ export default class NoticeHandler extends EventHandler {
|
|
|
32
32
|
/** 管理员 */
|
|
33
33
|
this.e.isAdmin = true
|
|
34
34
|
}
|
|
35
|
-
if (this.e.contact.scene === '
|
|
35
|
+
if (this.e.contact.scene === 'friend') {
|
|
36
36
|
this.e.isPrivate = true
|
|
37
37
|
this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]`
|
|
38
38
|
logger.bot('info', this.e.self_id, `${logger.green('私聊通知: ')}[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`)
|
|
@@ -32,7 +32,7 @@ export default class RequestHandler extends EventHandler {
|
|
|
32
32
|
/** 管理员 */
|
|
33
33
|
this.e.isAdmin = true
|
|
34
34
|
}
|
|
35
|
-
if (this.e.contact.scene === '
|
|
35
|
+
if (this.e.contact.scene === 'friend') {
|
|
36
36
|
this.e.isPrivate = true
|
|
37
37
|
this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]`
|
|
38
38
|
logger.bot('info', this.e.self_id, `${logger.green('私聊请求: ')}[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`)
|
package/lib/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare const Cfg: {
|
|
|
37
37
|
logger: import("log4js").Logger;
|
|
38
38
|
initCfg(): Promise<void>;
|
|
39
39
|
getPlugins(): string[];
|
|
40
|
-
|
|
40
|
+
mkdir(dirname: string): boolean;
|
|
41
41
|
dirPath(name: string, plugins: string[]): Promise<void>;
|
|
42
42
|
timeout(type?: "ws" | "grpc"): number;
|
|
43
43
|
readonly redis: import("./types/index.js").Redis;
|
package/lib/tools/init.js
CHANGED
|
@@ -23,15 +23,13 @@ for (const dir of delList) {
|
|
|
23
23
|
if (!fs.existsSync(path)) { fs.copyFileSync(pathDef, path) }
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
// 判断是否为第一次使用
|
|
27
|
-
if (!fs.existsSync('./index.js')) {
|
|
28
|
-
// 创建一个index.js文件 以供初次开箱使用,写入默认配置
|
|
29
|
-
fs.writeFileSync('./index.js', `import { Bot } from 'node-karin'
|
|
30
|
-
console.log(Bot.name + '开始初始化~')
|
|
31
|
-
`)
|
|
32
|
-
}
|
|
33
26
|
// 修改package.json为esm模块
|
|
34
27
|
const pack = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
|
|
35
|
-
|
|
36
|
-
fs.
|
|
37
|
-
|
|
28
|
+
// 解析包内的package.json文件
|
|
29
|
+
const npmPack = JSON.parse(fs.readFileSync(`${karinDir}/package.json`, 'utf-8'))
|
|
30
|
+
npmPack.main = './node_modules/node-karin/lib/index.js'
|
|
31
|
+
delete npmPack.bin
|
|
32
|
+
delete npmPack.types
|
|
33
|
+
npmPack.dependencies = pack.dependencies
|
|
34
|
+
fs.writeFileSync('./package.json', JSON.stringify(npmPack, null, 2))
|
|
35
|
+
console.log('初始化完成~,请通过 【 node . 】 启动程序~')
|
package/lib/types/event.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type Event = 'message' | 'notice' | 'request' | 'meta_event' | 'message_s
|
|
|
8
8
|
/**
|
|
9
9
|
* - 事件来源
|
|
10
10
|
*/
|
|
11
|
-
export type Scene = 'group' | '
|
|
11
|
+
export type Scene = 'group' | 'friend' | 'guild' | 'nearby' | 'stranger' | 'stranger_from_group';
|
|
12
12
|
/**
|
|
13
13
|
* - 类型映射
|
|
14
14
|
*/
|
package/lib/utils/config.d.ts
CHANGED
|
@@ -15,9 +15,10 @@ export declare const config: {
|
|
|
15
15
|
initCfg(): Promise<void>;
|
|
16
16
|
getPlugins(): string[];
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* 递归创建目录
|
|
19
|
+
* @param dirname - 要创建的文件夹路径
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
mkdir(dirname: string): boolean;
|
|
21
22
|
/**
|
|
22
23
|
* 为每一个插件建立对应的文件夹
|
|
23
24
|
*/
|
package/lib/utils/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from 'path'
|
|
1
2
|
import { karinDir } from '../core/dir.js'
|
|
2
3
|
import { fs, yaml as Yaml, chokidar } from '../modules.js'
|
|
3
4
|
/**
|
|
@@ -33,7 +34,7 @@ export const config = new (class Cfg {
|
|
|
33
34
|
'./plugins',
|
|
34
35
|
'./plugins/karin-plugin-example',
|
|
35
36
|
]
|
|
36
|
-
list.forEach(path => this.
|
|
37
|
+
list.forEach(path => this.mkdir(path))
|
|
37
38
|
if (this.npmCfgDir !== (this._path + '/defSet').replace(/\\/g, '/')) {
|
|
38
39
|
const files = fs.readdirSync(this.npmCfgDir).filter(file => file.endsWith('.yaml'))
|
|
39
40
|
files.forEach(file => {
|
|
@@ -58,10 +59,14 @@ export const config = new (class Cfg {
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/**
|
|
61
|
-
*
|
|
62
|
+
* 递归创建目录
|
|
63
|
+
* @param dirname - 要创建的文件夹路径
|
|
62
64
|
*/
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
+
mkdir (dirname) {
|
|
66
|
+
if (fs.existsSync(dirname)) { return true }
|
|
67
|
+
/** 递归自调用 */
|
|
68
|
+
if (this.mkdir(path.dirname(dirname))) { fs.mkdirSync(dirname) }
|
|
69
|
+
return true
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
/**
|
|
@@ -69,10 +74,10 @@ export const config = new (class Cfg {
|
|
|
69
74
|
*/
|
|
70
75
|
async dirPath (name, plugins) {
|
|
71
76
|
name = `./${name}`
|
|
72
|
-
this.
|
|
77
|
+
this.mkdir(name)
|
|
73
78
|
for (const plugin of plugins) {
|
|
74
79
|
const path = `${name}/${plugin}`
|
|
75
|
-
this.
|
|
80
|
+
this.mkdir(path)
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-karin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "基于 Kritor 进行开发的nodejs机器人框架",
|
|
6
6
|
"homepage": "https://github.com/KarinJS/Karin",
|
|
@@ -14,9 +14,6 @@
|
|
|
14
14
|
"license": "GPL-3.0-only",
|
|
15
15
|
"author": "Karin",
|
|
16
16
|
"type": "module",
|
|
17
|
-
"imports": {
|
|
18
|
-
"#Karin": "./lib/index.js"
|
|
19
|
-
},
|
|
20
17
|
"main": "./lib/index.js",
|
|
21
18
|
"types": "./lib/index.d.ts",
|
|
22
19
|
"bin": {
|