koishi-plugin-chat-patch 1.2.0 → 1.3.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/client/icons/activity.vue +9 -9
- package/client/icons/index.ts +4 -4
- package/client/index.scss +4 -4
- package/client/index.ts +22 -22
- package/client/vue/chat-logic.ts +3784 -3784
- package/client/vue/index.vue +361 -361
- package/client/vue/style.css +1997 -1973
- package/dist/index.js +1 -1
- package/dist/style.css +1 -1
- package/lib/index.js +20 -3
- package/package.json +40 -40
- package/readme.md +25 -25
- package/src/api-handlers.ts +657 -657
- package/src/config.ts +49 -49
- package/src/file-manager.ts +168 -168
- package/src/index.ts +125 -125
- package/src/message-handler.ts +304 -282
- package/src/types.ts +59 -59
- package/src/utils.ts +99 -99
- package/lib/config.d.ts +0 -14
package/src/types.ts
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { h } from 'koishi'
|
|
2
|
-
|
|
3
|
-
export interface BotInfo {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ChannelInfo {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface QuoteInfo {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface MessageInfo {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface ChatData {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
import { h } from 'koishi'
|
|
2
|
+
|
|
3
|
+
export interface BotInfo {
|
|
4
|
+
selfId: string
|
|
5
|
+
platform: string
|
|
6
|
+
username: string
|
|
7
|
+
avatar?: string
|
|
8
|
+
status: 'online' | 'offline'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ChannelInfo {
|
|
12
|
+
id: string
|
|
13
|
+
name: string
|
|
14
|
+
type: number | string
|
|
15
|
+
channelId?: string
|
|
16
|
+
guildName?: string
|
|
17
|
+
isDirect?: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface QuoteInfo {
|
|
21
|
+
messageId: string
|
|
22
|
+
id: string
|
|
23
|
+
content: string
|
|
24
|
+
elements?: h[]
|
|
25
|
+
user: {
|
|
26
|
+
id: string
|
|
27
|
+
name: string
|
|
28
|
+
userId: string
|
|
29
|
+
avatar?: string
|
|
30
|
+
username: string
|
|
31
|
+
}
|
|
32
|
+
timestamp: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface MessageInfo {
|
|
36
|
+
id: string
|
|
37
|
+
content: string
|
|
38
|
+
userId: string
|
|
39
|
+
username: string
|
|
40
|
+
avatar?: string
|
|
41
|
+
timestamp: number
|
|
42
|
+
channelId: string
|
|
43
|
+
selfId: string
|
|
44
|
+
elements?: h[]
|
|
45
|
+
type: 'user' | 'bot'
|
|
46
|
+
guildId?: string
|
|
47
|
+
guildName?: string
|
|
48
|
+
platform: string
|
|
49
|
+
quote?: QuoteInfo
|
|
50
|
+
isDirect?: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ChatData {
|
|
54
|
+
bots: Record<string, BotInfo>
|
|
55
|
+
channels: Record<string, Record<string, ChannelInfo>>
|
|
56
|
+
messages: Record<string, MessageInfo[]>
|
|
57
|
+
pinnedBots: string[]
|
|
58
|
+
pinnedChannels: string[]
|
|
59
|
+
lastSaveTime?: number
|
|
60
60
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import { Config } from './config'
|
|
2
|
-
|
|
3
|
-
export class Utils {
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
1
|
+
import { Config } from './config'
|
|
2
|
+
|
|
3
|
+
export class Utils {
|
|
4
|
+
constructor(private config: Config) { }
|
|
5
|
+
|
|
6
|
+
// 检查平台是否被屏蔽
|
|
7
|
+
isPlatformBlocked(platform: string): boolean {
|
|
8
|
+
if (!this.config.blockedPlatforms || this.config.blockedPlatforms.length === 0) {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
for (const blockedPlatform of this.config.blockedPlatforms) {
|
|
13
|
+
if (blockedPlatform.exactMatch) {
|
|
14
|
+
if (platform === blockedPlatform.platformName) {
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
if (platform.includes(blockedPlatform.platformName)) {
|
|
19
|
+
return true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 递归提取所有文本内容的函数
|
|
28
|
+
extractTextContent(elements: any[]): string {
|
|
29
|
+
let text = ''
|
|
30
|
+
for (const element of elements) {
|
|
31
|
+
if (element.type === 'text') {
|
|
32
|
+
text += element.attrs?.content || ''
|
|
33
|
+
} else if (element.type === 'p') {
|
|
34
|
+
if (element.children && element.children.length > 0) {
|
|
35
|
+
text += this.extractTextContent(element.children) + '\n'
|
|
36
|
+
}
|
|
37
|
+
} else if (element.children && element.children.length > 0) {
|
|
38
|
+
text += this.extractTextContent(element.children)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return text
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 检查字符串是否为base64格式
|
|
45
|
+
private isBase64(str: string): boolean {
|
|
46
|
+
if (!str || typeof str !== 'string') return false
|
|
47
|
+
|
|
48
|
+
// 检查是否以data:开头的base64格式
|
|
49
|
+
if (str.startsWith('data:')) {
|
|
50
|
+
return str.includes('base64,')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 检查纯base64字符串(长度大于100且符合base64格式)
|
|
54
|
+
if (str.length > 100) {
|
|
55
|
+
const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/
|
|
56
|
+
return base64Regex.test(str)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 清理对象中的base64内容
|
|
63
|
+
cleanBase64Content(obj: any): any {
|
|
64
|
+
if (obj === null || obj === undefined) {
|
|
65
|
+
return obj
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof obj === 'string') {
|
|
69
|
+
if (this.isBase64(obj)) {
|
|
70
|
+
return '暂不支持记录base64内容'
|
|
71
|
+
}
|
|
72
|
+
return obj
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (Array.isArray(obj)) {
|
|
76
|
+
return obj.map(item => this.cleanBase64Content(item))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (typeof obj === 'object') {
|
|
80
|
+
const cleaned: any = {}
|
|
81
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
82
|
+
// 特别处理常见的base64字段
|
|
83
|
+
if (typeof value === 'string' && (
|
|
84
|
+
key === 'src' ||
|
|
85
|
+
key === 'url' ||
|
|
86
|
+
key === 'file' ||
|
|
87
|
+
key === 'data' ||
|
|
88
|
+
key === 'content'
|
|
89
|
+
) && this.isBase64(value)) {
|
|
90
|
+
cleaned[key] = '暂不支持记录base64内容'
|
|
91
|
+
} else {
|
|
92
|
+
cleaned[key] = this.cleanBase64Content(value)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return cleaned
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return obj
|
|
99
|
+
}
|
|
100
100
|
}
|
package/lib/config.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Schema } from 'koishi';
|
|
2
|
-
export interface Config {
|
|
3
|
-
loggerinfo: boolean;
|
|
4
|
-
clearIndexedDBOnStart: boolean;
|
|
5
|
-
maxMessagesPerChannel: number;
|
|
6
|
-
keepMessagesOnClear: number;
|
|
7
|
-
keepTempImages: number;
|
|
8
|
-
blockedPlatforms: Array<{
|
|
9
|
-
platformName: string;
|
|
10
|
-
exactMatch: boolean;
|
|
11
|
-
}>;
|
|
12
|
-
chatContainerHeight: number;
|
|
13
|
-
}
|
|
14
|
-
export declare const Config: Schema<Config>;
|