[Config] Group.__call__() has same behaviour as Group.all() (#2018)

* Make calling groups useful

This makes config.Group.__call__ effectively an alias for Group.all(),
with the added bonus of becoming a context manager.

get_raw has been updated as well to reflect the new behaviour of
__call__.

* Fix unintended side-effects of new behaviour

* Add tests

* Add test for get_raw mixing in defaults

* Another cleanup for relying on old behaviour internally

* Fix bank relying on old behaviour

* Reformat
This commit is contained in:
Toby Harradine
2018-08-26 23:30:36 +10:00
committed by GitHub
parent 48a7a21aca
commit dbed24aaca
3 changed files with 99 additions and 29 deletions

View File

@@ -400,19 +400,18 @@ async def get_account(member: Union[discord.Member, discord.User]) -> Account:
"""
if await is_global():
acc_data = (await _conf.user(member)()).copy()
default = _DEFAULT_USER.copy()
all_accounts = await _conf.all_users()
else:
acc_data = (await _conf.member(member)()).copy()
default = _DEFAULT_MEMBER.copy()
all_accounts = await _conf.all_members(member.guild)
if acc_data == {}:
acc_data = default
acc_data["name"] = member.display_name
if member.id not in all_accounts:
acc_data = {"name": member.display_name, "created_at": _DEFAULT_MEMBER["created_at"]}
try:
acc_data["balance"] = await get_default_balance(member.guild)
except AttributeError:
acc_data["balance"] = await get_default_balance()
else:
acc_data = all_accounts[member.id]
acc_data["created_at"] = _decode_time(acc_data["created_at"])
return Account(**acc_data)