Merge pull request #13 from KevinCaires/change_syntax

Change syntax
pull/3/head
Kevin Caires 3 years ago committed by GitHub
commit bcc5456fc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,7 +5,7 @@
█ ▄ █ ▄▄▄█ ▄▄▄█ ▄ ██ █▄▄▄█ ▄▄▄█ █ ▄ █ ▄▄▄█ ▄▄▄█ ▄ ██ █▄▄▄█ ▄▄▄█
█ █ █ █ █▄▄▄█ █▄▄▄█ █▄█ █ █ █▄▄▄ █ █ █ █ █▄▄▄█ █▄▄▄█ █▄█ █ █ █▄▄▄
█▄█ █▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█ █▄█ █▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█
Neeble version: 2022.08.20 Neeble version: 2022.08.20a
You can help the development of neeble in You can help the development of neeble in
https://github.com/KevinCaires/neeble https://github.com/KevinCaires/neeble
Thank you! Thank you!

@ -68,7 +68,7 @@ LOGGING_CONFIG = {
}, },
}, },
} }
logger.dictConfig(LOGGING_CONFIG)
## INSTRUCTIONS ON SETTING UP PERMISSIONS: ## INSTRUCTIONS ON SETTING UP PERMISSIONS:
# Permissions are now granular, more than one distinct role # Permissions are now granular, more than one distinct role
@ -80,4 +80,7 @@ PERMISSIONS = {
'v' : ['Operador', 'BotMan'] 'v' : ['Operador', 'BotMan']
} }
logger.dictConfig(LOGGING_CONFIG) # Tuple of image type on image links.
# e.g: https://cdn.discordapp.com/attachments/720808802340962357/988542480981061702/cat.jpeg
# e.g: https://cdn.discordapp.com/attachments/720808802340962357/988542480981061702/unknow.png
IMAGE_TYPES = ('jpeg','jpg','png')

@ -5,39 +5,44 @@ import logging
from random import choice from random import choice
from discord.ext import commands from discord.ext import commands
from settings.config import IMAGE_TYPES, PERMISSIONS
from utils.database import get_by_id, get_quotes, remove_quote, set_quote, count_quotes from utils.database import (count_quotes, get_by_id, get_quote_contains,
get_quotes, remove_quote, set_quote)
from settings.config import PERMISSIONS
client = commands.Bot(command_prefix='--') client = commands.Bot(command_prefix='--')
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
quote_id_stack = [] quote_id_stack = []
@client.command(aliases=['q']) @client.command(aliases=['q'])
async def quote(bot: object, *quote: str) -> str: async def quote(bot: object, *quote: str) -> str:
""" """
Saves a quote into the database. Saves a quote into the database.
""" """
if not quote: if not quote:
return await bot.send('You\'re not my mute uncle, tell me something to remember.\n(You haven\'t provided a quote)') return await bot.send('You\'re not my mute uncle, tell me something to remember.\n'\
'(You haven\'t provided a quote)')
quote = ' '.join(quote) quote = ' '.join(quote)
if 'http' in quote and 'discord' in quote and not quote[-4:] == '.png': if 'http' in quote and 'discord' in quote and not quote[-4:] in IMAGE_TYPES:
return await bot.send("- _Check your link, dumbass! You're trying to quote an image from a message, but you're quoting the message itself!_\n"\ return await bot.send("- _Check your link, dumbass! You're trying to quote an image from a"\
'(Make sure to copy the link for the image by clicking on it, right-clicking the image and then clicking on "Save Link")') " 'message, but you're quoting the message itself!_\n"\
"'(Make sure to copy the link for the image by clicking on it, right-clicking the "\
"image and then clicking on \"Save Link\")'")
try: try:
user = bot.author.name user = bot.author.name
qtid = set_quote(user, quote) qtid = set_quote(user, quote)
except Exception as ex: except Exception as ex:
if ex.args[0].find("Duplicate") != -1: 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("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?_') return await bot.send(f'{ex.args}\n_What the fuck are you doing?_')
else: else:
return await bot.send("Done: `" + quote + "` ID: `" + str(qtid) + "`") return await bot.send(f"Done: `{quote}\n` ID: `{qtid}`")
@client.command(aliases=['rq']) @client.command(aliases=['rq'])
@ -53,7 +58,8 @@ async def random_quote(bot: object) -> str:
quote_id_stack.pop(0) quote_id_stack.pop(0)
quotes = get_quotes(quote_id_stack) quotes = get_quotes(quote_id_stack)
elif not quotes: elif not quotes:
return await bot.send('You\'ve got no quotes saved yet.\n(Save quotes by using `--q <quote`)') return await bot.send('You\'ve got no quotes saved yet.\n(Save quotes by using '\
'`--q <quote`)')
chosen_one = choice(quotes) chosen_one = choice(quotes)
quote_id_stack.append(chosen_one.id) quote_id_stack.append(chosen_one.id)
@ -72,17 +78,15 @@ async def random_quote(bot: object) -> str:
@client.command(aliases=['qid']) @client.command(aliases=['qid'])
async def by_id(bot, _id: int=None) -> str: async def by_id(bot: object, _id: int=None) -> str:
""" """
Gets one quote by ID. Gets one quote by ID.
""" """
syntax = "`--qid <quote id>`" syntax = "`--qid <quote id>`"
if not _id: if not _id:
return await bot.send(f"_If you don't tell me the ID, how the fuck do you expect me to quote it to you!?_\n(The correct syntax is {syntax})") return await bot.send("_If you don't tell me the ID, how the fuck do you expect me to "\
f"quote it to you!?_\n(The correct syntax is {syntax})")
if not isinstance(_id, int):
return await bot.send(f"_Don't fuck with me, you asshole. The ID needs to be an interger!_\n(The correct syntax is {syntax})")
quote = get_by_id(_id) quote = get_by_id(_id)
@ -107,22 +111,20 @@ async def delete_quote(bot, _id: int=None) -> str:
syntax = "`--dq <quote id>`" syntax = "`--dq <quote id>`"
roles = [r.name for r in bot.author.roles] roles = [r.name for r in bot.author.roles]
PermStatus = False PermStatus = False
if len(PERMISSIONS['dq']) < 1 or not len(set(PERMISSIONS['dq']).intersection(roles)) < 1: if len(PERMISSIONS['dq']) < 1 or not len(set(PERMISSIONS['dq']).intersection(roles)) < 1:
PermStatus = True PermStatus = True
if not PermStatus: if not PermStatus:
return await bot.send("_And who the fuck do **YOU** think you are!?_.\n"\ return await bot.send("_And who the fuck do **YOU** think you are!?_.\n"\
"(You don't have the necessary role for this command)") "(You don't have the necessary role for this command)")
if not _id:
return await bot.send(f"_If you don't tell me the ID, how the fuck do you expect me to delete it to you!?_\n(The correct syntax is {syntax})")
if not isinstance(_id, int): if not _id:
return await bot.send(f"_Don't fuck with me, you asshole. The ID needs to be an interger!_\n(The correct syntax is {syntax})") return await bot.send("_If you don't tell me the ID, how the fuck do you expect me to "\
f"delete it to you!?_\n(The correct syntax is {syntax})")
quote = get_by_id(_id) quote = get_by_id(_id)
if not quote: if not quote:
return await bot.send(f"_Wrong ID, sucker!_\n(There's no such quote with id {_id})") return await bot.send(f"_Wrong ID, sucker!_\n(There's no such quote with id {_id})")
@ -133,7 +135,7 @@ async def delete_quote(bot, _id: int=None) -> str:
except Exception as ex: except Exception as ex:
return await bot.send(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:
@ -143,19 +145,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']) @client.command(aliases=['cq', 'cquotes'])
async def quote_count(bot: object) -> str: async def quote_count(bot: object) -> str:
""" """
Outputs a quote count from the database Outputs a quote count from the database
""" """
amount = count_quotes() amount = count_quotes()
amount = str(amount) msg = f"Quote count: `{amount}`"
msg = "Quote count: `" + amount + "`"
return await bot.send(msg) return await bot.send(msg)
@client.command(aliases=['v', 'version']) @client.command(aliases=['v', 'version'])
async def info(bot: object) -> str: async def info(bot: object) -> str:
""" """
@ -174,8 +175,33 @@ async def info(bot: object) -> str:
motd = open("./motd", mode='r') motd = open("./motd", mode='r')
text = motd.readlines() text = motd.readlines()
fullbanner = "" fullbanner = ""
for lines in text: for lines in text:
fullbanner = fullbanner + lines fullbanner = fullbanner + lines
msg = f'''```\n''' + fullbanner + f'''\n```'''
return await bot.send(msg) msg = f'''```\n{fullbanner}\n```'''
return await bot.send(msg)
@client.command(aliases=['qcontains', 'qsearch'])
async def quote_contains(bot: object, part: str) -> str:
"""
Filter quote by part of saved message.
"""
syntax = '--qcontains <part>'
if not part:
return await bot.send("_If you don't tell me the part, how the fuck do you expect me to "\
f"find it to you!?_\n(The correct syntax is {syntax})")
quotes = get_quote_contains(part)
if not quotes:
return await bot.send(f"_Wrong text, sucker!_\n(There's no such quote with text `{part}`)")
for quote in quotes:
await bot.send(f'```\nID: {quote.id}\nMessage: {quote.quote[:10]} ... '\
f'{quote.quote[-10:]}\nUser: {quote.user}\n```')
return

@ -114,3 +114,12 @@ def count_quotes() -> int:
with Session(SQLACHEMY) as session: with Session(SQLACHEMY) as session:
response = session.query(Quotes.id).count() response = session.query(Quotes.id).count()
return response return response
def get_quote_contains(part: str) -> tuple:
"""
Get quotes by part of message.
"""
with Session(SQLACHEMY) as session:
response = session.query(Quotes).filter(Quotes.quote.contains(part))
return (r for r in response)

Loading…
Cancel
Save