Skip to content

Commit

Permalink
fix: qall formats quote with context correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dlg1206 committed Apr 25, 2024
1 parent 6228751 commit 7679119
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/quotebot/bot/QuoteBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ async def qall(ctx, *, quotee=None) -> None:
return

# Format and display all quotes
only_quotes = [f'> - {q}' for q in quotes]
only_quotes = [f'> - {q.format_quote()}' for q in quotes]
self.logger.log(str(ctx.message.author), "!qall", Status.SUCCESS, f"Found {len(quotes)} for {quotee}")
await ctx.channel.send(f"{'\n'.join(only_quotes)}\n"
f"**{format_quotee(quotee)} has {len(quotes)} quotes!**")
f"**{format_quotee(quotee)} has {len(quotes)} quote{'' if len(quotes) == 1 else 's' }!**")

@self.command()
async def qrand(ctx) -> None:
Expand Down
14 changes: 11 additions & 3 deletions src/quotebot/quote/Quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ def __init__(self, quote: str, quotee: str, pre_context: str = None, post_contex
self.post_context = post_context
self.quotee = quotee.strip().lower()

def format_quote(self) -> str:
"""
Format quote portion
:return: (pre-context) "quote" (post-context)
"""
pre_context = f"({self.pre_context}) " if self.pre_context is not None else ""
post_context = f" ({self.post_context})" if self.post_context is not None else ""
return f'{pre_context}"{self.quote}"{post_context}'

def __str__(self):
"""
Pre and post only if present
:return: (pre-context) "quote" (post-context) - quotee
"""
pre_context = f"({self.pre_context}) " if self.pre_context is not None else ""
post_context = f" ({self.post_context})" if self.post_context is not None else ""
return f'{pre_context}"{self.quote}"{post_context} -{format_quotee(self.quotee)}'

return f'{self.format_quote()} - {format_quotee(self.quotee)}'


def format_quotee(quotee: str) -> str:
Expand Down

0 comments on commit 7679119

Please sign in to comment.