ADD command to delete one quote by database ID.

pull/3/head
kevin.caires 3 years ago
parent c6bf309f1d
commit a94d9d9849

@ -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, set_quote from utils.database import get_by_id, get_quotes, remove_quote, set_quote
client = commands.Bot(command_prefix='--') client = commands.Bot(command_prefix='--')
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -90,6 +90,34 @@ async def by_id(bot, _id: int=None) -> str:
return await bot.send(ex) 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']) @client.command(aliases=['qstack'])
async def queue_stack(bot: object) -> str: async def queue_stack(bot: object) -> str:
""" """

@ -107,3 +107,19 @@ def get_by_id(id: int) -> object:
return None return None
return obj(*quote) 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

Loading…
Cancel
Save