Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
feat: add disable_components to interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
kiki7000 committed Oct 13, 2021
1 parent 9e791c5 commit 67c53e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
5 changes: 2 additions & 3 deletions discord_components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,8 @@ def disable(component: Component):
component.disabled = True
return component

disabled_row = list(map(disable, self._components))
self._components = disabled_row
return disabled_row
self._components = list(map(disable, self._components))
return self

def __list__(self) -> List[Component]:
return self.components
Expand Down
20 changes: 5 additions & 15 deletions discord_components/dpy_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ def get_component(self, custom_id: str) -> Optional[Component]:
return component

async def disable_components(self) -> None:
disabled_components = [row.disable_components() for row in self.components]
await self.edit(
components=disabled_components,
components=[row.disable_components() for row in self.components],
)

async def edit(
Expand All @@ -67,9 +66,7 @@ async def edit(
data["content"] = content

if embed is not None and embeds is not None:
raise InvalidArgument(
"cannot pass both embed and embeds parameter to edit()"
)
raise InvalidArgument("cannot pass both embed and embeds parameter to edit()")

if embed is not None:
data["embeds"] = [embed.to_dict()]
Expand All @@ -83,16 +80,11 @@ async def edit(
data["flags"] = flags.value

if allowed_mentions is None:
if (
state.allowed_mentions is not None
and self.author.id == self._state.self_id
):
if state.allowed_mentions is not None and self.author.id == self._state.self_id:
data["allowed_mentions"] = state.allowed_mentions.to_dict()
else:
if state.allowed_mentions is not None:
data["allowed_mentions"] = state.allowed_mentions.merge(
allowed_mentions
).to_dict()
data["allowed_mentions"] = state.allowed_mentions.merge(allowed_mentions).to_dict()
else:
data["allowed_mentions"] = allowed_mentions.to_dict()

Expand Down Expand Up @@ -253,9 +245,7 @@ async def send(

elif embeds is not None:
if len(embeds) > 10:
raise InvalidArgument(
"embeds parameter must be a list of up to 10 elements"
)
raise InvalidArgument("embeds parameter must be a list of up to 10 elements")
embeds = [embed.to_dict() for embed in embeds]

if stickers is not None:
Expand Down
5 changes: 5 additions & 0 deletions discord_components/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,8 @@ async def edit_origin(
return res
elif res is not None:
await res.delete(delay=delete_after)

async def disable_components(self) -> None:
await self.edit_origin(
components=[row.disable_components() for row in self.message.components],
)

0 comments on commit 67c53e2

Please sign in to comment.