mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
Rework StreamIntegration.edit to not rely on state
This commit is contained in:
parent
62b024803a
commit
c6a69062a8
@ -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,35 +238,30 @@ 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:
|
|
||||||
expire_behaviour = fields.get('expire_behavior', self.expire_behaviour)
|
|
||||||
|
|
||||||
if not isinstance(expire_behaviour, ExpireBehaviour):
|
if not isinstance(expire_behaviour, ExpireBehaviour):
|
||||||
raise InvalidArgument('expire_behaviour field must be of type ExpireBehaviour')
|
raise InvalidArgument('expire_behaviour field must be of type ExpireBehaviour')
|
||||||
|
|
||||||
expire_grace_period = fields.get('expire_grace_period', self.expire_grace_period)
|
payload['expire_behavior'] = expire_behaviour.value
|
||||||
|
|
||||||
payload = {
|
if expire_grace_period is not MISSING:
|
||||||
'expire_behavior': expire_behaviour.value,
|
payload['expire_grace_period'] = expire_grace_period
|
||||||
'expire_grace_period': expire_grace_period,
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
if enable_emoticons is not MISSING:
|
||||||
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)
|
||||||
|
|
||||||
|
if expire_behaviour is not MISSING:
|
||||||
self.expire_behaviour = expire_behaviour
|
self.expire_behaviour = expire_behaviour
|
||||||
self.expire_behavior = self.expire_behaviour
|
|
||||||
self.expire_grace_period = expire_grace_period
|
if enable_emoticons is not MISSING:
|
||||||
self.enable_emoticons = enable_emoticons
|
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|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user