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

Function isUserAdmin

lottery/lottery.ts:651–703  ·  view source on GitHub ↗
(client: TelegramClient, chatId: string, userId: string)

Source from the content-addressed store, hash-verified

649}
650
651async function isUserAdmin(client: TelegramClient, chatId: string, userId: string): Promise<boolean> {
652 try {
653 const chatEntity = await client.getEntity(chatId);
654
655 // 检查是否为超级群或频道
656 if (chatEntity.className === 'Channel' || (chatEntity as any).megagroup) {
657 try {
658 const participant = await client.invoke(
659 new Api.channels.GetParticipant({
660 channel: chatEntity,
661 participant: userId,
662 })
663 );
664
665 if (participant && participant.participant) {
666 const participantType = participant.participant.className;
667 return participantType === 'ChannelParticipantAdmin' ||
668 participantType === 'ChannelParticipantCreator';
669 }
670 } catch (e) {
671 // 如果GetParticipant失败,可能是普通群组,尝试其他方法
672 console.warn("GetParticipant failed, trying alternative method:", e);
673 }
674 }
675
676 // 对于普通群组,尝试获取消息发送者的权限
677 try {
678 const chatAdmins = await client.invoke(
679 new Api.channels.GetParticipants({
680 channel: chatEntity,
681 filter: new Api.ChannelParticipantsAdmins(),
682 offset: 0,
683 limit: 200,
684 hash: bigInt(0)
685 })
686 );
687
688 if (chatAdmins && (chatAdmins as any).participants) {
689 return (chatAdmins as any).participants.some((p: any) =>
690 String(p.userId || p.user_id) === String(userId)
691 );
692 }
693 } catch (e) {
694 // 如果仍然失败,返回false
695 console.warn("Alternative admin check failed:", e);
696 }
697
698 return false;
699 } catch (error) {
700 console.error("Error checking admin status:", error);
701 return false;
702 }
703}
704
705async function performLotteryDraw(client: TelegramClient, lottery: any): Promise<void> {
706 try {

Callers 1

lotteryFunction · 0.85

Calls 2

warnMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected