コード例 #1
0
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)
コード例 #2
0
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
コード例 #3
0
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)
コード例 #4
0
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)
コード例 #5
0
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