From 9a0cca1c0e58baa185bc713551490465e2375a4b Mon Sep 17 00:00:00 2001 From: FAZuH Date: Thu, 5 Dec 2024 07:59:26 +0700 Subject: [PATCH] refactor: allow embed being built without setting interaction --- .../discord/embed/builder/embed_builder.py | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/faz/bot/app/discord/embed/builder/embed_builder.py b/src/faz/bot/app/discord/embed/builder/embed_builder.py index 7b635ba..24edc3b 100644 --- a/src/faz/bot/app/discord/embed/builder/embed_builder.py +++ b/src/faz/bot/app/discord/embed/builder/embed_builder.py @@ -143,7 +143,8 @@ def build(self) -> Embed: Returns: Embed: The fully constructed embed object. """ - self._add_author() + if self._interaction: + self._add_author(self._interaction) return self._embed def reset(self) -> Self: @@ -178,7 +179,20 @@ def set_builder_initial_embed(self, embed: Embed) -> Self: self._initial_embed = embed return self - def _add_author(self) -> Self: + def set_builder_interaction(self, interaction: Interaction[Any]) -> Self: + """ + Sets the interaction for this builder. + + Args: + interaction (Interaction[Any]): The interaction to set. + + Returns: + Self: The instance of the embed builder to allow method chaining. + """ + self._interaction = interaction + return self + + def _add_author(self, interaction: Interaction[Any]) -> Self: """ Adds author information to the embed. @@ -190,27 +204,11 @@ def _add_author(self) -> Self: Raises: AssertionError: If the user is None. """ - user = self.interaction.user + user = interaction.user assert user, "User is None. Who is calling this command?" self._embed.set_author( name=user.display_name, icon_url=user.display_avatar.url, ) - self._embed.timestamp = self.interaction.created_at + self._embed.timestamp = interaction.created_at return self - - @property - def interaction(self) -> Interaction[Any]: - """ - Returns the interaction associated with this embed. - - Returns: - Interaction[Any]: The interaction object. - - Raises: - ValueError: If interaction is not set. - """ - ret = self._interaction - if ret is None: - raise ValueError("Interaction is not set.") - return ret