Example #1
0
def end_of_settings(update, context, settings_type):
    query = QueryBuffer().get_query(update.callback_query.message.message_id)
    # query looks like: settings_private,username,notify_participation/notify_vote/
    # or: settings_group,title,notify_not_admin/notify_unauthorized
    if "settings" in ps.parse_csv_to_array(query)[0]:
        to_set = ps.parse_csv_to_array(query)[-1].split('/')[:-1]
        to_unset = []
        if ps.parse_csv_to_array(query)[0] == "settings_private":
            possible_settings = ['notify_participation', 'notify_vote']
            table = "settings"
        else:  # ps.parse_csv_to_array(query)[0] == "settings_group":
            possible_settings = ['notify_not_admin', 'notify_unauthorized']
            table = "group_settings"
        for _ in possible_settings:
            if _ not in to_set:
                to_unset.append(_)
        who = ps.parse_csv_to_array(query)[1]
        dbf.update_settings(table, who, to_set, to_unset)
        context.bot.send_message(
            chat_id=update.callback_query.message.chat_id,
            text="Okay, ich habe mir die Einstellungen vermerkt.",
            reply_markup=ReplyKeyboardRemove())
        shrink_keyboard(update, context, "Einstellungen angepasst.")
    else:
        pass
    QueryBuffer().clear_query(update.callback_query.message.message_id)
Example #2
0
def expansion_title(update):
    if "/stop" in update.message.text:
        ForceReplyJobs().clear_query(
            update.message.reply_to_message.message_id)
        update.message.reply_text('Okay, hier ist nichts passiert.',
                                  reply_markup=ReplyKeyboardRemove())
    else:
        query = ForceReplyJobs().get_query(
            update.message.reply_to_message.message_id
        ) + "," + update.message.text
        # query has now structure new_expansion, <owner>, <uuid>, <exp_title>

        if ps.parse_csv_to_array(query)[0] == "new_expansion":
            try:
                dbf.add_expansion_into_db(
                    ps.parse_csv_to_array(ps.remove_first_string(query)))
                # dbf.add_expansion_into_db(ps.parse_values_from_query(
                #                             ps.remove_first_string(query)))
            except IntegrityError:
                update.message.reply_text(
                    "Wusste ich doch: Diese Erweiterung hast du schon "
                    "einmal eingetragen. Viel Spaß noch damit!",
                    reply_markup=ReplyKeyboardRemove())
                return
            update.message.reply_text(
                "Okay, die Erweiterung wurde hinzugefügt \\o/",
                reply_markup=ReplyKeyboardRemove())
        else:
            pass  # no idea how we got here...
        ForceReplyJobs().clear_query(
            update.message.reply_to_message.message_id)
Example #3
0
def handle_settings(update, context):
    update.callback_query.answer()
    setting = update.callback_query.data.split(";")[1]
    if setting == "stop":
        QueryBuffer().clear_query(update.callback_query.message.message_id)
        context.bot.send_message(chat_id=update.callback_query.message.chat_id,
                                 text='Okay, hier ist nichts passiert.',
                                 reply_markup=ReplyKeyboardRemove())
        shrink_keyboard(update, context, "Abbruch.")
    elif setting == "done":
        query = QueryBuffer().get_query(
            update.callback_query.message.message_id)
        settings_type = ps.parse_csv_to_array(query)[0]
        end_of_settings(update, context, settings_type)
    else:  # we actually got a setting, now register it
        if update.callback_query.data.split(";")[2] == "SET":
            query = QueryBuffer().get_query(
                update.callback_query.message.message_id) + setting + "/"
            settings_so_far = ps.parse_csv_to_array(query)[-1].split(
                '/')[:-1]  # last one is empty since set ends on /
            QueryBuffer().edit_query(update.callback_query.message.message_id,
                                     query)
            # change keyboard layout
            try:
                context.bot.edit_message_text(
                    text=update.callback_query.message.text,
                    chat_id=update.callback_query.message.chat_id,
                    message_id=update.callback_query.message.message_id,
                    reply_markup=generate_settings(
                        ps.parse_csv_to_array(query)[0],
                        to_set=settings_so_far))
            except BadRequest:
                pass
        elif update.callback_query.data.split(";")[2] == "UNSET":
            query = QueryBuffer().get_query(
                update.callback_query.message.message_id)
            query_csv = ps.parse_csv_to_array(query)
            settings_so_far = query_csv[-1].split('/')[:-1]
            settings_so_far.remove(setting)
            settings_string = '/'.join(settings_so_far)
            if len(settings_string) > 0:
                settings_string += '/'
            new_query = ps.parse_array_to_csv(
                query_csv[:-1]) + ',' + settings_string
            QueryBuffer().edit_query(update.callback_query.message.message_id,
                                     new_query)
            # change keyboard layout
            try:
                context.bot.edit_message_text(
                    text=update.callback_query.message.text,
                    chat_id=update.callback_query.message.chat_id,
                    message_id=update.callback_query.message.message_id,
                    reply_markup=generate_settings(
                        ps.parse_csv_to_array(query)[0],
                        to_set=settings_so_far))
            except BadRequest:
                pass
Example #4
0
def end_of_categories(update, context, no_category=False):
    query = QueryBuffer().get_query(update.callback_query.message.message_id)
    query_csv = ps.parse_csv_to_array(query)
    categories = query_csv[-1].split('/')[:-1]
    # remove categories from query buffer now
    uuid = ps.generate_uuid_32()
    query = ps.parse_array_to_csv(query_csv[:-1]) + "," + uuid

    if query_csv[0] == "new_game":
        if no_category:
            try:
                dbf.add_game_into_db(
                    ps.parse_csv_to_array(ps.remove_first_string(query)))
                # dbf.add_game_into_db(ps.parse_values_from_query(
                #                         ps.remove_first_string(query)))
            except IntegrityError:
                context.bot.send_message(
                    chat_id=update.callback_query.message.chat_id,
                    text="Wusste ich doch: Das Spiel hast du schon "
                    "einmal eingetragen. Viel Spaß noch damit!",
                    reply_markup=ReplyKeyboardRemove())
                inline_text = "Du wolltest das Spiel " + query_csv[
                    2] + " hinzufügen."
                shrink_keyboard(update, context, inline_text)
                return
        else:
            try:
                dbf.add_game_into_db(ps.parse_csv_to_array(
                    ps.remove_first_string(query)),
                                     cats=categories,
                                     uuid=uuid)
                # dbf.add_game_into_db(ps.parse_values_from_query(
                #                     ps.remove_first_string(query)),
                #                     cats=categories,
                #                     uuid=uuid)
            except IntegrityError:
                context.bot.send_message(
                    chat_id=update.callback_query.message.chat_id,
                    text="Wusste ich doch: Das Spiel hast du schon "
                    "einmal eingetragen. Viel Spaß noch damit!",
                    reply_markup=ReplyKeyboardRemove())
                inline_text = "Du wolltest das Spiel " + query_csv[
                    2] + " hinzufügen."
                shrink_keyboard(update, context, inline_text)
                return
        context.bot.send_message(chat_id=update.callback_query.message.chat_id,
                                 text="Okay, das Spiel wurde hinzugefügt \\o/",
                                 reply_markup=ReplyKeyboardRemove())
        inline_text = "Du hast das Spiel " + query_csv[2] + " hinzugefügt."
        shrink_keyboard(update, context, inline_text)
    else:
        pass
    QueryBuffer().clear_query(update.callback_query.message.message_id)
Example #5
0
def game_players(update):
    if "/stop" in update.message.text:
        ForceReplyJobs().clear_query(
            update.message.reply_to_message.message_id)
        update.message.reply_text('Okay, hier ist nichts passiert.',
                                  reply_markup=ReplyKeyboardRemove())
    else:
        query = ForceReplyJobs().get_query(
            update.message.reply_to_message.message_id
        ) + "," + update.message.text + ","
        msg = update.message.reply_text(
            'In welche Kategorien passt ' + ps.parse_csv_to_array(query)[2] +
            ' am besten?\n'
            'Wähle so viele, wie du willst, und drücke dann '
            'auf \'Fertig\'.\n'
            'Wenn du keine Kategorie angeben möchtest, drücke '
            'auf \'Keine Angabe\'.',
            reply_markup=generate_categories(first=True))
        ForceReplyJobs().clear_query(
            update.message.reply_to_message.message_id)
        # not adding a new ForceReply because this happens inline
        QueryBuffer().add(msg.message_id, query)
Example #6
0
def end_of_household(update, context):
    query = QueryBuffer().get_query(update.callback_query.message.message_id)
    # query looks like: household,username,member1/member2
    query_csv = ps.parse_csv_to_array(query)
    members = query_csv[-1].split('/')[:-1]
    if "household" in query_csv[0]:
        household = [query_csv[1]] + members
        dbf.add_household(household)
        context.bot.send_message(chat_id=update.callback_query.message.chat_id,
                                 text="Okay, ich weiß Bescheid.",
                                 reply_markup=ReplyKeyboardRemove())
        shrink_label = " ".join(household)
        shrink_keyboard(update, context, shrink_label)
        if LogToMessageFilter().ask_chat_type == "private":
            update.message.bot.send_message(
                chat_id=update.callback_query.message.chat_id,
                text=
                'Hey, soll ich meine Debug-Nachrichten hier rein schicken?',
                reply_markup=generate_debug())
    else:
        pass
    QueryBuffer().clear_query(update.callback_query.message.message_id)
Example #7
0
def handle_household(update, context):
    update.callback_query.answer()
    member = update.callback_query.data.split(";")[1]
    if member == "stop":
        QueryBuffer().clear_query(update.callback_query.message.message_id)
        context.bot.send_message(chat_id=update.callback_query.message.chat_id,
                                 text='Okay, hier ist nichts passiert.',
                                 reply_markup=ReplyKeyboardRemove())
        shrink_keyboard(update, context, "Nein.")
        if LogToMessageFilter().ask_chat_type == "private":
            context.bot.send_message(
                chat_id=update.callback_query.message.chat_id,
                text=
                'Hey, soll ich meine Debug-Nachrichten hier rein schicken?',
                reply_markup=generate_debug())
    elif member == "done":
        end_of_household(update, context)
    else:  # got a household member
        if update.callback_query.data.split(";")[2] == "SET":
            query = QueryBuffer().get_query(
                update.callback_query.message.message_id) + member + "/"
            members_so_far = ps.parse_csv_to_array(query)[-1].split(
                '/')[:-1]  # last one is empty since set ends on /
            remove = ps.parse_csv_to_array(query)[
                1]  # don't let user select himself...
            QueryBuffer().edit_query(update.callback_query.message.message_id,
                                     query)
            # change keyboard layout
            try:
                context.bot.edit_message_text(
                    text=update.callback_query.message.text,
                    chat_id=update.callback_query.message.chat_id,
                    message_id=update.callback_query.message.message_id,
                    reply_markup=generate_household(remove,
                                                    to_set=members_so_far))
            except BadRequest:
                pass
        elif update.callback_query.data.split(";")[2] == "UNSET":
            query = QueryBuffer().get_query(
                update.callback_query.message.message_id)
            query_csv = ps.parse_csv_to_array(query)
            remove = query_csv[1]
            members_so_far = query_csv[-1].split('/')[:-1]
            members_so_far.remove(member)
            members_string = '/'.join(members_so_far)
            if len(members_string) > 0:
                members_string += '/'
            new_query = ps.parse_array_to_csv(
                query_csv[:-1]) + ',' + members_string
            QueryBuffer().edit_query(update.callback_query.message.message_id,
                                     new_query)
            # change keyboard layout
            try:
                context.bot.edit_message_text(
                    text=update.callback_query.message.text,
                    chat_id=update.callback_query.message.chat_id,
                    message_id=update.callback_query.message.message_id,
                    reply_markup=generate_household(remove,
                                                    to_set=members_so_far))
            except BadRequest:
                pass