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

Method removeTemporaryAdmin

tmp_admin/tmp_admin.ts:584–657  ·  view source on GitHub ↗
(params: {
    msg: Api.Message;
    targetSourceMsg: Api.Message;
    trigger?: Api.Message;
    channel: any;
    chatEntity: Api.Channel;
    targetArg?: string;
    manual: boolean;
  })

Source from the content-addressed store, hash-verified

582 chatEntity: Api.Channel;
583 targetArg?: string;
584 manual: boolean;
585 }): Promise<void> {
586 const { msg, targetSourceMsg, trigger, channel, chatEntity, targetArg, manual } =
587 params;
588 const { entity: userEntity, id: userId } = await this.resolveUserFromReplyOrArg(
589 targetSourceMsg,
590 channel,
591 targetArg
592 );
593
594 if (!userEntity || !userId) {
595 await respondToCommand(msg, trigger, { text: "请回复一条消息或提供 用户ID/用户名" });
596 return;
597 }
598
599 const chatKey = getChatKey(chatEntity, msg);
600 const key = getJobKey(chatKey, userId);
601 const job = this.jobs.get(key);
602 let participant: any;
603 try {
604 participant = await this.getCurrentParticipantOrThrow(channel, userEntity);
605 } catch (e: any) {
606 await respondToCommand(msg, trigger, {
607 text:
608 `查询当前管理员状态失败:${codeTag(e?.message || e)}\n` +
609 "已保留临时管理员记录, 未执行解除。",
610 parseMode: "html",
611 });
612 return;
613 }
614
615 if (!isTemporaryAdminParticipant(participant)) {
616 if (job) {
617 this.clearLocalJob(key);
618 await this.deleteStoredJob(key);
619 await respondToCommand(msg, trigger, {
620 text: "目标当前已不再是插件设置的临时管理状态, 已清理记录, 未解除管理员。",
621 });
622 return;
623 }
624 await respondToCommand(msg, trigger, {
625 text: "目标不是当前插件记录的临时管理员, 也没有临时管理头衔。为避免误删真实管理员, 已取消。",
626 });
627 return;
628 }
629
630 try {
631 const client = await getGlobalClient();
632 if (!client) throw new Error("Telegram 客户端未初始化");
633
634 await this.demoteAdmin(client, channel, userEntity, job?.originalRank);
635
636 this.clearLocalJob(key);
637 await this.deleteStoredJob(key);
638
639 const user = await formatEntity(userId || userEntity, true);
640 await respondToCommand(msg, trigger, {
641 text: `${manual ? "已提前解除" : "已解除"}临时管理员: ${user.display}`,

Callers 1

TmpAdminPluginClass · 0.95

Calls 12

clearLocalJobMethod · 0.95
deleteStoredJobMethod · 0.95
demoteAdminMethod · 0.95
respondToCommandFunction · 0.85
getChatKeyFunction · 0.85
getJobKeyFunction · 0.85
codeTagFunction · 0.70
formatEntityFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected