예제 #1
0
파일: ban.py 프로젝트: mdnmdn/nebula8
def ban_success(update, context, chat, username=None, id=None):
    languages(update, context)
    message(update, context,
            languages.user_ban % (username if username is not None else id))
    logs_text = "<b>#Log User Banned!</b>\nGroup: {}\nUser: {}".format(
        chat.id, username or id)
    telegram_loggers(update, context, logs_text)
예제 #2
0
def init(update, context):
    bot = context.bot
    chat = chat_object(update)
    languages(update, context)
    record_arabic = GroupRepository.SET_ARABIC
    record_chinese = GroupRepository.SET_CHINESE
    record_cirillic = GroupRepository.SET_CIRILLIC
    record_no_user_photo = GroupRepository.SET_USER_PROFILE_PICT
    record_silence = GroupRepository.SET_SILENCE
    record_block_channel = GroupRepository.SENDER_CHAT_BLOCK
    record_zoophile = GroupRepository.ZOOPHILE_FILTER

    data = [(0, 1, chat.id)]
    GroupRepository().set_block_entry(data)
    update_db_settings(update, record_arabic, False)
    update_db_settings(update, record_chinese, False)
    update_db_settings(update, record_cirillic, False)
    update_db_settings(update, record_no_user_photo, False)
    update_db_settings(update, record_silence, False)
    update_db_settings(update, record_block_channel, False)
    update_db_settings(update, record_zoophile, False)
    buttons = []
    buttons.append(
        InlineKeyboardButton('❌ Remove Shield', callback_data='removeShield'))
    menu = build_menu(buttons, 1)

    bot.set_chat_permissions(update.effective_chat.id, PERM_FALSE)
    bot.send_message(chat.id,
                     languages.shield_on,
                     reply_markup=InlineKeyboardMarkup(menu),
                     parse_mode='HTML')
    logs_text = '🛡Shield Activated in {} <code>[{}]</code>'.format(
        chat.title, chat.id)
    telegram_loggers(update, context, logs_text)
예제 #3
0
def update_shield(update, context):
    bot = context.bot
    query = update.callback_query
    if query.data == 'removeShield':
        chat = update.effective_message.chat_id
        chat_title = update.effective_message.chat.title
        record_arabic = GroupRepository.SET_ARABIC
        record_chinese = GroupRepository.SET_CHINESE
        record_cirillic = GroupRepository.SET_CIRILLIC
        record_no_user_photo = GroupRepository.SET_USER_PROFILE_PICT
        record_silence = GroupRepository.SET_SILENCE
        record_block_channel = GroupRepository.SENDER_CHAT_BLOCK
        record_zoophile = GroupRepository.ZOOPHILE_FILTER

        data = [(1, 0, chat)]
        GroupRepository().set_block_entry(data)
        update_db_settings(update, record_arabic, True)
        update_db_settings(update, record_chinese, True)
        update_db_settings(update, record_cirillic, True)
        update_db_settings(update, record_no_user_photo, True)
        update_db_settings(update, record_silence, True)
        update_db_settings(update, record_block_channel, True)
        update_db_settings(update, record_zoophile, True)
        bot.set_chat_permissions(update.effective_chat.id, PERM_TRUE)
        msg = '✅ Shield removed!'
        query.edit_message_text(msg, parse_mode='HTML')
        logs_text = '🛡Shield Deactivated in {} <code>[{}]</code>'.format(
            chat_title, chat)
        telegram_loggers(update, context, logs_text)
예제 #4
0
def init(update,context):
    chat = chat_object(update)
    get_group = GroupRepository().getById(chat.id)
    max_warn = get_group['max_warn']
    current_time = datetime.datetime.utcnow().isoformat()
    default_warn = 1
    languages(update,context)
    if update.message.reply_to_message:
        reason = update.message.text[5:]
        user = user_reply_object(update)
        get_user = UserRepository().getUserByGroup([user.id,chat.id])
        warn_count = get_user['warn_count'] if get_user is not None else 0
        if warn_count != max_warn:
            buttons = []
            buttons.append(InlineKeyboardButton('➖ 1', callback_data='downWarn'))
            buttons.append(InlineKeyboardButton('➕ 1', callback_data='upWarn'))
            buttons.append(InlineKeyboardButton(languages.button_remove, callback_data='removeWarn'))
            menu = build_menu(buttons,3)
            if get_user:
                default_warn_count = 0
                username = "******"+user.username
                data = [(username,current_time,user.id)]
                UserRepository().update(data)
                data_mtm = [(user.id, chat.id, default_warn_count)]
                UserRepository().add_into_mtm(data_mtm)
                data_warn = [(user.id,chat.id)]
                UserRepository().updateWarn(data_warn)
                if reason:
                    msg = languages.warn_with_reason.format(mention_html(user.id, user.first_name),chat.title,chat.id,reason)
                    update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML')
                else:
                    msg = languages.warn_user.format(mention_html(user.id, user.first_name),chat.title,chat.id)
                    update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML')
                log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>".format(mention_html(user.id, user.first_name),chat.title,chat.id)
                if reason:
                    log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>\nReason: {}".format(mention_html(user.id, user.first_name),chat.title,chat.id,reason)
                telegram_loggers(update,context,log_txt)
            else:
                username = "******"+user.username
                data = [(user.id,username,current_time,current_time)]
                UserRepository().add(data)
                data_mtm = [(user.id, chat.id, default_warn)]
                UserRepository().add_into_mtm(data_mtm)
                if reason:
                    message(update,context,languages.warn_with_reason.format(username,chat.title,chat.id,reason))
                else:
                    message(update,context,languages.warn_user.format(username,chat.title,chat.id))
                log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>".format(mention_html(user.id, user.first_name),chat.title,chat.id)
                if reason:
                    log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>\nReason: {}".format(mention_html(user.id, user.first_name),chat.title,chat.id,reason)
                telegram_loggers(update,context,log_txt)
        else:
            ban_user_reply(update,context)
            buttons = []
            buttons.append(InlineKeyboardButton('Remove', callback_data='removeWarn'))
            menu = build_menu(buttons,2)
            msg = languages.warn_user_max.format(user.username,chat.title)
            update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML')
    else:
        message(update,context,languages.error_response_user_msg)
예제 #5
0
파일: report.py 프로젝트: mdnmdn/nebula8
def init(update, context):
    chat = update.effective_chat
    if str(update.effective_message.text).lower().startswith("@admin"):
        if update.effective_message.reply_to_message:
            msg = update.effective_message.reply_to_message
            format_link = "https://t.me/c/{}/{}".format(
                str(chat.id)[3:], msg.message_id)
            format_message = Strings.REPORT_MSG.format(chat.id, chat.title,
                                                       msg.text, format_link)
            reply_message(
                update, context,
                "<b>Segnalazione effettuata! un admin prenderà in carico la tua richiesta!</b>"
            )
            telegram_loggers(update, context, format_message)
            staff_loggers(update, context, format_message)
        else:
            msg_id = update.effective_message.message_id
            user_id = update.message.from_user.id
            user_first = update.message.from_user.first_name
            format_link = "https://t.me/c/{}/{}".format(
                str(chat.id)[3:], msg_id)
            format_message = '#Report\nUser: <a href="tg://user?id={}">{}</a>\nGroup Id: <code>{}</code>\nGroup Title: {}\nLink: {}'.format(
                user_id, user_first,
                str(chat.id)[3:], chat.title, format_link)
            reply_message(
                update, context,
                "<b>Segnalazione effettuata! un admin prenderà in carico la tua richiesta!</b>"
            )
            telegram_loggers(update, context, format_message)
            staff_loggers(update, context, format_message)
예제 #6
0
파일: exit.py 프로젝트: mdnmdn/nebula8
def init(update, context):
    bot = context.bot
    chat = chat_object(update)
    bot.leaveChat(update.message.chat_id)
    telegram_loggers(
        update, context,
        "#Log the bot has left the chat <code>{}</code>\nby operator <code>{}</code>"
        .format(chat.id, update.message.from_user.id))
    formatter = "Il bot è uscito dalla chat {} e il comando è stato eseguito da: {}".format(
        chat.id, update.message.from_user.id)
    sys_loggers("[BOT_EXIT_LOGS]", formatter, False, False, True)
예제 #7
0
파일: ban.py 프로젝트: mdnmdn/nebula8
def init(update, context):
    languages(update, context)

    bot = bot_object(update, context)
    chat = update.effective_chat
    reply = update.message.reply_to_message

    if reply is not None:
        if reply.from_user.id == bot.id:
            message(update, context, languages.bot_ban)
        else:
            ban_text = languages.ban_message.format(
                user=reply.from_user.username or reply.from_user.first_name,
                userid=reply.from_user.id,
                chat=chat.title)

            logs_text = Strings.BAN_LOG.format(
                username=reply.from_user.username
                or reply.from_user.first_name,
                id=reply.from_user.id,
                chat=chat.title)

            delete_message_reply(update, context)
            ban_user_reply(update, context)
            message(update, context, ban_text)
            telegram_loggers(update, context, logs_text)

            formatter = "Ban eseguito da: {} nella chat {}".format(
                update.message.from_user.id, chat.title)

            sys_loggers("[BAN_LOGS]", formatter, False, True)
    else:
        ban_argument = update.message.text[5:]

        is_user_id = Try.of(lambda: int(ban_argument)).valueOf() is not None

        if ban_argument[0] is '@':
            username = ban_argument

            Try.of(lambda: ban_user_by_username(update, context, username)) \
             .catch(lambda err: ban_error(update, context, username = username)) \
             .map(lambda x : ban_success(update, context, chat, username = username))
        elif is_user_id:
            userid = ban_argument

            Try.of(lambda: ban_user_by_id(update, context, userid)) \
             .catch(lambda err: ban_error(update, context, id = userid)) \
             .map(lambda x : ban_success(update, context, chat, id = userid))
        else:
            message(update, context, languages.ban_error.format(ban_argument))
            return
예제 #8
0
def init(update, context):
    user = user_reply_object(update)
    chat = chat_object(update)
    get_user = UserRepository().getUserByGroup([user.id, chat.id])
    get_group = GroupRepository().getById(chat.id)
    warn_count = get_user['warn_count'] if get_user is not None else 0
    max_warn = get_group['max_warn']
    default_warn = 1

    if warn_count != max_warn:
        if get_user:
            default_warn_count = 0
            username = "******" + user.username
            data = [(username, user.id)]
            UserRepository().update(data)
            data_mtm = [(user.id, chat.id, default_warn_count)]
            UserRepository().add_into_mtm(data_mtm)
            data_warn = [(user.id, chat.id)]
            UserRepository().updateWarn(data_warn)
            message(
                update, context,
                "{} was warned by the group {}".format(username, chat.title))
            log_txt = "#Log {} was warned by the group {}".format(
                username, chat.title)
            telegram_loggers(update, context, log_txt)
        else:
            username = "******" + user.username
            data = [(user.id, username, default_warn)]
            UserRepository().add(data)
            data_mtm = [(user.id, chat.id, default_warn)]
            UserRepository().add_into_mtm(data_mtm)
            message(
                update, context,
                "{} was warned by the group {}".format(username, chat.title))
            log_txt = "#Log {} was warned by the group {}".format(
                username, chat.title)
            telegram_loggers(update, context, log_txt)
    else:
        ban_user_reply(update, context)
        message(
            update, context,
            "User @{} has reached the maximum number\n of warns in the {} group and has been banned"
            .format(user.username, chat.title))
예제 #9
0
def init(update,context):
    motivation = update.message.text[2:].strip()
    reply = update.message.reply_to_message
    if reply is not None:
        if motivation != "":
            user_id = reply.from_user.id
            save_date = datetime.datetime.utcnow().isoformat()
            operator_id = update.message.from_user.id
            data = [(user_id,motivation,save_date,operator_id)]
            SuperbanRepository().add(data)
            ban_user_reply(update,context)
            delete_message_reply(update,context)
            logs_text = Strings.SUPERBAN_LOG.format(user_id,motivation,save_date,operator_id)
            msg = 'You got super banned <a href="tg://user?id={}">{}</a>\nGo to: https://squirrel-network.online/knowhere'.format(user_id,user_id)
            message(update,context,msg)
            telegram_loggers(update,context,logs_text)
            formatter = "Superban eseguito da: {}".format(update.message.from_user.id)
            sys_loggers("[SUPERBAN_LOGS]",formatter,False,False,True)
        else:
            message(update,context,"You need to specify a reason for the <b>superban!</b>")
    else:
        message(update,context,"You must use this command in response to a user!")
예제 #10
0
def init(update, context):
    bot = context.bot
    staff_group_id = -1001267698171
    buttons = []
    buttons.append(InlineKeyboardButton('Risolto✅', callback_data='resolved'))
    menu = build_menu(buttons, 2)
    if update.effective_message.forward_date is not None:
        return

    chat = update.effective_chat
    languages(update, context)
    if str(update.effective_message.text).lower().startswith("@admin"):
        if update.effective_message.reply_to_message:
            msg = update.effective_message.reply_to_message
            format_link = "https://t.me/c/{}/{}".format(
                str(chat.id)[3:], msg.message_id)
            format_message = Strings.REPORT_MSG.format(chat.id, chat.title,
                                                       msg.text, format_link)
            reply_message(update, context, languages.report_msg)
            telegram_loggers(update, context, format_message)
            bot.send_message(staff_group_id,
                             format_message,
                             reply_markup=InlineKeyboardMarkup(menu),
                             parse_mode='HTML')
        else:
            msg_id = update.effective_message.message_id
            user_id = update.message.from_user.id
            user_first = update.message.from_user.first_name
            format_link = "https://t.me/c/{}/{}".format(
                str(chat.id)[3:], msg_id)
            format_message = '#Report\nUser: <a href="tg://user?id={}">{}</a>\nGroup Id: <code>[{}]</code>\nGroup Title: {}\nLink: {}'.format(
                user_id, user_first,
                str(chat.id)[3:], chat.title, format_link)
            reply_message(update, context, languages.report_msg)
            telegram_loggers(update, context, format_message)
            bot.send_message(staff_group_id,
                             format_message,
                             reply_markup=InlineKeyboardMarkup(menu),
                             parse_mode='HTML')
예제 #11
0
def init(update, context):
    # Get settings
    chat = update.effective_message.chat_id
    group = GroupRepository().getById(chat)

    if group:
        row = group['set_welcome']
        block_user = group['block_new_member']
        arabic_filter = group['set_arabic_filter']
        cirillic_filter = group['set_cirillic_filter']
        chinese_filter = group['set_chinese_filter']
        user_profile_photo = group['set_user_profile_picture']
    else:
        row = 1
        block_user = 0
        arabic_filter = 1
        cirillic_filter = 1
        chinese_filter = 1
        user_profile_photo = 0

    if row == 0 and block_user == 1:
        for member in update.message.new_chat_members:
            kick_user(update, context)
            message(
                update, context,
                "<b>#Automatic Handler:</b> Kick User for group protection")

    if row == 1 and row is not None:
        for member in update.message.new_chat_members:
            user = member.username
            user_first = member.first_name
            user_id = member.id
            chat_title = update.effective_chat.title
            chat_id = update.effective_chat.id
            bot = bot_object(update, context)
            user_photo = member.get_profile_photos(member.id)

        if bot.id == user_id:
            welcome_bot(update, context)
            l_txt = "#Log <b>Bot added to group</b> {}\nId: <code>{}</code>".format(
                chat_title, chat_id)
            telegram_loggers(update, context, l_txt)
        # Banned user because username field is empty
        elif user is None:
            kick_user(update, context)
            message(
                update, context,
                "<code>{}</code> set a username! You were kicked for safety!".
                format(user_id))
        elif user_photo.total_count == 0 and user_profile_photo == 1:
            kick_user(update, context)
            message(
                update, context,
                "<code>{}</code> set a profile picture! You were kicked for safety!"
                .format(user_id))
        elif is_in_blacklist(user_id):
            ban_user(update, context)
            message(update, context,
                    "I got super banned <code>{}</code>".format(user_id))
        # Banned user with arabic characters
        elif has_arabic_character(user_first) and arabic_filter == 1:
            ban_user(update, context)
            message(
                update, context,
                "Non-Latin filter activated for the user <code>{}</code>".
                format(user_id))
        # Banned user with cirillic characters
        elif has_cirillic_character(user_first) and cirillic_filter == 1:
            ban_user(update, context)
            message(
                update, context,
                "Non-Latin filter activated for the user <code>{}</code>".
                format(user_id))
        # Banned user with chinese characters
        elif has_chinese_character(user_first) and chinese_filter == 1:
            ban_user(update, context)
            message(
                update, context,
                "Non-Latin filter activated for the user <code>{}</code>".
                format(user_id))
        else:
            save_user(member, chat_id)
            welcome_user(update, context, member)
예제 #12
0
def check_status(update, context):
    bot = context.bot
    chat_title = update.effective_chat.title
    chat_id = update.effective_chat.id
    get_bot = bot.getChatMember(chat_id, bot.id)
    get_group = GroupRepository().getById(chat_id)
    record_title = GroupRepository.SET_GROUP_NAME
    entities = list(update.effective_message.entities)
    get_chat_tg = bot.getChat(chat_id=chat_id)
    linked_chat = get_chat_tg.linked_chat_id
    group_members_count = update.effective_chat.get_member_count()
    #buttons = list(update.effective_message.reply_markup.inline_keyboard)
    """
    This function updates the group id on the database
    when a group changes from group to supergroup
    """
    if update.effective_message.migrate_from_chat_id is not None:
        old_chat_id = update.message.migrate_from_chat_id
        new_chat_id = update.message.chat.id
        data = [(new_chat_id, old_chat_id)]
        GroupRepository().update(data)
        message(
            update, context,
            "<b>#Automatic handler:</b>\nThe chat has been migrated to <b>supergroup</b> the bot has made the modification on the database.\n<i>It is necessary to put the bot admin</i>"
        )
        debug_channel(
            update, context,
            "[DEBUG_LOGGER] La chat {} è stata modifica da Gruppo a Supergruppo il suo nuovo id è: {}"
            .format(old_chat_id, new_chat_id))
    """
    This function saves the group to the database
    when the bot is added as soon as a group or supergroup is created
    """
    if update.effective_message.group_chat_created == True or update.effective_message.supergroup_chat_created == True:
        welcome_bot(update, context)
        l_txt = "#Log <b>Bot added to group</b> {}\nId: <code>{}</code>".format(
            chat_title, chat_id)
        telegram_loggers(update, context, l_txt)
    """
    This feature changes the chat title
    on the database when it is changed
    """
    if update.effective_message.new_chat_title:
        data = [(chat_title, chat_id)]
        GroupRepository().update_group_settings(record_title, data)
        debug_channel(
            update, context,
            "[DEBUG_LOGGER] La chat <code>[{}]</code> ha cambiato titolo".
            format(chat_id))
    """
    When a chat room changes group image it is saved to the webserver
    like this: example.com/group_photo/-100123456789.jpg (url variable)
    """
    if update.effective_message.new_chat_photo:
        chat = chat_object(update)
        if chat.type == "supergroup" or chat.type == "group":
            file_id = update.message.new_chat_photo[2].file_id
            newFile = bot.get_file(file_id)
            newFile.download(
                '/var/www/naos.hersel.it/group_photo/{}.jpg'.format(chat_id))
            url = "https://naos.hersel.it/group_photo/{}.jpg".format(chat_id)
            data = [(url, chat_id)]
            record = GroupRepository.SET_GROUP_PHOTO
            GroupRepository().update_group_settings(record, data)
            formatter = "New Url: {}".format(url)
            sys_loggers("[UPDATE_GROUP_PHOTO_LOGS]", formatter, False, True)
            debug_channel(
                update, context,
                "[DEBUG_LOGGER] La chat <code>[{}]</code> ha cambiato foto\nIl suo nuovo URL è: {}"
                .format(chat_id, url))
    """
    This function saves the number
    of users in the group in the database
    """
    if group_members_count > 0:
        record_count = GroupRepository.SET_GROUP_MEMBERS_COUNT
        data = [(group_members_count, chat_id)]
        GroupRepository().update_group_settings(record_count, data)
    """
    This function checks if the group is present in the blacklist
    if it is present the bot leaves the group
    """
    if check_group_blacklist(update) == True:
        message(
            update, context,
            "<b>#Automatic handler:</b>\nThe group is blacklisted the bot will automatically exit the chat"
        )
        log_txt = "#Log <b>Bot removed from group</b> {}\nId: <code>{}</code>".format(
            chat_title, chat_id)
        telegram_loggers(update, context, log_txt)
        time.sleep(2)
        bot.leave_chat(chat_id)
        debug_channel(
            update, context,
            "[DEBUG_LOGGER] Il bot è stato rimosso dalla chat <code>[{}]</code> perchè il gruppo è in Blacklist"
            .format(chat_id))
    """
    This function checks the
    badwords of the group
    """
    if check_group_badwords(update) == True:
        user = user_object(update)
        bot.delete_message(update.effective_message.chat_id,
                           update.message.message_id)
        message(
            update, context,
            "<b>#Automatic handler:</b>\n<code>{}</code> You used a forbidden word!"
            .format(user.id))
        debug_channel(
            update, context,
            "[DEBUG_LOGGER] L'utente <code>{}</code> ha usato una parola proibita"
            .format(user.id))
    """
    This function checks if there is a badword in a link
    """
    if entities is not None:
        for x in entities:
            if x['url'] is not None:
                bad_word = x['url']
                row = GroupRepository().get_group_badwords([bad_word, chat_id])
                if row:
                    user = user_object(update)
                    bot.delete_message(update.effective_message.chat_id,
                                       update.message.message_id)
                    message(
                        update, context,
                        "<b>#Automatic handler:</b>\n<code>{}</code> You used a forbidden word!"
                        .format(user.id))
    """
    This function checks if messages
    are arriving from a channel and deletes them
    """
    if update.effective_message.sender_chat and get_group[
            'sender_chat_block'] == 1:
        sender_chat_obj = update.effective_message.sender_chat

        if update.effective_message.voice_chat_started:
            return
        elif update.effective_message.voice_chat_ended:
            return
        elif get_chat_tg.type == "channel":
            return
        elif sender_chat_obj.id == linked_chat:
            return
        else:
            message(
                update, context,
                "<b>#Automatic Handler:</b>\nIn this group <code>[{}]</code> it is not allowed to write with the\n{} <code>[{}]</code> channel"
                .format(chat_id, sender_chat_obj.title, sender_chat_obj.id))
            bot.delete_message(update.effective_message.chat_id,
                               update.message.message_id)
    """
    This function checks that the bot is an administrator
    and sends an alert
    """
    if get_bot.status == 'member':
        message(
            update, context,
            "I am not an administrator of this group, you have to make me an administrator to function properly!"
        )
        debug_channel(
            update, context,
            "[DEBUG_LOGGER] Il bot non è un amministratore della chat {}".
            format(chat_id))
    """
    This function is used to filter messages with spoiler type
    and delete them if the group owner puts the block at 1
    """
    for a in entities:
        type_entities = a['type']
        if type_entities is not None:
            if type_entities == "spoiler" and get_group['spoiler_block'] == 1:
                message(
                    update, context,
                    "<b>#Automatic Handler:</b>\nIn this chat the use of spoilers is not allowed!"
                )
                bot.delete_message(update.effective_message.chat_id,
                                   update.message.message_id)
    #TODO NONETYPE PROBLEM
    """if buttons is not None:
        for url in buttons:
            if url[0]['url'] is not None:
                bad_word = url[0]['url'] or url[0]['text']
                row = GroupRepository().get_group_badwords([bad_word, chat_id])
                if row:
                    user = user_object(update)
                    bot.delete_message(update.effective_message.chat_id, update.message.message_id)
                    message(update,context,"<b>#Automatic handler:</b>\n<code>{}</code> You used a forbidden word!".format(user.id))
    else:
        print("no button")"""
    """
    Voice audio blocking
    """
    if update.effective_message.voice is not None and get_group[
            'set_no_vocal'] == 1:
        message(
            update, context,
            "<b>#Automatic Handler:</b>\nIs not allowed to use vocals in this chat!"
        )
        bot.delete_message(update.effective_message.chat_id,
                           update.message.message_id)
예제 #13
0
def init(update, context):
    # Get settings
    chat = update.effective_message.chat_id
    group = GroupRepository().getById(chat)

    if group:
        row = group['set_welcome']
        block_user = group['block_new_member']
        arabic_filter = group['set_arabic_filter']
        cirillic_filter = group['set_cirillic_filter']
        chinese_filter = group['set_chinese_filter']
        user_profile_photo = group['set_user_profile_picture']
        type_no_username = group['type_no_username']
        zoophile_filter = group["zoophile_filter"]
    else:
        row = 1
        block_user = 0
        arabic_filter = 1
        cirillic_filter = 1
        chinese_filter = 1
        user_profile_photo = 0
        zoophile_filter = 1

    if row == 0 and block_user == 1:
        for member in update.message.new_chat_members:
            kick_user(update, context)
            message(
                update, context,
                "<b>#Automatic Handler:</b> Kick User for group protection")

    if row == 1 and row is not None:
        for member in update.message.new_chat_members:
            user = member.username
            user_first = member.first_name
            user_id = member.id
            chat_title = update.effective_chat.title
            chat_id = update.effective_chat.id
            bot = bot_object(update, context)
            user_photo = member.get_profile_photos(member.id)
            # Welcome the bot when it is added
            if bot.id == user_id:
                l_txt = "#Log <b>Bot added to group</b> {}\nId: <code>{}</code>".format(
                    chat_title, chat_id)
                telegram_loggers(update, context, l_txt)
                welcome_bot(update, context)
            # Kicked user because username field is empty
            elif user is None:
                if type_no_username == 1:
                    message(
                        update, context,
                        '<a href="tg://user?id={}">{}</a> set an <b>username!</b> You were kicked for safety!'
                        .format(user_id, user_first))
                    time.sleep(2)
                    kick_user(update, context)
                elif type_no_username == 2:
                    message(
                        update, context,
                        '<a href="tg://user?id={}">{}</a> set an <b>username!</b>'
                        .format(user_id, user_first))
                elif type_no_username == 3:
                    message(
                        update, context,
                        '<a href="tg://user?id={}">{}</a> set an <b>username!</b> You were Muted for safety!'
                        .format(user_id, user_first))
                    mute_user_by_id(update, context, member.id, True)
                elif type_no_username == 4:
                    ban_user(update, context)
                    message(
                        update, context,
                        '<a href="tg://user?id={}">{}</a> was banned because they did not have an username'
                        .format(user_id, user_first))
                elif type_no_username == 5:
                    kick_user(update, context)
                elif has_zoophile(user_first) and zoophile_filter == 1:
                    ban_user(update, context)
                    message(
                        update, context,
                        "Nebula's automatic system intercepted a <b>zoophile!</b>\nI banned user {}"
                        .format(mention_html(user_id, user_first)))
                else:
                    arr_buttons = []
                    arr_buttons.append(
                        InlineKeyboardButton(text="Bot_logs",
                                             url="https://t.me/nebulalogs"))
                    menu = build_menu(arr_buttons, 2)
                    main_msg = "Welcome {} in {}".format(
                        mention_html(member.id, member.first_name), chat_title)
                    update.message.reply_text(
                        main_msg,
                        reply_markup=InlineKeyboardMarkup(menu),
                        parse_mode='HTML')
                    print("No action even if you don't have a username")
            # They ban the user because he is blacklisted
            elif is_in_blacklist(user_id):
                ban_user(update, context)
                message(
                    update, context,
                    'I got super banned <a href="tg://user?id={}">{}</a> [{}]'.
                    format(user_id, user_first, user_id))
            # They ban the user because he doesn't have a profile picture
            elif user_photo.total_count == 0 and user_profile_photo == 1:
                kick_user(update, context)
                message(
                    update, context,
                    '<a href="tg://user?id={}">{}</a> set a profile picture! You were kicked for safety!'
                    .format(user_id, user_first))
            # Banned user with arabic characters
            elif has_arabic_character(user_first) and arabic_filter == 1:
                ban_user(update, context)
                message(
                    update, context,
                    "Non-Latin filter activated for the user <code>{}</code>".
                    format(mention_html(user_id, user_first)))
            # Banned user with cirillic characters
            elif has_cirillic_character(user_first) and cirillic_filter == 1:
                ban_user(update, context)
                message(
                    update, context,
                    "Non-Latin filter activated for the user <code>{}</code>".
                    format(mention_html(user_id, user_first)))
            # Banned user with chinese characters
            elif has_chinese_character(user_first) and chinese_filter == 1:
                ban_user(update, context)
                message(
                    update, context,
                    "Non-Latin filter activated for the user <code>{}</code>".
                    format(mention_html(user_id, user_first)))
            # Banned user with Zoophile characters
            elif has_zoophile(user_first) and zoophile_filter == 1:
                ban_user(update, context)
                message(
                    update, context,
                    "Nebula's automatic system intercepted a <b>zoophile!</b>\nI banned user {}"
                    .format(mention_html(user_id, user_first)))
            # Welcome for bot owner
            elif user_id in OWNER_LIST:
                message(
                    update, context,
                    'The bot operator <a href="tg://user?id={}">{}</a> has just joined the group'
                    .format(user_id, user_first))
            else:
                save_user(member, chat_id)
                welcome_user(update, context, member)
예제 #14
0
def init(update, context):
    languages(update, context)

    bot = bot_object(update, context)
    chat = update.effective_chat
    reply = update.message.reply_to_message
    if reply is not None:
        user_status = reply_member_status_object(update, context)
        user = reply.from_user
        row = GroupRepository().getById(chat.id)
        if user.id == bot.id:
            text = "I can't ban myself!"

            message(update, context, text)
        elif user_status.status == 'administrator' or user_status.status == 'creator':
            message(update, context,
                    "I can't <i>ban</i> an administrator or creator!")
        else:
            if row['ban_message']:
                parsed_message = row['ban_message'].replace(
                    '{first_name}', user.first_name).replace(
                        '{chat}', update.message.chat.title).replace(
                            '{username}', "@" + user.username).replace(
                                '{mention}',
                                mention_html(user.id,
                                             user.first_name)).replace(
                                                 '{userid}', str(user.id))
                ban_text = "{}".format(parsed_message)
            else:
                ban_text = languages.ban_message.format(
                    user=reply.from_user.username
                    or reply.from_user.first_name,
                    userid=reply.from_user.id,
                    chat=chat.title)
            #Log Ban
            logs_text = Strings.BAN_LOG.format(
                username=reply.from_user.username
                or reply.from_user.first_name,
                id=reply.from_user.id,
                chat=chat.title)

            delete_message_reply(update, context)
            ban_user_reply(update, context)
            message(update, context, ban_text)
            telegram_loggers(update, context, logs_text)

            formatter = "Ban eseguito da: {} nella chat {}".format(
                update.message.from_user.id, chat.title)

            sys_loggers("[BAN_LOGS]", formatter, False, True)
    else:
        ban_argument = update.message.text[5:]

        is_user_id = Try.of(lambda: int(ban_argument)).valueOf() is not None

        if ban_argument[0] == '@':
            username = ban_argument

            Try.of(lambda: ban_user_by_username(update, context, username)) \
             .catch(lambda err: ban_error(update, context, username = username)) \
             .map(lambda x : ban_success(update, context, username = username))
        elif is_user_id:
            userid = ban_argument

            Try.of(lambda: ban_user_by_id(update, context, userid)) \
             .catch(lambda err: ban_error(update, context, id = userid)) \
             .map(lambda x : ban_success(update, context, id = userid))
        else:
            message(
                update, context,
                "Sintassi del comando errata o utente non riconosciuto: {}".
                format(ban_argument))
            return