Skip to content

Commit 03a46e8

Browse files
committed
refactor(AppInfo): rename event_webhooks_status to _event_webhooks_status and add setter for event_webhooks_enabled
1 parent 8c0dcd7 commit 03a46e8

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

discord/appinfo.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,6 @@ class AppInfo:
151151
152152
.. versionadded:: 2.7
153153
154-
event_webhooks_status: Optional[:class:`int`]
155-
The raw event webhooks status integer from the API (``2`` enabled, ``1`` disabled) if present.
156-
Prefer :attr:`event_webhooks_enabled` for a boolean form.
157-
158-
.. versionadded:: 2.7
159-
160154
event_webhooks_types: Optional[List[:class:`str`]]
161155
List of event webhook types subscribed to, if set.
162156
@@ -213,7 +207,7 @@ class AppInfo:
213207
"interactions_endpoint_url",
214208
"role_connections_verification_url",
215209
"event_webhooks_url",
216-
"event_webhooks_status",
210+
"_event_webhooks_status",
217211
"event_webhooks_types",
218212
"integration_types_config",
219213
"install_params",
@@ -266,7 +260,7 @@ def __init__(self, state: ConnectionState, data: AppInfoPayload):
266260
"role_connections_verification_url"
267261
)
268262
self.event_webhooks_url: str | None = data.get("event_webhooks_url")
269-
self.event_webhooks_status: int | None = data.get("event_webhooks_status")
263+
self._event_webhooks_status: int | None = data.get("event_webhooks_status")
270264
self.event_webhooks_types: list[str] | None = data.get("event_webhooks_types")
271265

272266
self.install_params: AppInstallParams | None = data.get("install_params") and (
@@ -461,13 +455,24 @@ def summary(self) -> str | None:
461455
@property
462456
def event_webhooks_enabled(self) -> bool | None:
463457
"""Returns whether event webhooks are enabled.
464-
465-
This is a convenience around :attr:`event_webhooks_status` where ``True`` means enabled and ``False`` means disabled.
458+
This is a convenience around the raw API status integer where ``True`` means enabled and ``False`` means disabled.
466459
``None`` indicates the status is not present.
467460
"""
468-
if self.event_webhooks_status is None:
461+
if self._event_webhooks_status is None:
469462
return None
470-
return self.event_webhooks_status == 2
463+
return self._event_webhooks_status == 2
464+
465+
@event_webhooks_enabled.setter
466+
def event_webhooks_enabled(self, value: bool | None) -> None:
467+
"""Set whether event webhooks are enabled.
468+
469+
Setting to ``True`` maps to the API value ``2`` (enabled), ``False`` maps to ``1`` (disabled),
470+
and ``None`` clears the status (sets it to ``None``).
471+
"""
472+
if value is None:
473+
self._event_webhooks_status = None
474+
return
475+
self._event_webhooks_status = 2 if value else 1
471476

472477

473478
class PartialAppInfo:

0 commit comments

Comments
 (0)