Run black on the repository, with the default configuration.

This commit is contained in:
Arthur Jovart
2021-09-01 21:30:56 +02:00
parent 6f5614373a
commit 4d9a1989a0
107 changed files with 8671 additions and 5258 deletions

View File

@@ -32,8 +32,8 @@ from .mixins import Hashable
from .utils import snowflake_time, _get_as_snowflake, MISSING
__all__ = (
'RoleTags',
'Role',
"RoleTags",
"Role",
)
if TYPE_CHECKING:
@@ -68,19 +68,21 @@ class RoleTags:
"""
__slots__ = (
'bot_id',
'integration_id',
'_premium_subscriber',
"bot_id",
"integration_id",
"_premium_subscriber",
)
def __init__(self, data: RoleTagPayload):
self.bot_id: Optional[int] = _get_as_snowflake(data, 'bot_id')
self.integration_id: Optional[int] = _get_as_snowflake(data, 'integration_id')
self.bot_id: Optional[int] = _get_as_snowflake(data, "bot_id")
self.integration_id: Optional[int] = _get_as_snowflake(data, "integration_id")
# NOTE: The API returns "null" for this if it's valid, which corresponds to None.
# This is different from other fields where "null" means "not there".
# So in this case, a value of None is the same as True.
# Which means we would need a different sentinel.
self._premium_subscriber: Optional[Any] = data.get('premium_subscriber', MISSING)
self._premium_subscriber: Optional[Any] = data.get(
"premium_subscriber", MISSING
)
def is_bot_managed(self) -> bool:
""":class:`bool`: Whether the role is associated with a bot."""
@@ -96,12 +98,12 @@ class RoleTags:
def __repr__(self) -> str:
return (
f'<RoleTags bot_id={self.bot_id} integration_id={self.integration_id} '
f'premium_subscriber={self.is_premium_subscriber()}>'
f"<RoleTags bot_id={self.bot_id} integration_id={self.integration_id} "
f"premium_subscriber={self.is_premium_subscriber()}>"
)
R = TypeVar('R', bound='Role')
R = TypeVar("R", bound="Role")
class Role(Hashable):
@@ -181,23 +183,23 @@ class Role(Hashable):
"""
__slots__ = (
'id',
'name',
'_permissions',
'_colour',
'position',
'managed',
'mentionable',
'hoist',
'guild',
'tags',
'_state',
"id",
"name",
"_permissions",
"_colour",
"position",
"managed",
"mentionable",
"hoist",
"guild",
"tags",
"_state",
)
def __init__(self, *, guild: Guild, state: ConnectionState, data: RolePayload):
self.guild: Guild = guild
self._state: ConnectionState = state
self.id: int = int(data['id'])
self.id: int = int(data["id"])
self._update(data)
def __str__(self) -> str:
@@ -207,14 +209,14 @@ class Role(Hashable):
return self.id
def __repr__(self) -> str:
return f'<Role id={self.id} name={self.name!r}>'
return f"<Role id={self.id} name={self.name!r}>"
def __lt__(self: R, other: R) -> bool:
if not isinstance(other, Role) or not isinstance(self, Role):
return NotImplemented
if self.guild != other.guild:
raise RuntimeError('cannot compare roles from two different guilds.')
raise RuntimeError("cannot compare roles from two different guilds.")
# the @everyone role is always the lowest role in hierarchy
guild_id = self.guild.id
@@ -246,17 +248,17 @@ class Role(Hashable):
return not r
def _update(self, data: RolePayload):
self.name: str = data['name']
self._permissions: int = int(data.get('permissions', 0))
self.position: int = data.get('position', 0)
self._colour: int = data.get('color', 0)
self.hoist: bool = data.get('hoist', False)
self.managed: bool = data.get('managed', False)
self.mentionable: bool = data.get('mentionable', False)
self.name: str = data["name"]
self._permissions: int = int(data.get("permissions", 0))
self.position: int = data.get("position", 0)
self._colour: int = data.get("color", 0)
self.hoist: bool = data.get("hoist", False)
self.managed: bool = data.get("managed", False)
self.mentionable: bool = data.get("mentionable", False)
self.tags: Optional[RoleTags]
try:
self.tags = RoleTags(data['tags'])
self.tags = RoleTags(data["tags"])
except KeyError:
self.tags = None
@@ -291,7 +293,11 @@ class Role(Hashable):
.. versionadded:: 2.0
"""
me = self.guild.me
return not self.is_default() and not self.managed and (me.top_role > self or me.id == self.guild.owner_id)
return (
not self.is_default()
and not self.managed
and (me.top_role > self or me.id == self.guild.owner_id)
)
@property
def permissions(self) -> Permissions:
@@ -316,7 +322,7 @@ class Role(Hashable):
@property
def mention(self) -> str:
""":class:`str`: Returns a string that allows you to mention a role."""
return f'<@&{self.id}>'
return f"<@&{self.id}>"
@property
def members(self) -> List[Member]:
@@ -340,15 +346,23 @@ class Role(Hashable):
http = self._state.http
change_range = range(min(self.position, position), max(self.position, position) + 1)
roles = [r.id for r in self.guild.roles[1:] if r.position in change_range and r.id != self.id]
change_range = range(
min(self.position, position), max(self.position, position) + 1
)
roles = [
r.id
for r in self.guild.roles[1:]
if r.position in change_range and r.id != self.id
]
if self.position > position:
roles.insert(0, self.id)
else:
roles.append(self.id)
payload: List[RolePositionUpdate] = [{"id": z[0], "position": z[1]} for z in zip(roles, change_range)]
payload: List[RolePositionUpdate] = [
{"id": z[0], "position": z[1]} for z in zip(roles, change_range)
]
await http.move_role_position(self.guild.id, payload, reason=reason)
async def edit(
@@ -420,23 +434,25 @@ class Role(Hashable):
if colour is not MISSING:
if isinstance(colour, int):
payload['color'] = colour
payload["color"] = colour
else:
payload['color'] = colour.value
payload["color"] = colour.value
if name is not MISSING:
payload['name'] = name
payload["name"] = name
if permissions is not MISSING:
payload['permissions'] = permissions.value
payload["permissions"] = permissions.value
if hoist is not MISSING:
payload['hoist'] = hoist
payload["hoist"] = hoist
if mentionable is not MISSING:
payload['mentionable'] = mentionable
payload["mentionable"] = mentionable
data = await self._state.http.edit_role(self.guild.id, self.id, reason=reason, **payload)
data = await self._state.http.edit_role(
self.guild.id, self.id, reason=reason, **payload
)
return Role(guild=self.guild, data=data, state=self._state)
async def delete(self, *, reason: Optional[str] = None) -> None: