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

Class CyPlugin

cy/cy.ts:385–504  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383 ].join("\n");
384}
385
386class CyPlugin extends Plugin {
387 description = `词云
388<code>${mainPrefix}cy [消息数]</code> - 当前群立即生成
389<code>${mainPrefix}cy help</code> - 查看词云帮助
390<code>${mainPrefix}cy target here</code> - 设置当前群为定时目标
391<code>${mainPrefix}cy time 09:00 500</code> - 设置定时发送
392<code>${mainPrefix}cy on|off|status</code> - 开关/查看定时`;
393 private timer?: NodeJS.Timeout;
394 private lastRuns = new Set<string>();
395 private runningRuns = new Set<string>();
396
397 constructor() {
398 super();
399 this.timer = setInterval(() => {
400 this.tickSchedule().catch((error) => console.error("[cy] 定时词云失败:", error));
401 }, 30_000);
402 }
403
404 cleanup(): void {
405 if (this.timer) clearInterval(this.timer);
406 }
407
408 private async tickSchedule(): Promise<void> {
409 const config = readScheduleConfig();
410 if (!config.enabled || !config.target || !config.times.length) return;
411 const now = new Date();
412 const hh = String(now.getHours()).padStart(2, "0");
413 const mm = String(now.getMinutes()).padStart(2, "0");
414 const current = `${hh}:${mm}`;
415 if (!config.times.includes(current)) return;
416 const day = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
417 const key = `${day}:${current}`;
418 if (this.lastRuns.has(key) || this.runningRuns.has(key)) return;
419 this.runningRuns.add(key);
420 if (this.lastRuns.size > 200) this.lastRuns = new Set([...this.lastRuns].slice(-80));
421 try {
422 const client = await getGlobalClient();
423 if (!client) return;
424 await sendCloudToTarget(client, config.target, config.limit);
425 this.lastRuns.add(key);
426 } finally {
427 this.runningRuns.delete(key);
428 }
429 }
430
431 cmdHandlers: Record<string, (msg: Api.Message, trigger?: Api.Message) => Promise<void>> = {
432 cy: async (msg) => {
433 const args = getArgs(String(msg.text || msg.message || ""));
434 const [subCommand = "", ...restParts] = args.split(/\s+/).filter(Boolean);
435 const rest = restParts.join(" ");
436 const config = readScheduleConfig();
437
438 if (["help", "?"].includes(subCommand)) {
439 await msg.edit({ text: buildHelpText() });
440 return;
441 }
442 if (["target", "chat", "group"].includes(subCommand)) {

Callers

nothing calls this directly

Calls 12

readScheduleConfigFunction · 0.85
buildHelpTextFunction · 0.85
targetFromCurrentChatFunction · 0.85
writeScheduleConfigFunction · 0.85
parseTimeArgsFunction · 0.85
formatStatusFunction · 0.85
normalizeLimitFunction · 0.85
sendCloudToTargetFunction · 0.85
parseLimitFromPartsFunction · 0.85
safeDeleteMethod · 0.80
getArgsFunction · 0.70
editMethod · 0.45

Tested by

no test coverage detected