node-karin 0.6.18 → 0.6.20
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/index.d.ts +1 -1
- package/lib/adapter/index.js +1 -1
- package/lib/adapter/input/index.d.ts +16 -3
- package/lib/adapter/input/index.js +52 -38
- package/lib/adapter/kritor/grpc.d.ts +3 -2
- package/lib/adapter/kritor/grpc.js +80 -64
- package/lib/adapter/kritor/index.d.ts +35 -18
- package/lib/adapter/kritor/index.js +26 -10
- package/lib/adapter/onebot/11/convert.d.ts +11 -0
- package/lib/adapter/onebot/11/convert.js +168 -0
- package/lib/adapter/onebot/11/event.d.ts +25 -0
- package/lib/adapter/onebot/11/event.js +425 -0
- package/lib/adapter/onebot/11/index.d.ts +506 -0
- package/lib/adapter/onebot/11/index.js +1047 -0
- package/lib/cli/init.js +11 -0
- package/lib/core/karin.d.ts +3 -4
- package/lib/core/karin.js +3 -2
- package/lib/core/listener.d.ts +2 -2
- package/lib/core/listener.js +2 -2
- package/lib/core/plugin.app.js +2 -1
- package/lib/core/plugin.d.ts +4 -4
- package/lib/core/plugin.js +2 -1
- package/lib/core/plugin.loader.d.ts +3 -3
- package/lib/core/plugin.loader.js +2 -1
- package/lib/core/server.js +3 -3
- package/lib/event/event.handler.d.ts +5 -5
- package/lib/event/event.handler.js +6 -5
- package/lib/event/index.d.ts +0 -4
- package/lib/event/index.js +0 -4
- package/lib/event/message.handler.d.ts +3 -3
- package/lib/event/notice.handler.d.ts +3 -3
- package/lib/event/notice.handler.js +17 -16
- package/lib/event/request.handler.d.ts +3 -3
- package/lib/event/request.handler.js +4 -3
- package/lib/event/review.handler.d.ts +7 -8
- package/lib/index.js +1 -1
- package/lib/types/adapter/adapter.d.ts +564 -0
- package/lib/types/adapter/adapter.js +1 -0
- package/lib/types/{api.d.ts → adapter/api.d.ts} +103 -3
- package/lib/types/adapter/api.js +1 -0
- package/lib/types/element.d.ts +5 -4
- package/lib/types/event/contact.d.ts +28 -0
- package/lib/types/event/contact.js +13 -0
- package/lib/types/event/event.d.ts +390 -0
- package/lib/types/event/event.js +234 -0
- package/lib/types/event/index.d.ts +12 -0
- package/lib/types/event/index.js +7 -0
- package/lib/types/event/message.d.ts +104 -0
- package/lib/types/event/message.js +72 -0
- package/lib/types/event/notice.d.ts +513 -0
- package/lib/types/event/notice.js +52 -0
- package/lib/types/{reply.d.ts → event/reply.d.ts} +2 -2
- package/lib/types/event/reply.js +1 -0
- package/lib/types/event/request.d.ts +126 -0
- package/lib/types/event/request.js +52 -0
- package/lib/types/event/sender.d.ts +44 -0
- package/lib/types/event/sender.js +22 -0
- package/lib/types/index.d.ts +6 -5
- package/lib/types/index.js +6 -5
- package/lib/types/onebot11/api.d.ts +53 -0
- package/lib/types/onebot11/api.js +54 -0
- package/lib/types/onebot11/event.d.ts +619 -0
- package/lib/types/onebot11/event.js +56 -0
- package/lib/types/onebot11/index.d.ts +6 -0
- package/lib/types/onebot11/index.js +6 -0
- package/lib/types/onebot11/params.d.ts +609 -0
- package/lib/types/onebot11/params.js +7 -0
- package/lib/types/onebot11/response.d.ts +516 -0
- package/lib/types/onebot11/response.js +1 -0
- package/lib/types/onebot11/segment.d.ts +268 -0
- package/lib/types/onebot11/segment.js +30 -0
- package/lib/types/onebot11/sender.d.ts +59 -0
- package/lib/types/onebot11/sender.js +1 -0
- package/lib/types/plugin.d.ts +10 -11
- package/lib/utils/button.d.ts +2 -2
- package/lib/utils/common.d.ts +2 -2
- package/lib/utils/config.js +3 -3
- package/lib/utils/handler.d.ts +2 -2
- package/lib/utils/handler.js +1 -1
- package/lib/utils/init.d.ts +1 -1
- package/lib/utils/init.js +2 -1
- package/lib/utils/segment.d.ts +2 -2
- package/package.json +1 -1
- package/lib/adapter/onebot/onebot11.d.ts +0 -309
- package/lib/adapter/onebot/onebot11.js +0 -1285
- package/lib/event/event.d.ts +0 -140
- package/lib/event/event.js +0 -125
- package/lib/event/message.d.ts +0 -105
- package/lib/event/message.js +0 -70
- package/lib/event/notice.d.ts +0 -49
- package/lib/event/notice.js +0 -15
- package/lib/event/request.d.ts +0 -49
- package/lib/event/request.js +0 -15
- package/lib/types/adapter.d.ts +0 -581
- package/lib/types/adapter.js +0 -1
- package/lib/types/api.js +0 -1
- package/lib/types/event.d.ts +0 -789
- package/lib/types/event.js +0 -1
- package/lib/types/onebots11.d.ts +0 -1426
- package/lib/types/onebots11.js +0 -1
- package/lib/types/reply.js +0 -1
package/lib/cli/init.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { select } from '@inquirer/prompts'
|
|
3
3
|
import { KarinInit } from '../utils/init.js'
|
|
4
|
+
/**
|
|
5
|
+
* 休眠函数
|
|
6
|
+
* @param ms 毫秒
|
|
7
|
+
*/
|
|
8
|
+
function sleep (ms) {
|
|
9
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
10
|
+
}
|
|
4
11
|
async function main () {
|
|
5
12
|
/** 捕获错误 打印日志 */
|
|
6
13
|
process.on('uncaughtException', err => console.error(err))
|
|
7
14
|
process.on('unhandledRejection', err => console.error(err))
|
|
8
15
|
const init = new KarinInit()
|
|
9
16
|
init.init()
|
|
17
|
+
await sleep(1000)
|
|
10
18
|
const prompt = await select({
|
|
11
19
|
message: '请选择npm源 中国大陆服务器一定要更换!!!',
|
|
12
20
|
choices: [
|
|
@@ -14,8 +22,11 @@ async function main () {
|
|
|
14
22
|
{ name: '官方源', value: 'https://registry.npmjs.org' },
|
|
15
23
|
],
|
|
16
24
|
})
|
|
25
|
+
console.log('正在更换npm源...请稍等~')
|
|
26
|
+
await sleep(1000)
|
|
17
27
|
/** 结果 */
|
|
18
28
|
await init.changeRegistry(prompt)
|
|
29
|
+
await sleep(1000)
|
|
19
30
|
const pkg = await select({
|
|
20
31
|
message: '请选择包管理器 如果不知道怎么选 请选pnpm',
|
|
21
32
|
choices: [
|
package/lib/core/karin.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { KarinMessage } from '../
|
|
2
|
-
import { Permission, PluginApps, KarinElement, contact, KarinRenderType } from '../types/index.js';
|
|
1
|
+
import { KarinMessage, PluginApps, KarinElement, Contact, KarinRenderType, PermissionType } from '../types/index.js';
|
|
3
2
|
type FncFunction = (e: KarinMessage) => Promise<boolean>;
|
|
4
3
|
type FncElement = string | KarinElement | Array<KarinElement>;
|
|
5
4
|
export interface OptionsCommand {
|
|
@@ -16,7 +15,7 @@ export interface OptionsCommand {
|
|
|
16
15
|
* - 权限
|
|
17
16
|
* @default 'all'
|
|
18
17
|
*/
|
|
19
|
-
permission?:
|
|
18
|
+
permission?: PermissionType;
|
|
20
19
|
/**
|
|
21
20
|
* - 打印日志
|
|
22
21
|
* @default false
|
|
@@ -113,7 +112,7 @@ export declare class Karin {
|
|
|
113
112
|
* @param isGroup - 是否是群聊
|
|
114
113
|
* @param sub_peer - 子id
|
|
115
114
|
*/
|
|
116
|
-
contact(peer: string, isGroup?: boolean, sub_peer?: string):
|
|
115
|
+
contact(peer: string, isGroup?: boolean, sub_peer?: string): Contact;
|
|
117
116
|
/**
|
|
118
117
|
* - 渲染
|
|
119
118
|
* @param options - 渲染参数
|
package/lib/core/karin.js
CHANGED
|
@@ -3,6 +3,7 @@ import { common } from '../utils/index.js'
|
|
|
3
3
|
import { render } from '../render/index.js'
|
|
4
4
|
import { stateArr } from './plugin.js'
|
|
5
5
|
import { listener } from './listener.js'
|
|
6
|
+
import { Scene } from '../types/index.js'
|
|
6
7
|
export class Karin {
|
|
7
8
|
/**
|
|
8
9
|
* - 快速构建命令
|
|
@@ -99,13 +100,13 @@ export class Karin {
|
|
|
99
100
|
contact (peer, isGroup = true, sub_peer) {
|
|
100
101
|
if (isGroup) {
|
|
101
102
|
return {
|
|
102
|
-
scene:
|
|
103
|
+
scene: Scene.Group,
|
|
103
104
|
peer,
|
|
104
105
|
sub_peer: sub_peer || '',
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
return {
|
|
108
|
-
scene:
|
|
109
|
+
scene: Scene.Private,
|
|
109
110
|
peer,
|
|
110
111
|
sub_peer: sub_peer || '',
|
|
111
112
|
}
|
package/lib/core/listener.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import { KarinAdapter,
|
|
2
|
+
import { KarinAdapter, Contact, KarinElement } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* 监听器管理
|
|
5
5
|
*/
|
|
@@ -93,7 +93,7 @@ declare class Listeners extends EventEmitter {
|
|
|
93
93
|
* @param options.recallMsg - 发送成功后撤回消息时间
|
|
94
94
|
* @param options.retry_count - 重试次数
|
|
95
95
|
*/
|
|
96
|
-
sendMsg(uid: string, contact:
|
|
96
|
+
sendMsg(uid: string, contact: Contact, elements: KarinElement, options?: {
|
|
97
97
|
recallMsg?: number;
|
|
98
98
|
retry_count?: number;
|
|
99
99
|
}): Promise<{
|
package/lib/core/listener.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'events'
|
|
2
2
|
import { pluginLoader } from './plugin.loader.js'
|
|
3
3
|
import { common, logger, config } from '../utils/index.js'
|
|
4
|
-
import { MessageHandler } from '../event/message.handler.js'
|
|
5
4
|
import NoticeHandler from '../event/notice.handler.js'
|
|
6
5
|
import RequestHandler from '../event/request.handler.js'
|
|
6
|
+
import { MessageHandler } from '../event/message.handler.js'
|
|
7
7
|
/**
|
|
8
8
|
* 监听器管理
|
|
9
9
|
*/
|
|
@@ -29,7 +29,7 @@ class Listeners extends EventEmitter {
|
|
|
29
29
|
this.on('load.plugin', () => pluginLoader.load())
|
|
30
30
|
this.on('adapter', data => {
|
|
31
31
|
let path = data.path || '无'
|
|
32
|
-
if (path && data.type !== 'grpc') { path = `ws://127.0.0.1
|
|
32
|
+
if (path && data.type !== 'grpc') { path = `ws://127.0.0.1:${config.Server.http.port}${data.path}` }
|
|
33
33
|
path = logger.green(path)
|
|
34
34
|
logger.info(`[适配器][注册][${data.type}]: ` + path)
|
|
35
35
|
this.addAdapter(data)
|
package/lib/core/plugin.app.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EventType } from '../types/index.js'
|
|
1
2
|
export default function PluginApp (options) {
|
|
2
3
|
return {
|
|
3
4
|
file: {
|
|
@@ -7,7 +8,7 @@ export default function PluginApp (options) {
|
|
|
7
8
|
Fnc: options?.file?.fnc || '',
|
|
8
9
|
},
|
|
9
10
|
name: options.name || '',
|
|
10
|
-
event: options.event ||
|
|
11
|
+
event: options.event || EventType.Message,
|
|
11
12
|
priority: options.priority || 10000,
|
|
12
13
|
accept: options.accept ?? false,
|
|
13
14
|
rule: options.rule || [],
|
package/lib/core/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PluginType, KarinElement,
|
|
1
|
+
import { PluginType, KarinElement, NodeElement, stateArrType, KarinNoticeType, KarinRequestType, KarinEventTypes } from '../types/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* 插件基类
|
|
4
4
|
*/
|
|
@@ -124,7 +124,7 @@ export declare class Plugin implements PluginType {
|
|
|
124
124
|
/**
|
|
125
125
|
* - 快速回复合并转发
|
|
126
126
|
*/
|
|
127
|
-
replyForward(msg:
|
|
127
|
+
replyForward(msg: NodeElement[]): Promise<{
|
|
128
128
|
message_id?: string;
|
|
129
129
|
}>;
|
|
130
130
|
/**
|
|
@@ -155,7 +155,7 @@ export declare class Plugin implements PluginType {
|
|
|
155
155
|
* 清除上下文状态
|
|
156
156
|
*/
|
|
157
157
|
finish(): void;
|
|
158
|
-
e:
|
|
158
|
+
e: KarinEventTypes;
|
|
159
159
|
replyCallback: PluginType['replyCallback'];
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
@@ -166,5 +166,5 @@ export declare const stateArr: stateArrType;
|
|
|
166
166
|
* 通知事件 插件类型
|
|
167
167
|
*/
|
|
168
168
|
export interface ExtendedPlugin extends Plugin {
|
|
169
|
-
accept: (e:
|
|
169
|
+
accept: (e: KarinNoticeType | KarinRequestType) => Promise<void>;
|
|
170
170
|
}
|
package/lib/core/plugin.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EventType } from '../types/index.js'
|
|
1
2
|
/**
|
|
2
3
|
* 插件基类
|
|
3
4
|
*/
|
|
@@ -47,7 +48,7 @@ export class Plugin {
|
|
|
47
48
|
* @param timeout - 上下文超时
|
|
48
49
|
*/
|
|
49
50
|
timeout
|
|
50
|
-
constructor ({ name, dsc = name, desc = name, event =
|
|
51
|
+
constructor ({ name, dsc = name, desc = name, event = EventType.Message, priority = 10000, task = [], rule = [], handler = [], button = [] }) {
|
|
51
52
|
this.name = name
|
|
52
53
|
this.dsc = dsc
|
|
53
54
|
this.desc = desc
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chokidar from 'chokidar';
|
|
2
2
|
import schedule from 'node-schedule';
|
|
3
3
|
import { Plugin } from './plugin.js';
|
|
4
|
-
import { PluginApps, PluginTask, dirName, fileName, AppInfo,
|
|
4
|
+
import { PluginApps, PluginTask, dirName, fileName, AppInfo, NewMessagePlugin } from '../types/index.js';
|
|
5
5
|
declare class PluginLoader {
|
|
6
6
|
dir: './plugins';
|
|
7
7
|
dirPath: string;
|
|
@@ -53,7 +53,7 @@ declare class PluginLoader {
|
|
|
53
53
|
* - 定时任务
|
|
54
54
|
*/
|
|
55
55
|
task: Array<PluginTask & {
|
|
56
|
-
App:
|
|
56
|
+
App: NewMessagePlugin;
|
|
57
57
|
schedule?: schedule.Job;
|
|
58
58
|
file: {
|
|
59
59
|
dir: dirName;
|
|
@@ -118,7 +118,7 @@ declare class PluginLoader {
|
|
|
118
118
|
/**
|
|
119
119
|
* 新增task
|
|
120
120
|
*/
|
|
121
|
-
addTask(dir: dirName, name: fileName, index: number, Class: Plugin, App:
|
|
121
|
+
addTask(dir: dirName, name: fileName, index: number, Class: Plugin, App: NewMessagePlugin): Promise<void>;
|
|
122
122
|
/**
|
|
123
123
|
* 新增accept、handler
|
|
124
124
|
*/
|
|
@@ -7,6 +7,7 @@ import { listener } from './listener.js'
|
|
|
7
7
|
import PluginApp from './plugin.app.js'
|
|
8
8
|
import { render } from '../render/index.js'
|
|
9
9
|
import { common, handler, logger } from '../utils/index.js'
|
|
10
|
+
import { Permission } from '../types/index.js'
|
|
10
11
|
class PluginLoader {
|
|
11
12
|
dir
|
|
12
13
|
dirPath
|
|
@@ -321,7 +322,7 @@ class PluginLoader {
|
|
|
321
322
|
reg: val.reg instanceof RegExp ? val.reg : new RegExp(val.reg),
|
|
322
323
|
fnc: val.fnc,
|
|
323
324
|
event: val.event,
|
|
324
|
-
permission: val.permission ||
|
|
325
|
+
permission: val.permission || Permission.All,
|
|
325
326
|
log: val.log === false ? (id, log) => logger.debug('mark', id, log) : (id, log) => logger.bot('mark', id, log),
|
|
326
327
|
})
|
|
327
328
|
})
|
package/lib/core/server.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import Process from './process.js'
|
|
3
|
-
import { listener } from './listener.js'
|
|
4
3
|
import { WebSocketServer } from 'ws'
|
|
5
4
|
import { createServer } from 'http'
|
|
5
|
+
import { listener } from './listener.js'
|
|
6
6
|
import express from 'express'
|
|
7
|
+
import { KritorGrpc } from '../adapter/index.js'
|
|
7
8
|
import { exec, config, logger, common } from '../utils/index.js'
|
|
9
|
+
import { AdapterOneBot11 } from '../adapter/onebot/11/index.js'
|
|
8
10
|
import { render, HttpRenderer, Wormhole, RenderClient } from '../render/index.js'
|
|
9
|
-
import { AdapterOneBot11 } from '../adapter/onebot/onebot11.js'
|
|
10
|
-
import { KritorGrpc } from '../adapter/index.js'
|
|
11
11
|
export const server = new (class Server {
|
|
12
12
|
reg
|
|
13
13
|
list
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GroupCfg, KarinEventTypes, AllListenEvent, PluginRule } from '../types/index.js';
|
|
2
2
|
export default class EventHandler {
|
|
3
|
-
e:
|
|
3
|
+
e: KarinEventTypes;
|
|
4
4
|
config: GroupCfg | {};
|
|
5
5
|
/**
|
|
6
6
|
* - 是否打印群消息日志
|
|
@@ -9,7 +9,7 @@ export default class EventHandler {
|
|
|
9
9
|
/**
|
|
10
10
|
* 处理事件,加入自定义字段
|
|
11
11
|
*/
|
|
12
|
-
constructor(e:
|
|
12
|
+
constructor(e: KarinEventTypes);
|
|
13
13
|
/**
|
|
14
14
|
* 事件处理
|
|
15
15
|
*/
|
|
@@ -17,11 +17,11 @@ export default class EventHandler {
|
|
|
17
17
|
/**
|
|
18
18
|
* 根据事件类型过滤事件
|
|
19
19
|
*/
|
|
20
|
-
filtEvent(event:
|
|
20
|
+
filtEvent(event: AllListenEvent): boolean;
|
|
21
21
|
/**
|
|
22
22
|
* 判断权限
|
|
23
23
|
*/
|
|
24
|
-
filterPermission(permission
|
|
24
|
+
filterPermission(permission?: PluginRule['permission']): boolean;
|
|
25
25
|
/**
|
|
26
26
|
* 快速回复
|
|
27
27
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { review } from './review.handler.js'
|
|
2
1
|
import { listener } from '../core/index.js'
|
|
2
|
+
import { review } from './review.handler.js'
|
|
3
3
|
import { segment, common, logger, config } from '../utils/index.js'
|
|
4
4
|
export default class EventHandler {
|
|
5
5
|
e
|
|
@@ -90,10 +90,11 @@ export default class EventHandler {
|
|
|
90
90
|
},
|
|
91
91
|
}
|
|
92
92
|
const role = list[permission]
|
|
93
|
-
if (role
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
93
|
+
if (!role) { return true }
|
|
94
|
+
if (role.role === 'owner' && this.e.sender?.role === 'owner') { return true }
|
|
95
|
+
if (role.role === 'admin' && (this.e.sender?.role === 'owner' || this.e.sender?.role === 'admin')) { return true }
|
|
96
|
+
this.e.reply(`暂无权限,只有${role.name}才能操作`)
|
|
97
|
+
return false
|
|
97
98
|
}
|
|
98
99
|
return true
|
|
99
100
|
}
|
package/lib/event/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export * from './event.js';
|
|
2
1
|
export * from './event.handler.js';
|
|
3
|
-
export * from './message.js';
|
|
4
2
|
export * from './message.handler.js';
|
|
5
|
-
export * from './notice.js';
|
|
6
3
|
export * from './notice.handler.js';
|
|
7
|
-
export * from './request.js';
|
|
8
4
|
export * from './request.handler.js';
|
|
9
5
|
export * from './review.handler.js';
|
package/lib/event/index.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export * from './event.js'
|
|
2
1
|
export * from './event.handler.js'
|
|
3
|
-
export * from './message.js'
|
|
4
2
|
export * from './message.handler.js'
|
|
5
|
-
export * from './notice.js'
|
|
6
3
|
export * from './notice.handler.js'
|
|
7
|
-
export * from './request.js'
|
|
8
4
|
export * from './request.handler.js'
|
|
9
5
|
export * from './review.handler.js'
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import EventHandler from './event.handler.js';
|
|
2
|
-
import {
|
|
2
|
+
import { KarinMessageType } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* 消息事件
|
|
5
5
|
*/
|
|
6
6
|
export declare class MessageHandler extends EventHandler {
|
|
7
|
-
e:
|
|
7
|
+
e: KarinMessageType;
|
|
8
8
|
/**
|
|
9
9
|
* - 是否打印群消息日志
|
|
10
10
|
*/
|
|
11
11
|
GroupMsgPrint: boolean;
|
|
12
|
-
constructor(e:
|
|
12
|
+
constructor(e: KarinMessageType);
|
|
13
13
|
/**
|
|
14
14
|
* 处理消息
|
|
15
15
|
*/
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import EventHandler from './event.handler.js';
|
|
2
|
-
import {
|
|
2
|
+
import { KarinNoticeType } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* 通知事件
|
|
5
5
|
*/
|
|
6
6
|
export default class NoticeHandler extends EventHandler {
|
|
7
|
-
e:
|
|
8
|
-
constructor(e:
|
|
7
|
+
e: KarinNoticeType;
|
|
8
|
+
constructor(e: KarinNoticeType);
|
|
9
9
|
/**
|
|
10
10
|
* 处理事件
|
|
11
11
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { review } from './review.handler.js'
|
|
2
2
|
import EventHandler from './event.handler.js'
|
|
3
3
|
import { logger, config } from '../utils/index.js'
|
|
4
|
+
import { NoticeSubType } from '../types/index.js'
|
|
4
5
|
import { pluginLoader } from '../core/index.js'
|
|
5
6
|
/**
|
|
6
7
|
* 通知事件
|
|
@@ -84,48 +85,48 @@ export default class NoticeHandler extends EventHandler {
|
|
|
84
85
|
raw_message () {
|
|
85
86
|
switch (this.e.sub_event) {
|
|
86
87
|
/** 好友头像戳一戳 */
|
|
87
|
-
case
|
|
88
|
+
case NoticeSubType.PrivatePoke: {
|
|
88
89
|
this.e.raw_message = '[好友戳一戳]: 戳了你一下'
|
|
89
90
|
break
|
|
90
91
|
}
|
|
91
92
|
/** 好友消息撤回 */
|
|
92
|
-
case
|
|
93
|
+
case NoticeSubType.PrivateRecall: {
|
|
93
94
|
this.e.raw_message = `[好友消息撤回]: ${this.e.content.message_id}`
|
|
94
95
|
break
|
|
95
96
|
}
|
|
96
97
|
/** 私聊文件上传 */
|
|
97
|
-
case
|
|
98
|
+
case NoticeSubType.PrivateFileUploaded: {
|
|
98
99
|
const content = this.e.content
|
|
99
100
|
const { file_url } = content
|
|
100
101
|
this.e.raw_message = `[私聊文件上传]: ${file_url}`
|
|
101
102
|
break
|
|
102
103
|
}
|
|
103
104
|
/** 群头像戳一戳 */
|
|
104
|
-
case
|
|
105
|
+
case NoticeSubType.GroupPoke: {
|
|
105
106
|
const { operator_uid, operator_uin, target_uid, target_uin } = this.e.content
|
|
106
107
|
this.e.raw_message = `[群戳一戳]: ${operator_uid || operator_uin} 戳了戳 ${target_uid || target_uin}`
|
|
107
108
|
break
|
|
108
109
|
}
|
|
109
110
|
/** 群消息撤回 */
|
|
110
|
-
case
|
|
111
|
+
case NoticeSubType.GroupRecall: {
|
|
111
112
|
const { operator_uid, operator_uin, message_id } = this.e.content
|
|
112
113
|
this.e.raw_message = `[群消息撤回]: ${operator_uid || operator_uin} 撤回了一条消息 ${message_id}`
|
|
113
114
|
break
|
|
114
115
|
}
|
|
115
116
|
/** 群文件上传 */
|
|
116
|
-
case
|
|
117
|
+
case NoticeSubType.GroupFileUploaded: {
|
|
117
118
|
const { file_url, operator_uid, operator_uin } = this.e.content
|
|
118
119
|
this.e.raw_message = `[群文件上传]: ${operator_uid || operator_uin} 上传了 ${file_url}`
|
|
119
120
|
break
|
|
120
121
|
}
|
|
121
122
|
/** 群成员增加 */
|
|
122
|
-
case
|
|
123
|
+
case NoticeSubType.GroupMemberIncrease: {
|
|
123
124
|
const { operator_uid, operator_uin, target_uid, target_uin, type } = this.e.content
|
|
124
125
|
this.e.raw_message = `[群成员新增]: ${operator_uid || operator_uin} ${type === 'invite' ? '邀请' : '同意'} ${target_uid || target_uin} 加入群聊`
|
|
125
126
|
break
|
|
126
127
|
}
|
|
127
128
|
/** 群成员减少 */
|
|
128
|
-
case
|
|
129
|
+
case NoticeSubType.GroupMemberDecrease: {
|
|
129
130
|
switch (this.e.content.type) {
|
|
130
131
|
case 'leave': {
|
|
131
132
|
const { target_uid, target_uin } = this.e.content
|
|
@@ -148,49 +149,49 @@ export default class NoticeHandler extends EventHandler {
|
|
|
148
149
|
break
|
|
149
150
|
}
|
|
150
151
|
/** 群管理员变动 */
|
|
151
|
-
case
|
|
152
|
+
case NoticeSubType.GroupAdminChanged: {
|
|
152
153
|
const { target_uid, target_uin, is_admin } = this.e.content
|
|
153
154
|
this.e.raw_message = `[群管理员变动]: ${target_uid || target_uin} 被${is_admin ? '设置' : '取消'}群管理员`
|
|
154
155
|
break
|
|
155
156
|
}
|
|
156
157
|
/** 群成员被禁言 */
|
|
157
|
-
case
|
|
158
|
+
case NoticeSubType.GroupMemberBan: {
|
|
158
159
|
const { operator_uid, operator_uin, target_uid, target_uin, type } = this.e.content
|
|
159
160
|
this.e.raw_message = `[群成员禁言]: ${operator_uid || operator_uin} ${type === 'ban' ? '禁言' : '解禁'}了 ${target_uid || target_uin}`
|
|
160
161
|
break
|
|
161
162
|
}
|
|
162
163
|
/** 群签到 */
|
|
163
|
-
case
|
|
164
|
+
case NoticeSubType.GroupSignIn: {
|
|
164
165
|
const { target_uid, target_uin } = this.e.content
|
|
165
166
|
this.e.raw_message = `[群签到]: ${target_uid || target_uin}`
|
|
166
167
|
break
|
|
167
168
|
}
|
|
168
169
|
/** 群全员禁言 */
|
|
169
|
-
case
|
|
170
|
+
case NoticeSubType.GroupWholeBan: {
|
|
170
171
|
const { operator_uid, operator_uin, is_ban } = this.e.content
|
|
171
172
|
this.e.raw_message = `[群全员禁言]: ${operator_uid || operator_uin} ${is_ban ? '开启全员禁言' : '解除全员禁言'}`
|
|
172
173
|
break
|
|
173
174
|
}
|
|
174
175
|
/** 群名片改变 */
|
|
175
|
-
case
|
|
176
|
+
case NoticeSubType.GroupCardChanged: {
|
|
176
177
|
const { operator_uid, operator_uin, target_uid, target_uin, new_card } = this.e.content
|
|
177
178
|
this.e.raw_message = `[群名片改变]: ${operator_uid || operator_uin} 修改了 ${target_uid || target_uin} 的名片为 ${new_card}`
|
|
178
179
|
break
|
|
179
180
|
}
|
|
180
181
|
/** 群成员专属头衔改变 */
|
|
181
|
-
case
|
|
182
|
+
case NoticeSubType.GroupMemberUniqueTitleChanged: {
|
|
182
183
|
const { target_uid, target_uin, title } = this.e.content
|
|
183
184
|
this.e.raw_message = `[群头衔更改]: ${target_uid || target_uin} 的专属头衔改变为 ${title}`
|
|
184
185
|
break
|
|
185
186
|
}
|
|
186
187
|
/** 群精华消息改变 */
|
|
187
|
-
case
|
|
188
|
+
case NoticeSubType.GroupEssenceChanged: {
|
|
188
189
|
const { operator_uid, operator_uin, target_uid, target_uin, message_id, is_set } = this.e.content
|
|
189
190
|
this.e.raw_message = `[群精华消息]: ${operator_uid || operator_uin} ${is_set ? `将${target_uid || target_uin}的消息${message_id}设置为精华消息` : `取消了${target_uid || target_uin}精华消息 ${message_id}`}`
|
|
190
191
|
break
|
|
191
192
|
}
|
|
192
193
|
/** 群表情回应 */
|
|
193
|
-
case
|
|
194
|
+
case NoticeSubType.GroupMessageReaction: {
|
|
194
195
|
const { message_id, face_id } = this.e.content
|
|
195
196
|
this.e.raw_message = `[群表情回应]: ${this.e.user_id} 给消息 ${message_id} 回应了一个${face_id}的表情`
|
|
196
197
|
break
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import EventHandler from './event.handler.js';
|
|
2
|
-
import {
|
|
2
|
+
import { KarinRequestType } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* 请求事件
|
|
5
5
|
*/
|
|
6
6
|
export default class RequestHandler extends EventHandler {
|
|
7
|
-
e:
|
|
8
|
-
constructor(e:
|
|
7
|
+
e: KarinRequestType;
|
|
8
|
+
constructor(e: KarinRequestType);
|
|
9
9
|
/**
|
|
10
10
|
* 处理事件
|
|
11
11
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { review } from './review.handler.js'
|
|
2
2
|
import EventHandler from './event.handler.js'
|
|
3
3
|
import { logger, config } from '../utils/index.js'
|
|
4
|
+
import { RequestSubType } from '../types/index.js'
|
|
4
5
|
import { pluginLoader } from '../core/index.js'
|
|
5
6
|
/**
|
|
6
7
|
* 请求事件
|
|
@@ -84,19 +85,19 @@ export default class RequestHandler extends EventHandler {
|
|
|
84
85
|
raw_message () {
|
|
85
86
|
switch (this.e.sub_event) {
|
|
86
87
|
/** 好友申请 */
|
|
87
|
-
case
|
|
88
|
+
case RequestSubType.PrivateApply: {
|
|
88
89
|
const { applier_uid, applier_uin, message } = this.e.content
|
|
89
90
|
this.e.raw_message = `[好友申请]: ${applier_uid || applier_uin} 申请理由: ${message}`
|
|
90
91
|
break
|
|
91
92
|
}
|
|
92
93
|
/** 群申请 */
|
|
93
|
-
case
|
|
94
|
+
case RequestSubType.GroupApply: {
|
|
94
95
|
const { group_id, applier_uid, applier_uin, inviter_uid, inviter_uin, reason } = this.e.content
|
|
95
96
|
this.e.raw_message = `[群申请]: ${group_id} 申请人: ${applier_uid || applier_uin} 邀请人: ${inviter_uid || inviter_uin} 理由: ${reason}`
|
|
96
97
|
break
|
|
97
98
|
}
|
|
98
99
|
/** 邀请入群 */
|
|
99
|
-
case
|
|
100
|
+
case RequestSubType.InvitedGroup: {
|
|
100
101
|
const { group_id, inviter_uid, inviter_uin } = this.e.content
|
|
101
102
|
this.e.raw_message = `[邀请入群]: ${group_id} 邀请人: ${inviter_uid || inviter_uin}`
|
|
102
103
|
break
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EType, PluginApps, GroupCfg } from '../types/index.js';
|
|
1
|
+
import { KarinMessageType, PluginApps, GroupCfg, KarinEventTypes } from '../types/index.js';
|
|
3
2
|
/**
|
|
4
3
|
* 事件拦截器
|
|
5
4
|
* 利用可执行函数的特性,热更新所有拦截器
|
|
@@ -14,12 +13,12 @@ export declare const review: {
|
|
|
14
13
|
};
|
|
15
14
|
App: import("../types/index.js").App;
|
|
16
15
|
Config: import("../types/index.js").Config;
|
|
17
|
-
CD: (e:
|
|
18
|
-
mode: (e:
|
|
19
|
-
alias: (e:
|
|
20
|
-
GroupEnable: (e:
|
|
21
|
-
UserEnable: (e:
|
|
22
|
-
GroupMsgPrint: (e:
|
|
16
|
+
CD: (e: KarinEventTypes, config: GroupCfg) => boolean;
|
|
17
|
+
mode: (e: KarinMessageType, config: GroupCfg) => boolean;
|
|
18
|
+
alias: (e: KarinMessageType, config: GroupCfg) => boolean;
|
|
19
|
+
GroupEnable: (e: KarinEventTypes) => boolean;
|
|
20
|
+
UserEnable: (e: KarinEventTypes) => boolean;
|
|
21
|
+
GroupMsgPrint: (e: KarinEventTypes) => boolean;
|
|
23
22
|
PluginEnable: (app: PluginApps, config: GroupCfg) => boolean;
|
|
24
23
|
main(): void;
|
|
25
24
|
/**
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export * from './adapter/index.js';
|
|
|
15
15
|
import { config, update } from './utils/index.js';
|
|
16
16
|
import { render } from './render/index.js';
|
|
17
17
|
import { RenderServer } from './render/index.js';
|
|
18
|
-
import OneBot11 from './adapter/onebot/
|
|
18
|
+
import OneBot11 from './adapter/onebot/11/index.js';
|
|
19
19
|
import { server, Karin, listener, Plugin } from './core/index.js';
|
|
20
20
|
// 初始化
|
|
21
21
|
server.init();
|