Example #1
0
async def is_user_in_chat(chat_id: int, user_id: int):
    status = False
    async for user in tbot.iter_participants(chat_id):
        if user_id == user.id:
            status = True
            break
    return status
Example #2
0
async def metabutler_is_admin(chat_id: int):
    try:
        participant = await tbot(GetParticipantRequest(chat_id, 'me'))
        return isinstance(participant.participant, ChannelParticipantAdmin)
    except TypeError:
        async for user in tbot.iter_participants(
                chat_id, filter=ChannelParticipantsAdmins):
            if user.is_self:
                return True
    return False
Example #3
0
async def is_user_admin(user_id: int, chat_id):
    if user_id in SUDO_USERS:
        return True

    try:
        participant = await tbot(GetParticipantRequest(chat_id, user_id))
        return isinstance(participant.participant,
                          (ChannelParticipantAdmin, ChannelParticipantCreator))
    except TypeError:
        async for user in tbot.iter_participants(
                chat_id, filter=ChannelParticipantsAdmins):
            if user_id == user.id:
                return True
    return False
Example #4
0
async def user_is_ban_protected(user_id: int, message):
    if message.is_private or user_id in (WHITELIST_USERS + SUDO_USERS):
        return True

    if message.is_channel:
        participant = await tbot(
            GetParticipantRequest(message.chat_id, user_id))
        return isinstance(participant.participant,
                          (ChannelParticipantAdmin, ChannelParticipantCreator))

    async for user in tbot.iter_participants(message.chat_id,
                                             filter=ChannelParticipantsAdmins):
        if user_id == user.id:
            return True
    return False