Esempio n. 1
0
def mute_user(client, message):
    args = extract_args(message)
    reply = message.reply_to_message
    edit(message, f'`{get_translation("muteProcess")}`')
    if len(args):
        try:
            user = client.get_users(args)
        except Exception:
            edit(message, f'`{get_translation("banFailUser")}`')
            return
    elif reply:
        user_id = reply.from_user.id
        user = client.get_users(user_id)
    else:
        edit(message, f'`{get_translation("banFailUser")}`')
        return

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

    if user.id in BRAIN:
        return edit(
            message,
            get_translation('brainError',
                            ['`', '**', user.first_name, user.id]),
        )

    try:
        chat_id = message.chat.id
        if sql.is_muted(chat_id, user.id):
            return
        sql.mute(chat_id, user.id)
        edit(
            message,
            get_translation('muteResult',
                            ['**', user.first_name, user.id, '`']),
        )
        sleep(1)
        send_log(
            get_translation(
                'muteLog',
                [user.first_name, user.id, message.chat.title, '`', chat_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