Example #1
0
def recull(update, context):
    # if update.effective_chat.type == 'private':
    message_parts = update.message.text.split()
    if manage_users(context, update.message.from_user.id, config.GROUP_ID):
        try:
            total_test = int(message_parts[2])
        except (ValueError, TypeError):
            total_test = 0
            context.bot.send_message(chat_id=update.effective_chat.id, text='Error de format')
        requested_polls = dataManager.get_group_test(message_parts[1].strip(), total_test)
        if update.effective_chat.type == 'private':
            if len(requested_polls) < 1:
                context.bot.send_message(chat_id=update.effective_chat.id, text="No hi han enquestes d'aquest recull")
            else:
                send_polls(context, update.effective_user.id, requested_polls)
        else:
            if dataManager.is_impugnator(update.message.from_user.id):
                if len(requested_polls) < 1:
                    context.bot.send_message(chat_id=update.effective_chat.id,
                                             text="No hi han enquestes d'aquest recull")
                else:
                    send_polls(context, config.GROUP_ID, requested_polls)
            else:
                context.bot.send_message(chat_id=update.effective_chat.id,
                                         text=random.choice(UNAUTHORIZED_JOKES))
    else:
        context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(UNAUTHORIZED_JOKES))
Example #2
0
def pendents(update, context):
    message_parts = update.message.text.split()
    if manage_users(context, update.message.from_user.id, config.GROUP_ID):
        if len(message_parts) < 3:
            context.bot.send_message(chat_id=update.effective_chat.id, text='Digues un número final')
        else:
            try:
                first_id = int(message_parts[1])
                last_id = int(message_parts[2])
            except (ValueError, TypeError):
                first_id = 0
                last_id = 0
                context.bot.send_message(chat_id=update.effective_chat.id, text='Error de format')

            polls_pendents = dataManager.get_pendents(first_id, last_id)
            if len(polls_pendents) > 0:
                if update.effective_chat.type == 'private':
                    send_polls(context, update.effective_user.id, polls_pendents)
                else:
                    if dataManager.is_impugnator(update.message.from_user.id):
                        send_polls(context, config.GROUP_ID, polls_pendents)
                    else:
                        context.bot.send_message(chat_id=update.effective_chat.id,
                                                 text=random.choice(UNAUTHORIZED_JOKES))

            else:
                context.bot.send_message(chat_id=update.effective_chat.id,
                                         text='No hi ha enquestes de les seleccionades ')
    else:
        context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(UNAUTHORIZED_JOKES))
Example #3
0
def start_weekly(update, context_passed):
    if dataManager.is_impugnator(update.message.from_user.id):
        context_passed.job_queue.run_daily(callback=check_weekly, time=datetime.time(0, 0, 0),days=[0], context= context_passed, name='weekly')
        context_passed.bot.send_message(chat_id=update.message.chat_id, text='https://media.giphy.com/media/1qnuGtWiouZUI/giphy.gif')
        context_passed.bot.send_message(chat_id=update.message.chat_id, text='Comença el joc!')
        context_passed.bot.send_message(chat_id=update.message.chat_id, text='El mínim de preguntes setmanals son: {}'.format(str(config.MIN_WEEKLY_POLLS)))
    else:
        context_passed.bot.send_message(chat_id=update.message.chat_id, text=random.choice(UNAUTHORIZED_JOKES))
Example #4
0
def xulla_pro(update, context):
    if manage_users(context, update.message.from_user.id, config.GROUP_ID):
        if update.effective_chat.type == 'private' or dataManager.is_impugnator(update.message.from_user.id):
            message = 'Comandos: \n /test TEMA num \n /simulacre num \n /recull TIPUS num \n /pendents INICI FINAL \n /enquesta num \n/stats \n \nTipus de reculls: '
            for sim, name in config.TEST_GROUP.items():
                message += "\n {0} : {1} ".format(sim, name)
            context.bot.send_message(chat_id=update.effective_chat.id, text=message)
    else:
        context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(UNAUTHORIZED_JOKES))
Example #5
0
def add_member(update, context):
    if dataManager.is_impugnator(update.message.from_user.id):
        username = "******".join(update.message.text.split()[1:])
        userid = get_user_id(context, username)
        if userid != 0:
            old = dataManager.add_member(userid)
            context.bot.send_message(chat_id=update.message.chat_id,text=("Usuari {} afegit a la bbdd d'usuaris").format(username))
        else:
            context.bot.send_message(chat_id=update.message.chat_id,text=('Usuari {} no trobat').format(username))
    else:
        context.bot.send_message(chat_id=update.message.chat_id,text=random.choice(UNAUTHORIZED_JOKES))
Example #6
0
def remove_impugnator(update, context):
    if dataManager.is_impugnator(update.message.from_user.id):
        username = "******".join(update.message.text.split()[1:])
        userid = get_user_id(context, username)
        if userid != 0:
            old = dataManager.set_new_impugnator(True, userid)
            context.bot.send_message(chat_id=update.message.chat_id,text=('Usuari {} llevat dels impugnators').format(username))
        else:
            context.bot.send_message(chat_id=update.message.chat_id,text=('Usuari {} no trobat').format(username))
    else:
        context.bot.send_message(chat_id=update.message.chat_id,text=random.choice(UNAUTHORIZED_JOKES))
Example #7
0
def remove_ban_user(update, context):
    if dataManager.is_impugnator(update.message.from_user.id):   
        username = "******".join(update.message.text.split()[1:])
        userid = get_user_id(context, username)
        if userid != 0:
            banned = dataManager.ban_new_user(False, userid)
            context.bot.send_message(chat_id=update.message.chat_id, text='Ban llevat al usuari {}'.format(username))
        else:
            context.bot.send_message(chat_id=update.message.chat_id, text='Usuari {} no trobat'.format(username))
    else:
        context.bot.send_message(chat_id=update.message.chat_id, text=random.choice(UNAUTHORIZED_JOKES))
Example #8
0
def user_info(update, context):
    if dataManager.is_impugnator(update.message.from_user.id):
        username = "******".join(update.message.text.split()[1:])
        userid = get_user_id(context, username)
        if userid != 0:
            user_info_data = dataManager.check_user(userid)
            message = "Informació del usuari {}: \n".format(username)
            for data_name, data_info in user_info_data.items():
                message += "\n" + str(data_name) + ": " + str(data_info)
            context.bot.send_message(chat_id=update.message.chat_id,text=message)
        else:
            context.bot.send_message(chat_id=update.message.chat_id,text=('Usuari {} no trobat').format(username))
    else:
        context.bot.send_message(chat_id=update.message.chat_id,text=random.choice(UNAUTHORIZED_JOKES))
Example #9
0
def enquesta(update, context):
    if manage_users(context, update.message.from_user.id, config.GROUP_ID):
        message_parts = update.message.text.split()
        requested_poll = [dataManager.get_single_poll(int(message_parts[1]))]
        if update.effective_chat.type == 'private':
            send_polls(context, update.effective_chat.id, requested_poll)
        else:
            if dataManager.is_impugnator(update.message.from_user.id):
                send_polls(context, update.effective_chat.id, requested_poll)
            else:
                context.bot.send_message(chat_id=update.effective_chat.id,
                                         text=random.choice(UNAUTHORIZED_JOKES))
    else:
        context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(UNAUTHORIZED_JOKES))
Example #10
0
def set_min_weekly(update, context):
    new_min = str(update.message.text.split()[1])
    if dataManager.is_impugnator(update.message.from_user.id):
        for line in fileinput.input(['config.py'], inplace=True, backup='.bak'):
            if line.startswith('MIN_WEEKLY_POLLS '):
                # line = 'MIN_WEEKLY_POLLS = {} \n'.format(new_min)
                print(line.replace(str(line), 'MIN_WEEKLY_POLLS = {} \n'.format(new_min)))
                imp.reload(config)
                context.bot.send_message(chat_id=update.message.chat_id, text="El nou mínim de preguntes es {}".format(new_min))

            else:
                print(line, end='')
    else:
        context.bot.send_message(chat_id=update.message.chat_id, text=random.choice(UNAUTHORIZED_JOKES))
    pass
Example #11
0
def stats(update, context):
    if manage_users(context, update.message.from_user.id, config.GROUP_ID):
        if update.effective_chat.type == 'private' or dataManager.is_impugnator(update.message.from_user.id):
            stats_result = dataManager.get_stats()
            message = "Enquestes per tema: \n"
            total_polls = 0
            for subject in stats_result:
                message += "\n" + str(subject[0]) + ": " + str(subject[1]) + ' enquestes'
                total_polls += subject[1]
            message += "\n \nTOTAL: " + str(total_polls) + ' enquestes'
            context.bot.send_message(chat_id=update.effective_chat.id, text=message)
        else:
            context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(UNAUTHORIZED_JOKES))
    else:
        context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(UNAUTHORIZED_JOKES))
Example #12
0
def restaurator(update, context):
    if dataManager.is_impugnator(update.message.from_user.id):
        message_parts = update.message.text.split()
        if manage_users(context, update.message.from_user.id, config.GROUP_ID):
            try:
                restaurate_poll = int(message_parts[1])
            except (ValueError, TypeError):
                restaurate_poll = 0
                context.bot.send_message(chat_id=update.effective_chat.id, text='Error de format')
            impugnated_poll = dataManager.poll_impugnation(restaurate_poll, False)
            if impugnated_poll:
                context.bot.send_message(chat_id=update.effective_chat.id, text='Enquesta restaurada')
            else:
                context.bot.send_message(chat_id=update.effective_chat.id, text='Hi ha hagut algun error')
        else:
            context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(UNAUTHORIZED_JOKES))
    else:
        context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(UNAUTHORIZED_JOKES))
Example #13
0
def user_stats(update, context):
    if dataManager.is_impugnator(update.message.from_user.id):
        user_ranking = dataManager.get_user_stats()
        message = "Ranking per usuari: \n"
        userName = ""
        for (user, ranking) in user_ranking:
            if config.PRODUCTION_BUILD:
                # On Production
                try:
                    member_username = context.bot.get_chat_member(config.GROUP_ID, user)
                    userName = member_username.user.full_name
                except BadRequest:
                    userName = '******'
            else:
                # Testing
                True
            message += "{}: {} \n".format(userName, ranking)
        context.bot.send_message(chat_id=update.effective_chat.id, text=message)
    else:
        context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(UNAUTHORIZED_JOKES))
Example #14
0
def simulacre(update, context):
    message_parts = update.message.text.split()
    if manage_users(context, update.message.from_user.id, config.GROUP_ID):
        try:
            total_sim = int(message_parts[1])
        except (ValueError, TypeError):
            total_sim = 0
            context.bot.send_message(chat_id=update.effective_chat.id, text='Error de format')

        requested_polls = dataManager.get_simul(total_sim)
        if len(requested_polls) > 0:
            if update.effective_chat.type == 'private':
                send_polls(context, update.effective_user.id, requested_polls)
            else:
                if dataManager.is_impugnator(update.message.from_user.id):
                    send_polls(context, config.GROUP_ID, requested_polls)
                else:
                    context.bot.send_message(chat_id=update.effective_chat.id,
                                             text=random.choice(UNAUTHORIZED_JOKES))

        else:
            context.bot.send_message(chat_id=update.effective_chat.id, text='No hi ha enquestes de les seleccionades ')
    else:
        context.bot.send_message(chat_id=update.effective_chat.id, text=random.choice(UNAUTHORIZED_JOKES))
Example #15
0
def stop_weekly(update, context):
    if dataManager.is_impugnator(update.message.from_user.id):
        context.job_queue.stop()
        context.bot.send_message(chat_id=update.message.chat_id,text='Joc Parat!')
    else:
        context.bot.send_message(chat_id=update.message.chat_id,text=random.choice(UNAUTHORIZED_JOKES))