Exemplo n.º 1
0
def send_reminder_for(from_user_id, _id=None):
    if _id[:2] == 'su':
        l = util_db.get_survey(survey_id=_id)
    elif _id[:2] == 'ev':
        l = util_db.get_event(event_id=_id)

    frichtle = util_db.get_frichtle()
    username = util_db.get_frichtle(user_id=from_user_id).get_inline_str()
    for f in frichtle:
        if f.user_id == from_user_id:
            continue
        if isinstance(l, Survey):
            needs = util_db.check_survey_response(user_id=f.user_id, survey_id=_id) == None
            markup = markups.selection.new_survey_alert()
            text = "{} bittet um Rückmeldung für folgende Umfrage:\n".format(username) + str(l)
        elif isinstance(l, Event):
            needs = util_db.check_attendance(user_id=f.user_id, event_id=_id) == 1
            markup = markups.selection.new_event_alert()
            text = "{} bittet um Rückmeldung für folgenden Termin:\n".format(username) + str(l)
        else:
            needs = False

        if needs:
            bot.send_message(f.user_id, text=text, reply_markup=markup)
        logger.info("Send reminder for: {}".format(str(l).replace("\n", ";")))
    return
def send_event_reminder_to_user(to_user, from_user_id, ev):
    username = get_username(from_user_id)
    text = "@{} bittet um Rückmeldung für folgendes Event:\n".format(
        username) + str(ev)
    bot.send_message(to_user,
                     text=text,
                     reply_markup=markups.selection.new_event_alert())
Exemplo n.º 3
0
def send_cancel_event_notice(who_cancel, event_id):
    frichtle = util_db.get_frichtle()
    ev = util_db.get_event(event_id=event_id)
    name = util_db.get_username(who_cancel).get_inline_str()
    text = "Benachrichtigung:\n{} hat folgenden Termin abgesagt:\n".format(name) + str(ev)
    for user_id in [f.user_id for f in frichtle]:
        if user_id == who_cancel:
            continue
        bot.send_message(chat_id=user_id, text=text)
Exemplo n.º 4
0
def send_event_edit_notice(who_edit, event_id):
    frichtle = util_db.get_frichtle()
    ev = util_db.get_event(event_id=event_id)
    name = util_db.get_frichtle(user_id=who_edit).get_inline_str()
    text = "Benachrichtigung:\n{} hat folgenden Termin bearbeitet. Bitte überprüfe, ob deine Zu- oder Absage noch stimmt:\n"\
        .format(name) + str(ev)
    for user_id in [f.user_id for f in frichtle]:
        if user_id == who_edit:
            continue
        bot.send_message(user_id, text=text)
Exemplo n.º 5
0
def welcome_user(message):
    if db.exist_frichtle(message.from_user.id):
        bot.send_message(
            message.chat.id,
            'Willkommen zurück. \nWie du diesen Bot benutzt, erfährst du von '
            '@LucasBurger oder in der Hilfe Sektion.',
            reply_markup=markups.menu.main(message.from_user.id))
    else:
        if pw_manager.check_password(message.text.replace("/start ", "")):
            welcome(message)
def request_id_event_reminder(message):
    events = events_that_need_reminder()
    if events:
        bot.send_message(
            message.chat.id,
            text=
            "Bitte wähle eine Event ID für die du einen Reminder verschicken möchstes "
            "(Mehrfachwahl möglich):",
            reply_markup=markups.inline.ask_for_event(
                command="remind_which_event", events=events))
    else:
        bot.reply_to(message, text="Es stehen keine Rückmeldungen aus.")
Exemplo n.º 7
0
 def edit_property_reply(self, message):
     user_id = message.from_user.id
     event = database.get_event(event_id=self.store[user_id]['data']['event_id'])
     prop = self.store[user_id]['data']['property']
     try:
         setattr(event, prop, message.text)
         self.store[user_id]['data']['new_value'] = message.text
     except ValueError:
         text = "Der neue Wert wurde nicht erkannt."
         markup = markups.menu.manage_events()
         bot.send_message(message.chat.id, text=text, reply_markup=markup)
         return
     self.__call__(user_message=message)
Exemplo n.º 8
0
def welcome(message):
    new_frichtle = Frichtle.from_json({
        "user_id": message.from_user.id,
        "admin": False,
        "master": False,
        "name": "Neuling",
        "username": message.from_user.username
    })

    if new_frichtle.user_id == meta.lucas_user_id:
        new_frichtle.admin = True
        new_frichtle.master = True

    if new_frichtle.username is not None:
        text = 'Willkommen @{} beim Frichtle Bot!'.format(
            new_frichtle.username)
    else:
        text = "Willkommen beim Frichtle Bot!"

    bot.reply_to(message, text)
    db.add_frichtle(new_frichtle)
    msg = bot.send_message(
        message.chat.id,
        text=
        "Bitte gib deinen Namen, unter dem dich die anderen erkennen: 😉",
    )
    bot.register_next_step_handler(msg, process_name_reply)
Exemplo n.º 9
0
def show_users(message, reply=True):
    frichtle = get_frichtle()
    if not isinstance(frichtle, list):
        frichtle = [frichtle]
    s = ""
    for f in frichtle:
        s += f.get_inline_str()
        if f.master:
            s += " (Master)"
        elif f.admin:
            s += " (Admin)"
        s += "\n"
    if reply:
        bot.reply_to(message, s)
    else:
        bot.send_message(message.chat.id, text=s)
Exemplo n.º 10
0
def process_name_reply(message):

    new_name = message.text
    db.update_frichtle(user_id=message.from_user.id, name=new_name)

    msg = bot.send_message(
        message.chat.id,
        text=f"Vielen Dank {new_name}.\nWähle dein Instrument:?",
        reply_markup=markups.selection.instrument())
    bot.register_next_step_handler(msg, process_instrument_reply)
Exemplo n.º 11
0
def process_command(message):
    if message.text == "0":
        bot.send_message(message.chat.id,
                         text="Command Eingabe beendet.",
                         reply_markup=markups.menu.master())
        return
    elif message.text == "hints":
        bot.send_message(message.chat.id, text=meta.sql_command_hints)
    else:
        success, res = execute_sql_command(message.text)
        if success:
            if res:
                text = res
            else:
                text = "<NO RETURN VALUE>"
            bot.reply_to(message, text=text)
        else:
            bot.reply_to(message, text="ERROR: " + res)

    sql_command(message)
Exemplo n.º 12
0
    def main(self,
             initial_message=None,
             call=None,
             inline_message=None,
             **kwargs):

        if inline_message:
            user_id = inline_message.chat.id
        else:
            user_id = (initial_message or call).from_user.id

        if call:
            inline_message = call.message

        if kwargs.get('name', None) is None:
            text = "Welche Tabelle möchtest du anzeigen?"
            tables = database.get_all_tables()
            markup = InlineKeyboardMarkup(row_width=2)
            t = tuple([
                InlineKeyboardButton(
                    t, callback_data=self.command + json.dumps({'name': t}))
                for t in tables
            ] + [InlineKeyboardButton("Abbrechen", callback_data="abort")])
            markup.add(*t)

            if inline_message:
                msg = bot.edit_message_text(inline_message=inline_message,
                                            text=text,
                                            reply_markup=markup)
            else:
                msg = bot.send_message(initial_message.chat.id,
                                       text=text,
                                       reply_markup=markup)
            self.store[user_id]['inline_message'] = msg
            return

        table = kwargs['name']
        text = util.database.get_table_as_string(table)

        if text is None:
            text = "Die Tabelle ist leer."

        markup = InlineKeyboardMarkup(row_width=1)
        markup.add(
            InlineKeyboardButton("Zurück",
                                 callback_data=self.command +
                                 json.dumps({'name': None})))

        bot.edit_message_text(inline_message=inline_message,
                              text=text,
                              reply_markup=markup)
Exemplo n.º 13
0
    def main(self,
             initial_message=None,
             user_message=None,
             call=None,
             inline_message=None,
             **kwargs):

        if inline_message:
            user_id = inline_message.chat.id
        else:
            user_id = (initial_message or user_message or call).from_user.id

        if call:
            inline_message = call.message

        if kwargs.get('id', None) is None:
            text = "Bitte wähle aus, für was du eine Erinnerung versenden möchtest:"
            events = util.database.events_that_need_reminder()
            surveys = util.database.surveys_that_need_reminder()

            markup = InlineKeyboardMarkup(row_width=1)
            buttons = list(
                InlineKeyboardButton(text=e.get_inline_str(),
                                     callback_data=self.command +
                                     json.dumps({'id': e.id})) for e in events)
            buttons += list(
                InlineKeyboardButton(text="Umfrage: " + s.get_inline_str(),
                                     callback_data=self.command +
                                     json.dumps({'id': s.id}))
                for s in surveys)

            markup.add(*tuple(buttons))
            markup.add(InlineKeyboardButton("Abbrechen",
                                            callback_data="abort"))
            if inline_message:
                msg = bot.edit_message_text(inline_message=inline_message,
                                            text=text,
                                            reply_markup=markup)
            else:
                msg = bot.send_message(initial_message.chat.id,
                                       text=text,
                                       reply_markup=markup)
            self.store[user_id]['inline_message'] = msg
            return
        else:
            text = "Okay, es wurden Erinnerungen versendet"
            bot.edit_message_text(inline_message=inline_message, text=text)
            util.functions.send_reminder_for(from_user_id=user_id,
                                             id=kwargs['id'])
Exemplo n.º 14
0
    def new_func(*args, **kwargs):
        return func(*args, **kwargs)
        try:
            return func(*args, **kwargs)
        except ConnectionResetError:
            logger.exception("Couldn't catch ConnectionResetError:")
            pass
        except ConnectionError:
            logger.exception("Couldn't catch ConnectionError:")
            pass
        except Exception as e:
            caught = False
            for a in args:
                if isinstance(a, Message):
                    chat_id = a.chat.id
                    username = a.from_user.username
                    user_id = a.from_user.id
                    caught = True
                    bot.send_message(chat_id, text=meta.error_text,
                                     reply_markup=markups.menu.main(user_id))
                elif isinstance(a, CallbackQuery):
                    bot.edit_message_reply_markup(call=a, reply_markup=None)
                    bot.edit_message_text(text=meta.error_text, call=a, reply_markup=None)
                    username = a.from_user.username
                    user_id = a.from_user.id
                    caught = True

                if caught:
                    bot.send_message(meta.lucas_chat_id,
                                     "Bei @{} ist folgender Fehler in der Funktion {} aufgetreten:\n"
                                     .format(username, func.__name__) + str(e),
                                     reply_markup=markups.menu.main(user_id))
                    logger.exception("Caught Exception:")
                    break

            return
Exemplo n.º 15
0
def process_instrument_reply(message):
    mid = message.chat.id
    text = message.text

    if text in meta.instruments:
        db.set_instrument(message.from_user.id, text)
        text = "Instrument wurde gespeichert."
    else:
        db.remove_frichtle(message.from_user.id)
        bot.send_message(
            message.chat.id,
            text="Instrument wurde nicht erkannt.\n"
            "Vorgang abgebrochen. Zum Neustart, bitte erneut den Link verwenden."
        )
        return

    f = db.get_frichtle(user_id=message.from_user.id)
    bot.send_message(
        meta.lucas_chat_id,
        "{} ist dem FrichtleBot beigetreten.".format(f.get_inline_str()))

    bot.send_message(mid,
                     text=text + " Du wirst zum Hauptmenü weitergeleitet.",
                     reply_markup=markups.menu.main(message.from_user.id))
Exemplo n.º 16
0
    def main(self,
             initial_message=None,
             user_message=None,
             call=None,
             inline_message=None,
             **kwargs):

        if inline_message:
            user_id = inline_message.chat.id
        else:
            user_id = (initial_message or user_message or call).from_user.id

        if call:
            inline_message = call.message

        surveys = util.database.get_survey()

        if len(surveys) == 0:
            bot.reply_to(initial_message, text="Es gibt keine Umfragen.")
            return

        if 'survey_id' not in kwargs.keys():
            text = "Wähle eine Umfrage aus, die du schließen möchtest:"
            markup = InlineKeyboardMarkup(row_width=1)
            buttons = list(
                InlineKeyboardButton(text=s.get_inline_str(),
                                     callback_data=self.command +
                                     json.dumps({'survey_id': s.survey_id}))
                for s in surveys)
            markup.add(*tuple(buttons))
            markup.add(InlineKeyboardButton("Abbrechen",
                                            callback_data="abort"))
            msg = bot.send_message(initial_message.chat.id,
                                   text=text,
                                   reply_markup=markup)
            self.store[user_id]['inline_message'] = msg
            return

        if 'sure' not in kwargs.keys():
            survey = database.get_survey(survey_id=kwargs.get('survey_id'))
            text = "Bist du sicher, dass du folgende Umfrage schließen möchtest?\n\n" + survey.get_detail_str(
            )
            markup = InlineKeyboardMarkup(row_width=2)
            markup.add(
                InlineKeyboardButton(text="Ja",
                                     callback_data=self.command +
                                     json.dumps({'sure': True})),
                InlineKeyboardButton(text="Nein",
                                     callback_data=self.command +
                                     json.dumps({'sure': False})))
            markup.add(
                InlineKeyboardButton(text="Abbrechen", callback_data="abort"))
            bot.edit_message_text(inline_message=inline_message,
                                  text=text,
                                  reply_markup=markup)
            return

        if not kwargs['sure']:
            text = "Schade, dann ist wohl etwas schiefgegangen... Bitte versuche es ggfs erneut."
        else:
            text = "Okay, die Umfrage wurde geschlossen. Antworten können nicht mehr geändert werden."
            util.database.close_survey(survey_id=kwargs['survey_id'])

        bot.edit_message_text(inline_message=inline_message, text=text)
        self.store[user_id] = dict()
        self.store[user_id]['data'] = dict()
        self.store[user_id]['inline_message'] = None
        return
Exemplo n.º 17
0
    def main(self,
             initial_message=None,
             call=None,
             inline_message=None,
             **kwargs):

        if inline_message:
            user_id = inline_message.chat.id
        else:
            user_id = (initial_message or call).from_user.id

        if call:
            inline_message = call.message

        if kwargs.get('typ', None) is None:
            text = "Bitte wähle aus:"
            markup = InlineKeyboardMarkup(row_width=1)
            markup.add(
                InlineKeyboardButton(text="Schritte",
                                     callback_data=self.command +
                                     json.dumps({'typ': "s"})))
            markup.add(
                InlineKeyboardButton(text="Märsche",
                                     callback_data=self.command +
                                     json.dumps({'typ': "m"})))
            markup.add(
                InlineKeyboardButton(text="Bühnenstücke",
                                     callback_data=self.command +
                                     json.dumps({'typ': "b"})))
            markup.add(InlineKeyboardButton("Beenden", callback_data="end"))
            if inline_message:
                msg = bot.edit_message_text(inline_message=inline_message,
                                            text=text,
                                            reply_markup=markup)
            else:
                msg = bot.send_message(initial_message.chat.id,
                                       text=text,
                                       reply_markup=markup)
            self.store[user_id]['inline_message'] = msg
            return

        typ = {
            "s": "Schritte",
            "m": "Maersche",
            "b": "Buehnenstuecke"
        }[kwargs['typ']]

        if kwargs.get('sheet_id', None) is None:
            noten = copy(meta.noten[typ])
            for i, n in enumerate(noten):
                v = n[0]
                v = v.replace("ae", "ä")
                v = v.replace("ue", "ü")
                v = v.replace("oe", "ö")
                v = v.replace("_", " ")
                noten[i] = (v, noten[i][1])

            markup = InlineKeyboardMarkup(row_width=1)
            buttons = list(
                InlineKeyboardButton(text=n[0],
                                     callback_data=self.command +
                                     json.dumps({'sheet_id': n[1]}))
                for n in noten)
            markup.add(*tuple(buttons))
            markup.add(
                InlineKeyboardButton("Zurück",
                                     callback_data=self.command +
                                     json.dumps({'typ': None})))
            bot.edit_message_text(text="Bitte wähle aus:",
                                  inline_message=inline_message,
                                  reply_markup=markup)

            return

        noten = meta.noten[typ]
        for l in noten:
            if l[1] == kwargs['sheet_id']:
                name = l[0]
                break

        noten_path = meta.noten_path.format(typ=typ, name=name)

        bot.delete_message(message=inline_message)

        bot.send_document(chat_id=inline_message.chat.id,
                          data=open(noten_path, "rb"),
                          caption="Bitteschön!")
Exemplo n.º 18
0
    def main(self,
             initial_message=None,
             user_message=None,
             call=None,
             inline_message=None,
             **kwargs):

        if inline_message:
            user_id = inline_message.chat.id
        else:
            user_id = (initial_message or user_message or call).from_user.id

        surveys = util.database.get_survey()

        if len(surveys) == 0:
            bot.reply_to(message=initial_message,
                         text="Es gibt aktuell keine Umfragen.")
            del self.store[user_id]
            return

        if call:
            inline_message = call.message

        if user_message:
            bot.delete_message(chat_id=user_message.chat.id,
                               message_id=user_message.message_id)

        if kwargs.get('survey_id', None) is None:
            text = "Welche Umfrage möchtest du anzeigen?"

            buttons = []
            for s in surveys:
                if util.database.check_survey_response(
                        user_id=user_id, survey_id=s.survey_id) is None:
                    replace = "Unbeantwortet: "
                else:
                    replace = ""
                buttons.append(
                    InlineKeyboardButton(
                        text=s.get_inline_str().replace("Umfrage: ", replace),
                        callback_data=self.command +
                        json.dumps({'survey_id': s.survey_id})))
            markup = InlineKeyboardMarkup(row_width=1)
            markup.add(*tuple(buttons))
            markup.add(InlineKeyboardButton("Beenden", callback_data="end"))

            if inline_message:
                msg = bot.edit_message_text(inline_message=inline_message,
                                            text=text,
                                            reply_markup=markup)
            else:
                msg = bot.send_message(initial_message.chat.id,
                                       text=text,
                                       reply_markup=markup)
            self.store[user_id]['inline_message'] = msg
            return

        survey = util.database.get_survey(survey_id=kwargs['survey_id'])

        if kwargs.get('edit', None) is None:
            text = survey.get_detail_str()
            res = survey.results[user_id]
            buttons = []
            if res is None:
                text += "\n\nDu hast noch nicht geantwortet."
                buttons.append(
                    InlineKeyboardButton(text="Jetzt antworten",
                                         callback_data=self.command +
                                         json.dumps({'edit': True})))
            else:
                text += "\n\nDu hast mit '{}' geantwortet".format(res)
                if survey.active:
                    buttons.append(
                        InlineKeyboardButton(text="Ändern",
                                             callback_data=self.command +
                                             json.dumps({'edit': True})))
            if not survey.active:
                text += "\nDie Umfrage ist geschlossen."
            buttons.append(
                InlineKeyboardButton(text="Zurück",
                                     callback_data=self.command +
                                     json.dumps({'survey_id': None})))

            markup = InlineKeyboardMarkup(row_width=2)
            markup.add(*tuple(buttons))
            bot.edit_message_text(inline_message=inline_message,
                                  text=text,
                                  reply_markup=markup)
            return

        if kwargs["edit"] and self.store[user_id]["data"].get(
                "response", None) is None:
            self.store[user_id]["data"]["response"] = [None] * len(
                survey.questions)

        res = kwargs.pop("res", None)
        if res is not None:
            self.store[user_id]["data"]["response"][res[0]] = res[1]

        i = 0
        while i < len(survey.questions):
            if self.store[user_id]["data"]["response"][i] is None:
                break
            i += 1

        if i < len(survey.questions):
            text = survey.get_detail_str(
                question=i) + "\n\nWie lautet deine Antwort?"
            if isinstance(survey.questions[i]["answers"], list):
                buttons = []
                for r in survey.questions[i]["answers"]:
                    buttons.append(
                        InlineKeyboardButton(text=r,
                                             callback_data=self.command +
                                             json.dumps({'res': [i, r]})))
                markup = InlineKeyboardMarkup(row_width=2)
                markup.add(
                    *tuple(buttons),
                    InlineKeyboardButton(text="Zurück",
                                         callback_data=self.command +
                                         json.dumps({'edit': None})))
            elif survey.questions[i]["answers"].lower() == 'count':
                page = kwargs.get('page', 1)
                markup = markups.inline.show_numbers(command=self.command,
                                                     return_name='res',
                                                     question=i,
                                                     page=page)
            else:
                # free reply
                text = survey.get_detail_str(
                ) + "\n\nOkay, gib deine Antwort ein:"
                msg = bot.edit_message_text(inline_message=inline_message,
                                            text=text)
                bot.register_next_step_handler(msg,
                                               self.survey_reply,
                                               question=i)
                return

            if i < len(survey.questions):
                bot.edit_message_text(inline_message=inline_message,
                                      text=text,
                                      reply_markup=markup)
                return

        util.database.set_response_to_survey(
            survey_id=kwargs['survey_id'],
            user_id=user_id,
            response=self.store[user_id]["data"]["response"])

        final_answer = " ".join(
            [str(r) for r in self.store[user_id]["data"]["response"]])

        text = f"\n\nDu hast mit '{final_answer}' geantwortet."

        text += "\n Wähle neue Umfrage aus:"

        buttons = []
        for s in surveys:
            if util.database.check_survey_response(
                    user_id=user_id, survey_id=s.survey_id) == '':
                replace = "Unbeantwortet: "
            else:
                replace = ""
            buttons.append(
                InlineKeyboardButton(text=s.get_inline_str().replace(
                    "Umfrage: ", replace),
                                     callback_data=self.command +
                                     json.dumps({'survey_id': s.survey_id})))
        markup = InlineKeyboardMarkup(row_width=1)
        markup.add(*tuple(buttons))
        markup.add(InlineKeyboardButton("Beenden", callback_data="end"))

        self.store[user_id]['data'].update({
            'survey_id': None,
            'edit': None,
            'res': None,
            "response": None
        })

        bot.edit_message_text(inline_message=inline_message,
                              text=text,
                              reply_markup=markup)
Exemplo n.º 19
0
    def main(self,
             initial_message=None,
             user_message=None,
             call=None,
             inline_message=None,
             **kwargs):

        if inline_message:
            user_id = inline_message.chat.id
        else:
            user_id = (initial_message or user_message or call).from_user.id

        if call:
            inline_message = call.message

        if 'event_id' not in kwargs.keys():
            text = "Wähle einen Termin aus, den du absagen möchtest:"
            markup = InlineKeyboardMarkup(row_width=1)
            buttons = list(
                InlineKeyboardButton(text=e.get_inline_str(),
                                     callback_data=self.command +
                                     json.dumps({'event_id': e.event_id}))
                for e in database.get_event())
            markup.add(*tuple(buttons))
            markup.add(InlineKeyboardButton("Abbrechen",
                                            callback_data="abort"))
            msg = bot.send_message(initial_message.chat.id,
                                   text=text,
                                   reply_markup=markup)
            self.store[user_id]['inline_message'] = msg
            return

        if 'sure' not in kwargs.keys():
            event = database.get_event(event_id=kwargs.get('event_id'))
            text = "Bist du sicher, dass du folgenden Termin absagen möchtest?\n\n" + event.get_detail_str(
            )
            markup = InlineKeyboardMarkup(row_width=2)
            markup.add(
                InlineKeyboardButton(text="Ja",
                                     callback_data=self.command +
                                     json.dumps({'sure': True})),
                InlineKeyboardButton(text="Nein",
                                     callback_data=self.command +
                                     json.dumps({'sure': False})))
            markup.add(
                InlineKeyboardButton(text="Abbrechen", callback_data="abort"))
            bot.edit_message_text(inline_message=inline_message,
                                  text=text,
                                  reply_markup=markup)
            return

        if 'send_notice' not in kwargs.keys():
            if not kwargs.get('sure'):
                text = "Schade, dann ist wohl etwas schiefgegangen... Bitte versuche es ggfs erneut."
                markup = None
            else:
                event = database.get_event(event_id=kwargs.get('event_id'))
                text = "Okay, der Termin wurde abgesagt.\n" \
                       "Möchtest du alle wissen lassen, dass der Termin abgesagt wurde?"
                markup = InlineKeyboardMarkup(row_width=2)
                markup.add(
                    InlineKeyboardButton(text="Ja",
                                         callback_data=self.command +
                                         json.dumps({'send_notice': True})),
                    InlineKeyboardButton(text="Nein",
                                         callback_data=self.command +
                                         json.dumps({'send_notice': False})))
                markup.add(
                    InlineKeyboardButton(text="Abbrechen",
                                         callback_data="abort"))

            bot.edit_message_text(inline_message=inline_message,
                                  text=text,
                                  reply_markup=markup)

            return

        if not kwargs.get('send_notice'):
            text = "Okay, es werden keine Nachrichten versandt."
        else:
            text = "Okay, es wurden Nachrichten an alle versandt."
            util.functions.send_cancel_event_notice(
                who_cancel=user_id, event_id=kwargs['event_id'])

        bot.edit_message_text(inline_message=inline_message, text=text)
        self.store[user_id] = dict()
        self.store[user_id]['data'] = dict()
        self.store[user_id]['inline_message'] = None
        return
Exemplo n.º 20
0
def goto_master_menu(message):
    bot.send_message(message.chat.id, text="Mastermenü", reply_markup=markups.menu.master())
    return
    def main(self, initial_message=None, user_message=None, call=None, inline_message=None, **kwargs):

        if inline_message:
            user_id = inline_message.chat.id
        else:
            user_id = (initial_message or user_message or call).from_user.id

        if initial_message:
            d = initial_message.text.replace('_probe', '').strip()
            self.store[user_id]['data']['date'] = d

        if call:
            inline_message = call.message

        if self.store[user_id].get('frichtle') is None:
            #self.store[user_id]['frichtle'] = util.database.get_frichtle()
            self.store[user_id]['frichtle'] = util.classes.fake_frichtle.copy()

        if self.store[user_id].get('set_frichtle') is None:
            self.store[user_id]['set_frichtle'] = []

        if len(self.store[user_id]['set_frichtle']) > 0:
            self.store[user_id]['set_frichtle'] = sorted(self.store[user_id]['set_frichtle'], key=lambda f: f.first_name)
            text = "Ausgewählte Frichtle:\n" + "\n".join([f.get_inline_str() for f in self.store[user_id]['set_frichtle']])
            text += "\n\n"
        else:
            text = ""

        if not kwargs.get('done', False):
            if kwargs.get('register') is None:
                text += "Wähle Register aus:"
                markup = InlineKeyboardMarkup(row_width=1)
                buttons = list(InlineKeyboardButton(text=r, callback_data=self.command + json.dumps({'register': r}))
                               for r in meta.registers.keys())
                markup.add(*tuple(buttons))
                markup.add(InlineKeyboardButton("Fertig", callback_data=self.command + json.dumps({'done': True})))
                markup.add(InlineKeyboardButton("Abbrechen", callback_data="abort"))
                if inline_message:
                    msg = bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
                else:
                    msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup)
                self.store[user_id]['inline_message'] = msg
                return

            if kwargs.get('user_id') is None:
                text += "Wähle Frichtle aus {} aus:".format(kwargs['register'])
                register_instruments = meta.registers[kwargs['register']]
                register_frichtle = list(filter(lambda f: f.instrument in register_instruments, self.store[user_id]['frichtle']))
                markup = InlineKeyboardMarkup(row_width=1)
                buttons = list(InlineKeyboardButton(text=f.get_inline_str(), callback_data=self.command + json.dumps({'user_id': f.user_id}))
                               for f in register_frichtle)
                markup.add(*tuple(buttons))
                markup.add(InlineKeyboardButton("Zurück", callback_data=self.command + json.dumps({'register': None})))
                if inline_message:
                    msg = bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
                else:
                    msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup)
                self.store[user_id]['inline_message'] = msg
                return

        if kwargs.get('done') is None:
            f = list(filter(lambda f: f.user_id == kwargs['user_id'], self.store[user_id]['frichtle']))[0]
            self.store[user_id]['frichtle'].pop(self.store[user_id]['frichtle'].index(f))
            self.store[user_id]['set_frichtle'].append(f)
            self.store[user_id]['data'].pop('user_id')
            self.__call__(inline_message=inline_message)
            return

        if kwargs.get('email') is None:
            text = "Okay, gib deine Email Adresse ein:\nFalls du keine Email erhalten möchtest, gib '0' ein."
            msg = bot.edit_message_text(inline_message=inline_message, text=text)
            bot.register_next_step_handler(msg, self.process_email)
            return

        if kwargs.get('send') is None:
            if kwargs['email'] == '':
                text += "Keine Email angegeben."
                button_text = "Speichern"
            else:
                text += "Email Adresse: {}".format(kwargs['email'])
                button_text = "Senden"
            markup = InlineKeyboardMarkup(row_width=2)
            markup.add(InlineKeyboardButton(text=button_text, callback_data=self.command + json.dumps({'send': True})),
                       InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps({'send': False,
                                                                                                    'done': False})))
            if inline_message:
                msg = bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
            else:
                msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup)
            self.store[user_id]['inline_message'] = msg
            return

        if kwargs.get('send'):
            util.functions.save_rehersal_attendance(frichtle=self.store[user_id]['set_frichtle'],
                                                    date=self.store[user_id]['data']['date'])

            if '@' in kwargs.get('email'):
                email_text = util.functions.rehersal_email_text(frichtle=self.store[user_id]['set_frichtle'])
                subject = "Anwesenheit Probe {}".format(self.store[user_id]['data']['date'])
                success = util.functions.send_email(email=kwargs.get('email', 'Keine Email'),
                                                    subject=subject, text=email_text)

                if success:
                    text = "Okay, Email wurde gesendet. Anwesenheit abgeschlossen."
                else:
                    text = "Die Email konnte nicht versandt werden."
            else:
                text = "Es wurde keine Email versandt."

            text += "\nDie Anwesenheit wurde lokal gespeichert."
            bot.edit_message_text(inline_message=inline_message, text=text)
            return
        else:
            self.store[user_id]['done'] = False
            self.__call__(inline_message=inline_message)
        return
Exemplo n.º 22
0
def goto_events_menu(message):
    chat_id = message.chat.id
    bot.send_message(chat_id, text="Termine", reply_markup=markups.menu.events())
    return
Exemplo n.º 23
0
def goto_survey_menu(message):
    chat_id = message.chat.id
    bot.send_message(chat_id, text="Umfragen", reply_markup=markups.menu.surveys())
    return
Exemplo n.º 24
0
def goto_main_menu(message=None):
    chat_id = message.chat.id
    user_id = message.from_user.id
    bot.send_message(chat_id, text=message.text, reply_markup=markups.menu.main(user_id))
    return
Exemplo n.º 25
0
def goto_manage_events_menu(message=None, chat_id=None):
    if chat_id is None:
        chat_id = message.chat.id
    bot.send_message(chat_id, text="Termine verwalten", reply_markup=markups.menu.manage_events())
    return
Exemplo n.º 26
0
def send_new_survey_alert(survey, by):
    text = "{} hat eine neue Umfrage erstellt:\n".format(by.get_inline_str()) + str(survey) + "\nBitte gehe in die '/Umfragen' Sektion, um zu antworten."
    for user_id in util_db.get_from_all_frichtle('user_id'):
        if user_id == by.user_id:
            continue
        bot.send_message(user_id, text, reply_markup=markups.selection.new_survey_alert())
Exemplo n.º 27
0
def send_new_event_alert(event, by):
    text = "{} hat einen neuen Termin erstellt:\n".format(by.get_inline_str()) + str(event) + "\nBitte gehe in die '/termine' Sektion, um zu- oder abzusagen."
    for user_id in util_db.get_from_all_frichtle('user_id'):
        if user_id == by.user_id:
            continue
        bot.send_message(user_id, text, reply_markup=markups.selection.new_event_alert())
    def main(self, initial_message=None, user_message=None, call=None, inline_message=None, **kwargs):

        if initial_message:
            f = Frichtle.from_user(initial_message.from_user)
            user_id = f.user_id
            self.store[user_id]['new_frichtle'] = f

        else:
            if inline_message:
                user_id = inline_message.chat.id
            else:
                user_id = (initial_message or user_message or call).from_user.id
            f = self.store[user_id]['new_frichtle']

        text = "Hallo {},\n\n".format(f.first_name)

        if user_message:
            bot.delete_message(chat_id=user_message.chat.id, message_id=user_message.message_id)

        if call:
            inline_message = call.message

        if inline_message is None:
            inline_message = self.store[user_id]['inline_message']

        if 'abort' in kwargs.keys():
            del self.store[user_id]
            bot.edit_message_text(inline_message=inline_message, text="Der Vorgang wurde abgebrochen und deine angegebenen Daten wurden gelöscht. Falls du möchtest, starte bitte erneut über den Einladungslink.\nLieben Gruß\nLucas")

        if 'done' in kwargs.keys() and kwargs.get('done'):
            util.database.add_frichtle(self.store[user_id]['new_frichtle'])
            bot.edit_message_text(inline_message=inline_message, text="Okay, du wurdest gespeichert und wirst jetzt zum Hauptmenü weitergeleitet.")
            bot.send_message(chat_id=user_id, text="Hauptmenü", reply_markup=markups.menu.main(user_id=user_id))
            return

        if initial_message:
            text += "Du hast folgenden Namen in Telegram hinterlegt:\n{} {}\nMöchtest du einen anderen Namen eingeben, mit dem dich andere sehen können? Ein Name, unter dem man dich erkennt wäre sehr hilfreich 😉".format(f.first_name, f.last_name)
            markup = InlineKeyboardMarkup(row_width=2)
            buttons = [InlineKeyboardButton(text="Ja, bitte", callback_data=self.command + json.dumps({'name_okay': False})),
                       InlineKeyboardButton(text="Nein, passt", callback_data=self.command + json.dumps({'name_okay': True}))]
            markup.add(*tuple(buttons))
            if inline_message:
                msg = bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
            else:
                msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup)
            self.store[user_id]['inline_message'] = msg
            return

        if not kwargs.get('name_okay'):
            text += "Okay, bitte gib einen anderen Namen ein:"
            msg = bot.edit_message_text(inline_message=self.store[user_id]['inline_message'],
                                        text=text)
            bot.register_next_step_handler(msg, self.change_name_reply)
            return

        if kwargs.get('instr', None) is None:
            text += "Bitte wähle dein Instrument?"
            markup = InlineKeyboardMarkup(row_width=2)
            buttons = [InlineKeyboardButton(text=instr, callback_data=self.command + json.dumps({'instr': instr}))
                       for instr in meta.instruments]
            markup.add(*tuple(buttons))
            bot.edit_message_text(text=text, inline_message=inline_message, reply_markup=markup)
            return
        else:
            self.store[user_id]['new_frichtle'].instrument = kwargs.get('instr')

        if not kwargs.get('done', False):
            text += "Die folgenden Daten werden in einer verschlüsselten Datenbank abgelegt. Dieser Bot steht in keiner direkten Verbindung zum Verein und umgeht deshalb jegliche Richtlinien der DSGVO. Bei Fragen zur Datenspeicherung, kannst du jederzeit Lucas (@LucasBurger) anschreiben.\n\n"
            text += "Zusammenfassung:\n{}\n\nEinverstanden?".format(self.store[user_id]['new_frichtle'].get_detail_str())
            markup = InlineKeyboardMarkup()
            markup.add(InlineKeyboardButton(text="Instrument ändern", callback_data=self.command + json.dumps({'instr': None})))
            markup.add(InlineKeyboardButton(text="Name ändern",
                                            callback_data=self.command + json.dumps({'name_okay': False})))
            markup.add(InlineKeyboardButton(text="Einverstanden!",
                                            callback_data=self.command + json.dumps({'done': True})))
            bot.edit_message_text(text=text, inline_message=inline_message, reply_markup=markup)

        return
Exemplo n.º 29
0
    def main(self, initial_message=None, call=None, inline_message=None, **kwargs):

        if inline_message:
            user_id = inline_message.chat.id
        else:
            user_id = (initial_message or call).from_user.id

        if call:
            inline_message = call.message

        if kwargs.get('att', None) is None:
            text = "Welche Termine möchtest du anzeigen?"
            markup = InlineKeyboardMarkup(row_width=1)
            markup.add(InlineKeyboardButton(text="Ausstehende Rückmeldungen",
                                            callback_data=self.command + json.dumps({'att': 1})))
            markup.add(InlineKeyboardButton(text="Meine Zusagen",
                                            callback_data=self.command + json.dumps({'att': 3})))
            markup.add(InlineKeyboardButton(text="Meine Absagen",
                                            callback_data=self.command + json.dumps({'att': 2})))
            markup.add(InlineKeyboardButton("Beenden", callback_data="end"))
            if inline_message:
                msg = bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
            else:
                msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup)
            self.store[user_id]['inline_message'] = msg
            return

        if kwargs.get('event_id', None) is None:
            events = [d['ev'] for d in util.database.get_events_from_user(user_id=user_id, attendance=kwargs['att'])]
            if len(events) > 0:
                text = "Wähle aus, um den Termin anzuzeigen:"
            else:
                text = "Keine entsprechenden Termine gefunden."

            markup = InlineKeyboardMarkup(row_width=1)
            buttons = list(InlineKeyboardButton(text=e.get_inline_str(),
                                                callback_data=self.command + json.dumps({'event_id': e.event_id}))
                           for e in events)
            markup.add(*tuple(buttons))
            markup.add(InlineKeyboardButton("Zurück", callback_data=self.command + json.dumps({'att': None})))
            bot.edit_message_text(text=text, inline_message=inline_message, reply_markup=markup)

            return

        event = util.database.get_event(event_id=kwargs['event_id'])

        if kwargs.get('edit', None) is None:
            text = event.get_detail_str()
            text += "\nDu hast {}"
            markup_text = "Ändern"
            if kwargs['att'] == 3:
                text = text.format("ZUGESAGT.")
            elif kwargs['att'] == 2:
                text = text.format("ABGESAGT.")
            elif kwargs['att'] == 1:
                text = text.format("noch keine Rückmeldung gegeben.")
                markup_text = "Rückmeldung geben"

            markup = InlineKeyboardMarkup(row_width=2)
            markup.add(InlineKeyboardButton(text=markup_text, callback_data=self.command + json.dumps({'edit': True})),
                       InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps({'event_id': None})))
            bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
            return

        text = "Kommst du zu folgendem Event?\n" + event.get_detail_str()

        if kwargs.get('att_new', None) is None:
            # send sure reply markup
            markup = InlineKeyboardMarkup(row_width=2)
            markup.add(InlineKeyboardButton(text="Ja", callback_data=self.command + json.dumps({'att_new': 3})),
                       InlineKeyboardButton(text="Nein", callback_data=self.command + json.dumps({'att_new': 2})),
                       InlineKeyboardButton(text="Weiß doch nicht", callback_data=self.command + json.dumps({"att_new": 1})),
                       InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps({'edit': None})))
            bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
            return

        util.database.set_attendance_to_event(event_id=kwargs['event_id'], user_id=user_id, att=kwargs['att_new'])

        if kwargs['att_new'] == 3:
            text = "\n\nDu hast ZUGESAGT."
        elif kwargs['att_new'] == 2:
            text = "\n\nDu hast ABGESAGT."
        elif kwargs['att_new'] == 1:
            text = "\n\nDeine Rückmeldung wurde entfernt."

        text += "\n Wähle neuen Termin aus:"

        events = [e['ev'] for e in util.database.get_events_from_user(user_id=user_id, attendance=kwargs['att'])]
        markup = InlineKeyboardMarkup(row_width=1)
        buttons = list(InlineKeyboardButton(text=e.get_inline_str(),
                                            callback_data=self.command + json.dumps({'event_id': e.event_id}))
                       for e in events)
        markup.add(*tuple(buttons))
        markup.add(InlineKeyboardButton("Zurück", callback_data=self.command + json.dumps({'att': None})))

        self.store[user_id]['data'].update({'event_id': None, 'att_new': None, 'edit': None})

        bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
Exemplo n.º 30
0
    def main(self, initial_message=None, user_message=None, call=None, inline_message=None, **kwargs):

        if inline_message:
            user_id = inline_message.chat.id
        else:
            user_id = (initial_message or user_message or call).from_user.id

        if user_message:
            bot.delete_message(chat_id=user_message.chat.id, message_id=user_message.message_id)

        if call:
            inline_message = call.message

        if initial_message:
            bot.reply_to(initial_message, text=meta.new_event_guide)

        if kwargs.get('done', False):
            # send sure reply markup
            if kwargs.get('sure') is None:
                event = self.store[user_id]['event']
                text = "Der Termin ist lautet:\n" + event.get_detail_str() + "\n\nSoll er gespeichert werden?"
                markup = InlineKeyboardMarkup(row_width=2)
                markup.add(InlineKeyboardButton(text="Ja", callback_data=self.command + json.dumps({'sure': True})))
                markup.add(InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps({'done': None,
                                                                                                        'property': None})))
                bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
                return

            if kwargs.get('send_notice') is None:
                if not kwargs.get('sure'):
                    self.store[user_id]['property'] = None
                    self.__call__(call=call)
                    return
                else:
                    event = self.store[user_id]['event']
                    database.save_event(event)
                    text = "Okay, der Termin wurde erstellt.\n" \
                           "Möchtest du alle wissen lassen, sodass sie zu oder absagen können?"
                    markup = InlineKeyboardMarkup(row_width=2)
                    markup.add(
                        InlineKeyboardButton(text="Ja", callback_data=self.command + json.dumps({'send_notice': True})),
                        InlineKeyboardButton(text="Nein",
                                             callback_data=self.command + json.dumps({'send_notice': False})))

                bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
                return
            if not kwargs.get('send_notice'):
                text = "Okay, es werden keine Nachrichten versandt."
            else:
                text = "Okay, es wurden Nachrichten an alle versandt."
                util.functions.send_new_event_alert(by=util.database.get_frichtle(user_id=user_id),
                                                    event=self.store[user_id]['event'])

            bot.edit_message_text(inline_message=inline_message, text=text)
            self.store[user_id] = dict()
            self.store[user_id]['data'] = dict()
            self.store[user_id]['inline_message'] = None

            return

        if kwargs.get('property') is None:
            e = self.store[user_id].get('event', Event())
            e.event_id = util.database.get_new_event_id()
            self.store[user_id]['event'] = e

            text = "Aktuell sieht der Termin folgendermaßen aus:\n" + e.get_detail_str() + "\n\nBitte wähle aus, um zu Daten einzugeben:"
            markup = InlineKeyboardMarkup(row_width=2)
            buttons = []
            for i, v in enumerate(meta.event_col_names_display):
                buttons.append(InlineKeyboardButton(text=v,
                                                    callback_data=self.command +
                                                    json.dumps({'property': meta.event_col_names[i]})))
            buttons.append(InlineKeyboardButton(text="Fertig", callback_data=self.command + json.dumps({'done': True,
                                                                                                        'property': ''})))
            buttons.append(InlineKeyboardButton(text="Abbrechen", callback_data="abort"))
            markup.add(*tuple(buttons))

            if inline_message:
                msg = bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
            elif call:
                msg = bot.edit_message_text(call=call, text=text, reply_markup=markup)
            else:
                msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup)
            self.store[user_id]['inline_message'] = msg
            return

        if kwargs['property'] == "dress":
            if kwargs.get('value') is None:
                text = "Okay, bitte wähle ein Outfit:"
                markup = InlineKeyboardMarkup(row_width=2)
                markup.add(*tuple([InlineKeyboardButton(text=s, callback_data=self.command + json.dumps(
                    {'value': s}
                )) for s in meta.dresses] +
                    [InlineKeyboardButton(text="Zurück", callback_data=self.command +
                                          json.dumps({'property': None, 'value': None}))]))
                bot.edit_message_text(text=text, inline_message=inline_message, reply_markup=markup)
            else:
                event = self.store[user_id]['event']
                event.dress = kwargs.pop('value')
                self.store[user_id]['data'].pop('value')
                self.store[user_id]['data'].pop('property')
                self.__call__(call=call)
            return

        else:
            prop_display = meta.event_col_names_display[meta.event_col_names.index(kwargs.get('property'))]
            text = "Okay, gib '{}' ein:".format(prop_display)
            hint = meta.event_col_names_hints.get(kwargs['property'])
            if hint is not None:
                text += "\n{}".format(hint)
            msg = bot.edit_message_text(inline_message=inline_message, text=text)
            bot.register_next_step_handler(msg, self.property_reply)
            return