[Config] Retrieve/save values with async context manager (#1131)

* [Config] Retrieve/save values with async context manager

* Add a little docstring

* Documentation

* Implement async with syntax in existing modules
This commit is contained in:
Tobotimus
2017-12-04 14:07:34 +11:00
committed by palmtree5
parent 9b1018fa96
commit 9dbf56f942
8 changed files with 165 additions and 75 deletions

View File

@@ -328,10 +328,9 @@ class Admin:
"""
Add a role to the list of available selfroles.
"""
curr_selfroles = await self.conf.guild(ctx.guild).selfroles()
if role.id not in curr_selfroles:
curr_selfroles.append(role.id)
await self.conf.guild(ctx.guild).selfroles.set(curr_selfroles)
async with self.conf.guild(ctx.guild).selfroles() as curr_selfroles:
if role.id not in curr_selfroles:
curr_selfroles.append(role.id)
await ctx.send("The selfroles list has been successfully modified.")
@@ -341,9 +340,8 @@ class Admin:
"""
Removes a role from the list of available selfroles.
"""
curr_selfroles = await self.conf.guild(ctx.guild).selfroles()
curr_selfroles.remove(role.id)
await self.conf.guild(ctx.guild).selfroles.set(curr_selfroles)
async with self.conf.guild(ctx.guild).selfroles() as curr_selfroles:
curr_selfroles.remove(role.id)
await ctx.send("The selfroles list has been successfully modified.")