def unban_user(message):
    args = extract_args_arr(message)
    if len(args) > 1:
        return edit(message, f'`{get_translation("wrongCommand")}`')
    reply = message.reply_to_message
    edit(message, f'`{get_translation("unbanProcess")}`')

    find_user = extract_user(message)
    if len(find_user) < 1:
        return edit(message, f'`{get_translation("banFailUser")}`')

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotUnbanMyself")}`')
    except BaseException:
        pass

    for user in find_user:
        try:
            chat = message.chat
            chat.unban_member(user.id)
            edit(
                message,
                get_translation('unbanResult',
                                ['**', user.first_name, user.id, '`']),
            )
        except Exception as e:
            edit(message, get_translation('banError', ['`', '**', e]))
            return
def promote_user(client, message):
    args = extract_args(message)
    reply = message.reply_to_message
    rank = None
    edit(message, f'`{get_translation("promoteProcess")}`')

    find_user = extract_user(message)
    if len(find_user) < 1:
        return edit(message, f'`{get_translation("banFailUser")}`')

    if reply:
        if args:
            rank = args
        else:
            rank = ''
    else:
        text = args.split(' ', 1)
        if len(text) > 1:
            rank = text[1]
        else:
            rank = ''

    for user in find_user:
        try:
            chat = message.chat
            chat.promote_member(
                user.id,
                privileges=ChatPrivileges(
                    can_manage_chat=True,
                    can_delete_messages=True,
                    can_manage_video_chats=True,
                    can_restrict_members=True,
                    can_change_info=True,
                    can_invite_users=True,
                    can_pin_messages=True,
                    can_promote_members=True,
                ),
            )
            if rank is not None:
                if len(rank) > 16:
                    rank = rank[:16]
                client.set_administrator_title(chat.id, user.id, rank)
            edit(
                message,
                get_translation('promoteResult',
                                ['**', user.first_name, user.id, '`']),
            )
            sleep(1)
            send_log(
                get_translation(
                    'promoteLog',
                    [user.first_name, user.id, chat.title, '`', chat.id],
                ))
        except Exception as e:
            edit(message, get_translation('banError', ['`', '**', e]))
            return
def ban_user(message):
    reply = message.reply_to_message
    edit(message, f'`{get_translation("banProcess")}`')

    find_user = extract_user(message)
    if len(find_user) < 1:
        return edit(message, f'`{get_translation("banFailUser")}`')

    reason = get_reason(message)

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotBanMyself")}`')
    except BaseException:
        pass

    for user in find_user:
        if user.id in BRAIN:
            return edit(
                message,
                get_translation('brainError',
                                ['`', '**', user.first_name, user.id]),
            )
        try:
            chat = message.chat
            chat.ban_member(user.id)
            edit(
                message,
                get_translation(
                    'banResult',
                    [
                        '**', user.first_name, user.id, '`',
                        reason if reason else ''
                    ],
                ),
            )
            sleep(1)
            send_log(
                get_translation(
                    'banLog',
                    [
                        user.first_name,
                        user.id,
                        chat.title,
                        '`',
                        chat.id,
                        reason if reason else '',
                    ],
                ))
        except UserAdminInvalid:
            edit(message, f'`{get_translation("banAdminError")}`')
        except BaseException as e:
            edit(message, get_translation('banError', ['`', '**', e]))
            return
Esempio n. 4
0
def gmute_user(client, message):
    reply = message.reply_to_message
    edit(message, f'`{get_translation("muteProcess")}`')

    find_user = extract_user(message)
    if len(find_user) < 1:
        return edit(message, f'`{get_translation("banFailUser")}`')

    reason = get_reason(message)

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotMuteMyself")}`')
    except BaseException:
        pass

    for user in find_user:
        if user.id in BRAIN:
            return edit(
                message,
                get_translation('brainError',
                                ['`', '**', user.first_name, user.id]),
            )
        try:
            if sql2.is_gmuted(user.id):
                return edit(message, f'`{get_translation("alreadyMuted")}`')
            sql2.gmute(user.id)
            edit(
                message,
                get_translation(
                    'gmuteResult',
                    [
                        '**', user.first_name, user.id, '`',
                        reason if reason else ''
                    ],
                ),
            )
            try:
                common_chats = client.get_common_chats(user.id)
                for i in common_chats:
                    i.restrict_member(user.id, permissions=ChatPermissions())
            except BaseException:
                pass
            sleep(1)
            send_log(
                get_translation(
                    'gmuteLog',
                    [user.first_name, user.id, '`', reason if reason else ''],
                ))
        except Exception as e:
            edit(message, get_translation('banError', ['`', '**', e]))
            return
def demote_user(message):
    args = extract_args_arr(message)
    if len(args) > 1:
        return edit(message, f'`{get_translation("wrongCommand")}`')
    reply = message.reply_to_message
    edit(message, f'`{get_translation("demoteProcess")}`')

    find_user = extract_user(message)
    if len(find_user) < 1:
        return edit(message, f'`{get_translation("banFailUser")}`')

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotDemoteMyself")}`')
    except BaseException:
        pass

    for user in find_user:
        try:
            chat = message.chat
            chat.promote_member(
                user.id,
                privileges=ChatPrivileges(
                    can_manage_chat=False,
                    can_delete_messages=False,
                    can_manage_video_chats=False,
                    can_restrict_members=False,
                    can_change_info=False,
                    can_invite_users=False,
                    can_pin_messages=False,
                    can_promote_members=False,
                ),
            )
            edit(
                message,
                get_translation('demoteResult',
                                ['**', user.first_name, user.id, '`']),
            )
        except Exception as e:
            edit(message, get_translation('banError', ['`', '**', e]))
            return
Esempio n. 6
0
def ungmute_user(client, message):
    args = extract_args_arr(message)
    if len(args) > 1:
        return edit(message, f'`{get_translation("wrongCommand")}`')
    reply = message.reply_to_message
    edit(message, f'`{get_translation("unmuteProcess")}`')

    find_user = extract_user(message)
    if len(find_user) < 1:
        return edit(message, f'`{get_translation("banFailUser")}`')

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotUnmuteMyself")}`')
    except BaseException:
        pass

    for user in find_user:
        try:
            if not sql2.is_gmuted(user.id):
                return edit(message, f'`{get_translation("alreadyUnmuted")}`')
            sql2.ungmute(user.id)
            try:
                common_chats = client.get_common_chats(user.id)
                for i in common_chats:
                    i.unban_member(user.id)
            except BaseException:
                pass
            edit(
                message,
                get_translation('unmuteResult',
                                ['**', user.first_name, user.id, '`']),
            )
        except Exception as e:
            edit(message, get_translation('banError', ['`', '**', e]))
            return
def unmute_user(message):
    try:
        from sedenecem.sql import mute_sql as sql
    except BaseException:
        edit(message, f'`{get_translation("nonSqlMode")}`')
        return

    args = extract_args_arr(message)
    if len(args) > 1:
        return edit(message, f'`{get_translation("wrongCommand")}`')
    reply = message.reply_to_message
    edit(message, f'`{get_translation("unmuteProcess")}`')

    find_user = extract_user(message)
    if len(find_user) < 1:
        return edit(message, f'`{get_translation("banFailUser")}`')

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotMuteMyself")}`')
    except BaseException:
        pass

    for user in find_user:
        try:
            chat = message.chat
            sql.unmute(chat.id, user.id)
            chat.unban_member(user.id)
            edit(
                message,
                get_translation('unmuteResult',
                                ['**', user.first_name, user.id, '`']),
            )
        except Exception as e:
            edit(message, get_translation('banError', ['`', '**', e]))
            return
Esempio n. 8
0
def who_is(client, message):
    find_user = extract_user(message)
    reply = message.reply_to_message
    media_perm = None
    edit(message, f'`{get_translation("whoisProcess")}`')

    if len(find_user) < 1:
        return edit(message, f'`{get_translation("banFailUser")}`')

    if message.chat.type in [enums.ChatType.SUPERGROUP, enums.ChatType.GROUP]:
        perm = message.chat.permissions
        media_perm = perm.can_send_media_messages

    for reply_user in find_user:
        try:
            reply_chat = client.get_chat(reply_user.id)
        except Exception:
            return edit(message, f'`{get_translation("whoisError")}`')
        if reply_user or reply_chat is not None:
            try:
                user_photo = reply_user.photo.big_file_id
                photo = download_media_wc(user_photo, 'photo.png')
            except BaseException:
                photo = None
                pass

            first_name = reply_user.first_name or get_translation('notSet')
            last_name = reply_user.last_name or get_translation('notSet')
            username = (f'@{reply_user.username}'
                        if reply_user.username else get_translation('notSet'))
            user_id = reply_user.id
            photos = client.get_chat_photos_count(user_id)
            dc_id = reply_user.dc_id or get_translation('notSet')
            bot = reply_user.is_bot
            chats = len(client.get_common_chats(user_id))
            premium = reply_user.is_premium
            bio = reply_chat.bio or get_translation('notSet')
            status = reply_user.status
            last_seen = LastSeen(bot, status)
            sudo = SudoCheck(user_id)
            blacklist = BlacklistCheck(user_id)

            caption = get_translation(
                'whoisResult',
                [
                    '**',
                    '`',
                    first_name,
                    last_name,
                    username,
                    user_id,
                    photos,
                    dc_id,
                    chats,
                    premium,
                    bio,
                    last_seen,
                    sudo if sudo else '',
                    blacklist if blacklist else '',
                ],
            )

    if photo and media_perm:
        reply_img(reply or message, photo, caption=caption, delete_file=True)
        message.delete()
    else:
        return edit(message, caption)
Esempio n. 9
0
def ungban_user(client, message):
    args = extract_args_arr(message)
    if len(args) > 1:
        return edit(message, f'`{get_translation("wrongCommand")}`')
    reply = message.reply_to_message
    edit(message, f'`{get_translation("unbanProcess")}`')

    find_user = extract_user(message)
    if len(find_user) < 1:
        return edit(message, f'`{get_translation("banFailUser")}`')

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotUnbanMyself")}`')
    except BaseException:
        pass

    for user in find_user:
        try:
            if not sql.is_gbanned(user.id):
                return edit(message, f'`{get_translation("alreadyUnbanned")}`')
            sql.ungban(user.id)

            def find_me(dialog):
                try:
                    return (dialog.chat.get_member(me_id).privileges
                            and dialog.chat.get_member(
                                me_id).privileges.can_restrict_members)
                except BaseException:
                    return False

            def find_member(dialog):
                try:
                    return (dialog.chat.get_member(user.id)
                            and dialog.chat.get_member(user.id).restricted_by
                            and dialog.chat.get_member(
                                user.id).restricted_by.id == me_id)
                except BaseException:
                    return False

            try:
                dialogs = client.get_dialogs()
                me_id = TEMP_SETTINGS['ME'].id
                chats = [
                    dialog.chat for dialog in dialogs
                    if (dialog.chat.type in
                        [enums.ChatType.SUPERGROUP, enums.ChatType.GROUP]
                        and find_me(dialog) and find_member(dialog))
                ]
                for chat in chats:
                    chat.unban_member(user.id)
            except BaseException:
                pass
            edit(
                message,
                get_translation('unbanResult',
                                ['**', user.first_name, user.id, '`']),
            )
        except Exception as e:
            edit(message, get_translation('banError', ['`', '**', e]))
            return
def mute_user(message):
    try:
        from sedenecem.sql import mute_sql as sql
    except BaseException:
        edit(message, f'`{get_translation("nonSqlMode")}`')
        return

    reply = message.reply_to_message
    edit(message, f'`{get_translation("muteProcess")}`')

    find_user = extract_user(message)
    if len(find_user) < 1:
        return edit(message, f'`{get_translation("banFailUser")}`')

    reason = get_reason(message)

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotMuteMyself")}`')
    except BaseException:
        pass

    for user in find_user:
        if user.id in BRAIN:
            return edit(
                message,
                get_translation('brainError',
                                ['`', '**', user.first_name, user.id]),
            )
        try:
            chat = message.chat
            if sql.is_muted(chat.id, user.id):
                return edit(message, 'kullanici zaten susturulmus')
            sql.mute(chat.id, user.id)
            edit(
                message,
                get_translation(
                    'muteResult',
                    [
                        '**', user.first_name, user.id, '`',
                        reason if reason else ''
                    ],
                ),
            )
            sleep(1)
            send_log(
                get_translation(
                    'muteLog',
                    [
                        user.first_name,
                        user.id,
                        chat.title,
                        '`',
                        chat.id,
                        reason if reason else '',
                    ],
                ))
        except Exception as e:
            edit(message, get_translation('banError', ['`', '**', e]))
            return