def replace(user_id, name=None, admin=False, frce=False): if frce: user = get_real_user(user_id) else: user = get_user(user_id) if user is None or user.house is model.Houses.NONE.value and ( user.level is None or user.profession is model.Professions.NONE.value): text_house = "🖤" elif user.house is model.Houses.NONE.value: text_house = "🙈" elif user.house is model.Houses.GRYFFINDOR.value: text_house = "🦁" elif user.house is model.Houses.HUFFLEPUFF.value: text_house = "🦡" elif user.house is model.Houses.RAVENCLAW.value: text_house = "🦅" elif user.house is model.Houses.SLYTHERIN.value: text_house = "🐍" elif user.house is model.Houses.BOTS.value: text_house = "💻" if user is None or user.profession is model.Professions.NONE.value: text_prof = "_Desconocida_" elif user.profession is model.Professions.AUROR.value: text_prof = "⚔" elif user.profession is model.Professions.MAGIZOOLOGIST.value: text_prof = "🐾" elif user.profession is model.Professions.PROFESSOR.value: text_prof = "📚" elif user.profession is model.Professions.BOT.value: text_prof = "🤖" if user and user.alias is not None: text_alias = escape_markdown("@{}".format(user.alias)) elif name is not None: text_alias = f"[{escape_markdown(name)}](tg://user?id={user_id})" else: text_alias = "_Desconocido_" text_level = ("*{}*".format(user.level) if user and user.level else "*??*") text_validationstatus = "✅" if user and user.banned: text_validationstatus = "⛔️" if user and user.flag is not None: text_flag = f"{user.flag} " else: text_flag = "" replace_pogo = "{0} - *L*{1} {2} {3} {4} {5}".format( text_alias, text_level, text_prof, text_house, text_validationstatus, text_flag) if admin: replace_pogo = replace_pogo + " `{0}`".format(user_id) return replace_pogo
def sighting_cmd(bot, update): chat_id, chat_type, user_id, text, message = support.extract_update_info( update) username = message.from_user.username support.delete_message(chat_id, message.message_id, bot) if are_banned(user_id, chat_id): return user = get_real_user(user_id) if user is None: bot.sendMessage(chat_id=chat_id, text="❌ Debes registrarte para usar este comando.", parse_mode=telegram.ParseMode.MARKDOWN) return if message.reply_to_message is not None: if message.reply_to_message.location is not None: support.delete_message(chat_id, message.reply_to_message.message_id, bot) lat = message.reply_to_message.location.latitude lon = message.reply_to_message.location.longitude group = get_group(chat_id) group_tz = group.timezone tz = pytz.timezone(group_tz) localTime = datetime.now().replace(tzinfo=pytz.utc) groupDateTime = localTime.astimezone(tz) groupTime = groupDateTime.time() button_list = [ [ InlineKeyboardButton( text="📍 Ubicación", callback_data='sighting_ubi_{0}_{1}'.format(lat, lon)) ], [ InlineKeyboardButton( text="🙋♀️ ¡Está!", callback_data='sighting_yes_{0}_{1}'.format(lat, lon)), InlineKeyboardButton( text="🙅♀️ No está...", callback_data='sighting_no_{0}_{1}'.format(lat, lon)) ] ] output = text.split(None, 1) out = "🐾 " + escape_markdown( output[1] ) + f"\n\n👤 Avistado por @{username} a las {groupTime.hour:02}:{groupTime.minute:02}\nℹ️ Información:" bot.sendMessage(chat_id=chat_id, text=out, reply_markup=InlineKeyboardMarkup(button_list))
def plants_list_cmd(bot, update, args=None): chat_id, chat_type, user_id, text, message = support.extract_update_info( update) support.delete_message(chat_id, message.message_id, bot) if are_banned(chat_id, user_id): return user = get_real_user(user_id) if user is None: bot.sendMessage(chat_id=chat_id, text="❌ Debes registrarte para usar este comando.", parse_mode=telegram.ParseMode.MARKDOWN) return text = "Lista de plantaciones en *{}*:\n".format(message.chat.title) plants_list = get_plant_list(chat_id) if not list(plants_list): bot.sendMessage(chat_id=user_id, text="❌ No hay plantaciones registradas.", parse_mode=telegram.ParseMode.MARKDOWN, disable_web_page_preview=True) return count = 0 for plant in plants_list: plantName = support.replace_plants(plant.plant_type) poi = get_poi(plant.portal) if plant.alerted: text = text + "\n- #{0} *{1}* - ⚠️ {2} ⚠️ - [{3}](https://maps.google.com/maps?q={4},{5})".format( plant.id, plantName, f"{plant.grow_end.hour:02}:{plant.grow_end.minute:02}", poi.name, poi.latitude, poi.longitude) else: text = text + "\n- #{0} *{1}* - {2} - [{3}](https://maps.google.com/maps?q={4},{5})".format( plant.id, plantName, f"{plant.grow_end.hour:02}:{plant.grow_end.minute:02}", poi.name, poi.latitude, poi.longitude) count += 1 if count == 100: pass bot.sendMessage(chat_id=user_id, text=text, parse_mode=telegram.ParseMode.MARKDOWN, disable_web_page_preview=True)
def add_ingredients_cmd(bot, update, args=None): chat_id, chat_type, user_id, text, message = support.extract_update_info( update) support.delete_message(chat_id, message.message_id, bot) if are_banned(chat_id, user_id): return user = get_real_user(user_id) if user is None: bot.sendMessage(chat_id=chat_id, text="❌ Debes registrarte para usar este comando.", parse_mode=telegram.ParseMode.MARKDOWN) return if args is not None and len(args) > 0: if message.reply_to_message is not None: if message.reply_to_message.location is not None: support.delete_message(chat_id, message.reply_to_message.message_id, bot) lat = message.reply_to_message.location.latitude lon = message.reply_to_message.location.longitude reg = re.match( r"(([0-1]?[0-9])|([0-9])|([2][0-3])):([0-5][0-9])", args[0]).group() if reg: button_list = [ [ InlineKeyboardButton( "Ajenjo", callback_data='gh_addplant_1_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Campanilla de invierno", callback_data='gh_addplant_2_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Grano de sopóforo", callback_data='gh_addplant_3_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Raíz de jengibre", callback_data='gh_addplant_4_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Coclearia", callback_data='gh_addplant_5_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Raíz de valeriana", callback_data='gh_addplant_6_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Raíz amarga", callback_data='gh_addplant_7_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Ligústico", callback_data='gh_addplant_8_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Tármica", callback_data='gh_addplant_9_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Hongo saltarín", callback_data='gh_addplant_10_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Cristoforiana", callback_data='gh_addplant_11_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "Trompeta de ángel", callback_data='gh_addplant_12_{0}_{1}'.format( reg, user_id)) ], [ InlineKeyboardButton( "❌ Cancelar", callback_data='gh_cancel_._._{}'.format( user_id)) ] ] bot.send_venue( chat_id=chat_id, title=reg, address="¿Qué planta hay en el invernadero?", latitude=lat, longitude=lon, reply_markup=InlineKeyboardMarkup(button_list))
def rem_plant_cmd(bot, update, job_queue, args=None): chat_id, chat_type, user_id, text, message = support.extract_update_info( update) support.delete_message(chat_id, message.message_id, bot) if are_banned(chat_id, user_id) or not support.is_admin(chat_id, user_id, bot): return user = get_real_user(user_id) if user is None: bot.sendMessage(chat_id=chat_id, text="❌ Debes registrarte para usar este comando.", parse_mode=telegram.ParseMode.MARKDOWN) return if args is not None and len(args) != 0: if re.match(r"^[0-9]{0,10}$", args[0]): try: alert15PlantJob = job_queue.get_jobs_by_name( "{}_plantJob15".format(args[0])) alert15PlantJob[0].schedule_removal() except: pass try: alertPlantJob = job_queue.get_jobs_by_name( "{}_plantJob".format(args[0])) alertPlantJob[0].schedule_removal() except: pass try: deletePlantJob = job_queue.get_jobs_by_name( "{}_plantJobDelete".format(args[0])) deletePlantJob[0].schedule_removal() except: pass support.save_jobs(job_queue) if delete_plant(plant_id=args[0], group_id=chat_id): text = "Plantación eliminada correctamente." else: text = "❌ No se pudo eliminar la plantación." bot.sendMessage(chat_id=chat_id, text=text, parse_mode=telegram.ParseMode.MARKDOWN) elif args[0] == "all": plants = delete_plant(group_id=chat_id, group=True) for plant in plants: try: alert15PlantJob = job_queue.get_jobs_by_name( "{}_plantJob15".format(plant.id)) alert15PlantJob[0].schedule_removal() except: continue try: alertPlantJob = job_queue.get_jobs_by_name( "{}_plantJob".format(plant.id)) alertPlantJob[0].schedule_removal() except: continue try: deletePlantJob = job_queue.get_jobs_by_name( "{}_plantJobDelete".format(plant.id)) deletePlantJob[0].schedule_removal() except: continue support.save_jobs(job_queue) bot.sendMessage( chat_id=chat_id, text="Todas las plantaciones eliminadas correctamente.", parse_mode=telegram.ParseMode.MARKDOWN)
def staff_register_cmd(bot, update, args=None): (chat_id, chat_type, user_id, text, message) = support.extract_update_info(update) support.delete_message(chat_id, message.message_id, bot) if not is_staff(user_id): return if len(args) == 0: return if message.reply_to_message is not None: replied_userid = message.reply_to_message.from_user.id if message.reply_to_message.from_user.username is None: replied_username = "******" else: replied_username = support.ensure_escaped(message.reply_to_message.from_user.username) user_username = message.from_user.username else: return if args == None or len(args)>5: logging.debug("%s", len(args)) bot.sendMessage( chat_id=chat_id, text="Has puesto demasiadas opciones, o ninguna.", parse_mode=telegram.ParseMode.MARKDOWN) return output="🧙 [{0}](tg://user?id={1}) made changes to [{2}](tg://user?id={3}):".format( message.from_user.first_name, message.from_user.id, replied_username, replied_userid ) user = get_real_user(replied_userid) if user is None: set_user(replied_userid) alias = None level = None profession = None house = None team = None validation = None for arg in args: if arg=="v": validation = True change="\n- Validation set to *validated*" elif arg.lower() in ["p","m","a","bot"]: if arg=="p": profession = model.Professions.PROFESSOR.value change="\n- Profession set to *Professor*" elif arg=="m": profession = model.Professions.MAGIZOOLOGIST.value change="\n- Profession set to *Magizoologist*" elif arg=="a": profession = model.Professions.AUROR.value change="\n- Profession set to *Auror*" elif arg=="bot": profession = model.Professions.BOT.value change="\n- Profession set to *Bot*" elif arg.lower() in ["n","g","h","r","s","bothouse"]: if arg=="n": house = model.Houses.NONE.value change="\n- House set to *None*" elif arg=="g": house = model.Houses.GRYFFINDOR.value change="\n- House set to *Gryffindor*" elif arg=="h": house = model.Houses.HUFFLEPUFF.value change="\n- House set to *Hufflepuff*" elif arg=="r": house = model.Houses.RAVENCLAW.value change="\n- House set to *Ravenclaw*" elif arg=="s": house = model.Houses.SLYTHERIN.value change="\n- House set to *Slytherin*" elif arg=="bothouse": house = model.Houses.BOTS.value change="\n- House set to *Bots*" elif arg.isdigit() and int(arg) >= 1 and int(arg) <= 60: level = int(arg) change="\n- Level set to *{}*".format(level) elif re.match(r'[a-zA-Z0-9]{3,30}$', arg) is not None: alias = arg change="\n- Alias set to *{}*".format(alias) else: change="\n- *{}* was not a valid argument and was skipped.".format(arg) output="{}{}".format(output,change) try: commit_user(user_id=replied_userid, alias=alias, level=level, profession=profession, house=house, team=team, validation=validation) except: output="Huh... Se ha roto algo en el proceso @Sarayalth" bot.sendMessage(chat_id=chat_id, text=output, parse_mode=telegram.ParseMode.MARKDOWN)
def fort_list_cmd(bot, update, args=None): chat_id, chat_type, user_id, text, message = support.extract_update_info( update) support.delete_message(chat_id, message.message_id, bot) if are_banned(chat_id, user_id): return user = get_real_user(user_id) if user is None: bot.sendMessage(chat_id=chat_id, text="❌ Debes registrarte para usar este comando.", parse_mode=telegram.ParseMode.MARKDOWN) return if args is not None and len(args) > 0: if message.reply_to_message is not None: if message.reply_to_message.location is not None: support.delete_message(chat_id, message.reply_to_message.message_id, bot) lat = message.reply_to_message.location.latitude lon = message.reply_to_message.location.longitude coords = str(lat) + ", " + str(lon) if re.match(r"(([0-1]?[0-9])|([0-9])|([2][0-3])):([0-5][0-9])", args[0]): regDay = None reg = re.match( r"(([0-1]?[0-9])|([0-9])|([2][0-3])):([0-5][0-9])", args[0]).group() elif re.match( r"(([0-2][0-9])|([1-9])|([3][0-1]))\/(([0-1]?[0-9])|([0-9])|([2][0-3])):([0-5][0-9])", args[0]): reg = None regDay = re.match( r"(([0-2][0-9])|([1-9])|([3][0-1]))\/(([0-1]?[0-9])|([0-9])|([2][0-3])):([0-5][0-9])", args[0]).group() if reg: poi_list = get_poi_list(chat_id, PortalType.FORTRESS.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='fort_addubi_{0}_{1}_{2}'.format( poi_sorted[0].id, user_id, reg)) ]) if len(poi_sorted) >= 2: button_list.append([ InlineKeyboardButton( poi_sorted[1].name, callback_data='fort_addubi_{0}_{1}_{2}'.format( poi_sorted[1].id, user_id, reg)) ]) if len(poi_sorted) >= 3: button_list.append([ InlineKeyboardButton( poi_sorted[2].name, callback_data='fort_addubi_{0}_{1}_{2}'.format( poi_sorted[2].id, user_id, reg)) ]) if len(poi_sorted) >= 4: button_list.append([ InlineKeyboardButton( poi_sorted[3].name, callback_data='fort_addubi_{0}_{1}_{2}'.format( poi_sorted[3].id, user_id, reg)) ]) if len(poi_sorted) >= 5: button_list.append([ InlineKeyboardButton( poi_sorted[4].name, callback_data='fort_addubi_{0}_{1}_{2}'.format( poi_sorted[4].id, user_id, reg)) ]) button_list.append([ InlineKeyboardButton( "❌ Cancelar", callback_data='fort_cancel_{}'.format(user_id)) ]) bot.send_venue( chat_id=chat_id, title=reg, address="¿En qué fortaleza vais a quedar?", latitude=lat, longitude=lon, reply_markup=InlineKeyboardMarkup(button_list)) return elif regDay: poi_list = get_poi_list(chat_id, PortalType.FORTRESS.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='fort_addubi_{0}_{1}_{2}'.format( poi_sorted[0].id, user_id, regDay)) ]) if len(poi_sorted) >= 2: button_list.append([ InlineKeyboardButton( poi_sorted[1].name, callback_data='fort_addubi_{0}_{1}_{2}'.format( poi_sorted[1].id, user_id, regDay)) ]) if len(poi_sorted) >= 3: button_list.append([ InlineKeyboardButton( poi_sorted[2].name, callback_data='fort_addubi_{0}_{1}_{2}'.format( poi_sorted[2].id, user_id, regDay)) ]) if len(poi_sorted) >= 4: button_list.append([ InlineKeyboardButton( poi_sorted[3].name, callback_data='fort_addubi_{0}_{1}_{2}'.format( poi_sorted[3].id, user_id, regDay)) ]) if len(poi_sorted) >= 5: button_list.append([ InlineKeyboardButton( poi_sorted[4].name, callback_data='fort_addubi_{0}_{1}_{2}'.format( poi_sorted[4].id, user_id, regDay)) ]) button_list.append([ InlineKeyboardButton( "❌ Cancelar", callback_data='fort_cancel_{}'.format(user_id)) ]) bot.send_venue( chat_id=chat_id, title=regDay, address="¿En qué fortaleza vais a quedar?", latitude=lat, longitude=lon, reply_markup=InlineKeyboardMarkup(button_list)) return bot.sendMessage( chat_id=chat_id, text="❌ Debes responder a una ubicación para crear la fortaleza.", parse_mode=telegram.ParseMode.MARKDOWN) else: bot.sendMessage( chat_id=chat_id, text="❌ Debes indicar una hora para crear la fortaleza.", parse_mode=telegram.ParseMode.MARKDOWN)