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)
def send_alert(bot, chat_id, job_queue, nanny_text=None): if nanny_text is None: text = ("Shhhh... Lo siento pero aquí no puedes enviar " "este tipo de mensaje por este grupo.\n\n_(Es" "te mensaje se borrará en unos segundos)_") else: text = nanny_text 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)
def gh_btn(bot, update, job_queue): query = update.callback_query data = query.data user = update.effective_user user_id = query.from_user.id text = query.message.text chat_id = query.message.chat.id message_id = query.message.message_id name = query.message.venue.title lat = query.message.location.latitude lon = query.message.location.longitude coords = str(lat) + ", " + str(lon) if are_banned(user_id, chat_id): return queryData = data.split("_") userBtn = queryData[4] if userBtn == str(user_id) or support.is_admin(chat_id, user_id, bot): if queryData[1] == "addplant": bot.delete_message(chat_id=chat_id, message_id=message_id) poi_list = get_poi_list(chat_id, PortalType.GREENHOUSE.value) poi_sorted = sort_list(poi_list, coords) button_list = [] if len(poi_sorted) >= 1: button_list.append([ InlineKeyboardButton( poi_sorted[0].name, callback_data='gh_addubi_{0}_{1}_{2}_{3}'.format( poi_sorted[0].id, queryData[2], user_id, queryData[3])) ]) if len(poi_sorted) >= 2: button_list.append([ InlineKeyboardButton( poi_sorted[1].name, callback_data='gh_addubi_{0}_{1}_{2}_{3}'.format( poi_sorted[1].id, queryData[2], user_id, queryData[3])) ]) if len(poi_sorted) >= 3: button_list.append([ InlineKeyboardButton( poi_sorted[2].name, callback_data='gh_addubi_{0}_{1}_{2}_{3}'.format( poi_sorted[2].id, queryData[2], user_id, queryData[3])) ]) if len(poi_sorted) >= 4: button_list.append([ InlineKeyboardButton( poi_sorted[3].name, callback_data='gh_addubi_{0}_{1}_{2}_{3}'.format( poi_sorted[3].id, queryData[2], user_id, queryData[3])) ]) if len(poi_sorted) >= 5: button_list.append([ InlineKeyboardButton( poi_sorted[4].name, callback_data='gh_addubi_{0}_{1}_{2}_{3}'.format( poi_sorted[4].id, queryData[2], user_id, queryData[3])) ]) button_list.append([ InlineKeyboardButton( "❌ Cancelar", callback_data='gh_cancel_._._{}'.format(user_id)) ]) plant = support.replace_plants(int(queryData[2])) bot.send_venue(chat_id=chat_id, title=plant + " " + queryData[3], address="¿En qué invernadero está plantado?", latitude=lat, longitude=lon, reply_markup=InlineKeyboardMarkup(button_list)) return elif queryData[1] == "addubi": userTime = datetime.strptime(queryData[5], '%H:%M') group = get_group(chat_id) group_tz = group.timezone tz = pytz.timezone(group_tz) userDatetime = datetime.now().replace(hour=userTime.hour, minute=userTime.minute, second=0) userAsLocal = tz.localize(userDatetime) userAsLocal = userAsLocal.astimezone(pytz.utc) ''' if datetime.now(pytz.utc) > userAsLocal: userAsLocal = userAsLocal + timedelta(days=1) ''' userAsLocal15 = userAsLocal - timedelta(minutes=15) userAsLocalDeletePlant = userAsLocal + timedelta(minutes=30) userAsLocal15 = userAsLocal15.time() userAsLocalTime = userAsLocal.time() userAsLocalDPTime = userAsLocalDeletePlant.time() plant = support.replace_plants(int(queryData[3])) setPlant = set_plant(queryData[2], queryData[3], chat_id, userDatetime, userAsLocalDeletePlant) thePlant = get_plant(setPlant) poi = get_poi(queryData[2]) ap_object = support.AlertPlantContext( chat_id, "¡Magos de *{0}*, en 15 minutos se podrá recoger *{1}* en [{2}](https://maps.google.com/maps?q={3},{4})!" .format(query.message.chat.title, plant, poi.name, poi.latitude, poi.longitude), False, thePlant.id) job_queue.run_once(support.callback_AlertPlant, userAsLocal15, context=ap_object, name="{}_plantJob15".format(thePlant.id)) ap_object = support.AlertPlantContext( chat_id, "¡Magos de *{0}*, ya se puede recoger *{1}* en [{2}](https://maps.google.com/maps?q={3},{4})!" .format(query.message.chat.title, plant, poi.name, poi.latitude, poi.longitude), True, thePlant.id) job_queue.run_once(support.callback_AlertPlant, userAsLocalTime, context=ap_object, name="{}_plantJob".format(thePlant.id)) dp_object = support.DeletePlantContext(thePlant.id) job_queue.run_once(support.callback_DeletePlant, userAsLocalDPTime, context=dp_object, name="{}_plantJobDelete".format(thePlant.id)) bot.delete_message(chat_id=chat_id, message_id=message_id) success_message = bot.sendMessage( chat_id=chat_id, text="🌱 Plantación añadida correctamente.", parse_mode=telegram.ParseMode.MARKDOWN) delete_object = support.DeleteContext(chat_id, success_message.message_id) job_queue.run_once(support.callback_delete, 10, context=delete_object) support.save_jobs(job_queue) return elif queryData[1] == "cancel": bot.delete_message(chat_id=chat_id, message_id=message_id) return else: bot.answer_callback_query( callback_query_id=query.id, text= "Sólo un administrador o el usuario que ha creado el aviso puede pulsar ese botón.", show_alert=True)
def joined_chat(bot, update, job_queue): chat_id, chat_type, user_id, text, message = support.extract_update_info( update) new_chat_member = message.new_chat_members[ 0] if message.new_chat_members else None config = get_config() bot_alias = config['telegram']['bot_alias'] if new_chat_member.username == bot_alias: if are_banned(user_id, chat_id): bot.leaveChat(chat_id=chat_id) return chat_title = message.chat.title chat_id = message.chat.id group = group_sql.get_real_group(chat_id) if group is None: group_sql.set_group(chat_id, message.chat.title) message_text = ("Si necesitais ayuda podéis lanzar chispas rojas c" "on vuestra varita o utilizando el comando `/help`" " para conocer todas las funciones. Aseguraos de v" "er la ayuda para prefectos de los grupos, donde s" "e explica en detalle todos los pasos que se deben" " seguir.".format(escape_markdown(chat_title))) admin = get_admin(chat_id) if admin is not None and admin.admin_bot is True: set_admin_settings(chat_id, "admin_bot") message_text = message_text + "\n\n*Fawkes emprendió el vuelo.*" bot.sendMessage(chat_id=chat_id, text=message_text, parse_mode=telegram.ParseMode.MARKDOWN) elif new_chat_member.username != bot_alias: chat_id = message.chat.id user_id = update.effective_message.new_chat_members[0].id group = get_join_settings(chat_id) if group is not None: if group.delete_header: support.delete_message(chat_id, message.message_id, bot) if are_banned(user_id, user_id): bot.kickChatMember(chat_id, user_id) return user = get_user(user_id) if user is None and group.requirment is not ValidationRequiered.NO_VALIDATION.value: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago sin registrarse expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") return elif group.requirment is ValidationRequiered.VALIDATION.value and user.level is None: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.PROFESSOR.value and user.profession is not Professions.PROFESSOR.value: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.MAGIZOOLOGIST.value and user.profession is not Professions.MAGIZOOLOGIST.value: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.AUROR.value and user.profession is not Professions.AUROR.value: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.GRYFFINDOR.value and user.house is not Houses.GRYFFINDOR.value: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.HUFFLEPUFF.value and user.house is not Houses.HUFFLEPUFF.value: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.RAVENCLAW.value and user.house is not Houses.RAVENCLAW.value: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return elif group.requirment is ValidationRequiered.SLYTHERIN.value and user.house is not Houses.SLYTHERIN.value: bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) if group.val_alert is False: output = "👌 Mago infiltrado expulsado!" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) good_luck(bot, chat_id, message, "El usuario no está registrado") try: bot.sendMessage( chat_id=user_id, text="❌ Debes validarte para entrar en este grupo", parse_mode=telegram.ParseMode.MARKDOWN) except Exception: pass return if group.max_members is not None and group.max_members > 0 and bot.get_chat_members_count( chat_id) >= group.max_members: if group.val_alert is False: output = "❌ El número máximo de integrantes en el grupo ha sido alcanzado" sent = bot.sendMessage( chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN) delete_object = support.DeleteContext( chat_id, sent.message_id) job_queue.run_once(support.callback_delete, 10, context=delete_object) time.sleep(2) bot.kickChatMember(chat_id=chat_id, user_id=user_id, until_date=time.time() + 31) return if (not exists_user_group(user_id, chat_id)): set_user_group(user_id, chat_id) else: join_group(user_id, chat_id) if has_rules(chat_id): bot.restrict_chat_member(chat_id, user_id, until_date=0, can_send_messages=False, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) if get_welc_pref(chat_id): sent = send_welcome(bot, update) if sent is not None and group.delete_cooldown is not None and group.delete_cooldown > 0: delete_object = support.DeleteContext( chat_id, sent.message_id) job_queue.run_once(support.callback_delete, group.delete_cooldown, context=delete_object) ''' if group.val_alert and (user is None or user.level is None): sent = bot.sendMessage( chat_id=chat_id, text="", parse_mode=telegram.ParseMode.MARKDOWN ) if sent is not None: delete_object = support.DeleteContext(chat_id, sent.message_id) job_queue.run_once( support.callback_delete, group.delete_cooldown or 60, context=delete_object ) ''' ladmin = get_particular_admin(chat_id) if ladmin is not None and ladmin.welcome: admin = get_admin_from_linked(chat_id) if admin is not None and admin.welcome 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👤 {} ha entrado en el grupo").format( message.chat.title, replace_pogo) adm_bot.sendMessage(chat_id=admin.id, text=message_text, parse_mode=telegram.ParseMode.MARKDOWN) elif admin is not None and admin.welcome: replace_pogo = support.replace( user_id, message.from_user.first_name, admin=True) message_text = ( "ℹ️ {}\n👤 {} ha entrado en el grupo").format( message.chat.title, replace_pogo) bot.sendMessage(chat_id=admin.id, text=message_text, parse_mode=telegram.ParseMode.MARKDOWN)
def rps_user_cmd(bot, update, job_queue, args=None): (chat_id, chat_type, user_id, text, message) = support.extract_update_info(update) username = update.effective_user.username support.delete_message(chat_id, message.message_id, bot) if update.effective_user.username is None: return if not is_staff(user_id): return if args is not None and len(args) > 0: if message.reply_to_message is not None: vs_user = message.reply_to_message.from_user if vs_user.username is None: sent = bot.sendMessage( chat_id=chat_id, text='Ese usuario no tiene una @.', disable_notification=True) delete_object = support.DeleteContext(chat_id, sent.message_id) job_queue.run_once( support.callback_delete, 10, context=delete_object) return if vs_user.id == user_id: bot.sendMessage( chat_id=chat_id, text='Necesitas a alguien más para jugar.', disable_notification=True) return if vs_user.is_bot == True: bot.sendMessage( chat_id=chat_id, text='No puedes jugar contra un bot.', disable_notification=True) return if args[0].lower() == "piedra": b1 = "g*rps_us_r_r_" + str(user_id) b2 = "g*rps_us_p_r_" + str(user_id) b3 = "g*rps_us_s_r_" + str(user_id) elif args[0].lower() == "papel": b1 = "g*rps_us_r_p_" + str(user_id) b2 = "g*rps_us_p_p_" + str(user_id) b3 = "g*rps_us_s_p_" + str(user_id) elif args[0].lower() == "tijera": b1 = "g*rps_us_r_s_" + str(user_id) b2 = "g*rps_us_p_s_" + str(user_id) b3 = "g*rps_us_s_s_" + str(user_id) else: sent = bot.sendMessage( chat_id=chat_id, text='No has escrito una de las opciones posibles (piedra, papel, tijera).', disable_notification=True) delete_object = support.DeleteContext(chat_id, sent.message_id) job_queue.run_once( support.callback_delete, 10, context=delete_object) return markup = [ [InlineKeyboardButton(text="Piedra", callback_data=b1)], [InlineKeyboardButton(text="Papel", callback_data=b2)], [InlineKeyboardButton(text="Tijera", callback_data=b3)]] bot.sendMessage( chat_id=chat_id, text='@' + username + ' ha retado a @' + vs_user.username + ' a Piedra, Papel o Tijera! \n ¿Qué eliges?', disable_notification=True, reply_markup=InlineKeyboardMarkup(markup)) else: bot.sendMessage( chat_id=chat_id, text='Tienes que responder al mensaje de otro usuario para poder retarlo.', disable_notification=True) else: bot.sendMessage( chat_id=chat_id, text='No has escrito una de las opciones posibles (piedra, papel, tijera).', disable_notification=True)