node-karin 0.0.3 → 0.1.0
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/LICENSE +674 -674
- package/README.md +57 -57
- package/config/defSet/App.yaml +37 -37
- package/config/defSet/config.yaml +43 -43
- package/config/defSet/group.yaml +18 -18
- package/config/defSet/pm2.yaml +21 -21
- package/config/defSet/server.yaml +42 -42
- package/config/view/App.yaml +74 -74
- package/config/view/config.yaml +100 -100
- package/config/view/group.yaml +62 -62
- package/config/view/pm2.yaml +41 -41
- package/config/view/redis.yaml +25 -25
- package/config/view/server.yaml +93 -93
- package/lib/adapter/onebot/onebot11.d.ts +430 -430
- package/lib/adapter/onebot/onebot11.js +1265 -1302
- package/lib/core/init.js +4 -4
- package/lib/core/karin.d.ts +72 -72
- package/lib/core/karin.js +51 -51
- package/lib/core/listener.d.ts +121 -121
- package/lib/core/listener.js +178 -178
- package/lib/core/plugin.app.d.ts +15 -15
- package/lib/core/plugin.app.js +18 -18
- package/lib/core/plugin.d.ts +182 -182
- package/lib/core/plugin.js +132 -132
- package/lib/core/plugin.loader.d.ts +149 -149
- package/lib/core/plugin.loader.js +451 -451
- package/lib/core/server.d.ts +26 -26
- package/lib/core/server.js +209 -209
- package/lib/db/level.d.ts +20 -20
- package/lib/db/level.js +36 -36
- package/lib/db/redis.d.ts +41 -41
- package/lib/db/redis.js +131 -131
- package/lib/db/redis_level.d.ts +113 -113
- package/lib/db/redis_level.js +274 -274
- package/lib/event/event.d.ts +138 -138
- package/lib/event/event.handler.d.ts +29 -29
- package/lib/event/event.handler.js +138 -138
- package/lib/event/event.js +120 -120
- package/lib/event/message.d.ts +102 -102
- package/lib/event/message.handler.d.ts +25 -25
- package/lib/event/message.handler.js +237 -237
- package/lib/event/message.js +69 -69
- package/lib/event/notice.d.ts +49 -49
- package/lib/event/notice.js +14 -14
- package/lib/event/request.d.ts +49 -49
- package/lib/event/request.js +14 -14
- package/lib/event/review.handler.d.ts +54 -54
- package/lib/event/review.handler.js +374 -374
- package/lib/index.d.ts +23 -23
- package/lib/index.js +39 -40
- package/lib/renderer/app.d.ts +53 -53
- package/lib/renderer/app.js +88 -88
- package/lib/renderer/base.d.ts +30 -30
- package/lib/renderer/base.js +68 -68
- package/lib/renderer/client.d.ts +30 -30
- package/lib/renderer/client.js +155 -155
- package/lib/renderer/http.d.ts +19 -19
- package/lib/renderer/http.js +50 -50
- package/lib/renderer/server.d.ts +42 -42
- package/lib/renderer/server.js +110 -110
- package/lib/renderer/wormhole.d.ts +1 -1
- package/lib/renderer/wormhole.js +154 -154
- package/lib/types/adapter.d.ts +575 -575
- package/lib/types/adapter.js +1 -1
- package/lib/types/config.d.ts +327 -327
- package/lib/types/config.js +1 -1
- package/lib/types/element.d.ts +576 -576
- package/lib/types/element.js +1 -1
- package/lib/types/index.d.ts +8 -8
- package/lib/types/index.js +8 -8
- package/lib/types/logger.d.ts +109 -109
- package/lib/types/logger.js +1 -1
- package/lib/types/onebots11.d.ts +1371 -1371
- package/lib/types/onebots11.js +1 -1
- package/lib/types/plugin.d.ts +282 -282
- package/lib/types/plugin.js +1 -1
- package/lib/types/render.d.ts +111 -111
- package/lib/types/render.js +1 -1
- package/lib/types/reply.d.ts +40 -40
- package/lib/types/reply.js +1 -1
- package/lib/types/types.d.ts +898 -898
- package/lib/types/types.js +1 -1
- package/lib/utils/YamlEditor.d.ts +62 -62
- package/lib/utils/YamlEditor.js +197 -197
- package/lib/utils/button.d.ts +49 -49
- package/lib/utils/button.js +75 -75
- package/lib/utils/common.d.ts +123 -123
- package/lib/utils/common.js +396 -396
- package/lib/utils/config.d.ts +72 -72
- package/lib/utils/config.js +254 -254
- package/lib/utils/exec.d.ts +22 -22
- package/lib/utils/exec.js +36 -36
- package/lib/utils/ffmpeg.d.ts +12 -12
- package/lib/utils/ffmpeg.js +25 -25
- package/lib/utils/handler.d.ts +76 -76
- package/lib/utils/handler.js +98 -98
- package/lib/utils/logger.d.ts +3 -3
- package/lib/utils/logger.js +104 -104
- package/lib/utils/segment.d.ts +276 -276
- package/lib/utils/segment.js +420 -420
- package/lib/utils/update.d.ts +69 -69
- package/lib/utils/update.js +145 -145
- package/lib/utils/updateVersion.d.ts +33 -33
- package/lib/utils/updateVersion.js +140 -140
- package/package.json +92 -91
|
@@ -1,240 +1,240 @@
|
|
|
1
|
-
import lodash from 'lodash'
|
|
2
|
-
import Config from '../utils/config.js'
|
|
3
|
-
import logger from '../utils/logger.js'
|
|
4
|
-
import Review from './review.handler.js'
|
|
5
|
-
import Listener from '../core/listener.js'
|
|
6
|
-
import { stateArr } from '../core/plugin.js'
|
|
7
|
-
import EventHandler from './event.handler.js'
|
|
8
|
-
import PluginLoader from '../core/plugin.loader.js'
|
|
9
|
-
/**
|
|
10
|
-
* 消息事件
|
|
11
|
-
*/
|
|
12
|
-
export default class Message extends EventHandler {
|
|
13
|
-
e
|
|
14
|
-
/**
|
|
15
|
-
* - 是否打印群消息日志
|
|
16
|
-
*/
|
|
17
|
-
GroupMsgPrint = false
|
|
18
|
-
constructor (e) {
|
|
19
|
-
super(e)
|
|
20
|
-
this.e = e
|
|
21
|
-
Listener.emit('karin:count:recv', 1)
|
|
22
|
-
/** 处理消息 保证日志的打印 */
|
|
23
|
-
this.dealMsg()
|
|
24
|
-
/** 事件处理 */
|
|
25
|
-
if (this.review()) { return }
|
|
26
|
-
/** 响应模式 */
|
|
27
|
-
if (this.e.group_id && 'mode' in this.config && this.config.mode && !Review.mode(this.e, this.config)) {
|
|
28
|
-
logger.debug('[消息拦截] 响应模式不匹配')
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
this.GroupMsgPrint = false
|
|
32
|
-
/** 处理回复 */
|
|
33
|
-
this.reply()
|
|
34
|
-
/** 处理消息 */
|
|
35
|
-
this.deal()
|
|
1
|
+
import lodash from 'lodash'
|
|
2
|
+
import Config from '../utils/config.js'
|
|
3
|
+
import logger from '../utils/logger.js'
|
|
4
|
+
import Review from './review.handler.js'
|
|
5
|
+
import Listener from '../core/listener.js'
|
|
6
|
+
import { stateArr } from '../core/plugin.js'
|
|
7
|
+
import EventHandler from './event.handler.js'
|
|
8
|
+
import PluginLoader from '../core/plugin.loader.js'
|
|
9
|
+
/**
|
|
10
|
+
* 消息事件
|
|
11
|
+
*/
|
|
12
|
+
export default class Message extends EventHandler {
|
|
13
|
+
e
|
|
14
|
+
/**
|
|
15
|
+
* - 是否打印群消息日志
|
|
16
|
+
*/
|
|
17
|
+
GroupMsgPrint = false
|
|
18
|
+
constructor (e) {
|
|
19
|
+
super(e)
|
|
20
|
+
this.e = e
|
|
21
|
+
Listener.emit('karin:count:recv', 1)
|
|
22
|
+
/** 处理消息 保证日志的打印 */
|
|
23
|
+
this.dealMsg()
|
|
24
|
+
/** 事件处理 */
|
|
25
|
+
if (this.review()) { return }
|
|
26
|
+
/** 响应模式 */
|
|
27
|
+
if (this.e.group_id && 'mode' in this.config && this.config.mode && !Review.mode(this.e, this.config)) {
|
|
28
|
+
logger.debug('[消息拦截] 响应模式不匹配')
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
this.GroupMsgPrint = false
|
|
32
|
+
/** 处理回复 */
|
|
33
|
+
this.reply()
|
|
34
|
+
/** 处理消息 */
|
|
35
|
+
this.deal()
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 处理消息
|
|
40
|
-
*/
|
|
41
|
-
async deal () {
|
|
42
|
-
/** 上下文 */
|
|
43
|
-
if (await this.context()) { return }
|
|
44
|
-
/* eslint-disable no-labels */
|
|
45
|
-
a: for (const index of PluginLoader.rule) {
|
|
46
|
-
const app = PluginLoader.PluginList[index]
|
|
47
|
-
/** 判断事件 */
|
|
48
|
-
if (app.event && !this.filtEvent(app.event)) { continue }
|
|
49
|
-
/** 正则匹配 */
|
|
50
|
-
for (const v of app.rule) {
|
|
51
|
-
/** 这里的lastIndex是为了防止正则无法从头开始匹配 */
|
|
52
|
-
v.reg.lastIndex = 0
|
|
53
|
-
if (v.reg.test(this.e.msg)) {
|
|
54
|
-
/** 检查黑白名单插件 */
|
|
55
|
-
if ('GroupCD' in this.config && !Review.PluginEnable(app, this.config)) { continue }
|
|
56
|
-
/** 判断子事件 */
|
|
57
|
-
if (v.event && !this.filtEvent(v.event)) { continue }
|
|
58
|
-
this.e.logFnc = `[${app.file.dir}][${app.name}][${v.fnc}]`
|
|
59
|
-
const logFnc = logger.fnc(`[${app.name}][${v.fnc}]`)
|
|
60
|
-
this.GroupMsgPrint && typeof v.log === 'function' && v.log(this.e.self_id, `${logFnc}${this.e.logText} ${lodash.truncate(this.e.msg, { length: 80 })}`)
|
|
61
|
-
/** 判断权限 */
|
|
62
|
-
if (!this.filterPermission(v.permission)) { break a }
|
|
63
|
-
try {
|
|
64
|
-
let res
|
|
65
|
-
if (app.file.type === 'function' && typeof v.fnc === 'function') {
|
|
66
|
-
res = v.fnc(this.e)
|
|
67
|
-
} else {
|
|
68
|
-
const cla = new app.file.Fnc()
|
|
69
|
-
cla.e = this.e
|
|
70
|
-
res = cla[v.fnc](this.e)
|
|
71
|
-
}
|
|
72
|
-
/** 计算插件处理时间 */
|
|
73
|
-
const start = Date.now()
|
|
74
|
-
Listener.emit('karin:count:fnc', this.e.logFnc)
|
|
75
|
-
res = await res
|
|
76
|
-
this.GroupMsgPrint && typeof v.log === 'function' && v.log(this.e.self_id, `${logFnc} ${lodash.truncate(this.e.msg, { length: 80 })} 处理完成 ${logger.green(Date.now() - start + 'ms')}`)
|
|
77
|
-
if (res !== false) { break a }
|
|
78
|
-
} catch (error) {
|
|
79
|
-
logger.error(`${this.e.logFnc}`)
|
|
80
|
-
logger.error(error.stack || error.message || JSON.stringify(error))
|
|
81
|
-
break a
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 处理消息
|
|
40
|
+
*/
|
|
41
|
+
async deal () {
|
|
42
|
+
/** 上下文 */
|
|
43
|
+
if (await this.context()) { return }
|
|
44
|
+
/* eslint-disable no-labels */
|
|
45
|
+
a: for (const index of PluginLoader.rule) {
|
|
46
|
+
const app = PluginLoader.PluginList[index]
|
|
47
|
+
/** 判断事件 */
|
|
48
|
+
if (app.event && !this.filtEvent(app.event)) { continue }
|
|
49
|
+
/** 正则匹配 */
|
|
50
|
+
for (const v of app.rule) {
|
|
51
|
+
/** 这里的lastIndex是为了防止正则无法从头开始匹配 */
|
|
52
|
+
v.reg.lastIndex = 0
|
|
53
|
+
if (v.reg.test(this.e.msg)) {
|
|
54
|
+
/** 检查黑白名单插件 */
|
|
55
|
+
if ('GroupCD' in this.config && !Review.PluginEnable(app, this.config)) { continue }
|
|
56
|
+
/** 判断子事件 */
|
|
57
|
+
if (v.event && !this.filtEvent(v.event)) { continue }
|
|
58
|
+
this.e.logFnc = `[${app.file.dir}][${app.name}][${v.fnc}]`
|
|
59
|
+
const logFnc = logger.fnc(`[${app.name}][${v.fnc}]`)
|
|
60
|
+
this.GroupMsgPrint && typeof v.log === 'function' && v.log(this.e.self_id, `${logFnc}${this.e.logText} ${lodash.truncate(this.e.msg, { length: 80 })}`)
|
|
61
|
+
/** 判断权限 */
|
|
62
|
+
if (!this.filterPermission(v.permission)) { break a }
|
|
63
|
+
try {
|
|
64
|
+
let res
|
|
65
|
+
if (app.file.type === 'function' && typeof v.fnc === 'function') {
|
|
66
|
+
res = v.fnc(this.e)
|
|
67
|
+
} else {
|
|
68
|
+
const cla = new app.file.Fnc()
|
|
69
|
+
cla.e = this.e
|
|
70
|
+
res = cla[v.fnc](this.e)
|
|
71
|
+
}
|
|
72
|
+
/** 计算插件处理时间 */
|
|
73
|
+
const start = Date.now()
|
|
74
|
+
Listener.emit('karin:count:fnc', this.e.logFnc)
|
|
75
|
+
res = await res
|
|
76
|
+
this.GroupMsgPrint && typeof v.log === 'function' && v.log(this.e.self_id, `${logFnc} ${lodash.truncate(this.e.msg, { length: 80 })} 处理完成 ${logger.green(Date.now() - start + 'ms')}`)
|
|
77
|
+
if (res !== false) { break a }
|
|
78
|
+
} catch (error) {
|
|
79
|
+
logger.error(`${this.e.logFnc}`)
|
|
80
|
+
logger.error(error.stack || error.message || JSON.stringify(error))
|
|
81
|
+
break a
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 处理消息体
|
|
90
|
-
*/
|
|
91
|
-
dealMsg () {
|
|
92
|
-
const logs = []
|
|
93
|
-
for (const val of this.e.elements) {
|
|
94
|
-
switch (val.type) {
|
|
95
|
-
case 'text': {
|
|
96
|
-
const msg = (val.text || '')
|
|
97
|
-
.replace(/^\s*[#井#]+\s*/, '#')
|
|
98
|
-
.replace(/^\s*[\\*※*]+\s*/, '*')
|
|
99
|
-
.trim()
|
|
100
|
-
this.e.msg += msg
|
|
101
|
-
/** 美观一点... */
|
|
102
|
-
logs.push(msg)
|
|
103
|
-
break
|
|
104
|
-
}
|
|
105
|
-
case 'face':
|
|
106
|
-
logs.push(`[face:${val.id}]`)
|
|
107
|
-
break
|
|
108
|
-
case 'video':
|
|
109
|
-
case 'record':
|
|
110
|
-
logs.push(`[${val.type}:${val.file}]`)
|
|
111
|
-
break
|
|
112
|
-
case 'image':
|
|
113
|
-
this.e.image.push(val.file)
|
|
114
|
-
logs.push(`[image:${val.file}]`)
|
|
115
|
-
break
|
|
116
|
-
case 'file':
|
|
117
|
-
this.e.file = val
|
|
118
|
-
logs.push(`[file:${val.file}]`)
|
|
119
|
-
break
|
|
120
|
-
case 'at':
|
|
121
|
-
/** atBot不计入e.at */
|
|
122
|
-
// eslint-disable-next-line eqeqeq
|
|
123
|
-
if (val.uid && val.uid == this.e.bot.account.uid) {
|
|
124
|
-
this.e.atBot = true
|
|
125
|
-
// eslint-disable-next-line eqeqeq
|
|
126
|
-
} else if (val.uin == this.e.bot.account.uin) {
|
|
127
|
-
this.e.atBot = true
|
|
128
|
-
} else if (val.uid && val.uid === 'all') {
|
|
129
|
-
this.e.atAll = true
|
|
130
|
-
} else {
|
|
131
|
-
const id = (val.uid || val.uin)
|
|
132
|
-
this.e.at.push(id)
|
|
133
|
-
}
|
|
134
|
-
logs.push(`[at:${val.uid || val.uin}]`)
|
|
135
|
-
break
|
|
136
|
-
case 'rps':
|
|
137
|
-
logs.push(`[rps:${val.id}]`)
|
|
138
|
-
break
|
|
139
|
-
case 'dice':
|
|
140
|
-
logs.push(`[dice:${val.id}]`)
|
|
141
|
-
break
|
|
142
|
-
case 'poke':
|
|
143
|
-
logs.push(`[poke:${val.id}]`)
|
|
144
|
-
break
|
|
145
|
-
case 'share':
|
|
146
|
-
logs.push(`[share:${val.url}]`)
|
|
147
|
-
break
|
|
148
|
-
case 'contact':
|
|
149
|
-
logs.push(`[contact:${val.peer}]`)
|
|
150
|
-
break
|
|
151
|
-
case 'location':
|
|
152
|
-
logs.push(`[location:${val.lat}-${val.lon}]`)
|
|
153
|
-
break
|
|
154
|
-
case 'music':
|
|
155
|
-
logs.push(`[music:${JSON.stringify(val)}]`)
|
|
156
|
-
break
|
|
157
|
-
case 'reply':
|
|
158
|
-
this.e.reply_id = val.message_id
|
|
159
|
-
logs.push(`[reply:${val.message_id}]`)
|
|
160
|
-
break
|
|
161
|
-
case 'forward':
|
|
162
|
-
logs.push(`[forward:${val.res_id}]`)
|
|
163
|
-
break
|
|
164
|
-
case 'xml':
|
|
165
|
-
this.e.msg += val.data
|
|
166
|
-
logs.push(`[xml:${val.data}]`)
|
|
167
|
-
break
|
|
168
|
-
case 'json':
|
|
169
|
-
this.e.msg += val.data
|
|
170
|
-
logs.push(`[json:${JSON.stringify(val.data)}]`)
|
|
171
|
-
break
|
|
172
|
-
case 'markdown': {
|
|
173
|
-
if (val.content) {
|
|
174
|
-
logs.push(`[markdown:${val.content}]`)
|
|
175
|
-
} else {
|
|
176
|
-
const content = { id: val.custom_template_id }
|
|
177
|
-
for (const v of val.params) { content[v.key] = v.values[0] }
|
|
178
|
-
logs.push(`[markdown:${JSON.stringify(content)}]`)
|
|
179
|
-
}
|
|
180
|
-
break
|
|
181
|
-
}
|
|
182
|
-
case 'rows': {
|
|
183
|
-
const rows = []
|
|
184
|
-
for (const v of val.rows) { rows.push(JSON.stringify(v.data)) }
|
|
185
|
-
logs.push(`[rows:${JSON.stringify(rows)}]`)
|
|
186
|
-
break
|
|
187
|
-
}
|
|
188
|
-
case 'button':
|
|
189
|
-
logs.push(`[button:${JSON.stringify(val.data)}]`)
|
|
190
|
-
break
|
|
191
|
-
default:
|
|
192
|
-
logs.push(`[未知:${JSON.stringify(val)}]`)
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
this.e.raw_message = logs.join('')
|
|
196
|
-
/** 前缀处理 */
|
|
197
|
-
this.e.group_id && 'GroupCD' in this.config && Review.alias(this.e, this.config)
|
|
198
|
-
/** 主人 这里强制是因为yaml在自动保存QQ号的时候会强制化为数字 */
|
|
199
|
-
const masterId = (Number(this.e.user_id) || String(this.e.user_id))
|
|
200
|
-
if (Config.master.includes(masterId)) {
|
|
201
|
-
this.e.isMaster = true
|
|
202
|
-
this.e.isAdmin = true
|
|
203
|
-
} else if (Config.admin.includes(masterId)) {
|
|
204
|
-
/** 管理员 */
|
|
205
|
-
this.e.isAdmin = true
|
|
206
|
-
}
|
|
207
|
-
this.GroupMsgPrint = false
|
|
208
|
-
if (this.e.contact.scene === 'private') {
|
|
209
|
-
this.e.isPrivate = true
|
|
210
|
-
this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]`
|
|
211
|
-
logger.bot('info', this.e.self_id, `私聊:[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`)
|
|
212
|
-
} else if (this.e.contact.scene === 'group') {
|
|
213
|
-
this.e.isGroup = true
|
|
214
|
-
this.e.logText = `[Group:${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})]`
|
|
215
|
-
this.GroupMsgPrint = Review.GroupMsgPrint(this.e)
|
|
216
|
-
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}`)
|
|
217
|
-
} else {
|
|
218
|
-
logger.bot('info', this.e.self_id, `未知消息:${JSON.stringify(this.e)}`)
|
|
219
|
-
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 处理消息体
|
|
90
|
+
*/
|
|
91
|
+
dealMsg () {
|
|
92
|
+
const logs = []
|
|
93
|
+
for (const val of this.e.elements) {
|
|
94
|
+
switch (val.type) {
|
|
95
|
+
case 'text': {
|
|
96
|
+
const msg = (val.text || '')
|
|
97
|
+
.replace(/^\s*[#井#]+\s*/, '#')
|
|
98
|
+
.replace(/^\s*[\\*※*]+\s*/, '*')
|
|
99
|
+
.trim()
|
|
100
|
+
this.e.msg += msg
|
|
101
|
+
/** 美观一点... */
|
|
102
|
+
logs.push(msg)
|
|
103
|
+
break
|
|
104
|
+
}
|
|
105
|
+
case 'face':
|
|
106
|
+
logs.push(`[face:${val.id}]`)
|
|
107
|
+
break
|
|
108
|
+
case 'video':
|
|
109
|
+
case 'record':
|
|
110
|
+
logs.push(`[${val.type}:${val.file}]`)
|
|
111
|
+
break
|
|
112
|
+
case 'image':
|
|
113
|
+
this.e.image.push(val.file)
|
|
114
|
+
logs.push(`[image:${val.file}]`)
|
|
115
|
+
break
|
|
116
|
+
case 'file':
|
|
117
|
+
this.e.file = val
|
|
118
|
+
logs.push(`[file:${val.file}]`)
|
|
119
|
+
break
|
|
120
|
+
case 'at':
|
|
121
|
+
/** atBot不计入e.at */
|
|
122
|
+
// eslint-disable-next-line eqeqeq
|
|
123
|
+
if (val.uid && val.uid == this.e.bot.account.uid) {
|
|
124
|
+
this.e.atBot = true
|
|
125
|
+
// eslint-disable-next-line eqeqeq
|
|
126
|
+
} else if (val.uin == this.e.bot.account.uin) {
|
|
127
|
+
this.e.atBot = true
|
|
128
|
+
} else if (val.uid && val.uid === 'all') {
|
|
129
|
+
this.e.atAll = true
|
|
130
|
+
} else {
|
|
131
|
+
const id = (val.uid || val.uin)
|
|
132
|
+
this.e.at.push(id)
|
|
133
|
+
}
|
|
134
|
+
logs.push(`[at:${val.uid || val.uin}]`)
|
|
135
|
+
break
|
|
136
|
+
case 'rps':
|
|
137
|
+
logs.push(`[rps:${val.id}]`)
|
|
138
|
+
break
|
|
139
|
+
case 'dice':
|
|
140
|
+
logs.push(`[dice:${val.id}]`)
|
|
141
|
+
break
|
|
142
|
+
case 'poke':
|
|
143
|
+
logs.push(`[poke:${val.id}]`)
|
|
144
|
+
break
|
|
145
|
+
case 'share':
|
|
146
|
+
logs.push(`[share:${val.url}]`)
|
|
147
|
+
break
|
|
148
|
+
case 'contact':
|
|
149
|
+
logs.push(`[contact:${val.peer}]`)
|
|
150
|
+
break
|
|
151
|
+
case 'location':
|
|
152
|
+
logs.push(`[location:${val.lat}-${val.lon}]`)
|
|
153
|
+
break
|
|
154
|
+
case 'music':
|
|
155
|
+
logs.push(`[music:${JSON.stringify(val)}]`)
|
|
156
|
+
break
|
|
157
|
+
case 'reply':
|
|
158
|
+
this.e.reply_id = val.message_id
|
|
159
|
+
logs.push(`[reply:${val.message_id}]`)
|
|
160
|
+
break
|
|
161
|
+
case 'forward':
|
|
162
|
+
logs.push(`[forward:${val.res_id}]`)
|
|
163
|
+
break
|
|
164
|
+
case 'xml':
|
|
165
|
+
this.e.msg += val.data
|
|
166
|
+
logs.push(`[xml:${val.data}]`)
|
|
167
|
+
break
|
|
168
|
+
case 'json':
|
|
169
|
+
this.e.msg += val.data
|
|
170
|
+
logs.push(`[json:${JSON.stringify(val.data)}]`)
|
|
171
|
+
break
|
|
172
|
+
case 'markdown': {
|
|
173
|
+
if (val.content) {
|
|
174
|
+
logs.push(`[markdown:${val.content}]`)
|
|
175
|
+
} else {
|
|
176
|
+
const content = { id: val.custom_template_id }
|
|
177
|
+
for (const v of val.params) { content[v.key] = v.values[0] }
|
|
178
|
+
logs.push(`[markdown:${JSON.stringify(content)}]`)
|
|
179
|
+
}
|
|
180
|
+
break
|
|
181
|
+
}
|
|
182
|
+
case 'rows': {
|
|
183
|
+
const rows = []
|
|
184
|
+
for (const v of val.rows) { rows.push(JSON.stringify(v.data)) }
|
|
185
|
+
logs.push(`[rows:${JSON.stringify(rows)}]`)
|
|
186
|
+
break
|
|
187
|
+
}
|
|
188
|
+
case 'button':
|
|
189
|
+
logs.push(`[button:${JSON.stringify(val.data)}]`)
|
|
190
|
+
break
|
|
191
|
+
default:
|
|
192
|
+
logs.push(`[未知:${JSON.stringify(val)}]`)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
this.e.raw_message = logs.join('')
|
|
196
|
+
/** 前缀处理 */
|
|
197
|
+
this.e.group_id && 'GroupCD' in this.config && Review.alias(this.e, this.config)
|
|
198
|
+
/** 主人 这里强制是因为yaml在自动保存QQ号的时候会强制化为数字 */
|
|
199
|
+
const masterId = (Number(this.e.user_id) || String(this.e.user_id))
|
|
200
|
+
if (Config.master.includes(masterId)) {
|
|
201
|
+
this.e.isMaster = true
|
|
202
|
+
this.e.isAdmin = true
|
|
203
|
+
} else if (Config.admin.includes(masterId)) {
|
|
204
|
+
/** 管理员 */
|
|
205
|
+
this.e.isAdmin = true
|
|
206
|
+
}
|
|
207
|
+
this.GroupMsgPrint = false
|
|
208
|
+
if (this.e.contact.scene === 'private') {
|
|
209
|
+
this.e.isPrivate = true
|
|
210
|
+
this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]`
|
|
211
|
+
logger.bot('info', this.e.self_id, `私聊:[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`)
|
|
212
|
+
} else if (this.e.contact.scene === 'group') {
|
|
213
|
+
this.e.isGroup = true
|
|
214
|
+
this.e.logText = `[Group:${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})]`
|
|
215
|
+
this.GroupMsgPrint = Review.GroupMsgPrint(this.e)
|
|
216
|
+
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}`)
|
|
217
|
+
} else {
|
|
218
|
+
logger.bot('info', this.e.self_id, `未知消息:${JSON.stringify(this.e)}`)
|
|
219
|
+
}
|
|
220
220
|
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* 处理上下文
|
|
224
|
-
*/
|
|
225
|
-
async context () {
|
|
226
|
-
const key = this.e.isGroup ? `${this.e.group_id}.${this.e.user_id}` : this.e.user_id
|
|
227
|
-
const App = stateArr[key]
|
|
228
|
-
if (App) {
|
|
229
|
-
const { plugin, fnc } = App
|
|
230
|
-
this.e.logFnc = `[${plugin.name}][${fnc}]`
|
|
231
|
-
/** 计算插件处理时间 */
|
|
232
|
-
const start = Date.now()
|
|
233
|
-
plugin.e = this.e
|
|
234
|
-
await plugin[fnc]()
|
|
235
|
-
logger.bot('mark', this.e.self_id, `${this.e.logFnc} 上下文处理完成 ${Date.now() - start}ms`)
|
|
236
|
-
return true
|
|
237
|
-
}
|
|
238
|
-
return false
|
|
239
|
-
}
|
|
240
|
-
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 处理上下文
|
|
224
|
+
*/
|
|
225
|
+
async context () {
|
|
226
|
+
const key = this.e.isGroup ? `${this.e.group_id}.${this.e.user_id}` : this.e.user_id
|
|
227
|
+
const App = stateArr[key]
|
|
228
|
+
if (App) {
|
|
229
|
+
const { plugin, fnc } = App
|
|
230
|
+
this.e.logFnc = `[${plugin.name}][${fnc}]`
|
|
231
|
+
/** 计算插件处理时间 */
|
|
232
|
+
const start = Date.now()
|
|
233
|
+
plugin.e = this.e
|
|
234
|
+
await plugin[fnc]()
|
|
235
|
+
logger.bot('mark', this.e.self_id, `${this.e.logFnc} 上下文处理完成 ${Date.now() - start}ms`)
|
|
236
|
+
return true
|
|
237
|
+
}
|
|
238
|
+
return false
|
|
239
|
+
}
|
|
240
|
+
}
|
package/lib/event/message.js
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { KarinEvent } from './event.js'
|
|
2
|
-
/**
|
|
3
|
-
* - 消息事件基类
|
|
4
|
-
*/
|
|
5
|
-
export class KarinMessage extends KarinEvent {
|
|
6
|
-
constructor ({ event = 'message', self_id, user_id, time, message_id, message_seq = '', raw_message = '', contact, sender, elements, group_id = '' }) {
|
|
7
|
-
super({ event, event_id: message_id, self_id, user_id, group_id, time, contact, sender, sub_event: contact.scene === 'group' ? 'group_message' : 'friend_message' })
|
|
8
|
-
this.message_id = message_id
|
|
9
|
-
this.message_seq = message_seq
|
|
10
|
-
this.raw_message = raw_message
|
|
11
|
-
this.elements = elements
|
|
12
|
-
this.msg = ''
|
|
13
|
-
this.at = []
|
|
14
|
-
this.image = []
|
|
15
|
-
this.file = {}
|
|
16
|
-
this.reply_id = ''
|
|
17
|
-
this.atBot = false
|
|
18
|
-
this.atAll = false
|
|
19
|
-
this.alias = ''
|
|
1
|
+
import { KarinEvent } from './event.js'
|
|
2
|
+
/**
|
|
3
|
+
* - 消息事件基类
|
|
4
|
+
*/
|
|
5
|
+
export class KarinMessage extends KarinEvent {
|
|
6
|
+
constructor ({ event = 'message', self_id, user_id, time, message_id, message_seq = '', raw_message = '', contact, sender, elements, group_id = '' }) {
|
|
7
|
+
super({ event, event_id: message_id, self_id, user_id, group_id, time, contact, sender, sub_event: contact.scene === 'group' ? 'group_message' : 'friend_message' })
|
|
8
|
+
this.message_id = message_id
|
|
9
|
+
this.message_seq = message_seq
|
|
10
|
+
this.raw_message = raw_message
|
|
11
|
+
this.elements = elements
|
|
12
|
+
this.msg = ''
|
|
13
|
+
this.at = []
|
|
14
|
+
this.image = []
|
|
15
|
+
this.file = {}
|
|
16
|
+
this.reply_id = ''
|
|
17
|
+
this.atBot = false
|
|
18
|
+
this.atAll = false
|
|
19
|
+
this.alias = ''
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* - 消息ID
|
|
24
|
-
*/
|
|
25
|
-
message_id
|
|
26
|
-
/**
|
|
27
|
-
* - 消息序列号
|
|
28
|
-
*/
|
|
29
|
-
message_seq
|
|
30
|
-
/**
|
|
31
|
-
* - 原始消息文本
|
|
32
|
-
*/
|
|
33
|
-
raw_message
|
|
34
|
-
/**
|
|
35
|
-
* - 消息体元素
|
|
36
|
-
*/
|
|
37
|
-
elements
|
|
38
|
-
/**
|
|
39
|
-
* - 框架处理后的文本
|
|
40
|
-
*/
|
|
41
|
-
msg
|
|
42
|
-
/**
|
|
43
|
-
* - 图片数组
|
|
44
|
-
*/
|
|
45
|
-
image
|
|
46
|
-
/**
|
|
47
|
-
* - AT数组
|
|
48
|
-
*/
|
|
49
|
-
at
|
|
50
|
-
/**
|
|
51
|
-
* - 是否AT机器人
|
|
52
|
-
*/
|
|
53
|
-
atBot
|
|
54
|
-
/**
|
|
55
|
-
* - 是否AT全体
|
|
56
|
-
*/
|
|
57
|
-
atAll
|
|
58
|
-
/**
|
|
59
|
-
* - 文件元素
|
|
60
|
-
*/
|
|
61
|
-
file
|
|
62
|
-
/**
|
|
63
|
-
* - 引用消息ID
|
|
64
|
-
*/
|
|
65
|
-
reply_id
|
|
66
|
-
/**
|
|
67
|
-
* - 消息别名
|
|
68
|
-
*/
|
|
69
|
-
alias
|
|
70
|
-
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* - 消息ID
|
|
24
|
+
*/
|
|
25
|
+
message_id
|
|
26
|
+
/**
|
|
27
|
+
* - 消息序列号
|
|
28
|
+
*/
|
|
29
|
+
message_seq
|
|
30
|
+
/**
|
|
31
|
+
* - 原始消息文本
|
|
32
|
+
*/
|
|
33
|
+
raw_message
|
|
34
|
+
/**
|
|
35
|
+
* - 消息体元素
|
|
36
|
+
*/
|
|
37
|
+
elements
|
|
38
|
+
/**
|
|
39
|
+
* - 框架处理后的文本
|
|
40
|
+
*/
|
|
41
|
+
msg
|
|
42
|
+
/**
|
|
43
|
+
* - 图片数组
|
|
44
|
+
*/
|
|
45
|
+
image
|
|
46
|
+
/**
|
|
47
|
+
* - AT数组
|
|
48
|
+
*/
|
|
49
|
+
at
|
|
50
|
+
/**
|
|
51
|
+
* - 是否AT机器人
|
|
52
|
+
*/
|
|
53
|
+
atBot
|
|
54
|
+
/**
|
|
55
|
+
* - 是否AT全体
|
|
56
|
+
*/
|
|
57
|
+
atAll
|
|
58
|
+
/**
|
|
59
|
+
* - 文件元素
|
|
60
|
+
*/
|
|
61
|
+
file
|
|
62
|
+
/**
|
|
63
|
+
* - 引用消息ID
|
|
64
|
+
*/
|
|
65
|
+
reply_id
|
|
66
|
+
/**
|
|
67
|
+
* - 消息别名
|
|
68
|
+
*/
|
|
69
|
+
alias
|
|
70
|
+
}
|