mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-20 16:00:29 +00:00
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.
This commit is contained in:
parent
92c3c2804d
commit
7ff7b0fb9c
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user