-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMsgProcess.js
50 lines (45 loc) · 1.06 KB
/
MsgProcess.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* 处理消息,合并多段文本为一段
*/
export class Intercept extends plugin {
constructor() {
super({
name: 'MsgProcess',
dsc: '处理消息',
event: 'message',
priority: Number.NEGATIVE_INFINITY
})
}
mergeTextElements(arr) {
let result = []
let tempText = ''
if(arr.length == undefined){ return arr }
for (let i = 0; i < arr.length; i++) {
if (typeof arr[i] === 'string') {
tempText += arr[i]
} else {
if (tempText) {
result.push(tempText)
tempText = ''
}
result.push(arr[i])
}
}
if (tempText) {
result.push(tempText)
}
return result
}
accept() {
let reply = this.e.reply
this.e.reply = (...args) => {
if(args.includes("\"type\":\"node\"")){
return reply(...args)
}
if(args.includes(true)){
return reply((this.mergeTextElements(...args)),true)
}
return reply(this.mergeTextElements(...args))
}
}
}