def _get_account(account_id: Union[AccountId, str], server: Server) -> Account: """Get account from server, unless it doesn't exist, in which case raise""" account_id = parse_account_id(account_id) if not server.has_account(account_id): raise AccountCommandException(account_id) return server.get_account(account_id)
def toggle_public(author_id: Union[AccountId, str], account_id: Union[AccountId, str], server: Server): """Marks account as public""" account = server.get_account(account_id) value = not account.public server.mark_public(author_id, account, value) return value
def process_balance(author: AccountId, message: str, server: Server, **kwargs): """Processes a message requesting the balance on an account.""" if not server.has_account(author): return 'Hi there %s. I can\'t tell you what the balance on your account is because you don\'t have an account yet. ' \ 'You can open one with the `open` command.' % author.readable() account = server.get_account(author) main_response = 'The balance on your account is %s.' % account.get_balance() return 'Hi there %s %s. %s Have a great day.' % (account.get_authorization().name.lower(), author.readable(), main_response)
def assert_is_account(account_name: Union[str, AccountId], server: Server) -> Account: """Asserts that a particular account exists. Returns the account.""" if isinstance(account_name, str): account_name = parse_account_id(account_name) if not server.has_account(account_name): raise CommandException( ('Sorry, I can\'t process your request because %s does not have an account yet. ' 'Accounts can be opened using the `open` command.') % account_name.readable()) return server.get_account(account_name)
def get_authorization_or_citizen(author: AccountId, server: Server): """Gets an account's authorization if it exists and the default citizen authorization otherwise.""" return server.get_account(author).get_authorization() \ if server.has_account(author) \ else Authorization.CITIZEN