Rework StreamIntegration.edit to not rely on state

This commit is contained in:
Rapptz 2021-06-29 21:45:06 -04:00
parent 62b024803a
commit c6a69062a8

View File

@ -25,8 +25,8 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations from __future__ import annotations
import datetime import datetime
from typing import Optional, TYPE_CHECKING, overload, Type, Tuple from typing import Any, Dict, Optional, TYPE_CHECKING, overload, Type, Tuple
from .utils import _get_as_snowflake, get, parse_time from .utils import _get_as_snowflake, parse_time, MISSING
from .user import User from .user import User
from .errors import InvalidArgument from .errors import InvalidArgument
from .enums import try_enum, ExpireBehaviour from .enums import try_enum, ExpireBehaviour
@ -204,23 +204,15 @@ class StreamIntegration(Integration):
@property @property
def role(self) -> Optional[Role]: def role(self) -> Optional[Role]:
"""Optional[:class:`Role`] The role which the integration uses for subscribers.""" """Optional[:class:`Role`] The role which the integration uses for subscribers."""
return self.guild.get_role(self._role_id) return self.guild.get_role(self._role_id) # type: ignore
@overload
async def edit( async def edit(
self, self,
*, *,
expire_behaviour: Optional[ExpireBehaviour] = ..., expire_behaviour: ExpireBehaviour = MISSING,
expire_grace_period: Optional[int] = ..., expire_grace_period: int = MISSING,
enable_emoticons: Optional[bool] = ..., enable_emoticons: bool = MISSING,
) -> None: ) -> None:
...
@overload
async def edit(self, **fields) -> None:
...
async def edit(self, **fields) -> None:
"""|coro| """|coro|
Edits the integration. Edits the integration.
@ -246,34 +238,29 @@ class StreamIntegration(Integration):
InvalidArgument InvalidArgument
``expire_behaviour`` did not receive a :class:`ExpireBehaviour`. ``expire_behaviour`` did not receive a :class:`ExpireBehaviour`.
""" """
try: payload: Dict[str, Any] = {}
expire_behaviour = fields['expire_behaviour'] if expire_behaviour is not MISSING:
except KeyError: if not isinstance(expire_behaviour, ExpireBehaviour):
expire_behaviour = fields.get('expire_behavior', self.expire_behaviour) raise InvalidArgument('expire_behaviour field must be of type ExpireBehaviour')
if not isinstance(expire_behaviour, ExpireBehaviour): payload['expire_behavior'] = expire_behaviour.value
raise InvalidArgument('expire_behaviour field must be of type ExpireBehaviour')
expire_grace_period = fields.get('expire_grace_period', self.expire_grace_period) if expire_grace_period is not MISSING:
payload['expire_grace_period'] = expire_grace_period
payload = { if enable_emoticons is not MISSING:
'expire_behavior': expire_behaviour.value,
'expire_grace_period': expire_grace_period,
}
try:
enable_emoticons = fields['enable_emoticons']
except KeyError:
enable_emoticons = self.enable_emoticons
else:
payload['enable_emoticons'] = enable_emoticons payload['enable_emoticons'] = enable_emoticons
await self._state.http.edit_integration(self.guild.id, self.id, **payload) await self._state.http.edit_integration(self.guild.id, self.id, **payload)
self.expire_behaviour = expire_behaviour if expire_behaviour is not MISSING:
self.expire_behavior = self.expire_behaviour self.expire_behaviour = expire_behaviour
self.expire_grace_period = expire_grace_period
self.enable_emoticons = enable_emoticons if enable_emoticons is not MISSING:
self.enable_emoticons = enable_emoticons
if expire_grace_period is not MISSING:
self.expire_grace_period = expire_grace_period
async def sync(self) -> None: async def sync(self) -> None:
"""|coro| """|coro|