Skip to content

Commit

Permalink
Fix Urban Dictionary failing creating embed
Browse files Browse the repository at this point in the history
  • Loading branch information
nattadasu authored Apr 6, 2024
1 parent 2630783 commit 539d25a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions classes/urbandictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class UrbanDictionaryEntry:
"""Current vote"""
written_on: datetime
"""Date written on"""
example: str
example: str | None
"""Example of the word"""
thumbs_down: int
"""Number of thumbs down"""
Expand All @@ -59,11 +59,12 @@ def embed(self) -> Embed:
description=f"{self.definition}",
color=0x1b2936,
)
embed.add_field(
name="Example",
value=self.example,
inline=False,
)
if self.example:
embed.add_field(
name="Example",
value=self.example,
inline=False,
)
embed.add_field(
name="Author",
value=self.author,
Expand All @@ -74,9 +75,12 @@ def embed(self) -> Embed:
url="https://www.urbandictionary.com/",
)
# percentage of thumbs up
percentage = round(
(self.thumbs_up / (self.thumbs_up + self.thumbs_down)) * 100
)
try:
percentage = round(
(self.thumbs_up / (self.thumbs_up + self.thumbs_down)) * 100
)
except ZeroDivisionError:
percentage = 0
embed.set_footer(
text=f"👍 {self.thumbs_up} / 👎 {self.thumbs_down} ({percentage}%), page {self.current}/{self.total_pages}"
)
Expand Down

0 comments on commit 539d25a

Please sign in to comment.