From 2c9a83f0f09153cf90e28e6e2e330bf498981cd2 Mon Sep 17 00:00:00 2001 From: Kamal Curi Date: Thu, 18 Aug 2022 23:19:32 -0300 Subject: [PATCH] CHANGE: Adding quotes now return their IDs --- utils/commands.py | 4 ++-- utils/database.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/utils/commands.py b/utils/commands.py index c97c079..32f68e5 100644 --- a/utils/commands.py +++ b/utils/commands.py @@ -29,13 +29,13 @@ async def quote(bot: object, *quote: str) -> str: try: user = bot.author.name - set_quote(user, quote) + qtid = set_quote(user, quote) except Exception as ex: if ex.args[0].find("Duplicate") != -1: return await bot.send("There's already a quote from that same person, with that exact match!") return await bot.send(f'{ex.args}\n_What the fuck are you doing?_') else: - return await bot.send('Done:\n`%s`' % quote) + return await bot.send("Done: `" + quote + "` ID: `" + str(qtid) + "`") @client.command(aliases=['rq']) diff --git a/utils/database.py b/utils/database.py index f15ec49..40e57d8 100644 --- a/utils/database.py +++ b/utils/database.py @@ -58,16 +58,20 @@ def migrate() -> None: logger.error(ex.args) -def set_quote(user: str, quote: str) -> None: +def set_quote(user: str, quote: str) -> int: """ Set a quote into database. """ + + qt = Quotes(quote=quote, user=user,) + qtid = 0 with Session(SQLACHEMY) as session: - session.add(Quotes( - quote=quote, - user=user, - )) + session.add(qt) + session.flush() + session.refresh(qt) + qtid = qt.id session.commit() + return qtid def get_quotes(ids: list) -> tuple: