Skip to content

Commit

Permalink
refactor: allow embed being built without setting interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
FAZuH committed Dec 27, 2024
1 parent 710793d commit 9a0cca1
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/faz/bot/app/discord/embed/builder/embed_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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

0 comments on commit 9a0cca1

Please sign in to comment.