MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / checkAndRepeat

Method checkAndRepeat

autorepeat/autorepeat.ts:300–340  ·  view source on GitHub ↗
(message: Api.Message)

Source from the content-addressed store, hash-verified

298
299 // 检查开关
300 if (!this.enabledGroups.has(chatId)) return;
301
302 // 必须是文本消息
303 const text = message.message;
304 if (!text) return;
305
306 const now = Math.floor(Date.now() / 1000);
307
308 // 定期清理过期消息和重置每日记录
309 this.maintenance(now);
310
311 // 获取当前群组的消息记录
312 let msgs = this.recentMessages.get(chatId) || [];
313
314 // 添加新消息
315 const senderId = message.senderId ? Number(message.senderId) : 0;
316 if (senderId === 0) return; // 忽略匿名发送者
317
318 msgs.push({
319 userId: senderId,
320 text: text,
321 time: now
322 });
323
324 // 过滤掉超过配置时间的消息
325 msgs = msgs.filter(m => now - m.time <= this.triggerConfig.timeWindow);
326 this.recentMessages.set(chatId, msgs);
327
328 // 检查是否满足复读条件
329 await this.tryRepeat(chatId, text, msgs);
330
331 } catch (e) {
332 console.error(`[AutoRepeat] Error: ${e}`);
333 }
334 }
335
336 private static async tryRepeat(chatId: number, text: string, msgs: Array<{ userId: number; text: string; time: number }>) {
337 // 统计发送由于该内容的不同用户数量
338 const senders = new Set<number>();
339 for (const msg of msgs) {
340 if (msg.text === text) {
341 senders.add(msg.userId);
342 }
343 }

Callers 1

AutoRepeatPluginClass · 0.80

Calls 5

maintenanceMethod · 0.95
tryRepeatMethod · 0.95
errorMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected