Esempio n. 1
0
def init(update, context):
    #Variables
    text = update.message.text
    operator_id = update.message.from_user.id
    operator_username = "******" + update.message.from_user.username
    save_date = datetime.datetime.utcnow().isoformat()
    #Build a Keyboard Buttons
    buttons = []
    buttons.append(InlineKeyboardButton('Spam', callback_data='mSpam'))
    buttons.append(InlineKeyboardButton('Scam', callback_data='mScam'))
    buttons.append(InlineKeyboardButton('Userbot', callback_data='mUserbot'))
    buttons.append(InlineKeyboardButton('P**n', callback_data='mPorn'))
    buttons.append(InlineKeyboardButton('Other', callback_data='mOther'))
    buttons.append(
        InlineKeyboardButton('Illegal Content',
                             callback_data='mIllegal_Content'))
    buttons.append(
        InlineKeyboardButton('Remove Superban',
                             callback_data='removeSuperban'))
    buttons.append(InlineKeyboardButton('Close', callback_data='closeMenu'))
    menu = build_menu(buttons, 2)
    if update.message.reply_to_message:
        user_id = update.message.reply_to_message.from_user.id
        update.message.reply_to_message.reply_text(
            "Select a reason for the Superban",
            reply_markup=InlineKeyboardMarkup(menu))
    else:
        input_user_id = text[2:].strip().split(" ", 1)
        user_id = input_user_id[0]
        if user_id != "":
            number = re.search(Regex.HAS_NUMBER, user_id)
            if number is None:
                message(update, context,
                        "Attention you must enter a number not letters!")
            else:
                default_motivation = "Other"
                data = [(user_id, default_motivation, save_date, operator_id)]
                SuperbanRepository().add(data)
                msg = 'You got super banned <a href="tg://user?id={}">{}</a>\nFor the following reason: <b>{}</b>\nGo to: https://squirrel-network.online/knowhere/?q={} to search for blacklisted users'.format(
                    user_id, user_id, default_motivation, user_id)
                message(update, context, msg)
                logs_text = Strings.SUPERBAN_LOG.format(
                    user_id, default_motivation, save_date, operator_username,
                    operator_id)
                messageWithId(update, context, Config.DEFAULT_LOG_CHANNEL,
                              logs_text)
                formatter = "Superban eseguito da: {}".format(operator_id)
                sys_loggers("[SUPERBAN_LOGS]", formatter, False, False, True)
                debug_channel(update, context,
                              "[DEBUG_LOGGER] {}".format(formatter))
        else:
            message(
                update, context,
                "Attention you can not superbanned without entering an TELEGRAM ID!"
            )
Esempio n. 2
0
def update_superban(update, context):
    bot = context.bot
    query = update.callback_query
    save_date = datetime.datetime.utcnow().isoformat()
    if query.data.startswith("m"):
        #Variables
        chat_id = query.message.chat_id
        operator_id = query.from_user.id
        operator_username = "******" + query.from_user.username
        user_id = query.message.reply_to_message.from_user.id
        motivation = query.data[1:]
        row = SuperbanRepository().getById(user_id)
        whitelist = SuperbanRepository().getWhitelistById(user_id)
        if whitelist:
            text_w = "This user is whitelisted you cannot blacklist!"
            query.edit_message_text(text_w, parse_mode='HTML')
        elif row:
            text = "Attention already superbanned user!"
            query.edit_message_text(text, parse_mode='HTML')
        else:
            data = [(user_id, motivation, save_date, operator_id)]
            SuperbanRepository().add(data)
            #Ban the User
            bot.ban_chat_member(chat_id, user_id)
            #Edit Message Text after push the button
            msg = 'You got super banned <a href="tg://user?id={}">{}</a>\nFor the following reason: <b>{}</b>\nGo to: https://squirrel-network.online/knowhere?q={} to search for blacklisted users'.format(
                user_id, user_id, motivation, user_id)
            query.edit_message_text(msg, parse_mode='HTML')
            #Telegram Logs
            logs_text = Strings.SUPERBAN_LOG.format(user_id, motivation,
                                                    save_date,
                                                    operator_username,
                                                    operator_id)
            messageWithId(update, context, Config.DEFAULT_LOG_CHANNEL,
                          logs_text)
            #System Logs
            formatter = "Superban eseguito da: {}".format(operator_id)
            sys_loggers("[SUPERBAN_LOGS]", formatter, False, False, True)
            debug_channel(update, context,
                          "[DEBUG_LOGGER] {}".format(formatter))

    if query.data == "removeSuperban":
        user_id = query.message.reply_to_message.from_user.id
        row = SuperbanRepository().getById(user_id)
        if row:
            data = [(user_id)]
            SuperbanRepository().remove(data)
            msg = "I removed the superban to user <code>{}</code>".format(
                user_id)
            query.edit_message_text(msg, parse_mode='HTML')
        else:
            query.edit_message_text("Attention this user not super banned!!!",
                                    parse_mode='HTML')
    if query.data == 'closeMenu':
        query.edit_message_text("You have closed the Menu", parse_mode='HTML')
Esempio n. 3
0
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)
Esempio n. 4
0
def init(update, context):
    bot = context.bot
    chat = chat_object(update)
    #GroupRepository.remove(chat.id)
    bot.leaveChat(update.message.chat_id)
    messageWithId(
        update, context, Config.DEFAULT_LOG_CHANNEL,
        "#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)
Esempio n. 5
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:
        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
Esempio n. 6
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!")
Esempio n. 7
0
def init(update, context):
    msg = system_status()
    message(update, context, msg)
    formatter = "Eseguito da: {}".format(update.message.from_user.id)
    sys_loggers("[SERVER_INFO_LOGS]", formatter, False, False, True)
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)
Esempio n. 9
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