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

Method scheduleWithDelay

tmp_admin/tmp_admin.ts:663–705  ·  view source on GitHub ↗
(delay: number)

Source from the content-addressed store, hash-verified

661 if (existing?.timer) clearTimeout(existing.timer);
662
663 const scheduleWithDelay = (delay: number) => {
664 job.timer = setTimeout(async () => {
665 if (Date.now() < job.expiresAt) {
666 scheduleNext();
667 return;
668 }
669
670 let participant: any;
671 try {
672 participant = await this.getCurrentParticipantOrThrow(
673 job.channel,
674 job.userEntity
675 );
676 } catch (e) {
677 scheduleRetry(e);
678 return;
679 }
680
681 if (!isTemporaryAdminParticipant(participant)) {
682 this.jobs.delete(key);
683 await this.deleteStoredJobQuiet(key);
684 await this.sendReplyQuiet(
685 job,
686 `临时管理员已到期, 但 ${job.userDisplay} 已不再是插件设置的临时管理状态, 未自动解除。`
687 );
688 return;
689 }
690
691 try {
692 await this.demoteAdmin(job.client, job.channel, job.userEntity, job.originalRank);
693 } catch (e) {
694 scheduleRetry(e);
695 return;
696 }
697
698 this.jobs.delete(key);
699 await this.deleteStoredJobQuiet(key);
700 await this.sendReplyQuiet(
701 job,
702 `临时管理员已到期并自动解除: ${job.userDisplay}`
703 );
704 }, Math.min(Math.max(0, delay), maxTimerDelayMs));
705 };
706
707 const scheduleRetry = (error: any) => {
708 if (job.retryCount >= maxExpiryRetries) {

Callers

nothing calls this directly

Calls 6

deleteStoredJobQuietMethod · 0.95
sendReplyQuietMethod · 0.95
demoteAdminMethod · 0.95
deleteMethod · 0.45

Tested by

no test coverage detected