(client: any, target: any, limit: number)
| 323 | } |
| 324 | |
| 325 | async function buildCloudImage(client: any, target: any, limit: number): Promise<{ png: Buffer; validMessages: number }> { |
| 326 | const messages = await fetchRecentMessages(client, target, limit); |
| 327 | const counts = new Map<string, number>(); |
| 328 | let validMessages = 0; |
| 329 | for (const item of messages) { |
| 330 | const text = messageText(item); |
| 331 | if (!text || text.startsWith(mainPrefix)) continue; |
| 332 | validMessages++; |
| 333 | collectWords(text, counts); |
| 334 | } |
| 335 | const words = buildWordItems(counts); |
| 336 | if (!words.length) throw new Error("没有统计到足够的热词。"); |
| 337 | return { png: renderWordCloud(words, limit, validMessages), validMessages }; |
| 338 | } |
| 339 | |
| 340 | async function sendCloudToTarget(client: any, target: any, limit: number, replyTo?: number): Promise<void> { |
| 341 | const { png } = await buildCloudImage(client, target, limit); |
no test coverage detected