ADD: Quote count command

pull/3/head
Kamal Curi 3 years ago
parent dbbd894159
commit 406577e2f5

@ -6,7 +6,7 @@ from random import choice
from discord.ext import commands 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='--') client = commands.Bot(command_prefix='--')
logger = logging.getLogger(__name__) 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:'\ return await bot.send('A list of the 5 latest message IDs follows:'\
f' `{",".join(str(q) for q in quote_id_stack[-5:])}`') 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)

@ -123,3 +123,17 @@ def remove_quote(_id: int) -> bool:
return True return True
except Exception: except Exception:
return False 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
Loading…
Cancel
Save