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

Callers 1

lotteryFunction · 0.85

Calls 2

warnMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected