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

Method getManagedGroups

aban/aban.ts:628–682  ·  view source on GitHub ↗
(
    client: TelegramClient
  )

Source from the content-addressed store, hash-verified

626 if (group.kind === 'chat') {
627 return { className: 'PeerChat', chatId: bigInt(group.id) };
628 }
629 return await resolveChannelInput(client, group);
630}
631
632class PermissionManager {
633 private static getChatKind(chatId: any): ChatKind {
634 const className = chatId?.className;
635 if (className === 'PeerChat' || className === 'Chat') {
636 return 'chat';
637 }
638 return 'channel';
639 }
640
641 private static getBasicGroupChatId(chatId: any): number {
642 return Number(chatId?.chatId ?? chatId?.id ?? chatId);
643 }
644
645 private static async getBasicGroupParticipants(client: TelegramClient, chatId: any): Promise<any[] | null> {
646 const full = await client.invoke(
647 new Api.messages.GetFullChat({
648 chatId: bigInt(this.getBasicGroupChatId(chatId)),
649 })
650 ) as any;
651
652 const participants = full?.fullChat?.participants;
653 if (!participants || participants instanceof Api.ChatParticipantsForbidden) {
654 return null;
655 }
656
657 return participants.participants || null;
658 }
659
660 static async checkAdminPermission(
661 client: TelegramClient,
662 chatId: any
663 ): Promise<boolean> {
664 try {
665 const me = await safeGetMe(client);
666 if (!me) return false;
667 if (this.getChatKind(chatId) === 'chat') {
668 const participants = await this.getBasicGroupParticipants(client, chatId);
669 if (!participants) {
670 return false;
671 }
672
673 const meParticipant = participants.find((p: any) => Number(p?.userId) === Number((me as any).id));
674 return meParticipant instanceof Api.ChatParticipantCreator || meParticipant instanceof Api.ChatParticipantAdmin;
675 }
676
677 const participant = await client.invoke(
678 new Api.channels.GetParticipant({
679 channel: chatId,
680 participant: me.id
681 })
682 );
683
684 const p = participant.participant;
685 if (p instanceof Api.ChannelParticipantCreator) return true;

Callers 3

handleSuperBanMethod · 0.80
handleSuperUnbanMethod · 0.80
AbanPluginClass · 0.80

Calls 5

errorMethod · 0.80
getMethod · 0.45
checkAdminPermissionMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected