mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 10:17:59 -05:00
[V3 Config] Redesign "all_from_XXX" and "clear_all" methods (#1033)
* Added alternative to all_from_kind * Returned dicts include default values Also added docstrings Also removed all_globals since it's kind of redundant and it wasn't working out for me * Refactored clear_all * Tests * Tests again.. * Make all new methods coroutines
This commit is contained in:
@@ -322,7 +322,7 @@ async def get_guild_accounts(guild: discord.Guild) -> List[Account]:
|
||||
raise RuntimeError("The bank is currently global.")
|
||||
|
||||
ret = []
|
||||
accs = await _conf.member(guild.owner).all_from_kind()
|
||||
accs = await _conf.all_members(guild)
|
||||
for user_id, acc in accs.items():
|
||||
acc_data = acc.copy() # There ya go kowlin
|
||||
acc_data['created_at'] = _decode_time(acc_data['created_at'])
|
||||
@@ -353,7 +353,7 @@ async def get_global_accounts(user: discord.User) -> List[Account]:
|
||||
raise RuntimeError("The bank is not currently global.")
|
||||
|
||||
ret = []
|
||||
accs = await _conf.user(user).all_from_kind() # this is a dict of user -> acc
|
||||
accs = await _conf.all_users() # this is a dict of user -> acc
|
||||
for user_id, acc in accs.items():
|
||||
acc_data = acc.copy()
|
||||
acc_data['created_at'] = _decode_time(acc_data['created_at'])
|
||||
@@ -412,8 +412,6 @@ async def is_global() -> bool:
|
||||
async def set_global(global_: bool, user: Union[discord.User, discord.Member]) -> bool:
|
||||
"""Set global status of the bank.
|
||||
|
||||
Requires the user parameter for technical reasons.
|
||||
|
||||
.. important::
|
||||
|
||||
All accounts are reset when you switch!
|
||||
@@ -422,8 +420,6 @@ async def set_global(global_: bool, user: Union[discord.User, discord.Member]) -
|
||||
----------
|
||||
global_ : bool
|
||||
:code:`True` will set bank to global mode.
|
||||
user : `discord.User` or `discord.Member`
|
||||
Must be a Member object if changing TO global mode.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -440,12 +436,9 @@ async def set_global(global_: bool, user: Union[discord.User, discord.Member]) -
|
||||
return global_
|
||||
|
||||
if is_global():
|
||||
await _conf.user(user).clear_all()
|
||||
elif isinstance(user, discord.Member):
|
||||
await _conf.member(user).clear_all()
|
||||
await _conf.clear_all_users()
|
||||
else:
|
||||
raise RuntimeError("You must provide a member if you're changing to global"
|
||||
" bank mode.")
|
||||
await _conf.clear_all_members()
|
||||
|
||||
await _conf.is_global.set(global_)
|
||||
return global_
|
||||
|
||||
Reference in New Issue
Block a user