|
26 | 26 | from __future__ import annotations |
27 | 27 |
|
28 | 28 | from typing import TYPE_CHECKING, Any |
| 29 | +from .enums import ApplicationEventWebhookStatus, try_enum |
29 | 30 |
|
30 | 31 | from . import utils |
31 | 32 | from .asset import Asset |
|
46 | 47 | "PartialAppInfo", |
47 | 48 | "AppInstallParams", |
48 | 49 | "IntegrationTypesConfig", |
| 50 | + "ApplicationEventWebhookStatus", |
49 | 51 | ) |
50 | 52 |
|
51 | 53 |
|
@@ -151,6 +153,11 @@ class AppInfo: |
151 | 153 |
|
152 | 154 | .. versionadded:: 2.7 |
153 | 155 |
|
| 156 | + event_webhooks_status: :class:`ApplicationEventWebhookStatus` |
| 157 | + The status of event webhooks for the application. |
| 158 | +
|
| 159 | + .. versionadded:: 2.7 |
| 160 | +
|
154 | 161 | event_webhooks_types: Optional[List[:class:`str`]] |
155 | 162 | List of event webhook types subscribed to, if set. |
156 | 163 |
|
@@ -260,7 +267,9 @@ def __init__(self, state: ConnectionState, data: AppInfoPayload): |
260 | 267 | "role_connections_verification_url" |
261 | 268 | ) |
262 | 269 | self.event_webhooks_url: str | None = data.get("event_webhooks_url") |
263 | | - self._event_webhooks_status: int | None = data.get("event_webhooks_status") |
| 270 | + self.event_webhooks_status: ApplicationEventWebhookStatus | None = data.get( |
| 271 | + "event_webhooks_status" |
| 272 | + ) and try_enum(ApplicationEventWebhookStatus, data["event_webhooks_status"]) |
264 | 273 | self.event_webhooks_types: list[str] | None = data.get("event_webhooks_types") |
265 | 274 |
|
266 | 275 | self.install_params: AppInstallParams | None = data.get("install_params") and ( |
@@ -307,7 +316,7 @@ async def edit( |
307 | 316 | integration_types_config: IntegrationTypesConfig | None = utils.MISSING, |
308 | 317 | flags: ApplicationFlags | None = utils.MISSING, |
309 | 318 | event_webhooks_url: str | None = utils.MISSING, |
310 | | - event_webhooks_status: bool = utils.MISSING, |
| 319 | + event_webhooks_status: ApplicationEventWebhookStatus = utils.MISSING, |
311 | 320 | event_webhooks_types: list[str] | None = utils.MISSING, |
312 | 321 | ) -> AppInfo: |
313 | 322 | """|coro| |
@@ -346,8 +355,9 @@ async def edit( |
346 | 355 | Application public flags. Pass ``None`` to clear (not typical). |
347 | 356 | event_webhooks_url: Optional[:class:`str`] |
348 | 357 | Event webhooks callback URL for receiving application webhook events. Pass ``None`` to clear. |
349 | | - event_webhooks_status: :class:`bool` |
350 | | - Whether webhook events are enabled. ``True`` maps to API value ``2`` (enabled), ``False`` maps to ``1`` (disabled). |
| 358 | + event_webhooks_status: :class:`ApplicationEventWebhookStatus` |
| 359 | + The desired webhook status. Pass an :class:`ApplicationEventWebhookStatus` value to set |
| 360 | + a specific status (``DISABLED``=1, ``ENABLED``=2, ``DISABLED_BY_DISCORD``=3). |
351 | 361 | event_webhooks_types: Optional[List[:class:`str`]] |
352 | 362 | List of webhook event types to subscribe to. Pass ``None`` to clear. |
353 | 363 |
|
@@ -402,7 +412,7 @@ async def edit( |
402 | 412 | if event_webhooks_url is not utils.MISSING: |
403 | 413 | payload["event_webhooks_url"] = event_webhooks_url |
404 | 414 | if event_webhooks_status is not utils.MISSING: |
405 | | - payload["event_webhooks_status"] = 2 if event_webhooks_status else 1 |
| 415 | + payload["event_webhooks_status"] = event_webhooks_status.value |
406 | 416 | if event_webhooks_types is not utils.MISSING: |
407 | 417 | payload["event_webhooks_types"] = event_webhooks_types |
408 | 418 |
|
@@ -452,16 +462,6 @@ def summary(self) -> str | None: |
452 | 462 | ) |
453 | 463 | return self._summary |
454 | 464 |
|
455 | | - @property |
456 | | - def event_webhooks_enabled(self) -> bool | None: |
457 | | - """Returns whether event webhooks are enabled. |
458 | | - This is a convenience around the raw API status integer where ``True`` means enabled and ``False`` means disabled. |
459 | | - ``None`` indicates the status is not present. |
460 | | - """ |
461 | | - if self._event_webhooks_status is None: |
462 | | - return None |
463 | | - return self._event_webhooks_status == 2 |
464 | | - |
465 | 465 |
|
466 | 466 | class PartialAppInfo: |
467 | 467 | """Represents a partial AppInfo given by :func:`~discord.abc.GuildChannel.create_invite` |
|
0 commit comments