|
109 | 109 | Guild as GuildPayload,
|
110 | 110 | RolePositionUpdate as RolePositionUpdatePayload,
|
111 | 111 | GuildFeature,
|
| 112 | + IncidentData, |
112 | 113 | )
|
113 | 114 | from .types.threads import (
|
114 | 115 | Thread as ThreadPayload,
|
@@ -320,6 +321,7 @@ class Guild(Hashable):
|
320 | 321 | 'premium_progress_bar_enabled',
|
321 | 322 | '_safety_alerts_channel_id',
|
322 | 323 | 'max_stage_video_users',
|
| 324 | + '_incidents_data', |
323 | 325 | )
|
324 | 326 |
|
325 | 327 | _PREMIUM_GUILD_LIMITS: ClassVar[Dict[Optional[int], _GuildLimit]] = {
|
@@ -509,6 +511,7 @@ def _from_data(self, guild: GuildPayload) -> None:
|
509 | 511 | self.owner_id: Optional[int] = utils._get_as_snowflake(guild, 'owner_id')
|
510 | 512 | self._large: Optional[bool] = None if self._member_count is None else self._member_count >= 250
|
511 | 513 | self._afk_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'afk_channel_id')
|
| 514 | + self._incidents_data: Optional[IncidentData] = guild.get('incidents_data') |
512 | 515 |
|
513 | 516 | if 'channels' in guild:
|
514 | 517 | channels = guild['channels']
|
@@ -1843,6 +1846,8 @@ async def edit(
|
1843 | 1846 | mfa_level: MFALevel = MISSING,
|
1844 | 1847 | raid_alerts_disabled: bool = MISSING,
|
1845 | 1848 | safety_alerts_channel: TextChannel = MISSING,
|
| 1849 | + invites_disabled_until: datetime.datetime = MISSING, |
| 1850 | + dms_disabled_until: datetime.datetime = MISSING, |
1846 | 1851 | ) -> Guild:
|
1847 | 1852 | r"""|coro|
|
1848 | 1853 |
|
@@ -1969,6 +1974,18 @@ async def edit(
|
1969 | 1974 |
|
1970 | 1975 | .. versionadded:: 2.3
|
1971 | 1976 |
|
| 1977 | + invites_disabled_until: Optional[:class:`datetime.datetime`] |
| 1978 | + The time when invites should be enabled again, or ``None`` to disable the action. |
| 1979 | + This must be a timezone-aware datetime object. Consider using :func:`utils.utcnow`. |
| 1980 | +
|
| 1981 | + .. versionadded:: 2.4 |
| 1982 | +
|
| 1983 | + dms_disabled_until: Optional[:class:`datetime.datetime`] |
| 1984 | + The time when direct messages should be allowed again, or ``None`` to disable the action. |
| 1985 | + This must be a timezone-aware datetime object. Consider using :func:`utils.utcnow`. |
| 1986 | +
|
| 1987 | + .. versionadded:: 2.4 |
| 1988 | +
|
1972 | 1989 | Raises
|
1973 | 1990 | -------
|
1974 | 1991 | Forbidden
|
@@ -2157,6 +2174,30 @@ async def edit(
|
2157 | 2174 |
|
2158 | 2175 | await http.edit_guild_mfa_level(self.id, mfa_level=mfa_level.value)
|
2159 | 2176 |
|
| 2177 | + incident_actions_payload: IncidentData = {} |
| 2178 | + if invites_disabled_until is not MISSING: |
| 2179 | + if invites_disabled_until is None: |
| 2180 | + incident_actions_payload['invites_disabled_until'] = None |
| 2181 | + else: |
| 2182 | + if invites_disabled_until.tzinfo is None: |
| 2183 | + raise TypeError( |
| 2184 | + 'invites_disabled_until must be an aware datetime. Consider using discord.utils.utcnow() or datetime.datetime.now().astimezone() for local time.' |
| 2185 | + ) |
| 2186 | + incident_actions_payload['invites_disabled_until'] = invites_disabled_until.isoformat() |
| 2187 | + |
| 2188 | + if dms_disabled_until is not MISSING: |
| 2189 | + if dms_disabled_until is None: |
| 2190 | + incident_actions_payload['dms_disabled_until'] = None |
| 2191 | + else: |
| 2192 | + if dms_disabled_until.tzinfo is None: |
| 2193 | + raise TypeError( |
| 2194 | + 'dms_disabled_until must be an aware datetime. Consider using discord.utils.utcnow() or datetime.datetime.now().astimezone() for local time.' |
| 2195 | + ) |
| 2196 | + incident_actions_payload['dms_disabled_until'] = dms_disabled_until.isoformat() |
| 2197 | + |
| 2198 | + if incident_actions_payload: |
| 2199 | + await http.edit_incident_actions(self.id, payload=incident_actions_payload) |
| 2200 | + |
2160 | 2201 | data = await http.edit_guild(self.id, reason=reason, **fields)
|
2161 | 2202 | return Guild(data=data, state=self._state)
|
2162 | 2203 |
|
@@ -4292,3 +4333,47 @@ async def create_automod_rule(
|
4292 | 4333 | )
|
4293 | 4334 |
|
4294 | 4335 | return AutoModRule(data=data, guild=self, state=self._state)
|
| 4336 | + |
| 4337 | + @property |
| 4338 | + def invites_paused_until(self) -> Optional[datetime.datetime]: |
| 4339 | + """Optional[:class:`datetime.datetime`]: If invites are paused, returns when |
| 4340 | + invites will get enabled in UTC, otherwise returns None. |
| 4341 | +
|
| 4342 | + .. versionadded:: 2.4 |
| 4343 | + """ |
| 4344 | + if not self._incidents_data: |
| 4345 | + return None |
| 4346 | + |
| 4347 | + return utils.parse_time(self._incidents_data.get('invites_disabled_until')) |
| 4348 | + |
| 4349 | + @property |
| 4350 | + def dms_paused_until(self) -> Optional[datetime.datetime]: |
| 4351 | + """Optional[:class:`datetime.datetime`]: If DMs are paused, returns when DMs |
| 4352 | + will get enabled in UTC, otherwise returns None. |
| 4353 | +
|
| 4354 | + .. versionadded:: 2.4 |
| 4355 | + """ |
| 4356 | + if not self._incidents_data: |
| 4357 | + return None |
| 4358 | + |
| 4359 | + return utils.parse_time(self._incidents_data.get('dms_disabled_until')) |
| 4360 | + |
| 4361 | + def invites_paused(self) -> bool: |
| 4362 | + """:class:`bool`: Whether invites are paused in the guild. |
| 4363 | +
|
| 4364 | + .. versionadded:: 2.4 |
| 4365 | + """ |
| 4366 | + if not self.invites_paused_until: |
| 4367 | + return False |
| 4368 | + |
| 4369 | + return self.invites_paused_until > utils.utcnow() |
| 4370 | + |
| 4371 | + def dms_paused(self) -> bool: |
| 4372 | + """:class:`bool`: Whether DMs are paused in the guild. |
| 4373 | +
|
| 4374 | + .. versionadded:: 2.4 |
| 4375 | + """ |
| 4376 | + if not self.dms_paused_until: |
| 4377 | + return False |
| 4378 | + |
| 4379 | + return self.dms_paused_until > utils.utcnow() |
0 commit comments