def become_wizard(bot, update): current_wizards = Pycampista.select().where(Pycampista.wizard is True) for w in current_wizards: w.current = False w.save() username = update.message.from_user.username chat_id = update.message.chat_id user = Pycampista.get_or_create(username=username, chat_id=chat_id)[0] user.wizard = True user.save() bot.send_message(chat_id=update.message.chat_id, text="Felicidades! Eres el Magx de turno")
def create_slot(bot, update): username = update.message.from_user.username chat_id = update.message.chat_id text = update.message.text times = list(range(int(text) + 1))[1:] starting_hour = 10 while len(times) > 0: new_slot = Slot(code=str(DAY_LETTERS[0] + str(times[0]))) new_slot.start = starting_hour pycampista = Pycampista.get_or_create(username=username, chat_id=chat_id)[0] new_slot.current_wizzard = pycampista new_slot.save() times.pop(0) starting_hour += 1 DAY_LETTERS.pop(0) if len(DAY_LETTERS) > 0: bot.send_message(chat_id=update.message.chat_id, text="Cuantos slots tiene tu dia {}".format( DAY_LETTERS[0])) return 2 else: bot.send_message(chat_id=update.message.chat_id, text="Genial! Slots Asignados") make_schedule(bot, update) return ConversationHandler.END
def button(bot, update): '''Save user vote in the database''' query = update.callback_query username = query.message['chat']['username'] chat_id = query.message.chat_id user = Pycampista.get_or_create(username=username, chat_id=chat_id)[0] project_name = query.message['text'] # Get project from the database project = Project.get(Project.name == project_name) # create a new vote object new_vote = Vote(pycampista=user, project=project) # Save vote in the database and send a message if query.data == "si": result = 'Interesadx en: ' + project_name + ' 馃憤' new_vote.interest = True new_vote.save(force_insert=True) else: new_vote.interest = False new_vote.save(force_insert=True) result = 'No te interesa el proyecto ' + project_name bot.edit_message_text(text=result, chat_id=query.message.chat_id, message_id=query.message.message_id)
def get_admins_username(): admins = [] pycampistas = Pycampista.select() for user in pycampistas: if user.admin: admins.append(user.username) return admins
def grant_admin(bot, update): username = update.message.from_user.username chat_id = update.message.chat_id text = update.message.text parameters = text.split(' ') if not len(parameters) == 2: bot.send_message(chat_id=chat_id, text='Parametros incorrectos.') return passwrd = parameters[1] user = Pycampista.get_or_create(username=username, chat_id=chat_id)[0] if 'PYCAMP_BOT_MASTER_KEY' in os.environ.keys(): if passwrd == os.environ['PYCAMP_BOT_MASTER_KEY']: user.admin = True user.save() rply_msg = 'Ahora tenes el poder. Cuidado!' else: logger.info('Wrong attempt on getting admin privileges.') rply_msg = 'Ah ah ah, you didn\'t say the magic word.' else: logger.error('PYCAMP_BOT_MASTER_KEY env not set.') rply_msg = 'Hay un problema en el servidor, avisale a un admin.' bot.send_message(chat_id=chat_id, text=rply_msg)
def summon_wizard(bot, update): username = update.message.from_user.username try: wizard = Pycampista.get(Pycampista.wizard is True) bot.send_message( chat_id=wizard.chat_id, text="PING PING PING MAGX! @{} te necesesita!".format(username)) except Pycampista.DoesNotExist: bot.send_message( chat_id=update.chat_id, text="Hubo un accidente, el mago esta en otro plano.".format( username))
def raffle(bot, update): if not is_auth(bot, update.message.from_user.username): return bot.send_message(chat_id=update.message.chat_id, text="Voy a sortear algo entre todxs lxs Pycampistas!") bot.send_message(chat_id=update.message.chat_id, text="Y la persona ganadora eeeeeeeeeeeeessss....") pycampistas = Pycampista.select(Pycampista.username) lista_pycampistas = [persona.username for persona in pycampistas] persona_ganadora = random.choice(lista_pycampistas) bot.send_message(chat_id=update.message.chat_id, text="@{}".format(persona_ganadora))
def add_pycampista_to_pycamp(bot, update): username = update.message.from_user.username chat_id = update.message.chat_id pycampista = Pycampista.get_or_create(username=username, chat_id=chat_id)[0] parameters = update.message.text.split(' ') if len(parameters) == 2: pycamp = get_pycamp_by_name(parameters[1]) else: is_active, pycamp = get_active_pycamp() PycampistaAtPycamp.get_or_create(pycamp=pycamp, pycampista=pycampista) bot.send_message( chat_id=update.message.chat_id, text="El pycampista {} fue agregado al pycamp {}".format(username, pycamp.headquarters))
def revoke_admin(bot, update): chat_id = update.message.chat_id text = update.message.text parameters = text.split(' ') if not len(parameters) == 2: bot.send_message(chat_id=chat_id, text='Parametros incorrectos.') return fallen_admin = parameters[1] user = Pycampista.select().where(Pycampista.username == fallen_admin)[0] user.admin = False user.save() bot.send_message(chat_id=chat_id, text='Un admin a caido --{}--.'.format(fallen_admin))
def is_admin(bot, update): """Checks if the user is authorized as admin""" # authorized = ["WinnaZ", "sofide", "ArthurMarduk", "xcancerberox", "lecovi"] authorized = [ p.username for p in Pycampista.select().filter(is_admin=True) ] username = update.message.from_user.username if username not in authorized: logger.info("{} is not authorized as admin".format(username)) bot.send_message(chat_id=update.message.chat_id, text="No estas Autorizadx para hacer esta acción") return False else: logger.info("{} is authorized as admin".format(username)) return True
def owning(bot, update): '''Dialog to set project responsable''' username = update.message.from_user.username text = update.message.text chat_id = update.message.chat_id lista_proyectos = [p.name for p in Project.select()] dic_proyectos = dict(enumerate(lista_proyectos)) project_name = dic_proyectos[int(text)] new_project = Project.get(Project.name == project_name) user = Pycampista.get_or_create(username=username, chat_id=chat_id)[0] new_project.owner = user new_project.save() bot.send_message(chat_id=update.message.chat_id, text="Perfecto. Chauchi")
def start(bot, update): logger.info('Start command') chat_id = update.message.chat_id username = update.message.from_user.username user = Pycampista.get_or_create(username=username, chat_id=chat_id)[0] user.save() logger.debug("Pycampista {} agregado a la DB".format(user.username)) if username is None: bot.send_message(chat_id=chat_id, text="""Hola! Necesitas tener un username primero. \nCreate uno siguiendo esta guia: https://ewtnet.com/technology/how-to/how-to-add-a-username-on-telegram-android-app. Y despues dame /start the nuevo :) """) elif username: bot.send_message(chat_id=chat_id, text='Hola ' + username + '! Bienvenidx')
def button(bot, update): '''Save user vote in the database''' query = update.callback_query username = query.message['chat']['username'] chat_id = query.message.chat_id user = Pycampista.get_or_create(username=username, chat_id=chat_id)[0] project_name = query.message['text'] # Get project from the database project = Project.get(Project.name == project_name) # create a new vote object new_vote = Vote( pycampista=user, project=project, _project_pycampista_id="{}-{}".format(project.id, user.id), ) # Save vote in the database and send a message if query.data == "si": result = 'Interesadx en: ' + project_name + ' 馃憤' new_vote.interest = True else: new_vote.interest = False result = 'No te interesa el proyecto ' + project_name try: new_vote.save() bot.edit_message_text(text=result, chat_id=query.message.chat_id, message_id=query.message.message_id) except peewee.IntegrityError: logger.warning("Error al guardar el voto de {} del proyecto {}".format( username, project_name )) bot.edit_message_text( text="Ya hab铆as votado el proyecto {}!!".format(project_name), chat_id=query.message.chat_id, message_id=query.message.message_id )
def project_topic(bot, update): '''Dialog to set project topic''' username = update.message.from_user.username text = update.message.text new_project = current_projects[username] new_project.topic = text chat_id = update.message.chat_id user = Pycampista.get_or_create(username=username, chat_id=chat_id)[0] new_project.owner = user new_project.save() bot.send_message( chat_id=update.message.chat_id, text="Excelente {}! La temática de tu proyecto es: {}.".format( username, text)) bot.send_message(chat_id=update.message.chat_id, text="Tu proyecto ha sido cargado".format(username, text)) return ConversationHandler.END
const=datetime.datetime.now().isoformat(), help='Add pycamp end time as isoformat\ datetime. Example:\ 2020-03-11T09:40:37.577157, 2020-03-11') return parser.parse_args() if __name__ == '__main__': args = parse_args() models_db_connection() if args.wich == 'pycampista': if args.add: logging.info('Adding pycampista') pycampista = Pycampista.create(username=args.name) if args.arrive: arrive_time = datetime.datetime.fromisoformat(args.arrive) logging.info('Changing arrive time to {}'.format(arrive_time)) pycampista = Pycampista.select().where( Pycampista.username == args.name)[0] pycampista.arrive = arrive_time pycampista.save() if args.departure: departure_time = datetime.datetime.fromisoformat(args.departure) logging.info( 'Changing departure time to {}'.format(departure_time)) pycampista = Pycampista.select().where( Pycampista.username == args.name)[0]
from pycamp_bot.models import Pycampista if __name__ == "__main__": admin = input("Ingresá tu Alias de Telegram para ser admin: ") pycampistas = Pycampista.filter(username=admin) if pycampistas.count() == 1: pycampista = pycampistas[0] pycampista.is_admin = True pycampista.save() print('\033[1;32mEl usuario {} fue habilitado como admin!\033[0m'.format(admin)) else: print('\033[1;31mEl usuario ingresado no existe!\033[0m')