diff --git a/utils/commands.py b/utils/commands.py index 788764e..33be317 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, set_quote +from utils.database import get_by_id, get_quotes, remove_quote, set_quote client = commands.Bot(command_prefix='--') logger = logging.getLogger(__name__) @@ -90,6 +90,34 @@ async def by_id(bot, _id: int=None) -> str: return await bot.send(ex) +@client.command(aliases=['dq']) +async def delete_quote(bot, _id: int=None) -> str: + """ + Delete one quote by database ID. + """ + roles = [r.name for r in bot.author.roles] + + if not 'Operador' in roles: + return await bot.send("_Don't fuck, you ass hole_.\n"\ + "_You have no permission for this command!_") + + if not isinstance(_id, int) or not _id: + return await bot.send("_Don't fuck, you ass hole_.\nThe ID need to be a interger!") + + quote = get_by_id(_id) + + if not quote: + return await bot.send("_Got wrong, you socker!_\nThis ID doesn't exist in database!") + + try: + if not remove_quote(_id): + return await bot.send('_Something wrong happen, dude!_') + return await bot.send('_Evidence deleted, fella!_') + + except Exception as ex: + return await bot.send(ex) + + @client.command(aliases=['qstack']) async def queue_stack(bot: object) -> str: """ diff --git a/utils/database.py b/utils/database.py index d072cb7..a74f808 100644 --- a/utils/database.py +++ b/utils/database.py @@ -107,3 +107,19 @@ def get_by_id(id: int) -> object: return None return obj(*quote) + +def remove_quote(_id: int) -> bool: + """ + Delete one quote by database ID. + """ + _sql = f''' + delete from neeble_quotes + where id={_id}; + ''' + + try: + with Cursor(MYSQL_CONFIG) as cursor: + cursor.execute(_sql) + return True + except Exception: + return False