Example #1
0
def send_warn(bot, chat_id, user_id, job_queue, nanny_text=None):
    warning = warn_user(chat_id, user_id, 1)
    group = get_group_settings(chat_id)
    if nanny_text is not None:
        text = nanny_text + "\n"
    else:
        text = ""

    if warning < group.warn:
        text = text + "Has recibido un aviso por enviar contenido prohibido en este grupo.*{}/{}*".format(
            warning, group.warn)
    else:
        text = "Un entrenador ha sido expulsado por alcanzar el máximo de avisos."
        warn_user(chat_id, user_id, 0)
        try:
            bot.kickChatMember(chat_id, user_id)
            if group.hard is False:
                bot.unbanChatMember(chat_id, user_id)
        except:
            text = "No tengo permisos suficientes para expulsar usuarios"

    sent_message = bot.sendMessage(chat_id=chat_id,
                                   text=text,
                                   parse_mode=telegram.ParseMode.MARKDOWN)
    delete_object = support.DeleteContext(chat_id, sent_message.message_id)
    job_queue.run_once(support.callback_delete, 10, context=delete_object)
Example #2
0
def send_rules(bot, update, group_id=None):
    chat_id, chat_type, user_id, text, message = support.extract_update_info(
        update)
    support.delete_message(chat_id, message.message_id, bot)

    if group_id is None:
        try:
            chat = bot.get_chat(chat_id)
        except BadRequest as excp:
            return
        rules = rul_sql.get_rules(chat_id)
        if chat_type != "private":
            group = get_group_settings(chat_id)
            if group.reply_on_group:
                dest_id = chat_id
            else:
                dest_id = user_id
        else:
            dest_id = user_id
    else:
        try:
            chat = bot.get_chat(group_id)
            rules = rul_sql.get_rules(group_id)
            dest_id = user_id
            bot.restrict_chat_member(group_id,
                                     user_id,
                                     can_send_messages=True,
                                     can_send_media_messages=True,
                                     can_send_other_messages=True,
                                     can_add_web_page_previews=True)
        except BadRequest as excp:
            return

    text = "Normas de *{}*:\n\n{}".format(escape_markdown(chat.title), rules)

    if rules:
        bot.sendMessage(dest_id, text, parse_mode=telegram.ParseMode.MARKDOWN)
    else:
        bot.sendMessage(dest_id,
                        "❌ No hay normas establecidas en este grupo.",
                        parse_mode=telegram.ParseMode.MARKDOWN)
Example #3
0
def get_settings_keyboard(chat_id, keyboard="main"):
    if keyboard == "main":
        settings_keyboard = [
            [
                InlineKeyboardButton("👷‍♂️ Administración »",
                                     callback_data='settings_goto_ladmin')
            ],
            [
                InlineKeyboardButton("🛠 Ajustes »",
                                     callback_data='settings_goto_general')
            ],
            [
                InlineKeyboardButton("👋 Bienvenida »",
                                     callback_data='settings_goto_welcome')
            ],
            [
                InlineKeyboardButton("🚪 Entrada »",
                                     callback_data='settings_goto_join')
            ],
            [
                InlineKeyboardButton("📯 Noticias »",
                                     callback_data='settings_goto_news')
            ],
            [
                InlineKeyboardButton("🏫 Modo biblioteca »",
                                     callback_data='settings_goto_nanny')
            ],
            [InlineKeyboardButton("Terminado", callback_data='settings_done')]
        ]

    #2.GROUP SETTINGS
    elif keyboard == "general":
        group = get_group_settings(chat_id)
        if group.games == 1:
            games_text = "✅ Juegos"
        else:
            games_text = "▪️ Juegos"
        if group.hard == 1:
            hard_text = "✅ Ban (Warns)"
        else:
            hard_text = "▪️ Kick (Warns)"
        if group.reply_on_group == 1:
            reply_on_group_text = "✅ Respuestas en el grupo"
        else:
            reply_on_group_text = "▪️ Respuestas al privado"
        if group.warn is model.WarnLimit.SO_EXTRICT.value:
            warn_text = "Limite de warns: 3"
        elif group.warn is model.WarnLimit.EXTRICT.value:
            warn_text = "Limite de warns: 5"
        elif group.warn is model.WarnLimit.LOW_PERMISIVE.value:
            warn_text = "Limite de warns: 10"
        elif group.warn is model.WarnLimit.MED_PERMISIVE.value:
            warn_text = "Limite de warns: 25"
        elif group.warn is model.WarnLimit.HIGH_PERMISIVE.value:
            warn_text = "Limite de warns: 50"
        elif group.warn is model.WarnLimit.SO_TOLERANT.value:
            warn_text = "Limite de warns: 100"

        settings_keyboard = [
            [
                InlineKeyboardButton(games_text,
                                     callback_data='settings_general_games')
            ],
            [
                InlineKeyboardButton(hard_text,
                                     callback_data='settings_general_hard')
            ],
            [
                InlineKeyboardButton(reply_on_group_text,
                                     callback_data='settings_general_reply')
            ],
            [
                InlineKeyboardButton(warn_text,
                                     callback_data='settings_general_warn')
            ],
            [
                InlineKeyboardButton("« Menú principal",
                                     callback_data='settings_goto_main')
            ]
        ]

    #3.JOIN SETTINGS
    elif keyboard == "join":
        join = get_join_settings(chat_id)
        if join.requirment is model.ValidationRequiered.NO_VALIDATION.value:
            validationrequired_text = "▪️ Grupo abierto"
        elif join.requirment is model.ValidationRequiered.VALIDATION.value:
            validationrequired_text = "✅ Validación obligatoria"
        elif join.requirment is model.ValidationRequiered.PROFESSOR.value:
            validationrequired_text = "📚 Profesor"
        elif join.requirment is model.ValidationRequiered.MAGIZOOLOGIST.value:
            validationrequired_text = "🐾 Magizoologo"
        elif join.requirment is model.ValidationRequiered.AUROR.value:
            validationrequired_text = "⚔ Auror"
        elif join.requirment is model.ValidationRequiered.GRYFFINDOR.value:
            validationrequired_text = "🦁 Gryffindor"
        elif join.requirment is model.ValidationRequiered.HUFFLEPUFF.value:
            validationrequired_text = "🦡 Hufflepuff"
        elif join.requirment is model.ValidationRequiered.RAVENCLAW.value:
            validationrequired_text = "🦅 Ravenclaw"
        elif join.requirment is model.ValidationRequiered.SLYTHERIN.value:
            validationrequired_text = "🐍 Slytherin"

        if join.val_alert is True:
            mute_text = "✅ Expulsiones silenciosas"
        else:
            mute_text = "▪️ Expulsiones notificadas"

        if join.delete_header is True:
            silence_text = "✅ Borrar -> entró al grupo"
        else:
            silence_text = "▪️ Borrar -> entró al grupo"

        settings_keyboard = [
            [
                InlineKeyboardButton(mute_text,
                                     callback_data='settings_join_mute')
            ],
            [
                InlineKeyboardButton(silence_text,
                                     callback_data='settings_join_silence')
            ],
            [
                InlineKeyboardButton(validationrequired_text,
                                     callback_data='settings_join_val')
            ],
            [
                InlineKeyboardButton("« Menú principal",
                                     callback_data='settings_goto_main')
            ]
        ]

    #5.NEWS SETTINGS
    elif keyboard == "news":
        providers = get_verified_providers()
        settings_keyboard = []
        for k in providers:
            if is_news_subscribed(chat_id, k.id):
                status = "✅ @"
            else:
                status = "▪️ @"
            text = status + k.alias
            settings_keyboard.append([
                InlineKeyboardButton(text,
                                     callback_data='settings_news_{}'.format(
                                         k.id))
            ])

        settings_keyboard.append([
            InlineKeyboardButton("« Menú principal",
                                 callback_data='settings_goto_main')
        ])

    #6.WELCOME SETTINGS
    elif keyboard == "welcome":
        welcome = get_welcome_settings(chat_id)
        if welcome.should_welcome == 1:
            welcome_text = "✅ Bienvenida"
        else:
            welcome_text = "▪️ Bienvenida"
        settings_keyboard = [[
            InlineKeyboardButton(welcome_text,
                                 callback_data='settings_welcome_welcome')
        ],
                             [
                                 InlineKeyboardButton(
                                     "« Menú principal",
                                     callback_data='settings_goto_main')
                             ]]

    #7.NANNY SETTINGS
    elif keyboard == "nanny":
        nanny = get_nanny_settings(chat_id)
        if nanny is None:
            set_nanny(chat_id)
            nanny = get_nanny_settings(chat_id)

        if nanny.voice == 1:
            voice_text = "✅ Audio y Voz"
        else:
            voice_text = "▪️ Audio y Voz"
        if nanny.command == 1:
            comandos_text = "✅ Comandos"
        else:
            comandos_text = "▪️ Comandos"
        if nanny.contact == 1:
            contact_text = "✅ Contactos"
        else:
            contact_text = "▪️ Contactos"
        if nanny.animation == 1:
            animation_text = "✅ GIFs y Documentos"
        else:
            animation_text = "▪️ GIFs y Documentos"
        if nanny.photo == 1:
            photo_text = "✅ Imagenes"
        else:
            photo_text = "▪️ Imagenes"
        if nanny.games == 1:
            games_text = "✅ Juegos"
        else:
            games_text = "▪️ Juegos"
        if nanny.text == 1:
            text_text = "✅ Mensajes"
        else:
            text_text = "▪️ Mensajes"
        if nanny.sticker == 1:
            sticker_text = "✅ Stickers"
        else:
            sticker_text = "▪️ Stickers"
        if nanny.location == 1:
            location_text = "✅ Ubicaciones"
        else:
            location_text = "▪️ Ubicaciones"
        if nanny.urls == 1:
            url_text = "✅ URLs"
        else:
            url_text = "▪️ URLs"
        if nanny.video == 1:
            video_text = "✅ Video"
        else:
            video_text = "▪️ Video"
        if nanny.warn == 1:
            warn_text = "✅ Warns"
        else:
            warn_text = "▪️ Warns"
        if nanny.admin_too == 1:
            admin_too_text = "️✅ Mensajes de administradores"
        else:
            admin_too_text = "️️️▪️ Mensajes de administradores"

        settings_keyboard = [
            [
                InlineKeyboardButton(voice_text,
                                     callback_data='settings_nanny_voice')
            ],
            [
                InlineKeyboardButton(comandos_text,
                                     callback_data='settings_nanny_command')
            ],
            [
                InlineKeyboardButton(contact_text,
                                     callback_data='settings_nanny_contact')
            ],
            [
                InlineKeyboardButton(animation_text,
                                     callback_data='settings_nanny_animation')
            ],
            [
                InlineKeyboardButton(photo_text,
                                     callback_data='settings_nanny_photo')
            ],
            [
                InlineKeyboardButton(games_text,
                                     callback_data='settings_nanny_games')
            ],
            [
                InlineKeyboardButton(text_text,
                                     callback_data='settings_nanny_text')
            ],
            [
                InlineKeyboardButton(sticker_text,
                                     callback_data='settings_nanny_sticker')
            ],
            [
                InlineKeyboardButton(location_text,
                                     callback_data='settings_nanny_location')
            ],
            [
                InlineKeyboardButton(url_text,
                                     callback_data='settings_nanny_url')
            ],
            [
                InlineKeyboardButton(video_text,
                                     callback_data='settings_nanny_video')
            ],
            [
                InlineKeyboardButton(warn_text,
                                     callback_data='settings_nanny_warn')
            ],
            [
                InlineKeyboardButton(admin_too_text,
                                     callback_data='settings_nanny_admin_too')
            ],
            [
                InlineKeyboardButton("« Menú principal",
                                     callback_data='settings_goto_main')
            ]
        ]

    #8. LOCAL ADMIN
    elif keyboard == "ladmin":
        adgroup = get_particular_admin(chat_id)
        if adgroup.admin == 1:
            admin_text = "✅ @admin"
        else:
            admin_text = "▪️ @admin"
        if adgroup.welcome == 1:
            welcome_text = "✅ Entrada de usuarios"
        else:
            welcome_text = "▪️ Entrada de usuarios"
        if adgroup.ejections == 1:
            ejections_text = "✅ Expulsiones"
        else:
            ejections_text = "▪️ Expulsiones"

        settings_keyboard = [
            [
                InlineKeyboardButton(admin_text,
                                     callback_data='settings_ladmin_admin')
            ],
            [
                InlineKeyboardButton(welcome_text,
                                     callback_data='settings_ladmin_welcome')
            ],
            [
                InlineKeyboardButton(ejections_text,
                                     callback_data='settings_ladmin_ejections')
            ],
            [
                InlineKeyboardButton("« Menú principal",
                                     callback_data='settings_goto_main')
            ]
        ]

    #0. ADMIN
    elif keyboard == "admin":
        adgroup = get_admin(chat_id)
        if adgroup.admin == 1:
            admin_text = "✅ @admin"
        else:
            admin_text = "▪️ @admin"
        if adgroup.welcome == 1:
            welcome_text = "✅ Entrada de usuarios"
        else:
            welcome_text = "▪️ Entrada de usuarios"
        if adgroup.ejections == 1:
            ejections_text = "✅ Expulsiones"
        else:
            ejections_text = "▪️ Expulsiones"

        spy_mode = "🦅 Fawkes"

        settings_keyboard = [
            [
                InlineKeyboardButton(admin_text,
                                     callback_data='settings_admin_admin')
            ],
            [
                InlineKeyboardButton(welcome_text,
                                     callback_data='settings_admin_welcome')
            ],
            [
                InlineKeyboardButton(ejections_text,
                                     callback_data='settings_admin_ejections')
            ],
            [
                InlineKeyboardButton(spy_mode,
                                     callback_data='settings_admin_spy')
            ],
            [InlineKeyboardButton("Terminado", callback_data='settings_done')]
        ]

    settings_markup = InlineKeyboardMarkup(settings_keyboard)
    return settings_markup
Example #4
0
def process_group_message(bot, update, job_queue):
    chat_id, chat_type, user_id, text, message = support.extract_update_info(
        update)
    msg = update.effective_message

    if are_banned(user_id, chat_id):
        return

    group = group_sql.get_group(chat_id)
    if group is None:
        group_sql.set_group(chat_id, message.chat.title)
    if not exists_user_group(user_id, chat_id):
        set_user_group(user_id, chat_id)

    message_counter(user_id, chat_id)
    if get_group_settings(chat_id).games == True and (chat_type == 'supergroup'
                                                      or chat_type == 'group'):
        games_cmd(bot, update)

    if text is None or msg.photo is None:
        if msg and msg.document:
            nanny.process_gif(bot, update, job_queue)
            return
        elif msg and msg.contact:
            nanny.process_contact(bot, update, job_queue)
            return
        elif msg and msg.game:
            nanny.process_game(bot, update, job_queue)
            return
        elif msg and msg.location or msg.venue:
            nanny.process_ubi(bot, update, job_queue)
            return
        elif msg and msg.photo:
            nanny.process_pic(bot, update, job_queue)
            return
        elif msg and msg.sticker:
            nanny.process_sticker(bot, update, job_queue)
            return
        elif msg and msg.voice or msg.audio:
            nanny.process_voice(bot, update, job_queue)
            return
        elif msg and msg.video or msg.video_note:
            nanny.process_video(bot, update, job_queue)
            return

    if msg and msg.entities and nanny.process_url(bot, update, job_queue):
        return

    if nanny.nanny_text(bot, user_id, chat_id, message, job_queue):
        return

    if text is not None and re.search("@admin(?!\w)", text) is not None:
        replace_pogo = support.replace(user_id,
                                       message.from_user.first_name,
                                       admin=True)

        chat_text = support.message_url(message, message.message_id,
                                        message.chat.title)

        message_text = (
            "ℹ️ {}\n👤 {} ha enviado una alerta a los administradores\n\nMensaje: {}"
        ).format(chat_text, replace_pogo, text)
        for admin in bot.get_chat_administrators(chat_id):
            user = get_user(admin.user.id)
            if user is not None and user.alerts:
                bot.sendMessage(chat_id=admin.user.id,
                                text=message_text,
                                parse_mode=telegram.ParseMode.MARKDOWN,
                                disable_web_page_preview=True)
        ladmin = get_particular_admin(chat_id)
        if ladmin is not None and ladmin.admin:
            admin = get_admin_from_linked(chat_id)
            if admin is not None and admin.admin and admin.admin_bot:
                config = get_config()
                adm_bot = Bot(token=config["telegram"]["admin_token"])
                replace_pogo = support.replace(user_id,
                                               message.from_user.first_name,
                                               admin=True)
                message_text = ("ℹ️ {}\n👤 {} {}").format(
                    chat_text, replace_pogo, text)
                adm_bot.sendMessage(chat_id=admin.id,
                                    text=message_text,
                                    parse_mode=telegram.ParseMode.MARKDOWN,
                                    disable_web_page_preview=True)
            elif admin is not None and admin.admin:
                replace_pogo = support.replace(user_id,
                                               message.from_user.first_name,
                                               admin=True)
                message_text = ("ℹ️ {}\n👤 {} {}").format(
                    chat_text, replace_pogo, text)
                bot.sendMessage(chat_id=admin.id,
                                text=message_text,
                                parse_mode=telegram.ParseMode.MARKDOWN,
                                disable_web_page_preview=True)