Skip to content

Commit

Permalink
cannot quote the same thing multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
Mole1424 committed Jan 26, 2024
1 parent aee62bb commit 0b753ca
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cogs/commands/quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class QuoteError(Enum):
NOT_FOUND = auto()
OPTED_OUT = auto()
DB_ERROR = auto()
ALREADY_EXISTS = auto()
NO_OP = auto()


Expand Down Expand Up @@ -144,6 +145,10 @@ def add_quote(author: Mention, quote, time, session=db_session) -> str:
new_quote = Quote.id_quote(author.id, quote, time)
else:
new_quote = Quote.string_quote(author.string, quote, time)

if len(session.query(Quote).filter(Quote.quote == quote).all()) > 0:
raise QuoteException(QuoteError.ALREADY_EXISTS)

try:
session.add(new_quote)
session.commit()
Expand Down Expand Up @@ -350,6 +355,8 @@ async def add(self, ctx: Context, author: MentionConverter, *, quote):
result = "Invalid Author: User has opted out of being quoted."
elif e.err == QuoteError.DB_ERROR:
result = "Database error."
elif e.err == QuoteError.ALREADY_EXISTS:
result = "Quote already exists."
else:
result = MYSTERY_ERROR

Expand Down Expand Up @@ -414,6 +421,8 @@ async def quote_discord_user(
result += "Invalid Author: User has opted out of being quoted."
elif e.err == QuoteError.DB_ERROR:
result += "Database error."
elif e.err == QuoteError.ALREADY_EXISTS:
result += "Quote already exists."
else:
result += MYSTERY_ERROR

Expand Down

0 comments on commit 0b753ca

Please sign in to comment.