Skip to content

Commit

Permalink
fix: make dm_permission a property
Browse files Browse the repository at this point in the history
  • Loading branch information
onerandomusername committed Sep 23, 2024
1 parent 79b0ca3 commit 93de3c8
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,7 @@ def __init__(
self.name_localizations: LocalizationValue = name_loc.localizations
self.nsfw: bool = False if nsfw is None else nsfw

# TODO: turn this into a property based on `1 in self.contexts` instead, stop sending dm_permission
self.dm_permission: bool = True if dm_permission is None else dm_permission
self._dm_permission: Optional[bool] = dm_permission

self._default_member_permissions: Optional[int]
if default_member_permissions is None:
Expand Down Expand Up @@ -603,6 +602,19 @@ def default_member_permissions(self) -> Optional[Permissions]:
return None
return Permissions(self._default_member_permissions)

@property
def dm_permission(self):
# check if contexts are in use at all
if self.contexts:
return InteractionContextType.bot_dm in self.contexts

return self._dm_permission

@dm_permission.setter
def dm_permission(self, value: bool) -> None:
# todo: add a deprecation warning here
self._dm_permission = value

def __repr__(self) -> str:
attrs = " ".join(f"{key}={getattr(self, key)!r}" for key in self.__repr_info__)
return f"<{type(self).__name__} {attrs}>"
Expand Down Expand Up @@ -641,7 +653,6 @@ def to_dict(self) -> EditApplicationCommandPayload:
if self._default_member_permissions is not None
else None
),
"dm_permission": self.dm_permission,
"default_permission": True,
"nsfw": self.nsfw,
"integration_types": (
Expand All @@ -657,6 +668,9 @@ def to_dict(self) -> EditApplicationCommandPayload:
if (loc := self.name_localizations.data) is not None:
data["name_localizations"] = loc

if not self.contexts and self.dm_permission is not None:
data["dm_permission"] = self.dm_permission

return data

def localize(self, store: LocalizationProtocol) -> None:
Expand Down

0 comments on commit 93de3c8

Please sign in to comment.