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

Method runAllSigns

checkin/checkin.ts:393–444  ·  view source on GitHub ↗
(source: string, fallbackPeer?: any, statusMsg?: Api.Message)

Source from the content-addressed store, hash-verified

391 }
392
393 private async checkAndRun(): Promise<void> {
394 if (this.running) return;
395 try {
396 const conf = this.cfg.get();
397 const now = new Date();
398 const today = this.dateCN(now);
399 const t = new Date(now.toLocaleString("en-US", { timeZone: SH_TZ }));
400
401 if (conf.lastRunDate === today) return;
402
403 // 每天重新生成随机时间,避免连续多天使用同一时间
404 this.todayRunTime = null;
405
406 const runTimeToday = this.getTodayRunTime();
407 if (!runTimeToday) {
408 this.todayRunTime = conf.runTime;
409 } else {
410 this.todayRunTime = runTimeToday;
411 }
412
413 const [h, m] = this.todayRunTime.split(":").map(Number);
414
415 if (t.getHours() !== h || t.getMinutes() !== m) return;
416
417 if (conf.runTimeEnd) {
418 const [endH, endM] = conf.runTimeEnd.split(":").map(Number);
419 const endMinutes = endH * 60 + endM;
420 const currentMinutes = t.getHours() * 60 + t.getMinutes();
421 if (currentMinutes > endMinutes) return;
422 }
423
424 this.running = true;
425 if (conf.randomDelay > 0) {
426 await this.sleep(Math.floor(Math.random() * conf.randomDelay * 60_000));
427 }
428 await this.runAllSigns("自动定时任务");
429 this.cfg.save({ lastRunDate: today });
430 } catch (e) {
431 console.error("[CheckIn] Scheduler error:", e);
432 } finally {
433 this.running = false;
434 }
435 }
436
437 private getTodayRunTime(): string | null {
438 const conf = this.cfg.get();
439 if (!conf.runTimeEnd) return null;
440 if (this.todayRunTime) return this.todayRunTime;
441
442 const [startH, startM] = conf.runTime.split(":").map(Number);
443 const [endH, endM] = conf.runTimeEnd.split(":").map(Number);
444
445 const startMinutes = startH * 60 + startM;
446 let endMinutes = endH * 60 + endM;
447

Callers 2

CheckInPluginClass · 0.95
checkAndRunMethod · 0.95

Calls 8

editMethod · 0.95
runSingleSignMethod · 0.95
sleepMethod · 0.95
escapeMethod · 0.95
sendViaBotMethod · 0.95
errorMethod · 0.80
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected