From 01aa7617453d10a0bd3ff43ced8406c37f55db30 Mon Sep 17 00:00:00 2001 From: Jeff Carter Date: Sun, 6 Feb 2022 23:58:00 -0600 Subject: [PATCH 1/3] feat: implement ctx.custom_id and ctx.label attributes --- interactions/context.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/interactions/context.py b/interactions/context.py index 0d8a854dc..0b2166b07 100644 --- a/interactions/context.py +++ b/interactions/context.py @@ -753,6 +753,8 @@ class ComponentContext(CommandContext): "type", "data", "target", + "custom_id", + "label", "version", "token", "guild_id", @@ -768,6 +770,11 @@ def __init__(self, **kwargs) -> None: super().__init__(**kwargs) self.responded = False # remind components that it was not responded to. self.deferred = False # remind components they not have been deferred + self.custom_id = self.data.custom_id + for action_row in self.message.components: + for component in action_row['components']: + if component['custom_id'] == self.custom_id and component['type'] == 2: + self.label = component.get("label") async def defer( self, ephemeral: Optional[bool] = False, edit_origin: Optional[bool] = False From 921d864cabf9f3f2cb565ccb49bebb2083b7e33b Mon Sep 17 00:00:00 2001 From: Jeff Carter Date: Mon, 7 Feb 2022 00:01:38 -0600 Subject: [PATCH 2/3] fix: black formatting --- interactions/context.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interactions/context.py b/interactions/context.py index 0b2166b07..693435fd6 100644 --- a/interactions/context.py +++ b/interactions/context.py @@ -772,8 +772,8 @@ def __init__(self, **kwargs) -> None: self.deferred = False # remind components they not have been deferred self.custom_id = self.data.custom_id for action_row in self.message.components: - for component in action_row['components']: - if component['custom_id'] == self.custom_id and component['type'] == 2: + for component in action_row["components"]: + if component["custom_id"] == self.custom_id and component["type"] == 2: self.label = component.get("label") async def defer( From 4c6d4efb8b83d6f7435fe6408309a043198e5598 Mon Sep 17 00:00:00 2001 From: Jeff Carter Date: Mon, 7 Feb 2022 11:36:49 -0600 Subject: [PATCH 3/3] feat: add ctx.custom_id and ctx.label as properties of ComponentContext --- interactions/context.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/interactions/context.py b/interactions/context.py index 693435fd6..8e243e0ec 100644 --- a/interactions/context.py +++ b/interactions/context.py @@ -753,8 +753,6 @@ class ComponentContext(CommandContext): "type", "data", "target", - "custom_id", - "label", "version", "token", "guild_id", @@ -770,11 +768,17 @@ def __init__(self, **kwargs) -> None: super().__init__(**kwargs) self.responded = False # remind components that it was not responded to. self.deferred = False # remind components they not have been deferred - self.custom_id = self.data.custom_id + + @property + def custom_id(self): + return self.data.custom_id + + @property + def label(self): for action_row in self.message.components: for component in action_row["components"]: if component["custom_id"] == self.custom_id and component["type"] == 2: - self.label = component.get("label") + return component.get("label") async def defer( self, ephemeral: Optional[bool] = False, edit_origin: Optional[bool] = False