@zhin.js/core 1.0.0 → 1.0.1
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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +295 -74
- package/lib/adapter.d.ts +39 -0
- package/lib/adapter.d.ts.map +1 -0
- package/{dist → lib}/adapter.js +20 -2
- package/lib/adapter.js.map +1 -0
- package/lib/app.d.ts +115 -0
- package/lib/app.d.ts.map +1 -0
- package/{dist → lib}/app.js +148 -78
- package/lib/app.js.map +1 -0
- package/lib/bot.d.ts +31 -0
- package/lib/bot.d.ts.map +1 -0
- package/lib/command.d.ts +32 -0
- package/lib/command.d.ts.map +1 -0
- package/lib/command.js +46 -0
- package/lib/command.js.map +1 -0
- package/lib/component.d.ts +107 -0
- package/lib/component.d.ts.map +1 -0
- package/lib/component.js +273 -0
- package/lib/component.js.map +1 -0
- package/{dist → lib}/config.d.ts.map +1 -1
- package/{dist → lib}/config.js +6 -9
- package/lib/config.js.map +1 -0
- package/lib/cron.d.ts +81 -0
- package/lib/cron.d.ts.map +1 -0
- package/lib/cron.js +159 -0
- package/lib/cron.js.map +1 -0
- package/lib/errors.d.ts +165 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +306 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +17 -0
- package/lib/index.js.map +1 -0
- package/lib/message.d.ts +44 -0
- package/lib/message.d.ts.map +1 -0
- package/lib/message.js +11 -0
- package/lib/message.js.map +1 -0
- package/lib/plugin.d.ts +50 -0
- package/lib/plugin.d.ts.map +1 -0
- package/lib/plugin.js +170 -0
- package/lib/plugin.js.map +1 -0
- package/lib/prompt.d.ts +116 -0
- package/lib/prompt.d.ts.map +1 -0
- package/lib/prompt.js +240 -0
- package/lib/prompt.js.map +1 -0
- package/lib/schema.d.ts +83 -0
- package/lib/schema.d.ts.map +1 -0
- package/lib/schema.js +245 -0
- package/lib/schema.js.map +1 -0
- package/{dist → lib}/types-generator.d.ts.map +1 -1
- package/{dist → lib}/types-generator.js +6 -3
- package/lib/types-generator.js.map +1 -0
- package/lib/types.d.ts +119 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/utils.d.ts +52 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +338 -0
- package/lib/utils.js.map +1 -0
- package/package.json +15 -9
- package/src/adapter.ts +25 -9
- package/src/app.ts +363 -258
- package/src/bot.ts +29 -8
- package/src/command.ts +50 -0
- package/src/component.ts +318 -0
- package/src/config.ts +9 -12
- package/src/cron.ts +176 -0
- package/src/errors.ts +365 -0
- package/src/index.ts +16 -13
- package/src/message.ts +44 -0
- package/src/plugin.ts +148 -66
- package/src/prompt.ts +290 -0
- package/src/schema.ts +273 -0
- package/src/types-generator.ts +7 -3
- package/src/types.ts +77 -30
- package/src/utils.ts +312 -0
- package/tests/adapter.test.ts +36 -22
- package/tests/app.test.ts +30 -0
- package/tests/command.test.ts +545 -0
- package/tests/component.test.ts +656 -0
- package/tests/config.test.ts +1 -1
- package/tests/errors.test.ts +311 -0
- package/tests/message.test.ts +402 -0
- package/tests/plugin.test.ts +275 -143
- package/tests/utils.test.ts +80 -0
- package/tsconfig.json +3 -4
- package/dist/adapter.d.ts +0 -22
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/app.d.ts +0 -69
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js.map +0 -1
- package/dist/bot.d.ts +0 -9
- package/dist/bot.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -12
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -3
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -3
- package/dist/logger.js.map +0 -1
- package/dist/plugin.d.ts +0 -41
- package/dist/plugin.d.ts.map +0 -1
- package/dist/plugin.js +0 -95
- package/dist/plugin.js.map +0 -1
- package/dist/types-generator.js.map +0 -1
- package/dist/types.d.ts +0 -69
- package/dist/types.d.ts.map +0 -1
- package/src/logger.ts +0 -3
- package/tests/logger.test.ts +0 -170
- package/tsconfig.tsbuildinfo +0 -1
- /package/{dist → lib}/bot.js +0 -0
- /package/{dist → lib}/bot.js.map +0 -0
- /package/{dist → lib}/config.d.ts +0 -0
- /package/{dist → lib}/types-generator.d.ts +0 -0
- /package/{dist → lib}/types.js +0 -0
- /package/{dist → lib}/types.js.map +0 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { Message, MessageBase, MessageChannel, MessageType } from '../src/message'
|
|
3
|
+
import { MessageSegment, MessageSender } from '../src/types'
|
|
4
|
+
|
|
5
|
+
describe('Message系统测试', () => {
|
|
6
|
+
describe('Message类型定义测试', () => {
|
|
7
|
+
it('应该正确定义MessageChannel接口', () => {
|
|
8
|
+
const channel: MessageChannel = {
|
|
9
|
+
id: 'test-channel-123',
|
|
10
|
+
type: 'private'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
expect(channel.id).toBe('test-channel-123')
|
|
14
|
+
expect(channel.type).toBe('private')
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('应该支持所有MessageType类型', () => {
|
|
18
|
+
const privateType: MessageType = 'private'
|
|
19
|
+
const groupType: MessageType = 'group'
|
|
20
|
+
const channelType: MessageType = 'channel'
|
|
21
|
+
|
|
22
|
+
expect(privateType).toBe('private')
|
|
23
|
+
expect(groupType).toBe('group')
|
|
24
|
+
expect(channelType).toBe('channel')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('应该正确定义MessageBase接口', () => {
|
|
28
|
+
const mockReply = vi.fn().mockResolvedValue(undefined)
|
|
29
|
+
const sender: MessageSender = {
|
|
30
|
+
id: 'user-123',
|
|
31
|
+
name: 'Test User',
|
|
32
|
+
avatar: 'https://example.com/avatar.png'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const messageBase: MessageBase = {
|
|
36
|
+
$id: 'msg-123',
|
|
37
|
+
$adapter: 'test-adapter',
|
|
38
|
+
$bot: 'test-bot',
|
|
39
|
+
$content: [
|
|
40
|
+
{ type: 'text', data: { text: 'Hello World' } }
|
|
41
|
+
],
|
|
42
|
+
$sender: sender,
|
|
43
|
+
$reply: mockReply,
|
|
44
|
+
$channel: { id: 'channel-123', type: 'private' },
|
|
45
|
+
$timestamp: Date.now(),
|
|
46
|
+
$raw: 'Hello World'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
expect(messageBase.$id).toBe('msg-123')
|
|
50
|
+
expect(messageBase.$adapter).toBe('test-adapter')
|
|
51
|
+
expect(messageBase.$bot).toBe('test-bot')
|
|
52
|
+
expect(messageBase.$content).toHaveLength(1)
|
|
53
|
+
expect(messageBase.$content[0].type).toBe('text')
|
|
54
|
+
expect(messageBase.$sender.id).toBe('user-123')
|
|
55
|
+
expect(typeof messageBase.$reply).toBe('function')
|
|
56
|
+
expect(messageBase.$channel.id).toBe('channel-123')
|
|
57
|
+
expect(messageBase.$timestamp).toBeTypeOf('number')
|
|
58
|
+
expect(messageBase.$raw).toBe('Hello World')
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('Message工厂函数测试', () => {
|
|
63
|
+
it('应该使用Message.from创建消息对象', () => {
|
|
64
|
+
const mockReply = vi.fn().mockResolvedValue(undefined)
|
|
65
|
+
const customData = {
|
|
66
|
+
platform: 'discord',
|
|
67
|
+
serverId: 'server-123',
|
|
68
|
+
messageId: 'discord-msg-456'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const messageBase: MessageBase = {
|
|
72
|
+
$id: 'msg-123',
|
|
73
|
+
$adapter: 'discord',
|
|
74
|
+
$bot: 'discord-bot',
|
|
75
|
+
$content: [
|
|
76
|
+
{ type: 'text', data: { text: 'Hello from Discord' } }
|
|
77
|
+
],
|
|
78
|
+
$sender: {
|
|
79
|
+
id: 'user-456',
|
|
80
|
+
name: 'Discord User'
|
|
81
|
+
},
|
|
82
|
+
$reply: mockReply,
|
|
83
|
+
$channel: { id: 'discord-channel', type: 'channel' },
|
|
84
|
+
$timestamp: Date.now(),
|
|
85
|
+
$raw: 'Hello from Discord'
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const message = Message.from(customData, messageBase)
|
|
89
|
+
|
|
90
|
+
// 验证合并结果
|
|
91
|
+
expect(message.$id).toBe('msg-123')
|
|
92
|
+
expect(message.$adapter).toBe('discord')
|
|
93
|
+
expect(message.platform).toBe('discord')
|
|
94
|
+
expect(message.serverId).toBe('server-123')
|
|
95
|
+
expect(message.messageId).toBe('discord-msg-456')
|
|
96
|
+
expect(typeof message.$reply).toBe('function')
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('应该保持原始数据的属性', () => {
|
|
100
|
+
const mockReply = vi.fn()
|
|
101
|
+
const originalData = {
|
|
102
|
+
customField: 'custom-value',
|
|
103
|
+
nested: {
|
|
104
|
+
prop: 'nested-value'
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const messageBase: MessageBase = {
|
|
109
|
+
$id: 'msg-456',
|
|
110
|
+
$adapter: 'test',
|
|
111
|
+
$bot: 'test-bot',
|
|
112
|
+
$content: [],
|
|
113
|
+
$sender: { id: 'user', name: 'User' },
|
|
114
|
+
$reply: mockReply,
|
|
115
|
+
$channel: { id: 'channel', type: 'private' },
|
|
116
|
+
$timestamp: Date.now(),
|
|
117
|
+
$raw: 'test'
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const message = Message.from(originalData, messageBase)
|
|
121
|
+
|
|
122
|
+
expect(message.customField).toBe('custom-value')
|
|
123
|
+
expect(message.nested.prop).toBe('nested-value')
|
|
124
|
+
expect(message.$id).toBe('msg-456')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('应该正确处理泛型类型', () => {
|
|
128
|
+
interface DiscordMessage {
|
|
129
|
+
guildId?: string
|
|
130
|
+
channelId: string
|
|
131
|
+
authorId: string
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const discordData: DiscordMessage = {
|
|
135
|
+
guildId: 'guild-123',
|
|
136
|
+
channelId: 'channel-456',
|
|
137
|
+
authorId: 'author-789'
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const messageBase: MessageBase = {
|
|
141
|
+
$id: 'msg-789',
|
|
142
|
+
$adapter: 'discord',
|
|
143
|
+
$bot: 'discord-bot',
|
|
144
|
+
$content: [
|
|
145
|
+
{ type: 'text', data: { text: 'Discord message' } }
|
|
146
|
+
],
|
|
147
|
+
$sender: { id: 'author-789', name: 'Discord Author' },
|
|
148
|
+
$reply: vi.fn(),
|
|
149
|
+
$channel: { id: 'channel-456', type: 'channel' },
|
|
150
|
+
$timestamp: Date.now(),
|
|
151
|
+
$raw: 'Discord message'
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const message: Message<DiscordMessage> = Message.from(discordData, messageBase)
|
|
155
|
+
|
|
156
|
+
// TypeScript类型检查 + 运行时验证
|
|
157
|
+
expect(message.guildId).toBe('guild-123')
|
|
158
|
+
expect(message.channelId).toBe('channel-456')
|
|
159
|
+
expect(message.authorId).toBe('author-789')
|
|
160
|
+
expect(message.$adapter).toBe('discord')
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
describe('消息内容处理测试', () => {
|
|
165
|
+
it('应该正确处理文本消息', () => {
|
|
166
|
+
const textSegment: MessageSegment = {
|
|
167
|
+
type: 'text',
|
|
168
|
+
data: { text: '这是一条文本消息' }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const messageBase: MessageBase = {
|
|
172
|
+
$id: 'text-msg',
|
|
173
|
+
$adapter: 'test',
|
|
174
|
+
$bot: 'test-bot',
|
|
175
|
+
$content: [textSegment],
|
|
176
|
+
$sender: { id: 'user', name: 'User' },
|
|
177
|
+
$reply: vi.fn(),
|
|
178
|
+
$channel: { id: 'channel', type: 'private' },
|
|
179
|
+
$timestamp: Date.now(),
|
|
180
|
+
$raw: '这是一条文本消息'
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
expect(messageBase.$content[0].type).toBe('text')
|
|
184
|
+
expect(messageBase.$content[0].data.text).toBe('这是一条文本消息')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('应该正确处理多媒体消息', () => {
|
|
188
|
+
const multiSegments: MessageSegment[] = [
|
|
189
|
+
{ type: 'text', data: { text: '看看这张图片:' } },
|
|
190
|
+
{ type: 'image', data: { url: 'https://example.com/image.png' } },
|
|
191
|
+
{ type: 'text', data: { text: '很漂亮吧!' } }
|
|
192
|
+
]
|
|
193
|
+
|
|
194
|
+
const messageBase: MessageBase = {
|
|
195
|
+
$id: 'multi-msg',
|
|
196
|
+
$adapter: 'test',
|
|
197
|
+
$bot: 'test-bot',
|
|
198
|
+
$content: multiSegments,
|
|
199
|
+
$sender: { id: 'user', name: 'User' },
|
|
200
|
+
$reply: vi.fn(),
|
|
201
|
+
$channel: { id: 'channel', type: 'group' },
|
|
202
|
+
$timestamp: Date.now(),
|
|
203
|
+
$raw: '看看这张图片:[图片]很漂亮吧!'
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
expect(messageBase.$content).toHaveLength(3)
|
|
207
|
+
expect(messageBase.$content[0].type).toBe('text')
|
|
208
|
+
expect(messageBase.$content[1].type).toBe('image')
|
|
209
|
+
expect(messageBase.$content[2].type).toBe('text')
|
|
210
|
+
expect(messageBase.$content[1].data.url).toBe('https://example.com/image.png')
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
it('应该正确处理特殊消息类型', () => {
|
|
214
|
+
const specialSegments: MessageSegment[] = [
|
|
215
|
+
{ type: 'at', data: { user_id: 'user-123', name: '@张三' } },
|
|
216
|
+
{ type: 'emoji', data: { id: 'emoji-456', name: '😀' } },
|
|
217
|
+
{ type: 'file', data: { url: 'https://example.com/file.pdf', name: 'document.pdf' } }
|
|
218
|
+
]
|
|
219
|
+
|
|
220
|
+
const messageBase: MessageBase = {
|
|
221
|
+
$id: 'special-msg',
|
|
222
|
+
$adapter: 'test',
|
|
223
|
+
$bot: 'test-bot',
|
|
224
|
+
$content: specialSegments,
|
|
225
|
+
$sender: { id: 'user', name: 'User' },
|
|
226
|
+
$reply: vi.fn(),
|
|
227
|
+
$channel: { id: 'channel', type: 'group' },
|
|
228
|
+
$timestamp: Date.now(),
|
|
229
|
+
$raw: '@张三 😀 [文件: document.pdf]'
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
expect(messageBase.$content[0].type).toBe('at')
|
|
233
|
+
expect(messageBase.$content[0].data.user_id).toBe('user-123')
|
|
234
|
+
expect(messageBase.$content[1].type).toBe('emoji')
|
|
235
|
+
expect(messageBase.$content[1].data.name).toBe('😀')
|
|
236
|
+
expect(messageBase.$content[2].type).toBe('file')
|
|
237
|
+
expect(messageBase.$content[2].data.name).toBe('document.pdf')
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
describe('消息回复功能测试', () => {
|
|
242
|
+
it('应该正确处理基本回复', async () => {
|
|
243
|
+
const mockReply = vi.fn().mockResolvedValue(undefined)
|
|
244
|
+
|
|
245
|
+
const message: Message = {
|
|
246
|
+
$id: 'reply-test',
|
|
247
|
+
$adapter: 'test',
|
|
248
|
+
$bot: 'test-bot',
|
|
249
|
+
$content: [{ type: 'text', data: { text: 'hello' } }],
|
|
250
|
+
$sender: { id: 'user', name: 'User' },
|
|
251
|
+
$reply: mockReply,
|
|
252
|
+
$channel: { id: 'channel', type: 'private' },
|
|
253
|
+
$timestamp: Date.now(),
|
|
254
|
+
$raw: 'hello'
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
await message.$reply('Hello back!')
|
|
258
|
+
|
|
259
|
+
expect(mockReply).toHaveBeenCalledWith('Hello back!')
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('应该正确处理带引用的回复', async () => {
|
|
263
|
+
const mockReply = vi.fn().mockResolvedValue(undefined)
|
|
264
|
+
|
|
265
|
+
const message: Message = {
|
|
266
|
+
$id: 'quote-test',
|
|
267
|
+
$adapter: 'test',
|
|
268
|
+
$bot: 'test-bot',
|
|
269
|
+
$content: [{ type: 'text', data: { text: 'original message' } }],
|
|
270
|
+
$sender: { id: 'user', name: 'User' },
|
|
271
|
+
$reply: mockReply,
|
|
272
|
+
$channel: { id: 'channel', type: 'group' },
|
|
273
|
+
$timestamp: Date.now(),
|
|
274
|
+
$raw: 'original message'
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
await message.$reply('Quoted reply', true)
|
|
278
|
+
await message.$reply('Custom quote', 'custom-quote-id')
|
|
279
|
+
|
|
280
|
+
expect(mockReply).toHaveBeenCalledWith('Quoted reply', true)
|
|
281
|
+
expect(mockReply).toHaveBeenCalledWith('Custom quote', 'custom-quote-id')
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
it('应该正确处理回复失败', async () => {
|
|
285
|
+
const mockReply = vi.fn().mockRejectedValue(new Error('回复失败'))
|
|
286
|
+
|
|
287
|
+
const message: Message = {
|
|
288
|
+
$id: 'fail-test',
|
|
289
|
+
$adapter: 'test',
|
|
290
|
+
$bot: 'test-bot',
|
|
291
|
+
$content: [{ type: 'text', data: { text: 'test' } }],
|
|
292
|
+
$sender: { id: 'user', name: 'User' },
|
|
293
|
+
$reply: mockReply,
|
|
294
|
+
$channel: { id: 'channel', type: 'private' },
|
|
295
|
+
$timestamp: Date.now(),
|
|
296
|
+
$raw: 'test'
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
await expect(message.$reply('This will fail')).rejects.toThrow('回复失败')
|
|
300
|
+
})
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
describe('发送者信息测试', () => {
|
|
304
|
+
it('应该正确处理基本发送者信息', () => {
|
|
305
|
+
const sender: MessageSender = {
|
|
306
|
+
id: 'sender-123',
|
|
307
|
+
name: '发送者'
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const message: Message = {
|
|
311
|
+
$id: 'sender-test',
|
|
312
|
+
$adapter: 'test',
|
|
313
|
+
$bot: 'test-bot',
|
|
314
|
+
$content: [],
|
|
315
|
+
$sender: sender,
|
|
316
|
+
$reply: vi.fn(),
|
|
317
|
+
$channel: { id: 'channel', type: 'private' },
|
|
318
|
+
$timestamp: Date.now(),
|
|
319
|
+
$raw: ''
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
expect(message.$sender.id).toBe('sender-123')
|
|
323
|
+
expect(message.$sender.name).toBe('发送者')
|
|
324
|
+
expect(message.$sender.avatar).toBeUndefined()
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
it('应该正确处理完整发送者信息', () => {
|
|
328
|
+
const sender: MessageSender = {
|
|
329
|
+
id: 'sender-456',
|
|
330
|
+
name: '完整发送者',
|
|
331
|
+
avatar: 'https://example.com/avatar.jpg',
|
|
332
|
+
nickname: '昵称',
|
|
333
|
+
roles: ['admin', 'moderator']
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const message: Message = {
|
|
337
|
+
$id: 'full-sender-test',
|
|
338
|
+
$adapter: 'test',
|
|
339
|
+
$bot: 'test-bot',
|
|
340
|
+
$content: [],
|
|
341
|
+
$sender: sender,
|
|
342
|
+
$reply: vi.fn(),
|
|
343
|
+
$channel: { id: 'channel', type: 'group' },
|
|
344
|
+
$timestamp: Date.now(),
|
|
345
|
+
$raw: ''
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
expect(message.$sender.avatar).toBe('https://example.com/avatar.jpg')
|
|
349
|
+
expect(message.$sender.nickname).toBe('昵称')
|
|
350
|
+
expect(message.$sender.roles).toEqual(['admin', 'moderator'])
|
|
351
|
+
})
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
describe('消息时间戳测试', () => {
|
|
355
|
+
it('应该正确处理时间戳', () => {
|
|
356
|
+
const timestamp = Date.now()
|
|
357
|
+
|
|
358
|
+
const message: Message = {
|
|
359
|
+
$id: 'timestamp-test',
|
|
360
|
+
$adapter: 'test',
|
|
361
|
+
$bot: 'test-bot',
|
|
362
|
+
$content: [],
|
|
363
|
+
$sender: { id: 'user', name: 'User' },
|
|
364
|
+
$reply: vi.fn(),
|
|
365
|
+
$channel: { id: 'channel', type: 'private' },
|
|
366
|
+
$timestamp: timestamp,
|
|
367
|
+
$raw: ''
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
expect(message.$timestamp).toBe(timestamp)
|
|
371
|
+
expect(typeof message.$timestamp).toBe('number')
|
|
372
|
+
expect(message.$timestamp).toBeGreaterThan(0)
|
|
373
|
+
})
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
describe('原始消息内容测试', () => {
|
|
377
|
+
it('应该保留原始消息内容', () => {
|
|
378
|
+
const rawContent = 'This is the raw message content with emojis 😀 and @mentions'
|
|
379
|
+
|
|
380
|
+
const message: Message = {
|
|
381
|
+
$id: 'raw-test',
|
|
382
|
+
$adapter: 'test',
|
|
383
|
+
$bot: 'test-bot',
|
|
384
|
+
$content: [
|
|
385
|
+
{ type: 'text', data: { text: 'This is the raw message content with emojis ' } },
|
|
386
|
+
{ type: 'emoji', data: { name: '😀' } },
|
|
387
|
+
{ type: 'text', data: { text: ' and ' } },
|
|
388
|
+
{ type: 'at', data: { user_id: 'user123', name: '@mentions' } }
|
|
389
|
+
],
|
|
390
|
+
$sender: { id: 'user', name: 'User' },
|
|
391
|
+
$reply: vi.fn(),
|
|
392
|
+
$channel: { id: 'channel', type: 'group' },
|
|
393
|
+
$timestamp: Date.now(),
|
|
394
|
+
$raw: rawContent
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
expect(message.$raw).toBe(rawContent)
|
|
398
|
+
expect(message.$raw).toContain('😀')
|
|
399
|
+
expect(message.$raw).toContain('@mentions')
|
|
400
|
+
})
|
|
401
|
+
})
|
|
402
|
+
})
|