Beispiel #1
0
def handle_plain(text, update):
    user_id = dt.traverse(update, "message.from.id")
    text = dt.traverse(update, "message.text")
    user = storage.get_user(user_id)

    if user is None:
        return

    if user.state == UserState.config and text == CONFIG_USERNAME:
        storage.update_user(user_id, state=UserState.config_username)
        return telegram.send_message(
            user_id,
            "Please send me your new username.",
            reply_markup={"hide_keyboard": True})

    if user.state == UserState.config_username:
        storage.update_user(user_id, username=text, state=UserState.none)
        return telegram.send_message(
            user_id,
            "Updated your username to {}.".format(text))
Beispiel #2
0
def handle_register(update):
    user_id = dt.traverse(update, "message.from.id")
    username = dt.traverse(update, "message.from.username")

    existing = storage.get_user(user_id)
    if existing is not None:
        return telegram.send_message(
            user_id,
            "You are already registered.")

    storage.register_user(user_id, username)

    message = "Welcome. Thank you for registering."
    if username is None:
        message += "\nBe sure to set a username with /config."
    else:
        message += "\nYour username is: {}".format(username)

    telegram.send_message(
        user_id,
        message)
def main():
    update = request.get_json()
    __logger.info("Received update: {}".format(update))

    text = dt.traverse(update, "message.text")
    if text is None:
      return ""

    if text.startswith("/"):
        handlers.handle(text[1:], update)
    else:
        handlers.handle_plain(text, update)

    return ""
Beispiel #4
0
def handle_config(update):
    user_id = dt.traverse(update, "message.from.id")
    user = storage.get_user(user_id)
    if user is None:
        return telegram.send_message(
            user_id,
            "You are not registered yet. Please do so with /start.")

    storage.update_user(user_id, state=UserState.config)
    telegram.send_message(
        user_id,
        "What would you like to change?",
        reply_markup={"keyboard": [[CONFIG_USERNAME]],
                      "one_time_keyboard": True,
                      "resize_keyboard": True})
Beispiel #5
0
def handle_playerlist(update):
    spyfall.list_players(dt.traverse(update, "message.chat.id"))
Beispiel #6
0
def handle_join(update):
    spyfall.player_join_game(
        dt.traverse(update, "message.chat.id"),
        dt.traverse(update, "message.from.id"))
Beispiel #7
0
def handle_end(update):
    spyfall.end_game(
        dt.traverse(update, "message.chat.id"),
        dt.traverse(update, "message.from.id"))
Beispiel #8
0
def handle_begin(update):
    spyfall.start_game(
        dt.traverse(update, "message.chat.id"),
        dt.traverse(update, "message.from.id"))
Beispiel #9
0
def handle_prepare(update):
    spyfall.create_game(
        dt.traverse(update, "message.chat.id"),
        dt.traverse(update, "message.from.id"))
Beispiel #10
0
def handle_about(update):
    telegram.send_message(
        dt.traverse(update, "message.chat.id"),
        filehandler.get_doc(filehandler.Document.about))
Beispiel #11
0
def handle_cancel(update):
    user_id = dt.traverse(update, "message.from.id")
    storage.update_user(user_id, state=UserState.none)
    return telegram.send_message(
        user_id,
        "Reset your state.")