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

Method addTemporaryAdmin

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

Source from the content-addressed store, hash-verified

442 chatEntity: Api.Channel;
443 targetArg?: string;
444 durationArg?: string;
445 }): Promise<void> {
446 const { msg, targetSourceMsg, trigger, channel, chatEntity, targetArg, durationArg } =
447 params;
448 let durationMinutes: number;
449 try {
450 durationMinutes = parseDurationMinutes(durationArg);
451 } catch (e: any) {
452 await respondToCommand(msg, trigger, {
453 text: `设置临时管理员失败:${codeTag(e?.message || e)}`,
454 parseMode: "html",
455 });
456 return;
457 }
458
459 const { entity: userEntity, id: userId } = await this.resolveUserFromReplyOrArg(
460 targetSourceMsg,
461 channel,
462 targetArg
463 );
464
465 if (!userEntity || !userId) {
466 await respondToCommand(msg, trigger, { text: "请回复一条消息或提供 用户ID/用户名" });
467 return;
468 }
469
470 const chatKey = getChatKey(chatEntity, msg);
471 const key = getJobKey(chatKey, userId);
472 let participant: any;
473 try {
474 participant = await this.getCurrentParticipantOrThrow(channel, userEntity);
475 } catch (e: any) {
476 await respondToCommand(msg, trigger, {
477 text:
478 `查询当前管理员状态失败:${codeTag(e?.message || e)}\n` +
479 "为避免覆盖现有管理员权限, 已取消设置。",
480 parseMode: "html",
481 });
482 return;
483 }
484
485 if (participant instanceof Api.ChannelParticipantCreator) {
486 await respondToCommand(msg, trigger, { text: "不能把群主设置为临时管理员" });
487 return;
488 }
489
490 if (
491 participant instanceof Api.ChannelParticipantAdmin &&
492 !isTemporaryAdminParticipant(participant)
493 ) {
494 if (this.jobs.has(key)) {
495 this.clearLocalJob(key);
496 await this.deleteStoredJob(key);
497 }
498 await respondToCommand(msg, trigger, {
499 text: "目标已经是管理员。为避免覆盖现有权限和头衔, 不会将其改为临时管理员。",
500 });
501 return;

Callers 1

TmpAdminPluginClass · 0.95

Calls 15

clearLocalJobMethod · 0.95
deleteStoredJobMethod · 0.95
scheduleExpiryMethod · 0.95
persistJobMethod · 0.95
parseDurationMinutesFunction · 0.85
respondToCommandFunction · 0.85
getChatKeyFunction · 0.85
getJobKeyFunction · 0.85
getParticipantRankFunction · 0.85

Tested by

no test coverage detected