From 406577e2f577029152e3be3dfd9eade8c6d10f28 Mon Sep 17 00:00:00 2001 From: Kamal Curi Date: Thu, 18 Aug 2022 16:15:04 -0300 Subject: [PATCH] ADD: Quote count command --- utils/commands.py | 17 ++++++++++++++++- utils/database.py | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/utils/commands.py b/utils/commands.py index 107fbdf..9561b8d 100644 --- a/utils/commands.py +++ b/utils/commands.py @@ -6,7 +6,7 @@ from random import choice from discord.ext import commands -from utils.database import get_by_id, get_quotes, remove_quote, set_quote +from utils.database import get_by_id, get_quotes, remove_quote, set_quote, count_quotes client = commands.Bot(command_prefix='--') logger = logging.getLogger(__name__) @@ -134,3 +134,18 @@ async def queue_stack(bot: object) -> str: """ return await bot.send('A list of the 5 latest message IDs follows:'\ f' `{",".join(str(q) for q in quote_id_stack[-5:])}`') + +@client.command(aliases=['cq', 'cquotes']) +async def quote_count(bot: object) -> str: + """ + Outputs a quote count from the database + """ + + # For len(amount) to work, first it needs to be converted into str + amount = count_quotes() + amount = str(amount) + amount = amount[1:len(amount)][:-2] + + msg = "Quote count: `" + amount + "`" + + return await bot.send(msg) \ No newline at end of file diff --git a/utils/database.py b/utils/database.py index a74f808..f73a133 100644 --- a/utils/database.py +++ b/utils/database.py @@ -123,3 +123,17 @@ def remove_quote(_id: int) -> bool: return True except Exception: return False + +def count_quotes() -> int: + """ + Counts the amount of quotes in the database + """ + _sql = f''' + select count(*) from neeble_quotes + ''' + + with Cursor(MYSQL_CONFIG) as cursor: + cursor.execute(_sql) + count = cursor.fetchone() + + return count \ No newline at end of file