From 0fca30bbdac79d8d33e152e7e7116c5ffa1356ca Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 1 Nov 2020 23:28:07 +0100 Subject: Add WrongAction exception and use it instaed of returning error Signed-off-by: Olivier Gayot --- swiftstory/Client.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'swiftstory/Client.py') diff --git a/swiftstory/Client.py b/swiftstory/Client.py index 93aa900..b1a6ae7 100644 --- a/swiftstory/Client.py +++ b/swiftstory/Client.py @@ -1,6 +1,7 @@ import asyncio import logging +from swiftstory.exception import WrongAction from swiftstory.Status import error @@ -14,7 +15,7 @@ class Client: def join_game(self, game_name, lang): if self.game is not None: - return error('You are already in a game') + raise WrongAction('You are already in a game') if lang is None: lang = 'en' @@ -29,37 +30,37 @@ class Client: def play_white_card(self, card_id): if self.game is None: - return error('You have to join a game first') + raise WrongAction('You have to join a game first') return self.game.try_play_card(self.player, card_id) def pick_black_card(self): if self.game is None: - return error('You have to join a game first') + raise WrongAction('You have to join a game first') return self.game.try_become_judge(self.player) def collect_cards(self): if self.game is None: - return error('You have to join a game first') + raise WrongAction('You have to join a game first') return self.game.try_collect_cards(self.player) def designate_card(self, card_id): if self.game is None: - return error('You have to join a game first') + raise WrongAction('You have to join a game first') return self.game.try_designate_card(self.player, card_id) def view_player_cards(self): if self.game is None: - return error('You have to join a game first') + raise WrongAction('You have to join a game first') return self.game.try_view_player_cards(self.player) def view_played_cards(self): if self.game is None: - return error('You have to join a game first') + raise WrongAction('You have to join a game first') return self.game.try_view_played_cards(self.player) def view_black_card(self): if self.game is None: - return error('You have to join a game first') + raise WrongAction('You have to join a game first') return self.game.try_view_black_card(self.player) def register_notification(self, message): -- cgit v1.2.3