Beispiel #1
0
def start_game(chat_id, user_id):
    game = storage.get_game(chat_id)
    user = storage.get_user(user_id)

    if game is None:
        return telegram.send_message(
            chat_id,
            "Trying to start non existing game!")

    if user is None:
        return telegram.send_message(
            chat_id,
            "You aren't registered yet.\n" +
            "Please send a '/start' to @Spyfall_Bot")

    if game.admin_user != user:
        return telegram.send_message(
            chat_id,
            "You are not the gamemaster.")

    if game.state != GameState.preparing.value:
        return telegram.send_message(
            chat_id,
            "This game is already running.")

    if len(game.users) < 3:
        return telegram.send_message(
            chat_id,
            "Not enough players.")

    storage.update_game(chat_id, state=GameState.running)
    telegram.send_message(
        chat_id,
        "Game started! Roles will be distributed...")
    distribute_roles(game)
Beispiel #2
0
def end_game(chat_id, user_id):
    game = storage.get_game(chat_id)
    user = storage.get_user(user_id)

    if game is None:
        return telegram.send_message(
            chat_id,
            "Trying to end non existing game!")

    if user is None:
        return telegram.send_message(
            chat_id,
            "You aren't registered yet.\n" +
            "Please send a '/start' to @Spyfall_Bot")

    if game.admin_user != user:
        return telegram.send_message(
            chat_id,
            "You are not the gamemaster.")

    storage.update_game(chat_id, state=GameState.finished)
    telegram.send_message(
        chat_id,
        "Game ended!")