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)
def list_players(chat_id): game = storage.get_game(chat_id) if game is None: return telegram.send_message( chat_id, "There is no game in this channel.") message = "Players:" for player in game.users: message += str("\n{0}").format(player.username) telegram.send_message(chat_id, message)
def player_join_game(chat_id, player_id): game = storage.get_game(chat_id) user = storage.get_user(player_id) if game is None: return telegram.send_message( chat_id, "There is no preparing game to join.") if user is None: return telegram.send_message( chat_id, "You aren't registered yet.\n" + "Please send me a private message (@Spyfall_Bot)") if user.username is None: return telegram.send_message( chat_id, "You haven't set a username yet.\n" + "Please do so with /config.") if game.state != GameState.preparing.value: return telegram.send_message( chat_id, "This game is already running.") if len(game.users) >= 8: return telegram.send_message( chat_id, "There are already 8 players in this game.") if user in game.users: return telegram.send_message( chat_id, "You already joined this game.") success = storage.join_game(chat_id, player_id) if success: return telegram.send_message( chat_id, "Player {} has joined the game.".format(user.username)) return telegram.send_message( chat_id, "You already joined another game.")
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!")
def create_game(chat_id, user_id): game = storage.get_game(chat_id) if game is not None: return telegram.send_message( chat_id, "There is already a game in this chat.") user = storage.get_user(user_id) if user is None: return telegram.send_message( chat_id, "You aren't registered yet.\n" + "Please send a '/start' to @Spyfall_Bot") if user.username is None: return telegram.send_message( chat_id, "You haven't set a username yet.\n" + "Please do so with /config.") storage.register_game(chat_id, user) telegram.send_message( chat_id, "Game created and joined.")