diff options
| author | Rapptz <[email protected]> | 2016-11-21 03:08:03 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-11-21 03:08:03 -0500 |
| commit | 7ff7b0fb9c373c2145788408e60ac18e24c9401a (patch) | |
| tree | dfc30f84d19fb9667341f67eb9af4cde7aa74a04 | |
| parent | Support MESSAGE_REACTION_REMOVE_ALL event. (diff) | |
| download | discord.py-7ff7b0fb9c373c2145788408e60ac18e24c9401a.tar.xz discord.py-7ff7b0fb9c373c2145788408e60ac18e24c9401a.zip | |
Add Permissions.update and PermissionOverwrite.update for bulk edits.
This should satisfy those that have a one-line obsession and make things
a little bit easier if you have a dict.
| -rw-r--r-- | discord/permissions.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/discord/permissions.py b/discord/permissions.py index e6a1df58..74be8a43 100644 --- a/discord/permissions.py +++ b/discord/permissions.py @@ -162,6 +162,26 @@ class Permissions: "Voice" permissions from the official Discord UI set to True.""" return cls(0b00000011111100000000000000000000) + def update(self, **kwargs): + """Bulk updates this permission object. + + Allows you to set multiple attributes by using keyword + arguments. The names must be equivalent to the properties + listed. Extraneous key/value pairs will be silently ignored. + + Parameters + ------------ + \*\*kwargs + A list of key/value pairs to bulk update permissions with. + """ + for key, value in kwargs.items(): + try: + is_property = isinstance(getattr(self.__class__, key), property) + except AttributeError: + continue + + if is_property: + setattr(self, key, value) def _bit(self, index): return bool((self.value >> index) & 1) @@ -537,6 +557,24 @@ class PermissionOverwrite: return ret + def update(self, **kwargs): + """Bulk updates this permission overwrite object. + + Allows you to set multiple attributes by using keyword + arguments. The names must be equivalent to the properties + listed. Extraneous key/value pairs will be silently ignored. + + Parameters + ------------ + \*\*kwargs + A list of key/value pairs to bulk update with. + """ + for key, value in kwargs.items(): + if key not in self.VALID_NAMES: + continue + + setattr(self, key, value) + def __iter__(self): for key in self.VALID_NAMES: yield key, self._values.get(key) |