Skip to content

Commit ef0cb75

Browse files
committed
feat: add ApplicationEventWebhookStatus enum and update AppInfo to use it
1 parent 20cd5ed commit ef0cb75

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

discord/appinfo.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from __future__ import annotations
2727

2828
from typing import TYPE_CHECKING, Any
29+
from .enums import ApplicationEventWebhookStatus, try_enum
2930

3031
from . import utils
3132
from .asset import Asset
@@ -46,6 +47,7 @@
4647
"PartialAppInfo",
4748
"AppInstallParams",
4849
"IntegrationTypesConfig",
50+
"ApplicationEventWebhookStatus",
4951
)
5052

5153

@@ -151,6 +153,11 @@ class AppInfo:
151153
152154
.. versionadded:: 2.7
153155
156+
event_webhooks_status: :class:`ApplicationEventWebhookStatus`
157+
The status of event webhooks for the application.
158+
159+
.. versionadded:: 2.7
160+
154161
event_webhooks_types: Optional[List[:class:`str`]]
155162
List of event webhook types subscribed to, if set.
156163
@@ -260,7 +267,9 @@ def __init__(self, state: ConnectionState, data: AppInfoPayload):
260267
"role_connections_verification_url"
261268
)
262269
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"])
264273
self.event_webhooks_types: list[str] | None = data.get("event_webhooks_types")
265274

266275
self.install_params: AppInstallParams | None = data.get("install_params") and (
@@ -307,7 +316,7 @@ async def edit(
307316
integration_types_config: IntegrationTypesConfig | None = utils.MISSING,
308317
flags: ApplicationFlags | None = utils.MISSING,
309318
event_webhooks_url: str | None = utils.MISSING,
310-
event_webhooks_status: bool = utils.MISSING,
319+
event_webhooks_status: ApplicationEventWebhookStatus = utils.MISSING,
311320
event_webhooks_types: list[str] | None = utils.MISSING,
312321
) -> AppInfo:
313322
"""|coro|
@@ -346,8 +355,9 @@ async def edit(
346355
Application public flags. Pass ``None`` to clear (not typical).
347356
event_webhooks_url: Optional[:class:`str`]
348357
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).
351361
event_webhooks_types: Optional[List[:class:`str`]]
352362
List of webhook event types to subscribe to. Pass ``None`` to clear.
353363
@@ -402,7 +412,7 @@ async def edit(
402412
if event_webhooks_url is not utils.MISSING:
403413
payload["event_webhooks_url"] = event_webhooks_url
404414
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
406416
if event_webhooks_types is not utils.MISSING:
407417
payload["event_webhooks_types"] = event_webhooks_types
408418

@@ -452,16 +462,6 @@ def summary(self) -> str | None:
452462
)
453463
return self._summary
454464

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-
465465

466466
class PartialAppInfo:
467467
"""Represents a partial AppInfo given by :func:`~discord.abc.GuildChannel.create_invite`

discord/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ def __init__(
244244
self.loop: asyncio.AbstractEventLoop = (
245245
asyncio.get_event_loop() if loop is None else loop
246246
)
247-
self._listeners: dict[str, list[tuple[asyncio.Future, Callable[..., bool]]]] = (
248-
{}
249-
)
247+
self._listeners: dict[
248+
str, list[tuple[asyncio.Future, Callable[..., bool]]]
249+
] = {}
250250
self.shard_id: int | None = options.get("shard_id")
251251
self.shard_count: int | None = options.get("shard_count")
252252

discord/enums.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"SubscriptionStatus",
8585
"SeparatorSpacingSize",
8686
"SelectDefaultValueType",
87+
"ApplicationEventWebhookStatus",
8788
)
8889

8990

@@ -1131,6 +1132,14 @@ class SelectDefaultValueType(Enum):
11311132
user = "user"
11321133

11331134

1135+
class ApplicationEventWebhookStatus(Enum):
1136+
"""Represents the application event webhook status."""
1137+
1138+
DISABLED = 1
1139+
ENABLED = 2
1140+
DISABLED_BY_DISCORD = 3
1141+
1142+
11341143
T = TypeVar("T")
11351144

11361145

0 commit comments

Comments
 (0)