def _quotes(self, ctx, *, author: str):
"""Retrieves a specified number of quotes from a specified author. Max number of quotes at a time is 5.
Examples:
[p]quotes Morgan Freeman; 5
[p]quotes Margaret Thatcher; 2"""
regex = "title=\"view quote\">([^`]*?)<\/a>"
url = 'http://www.brainyquote.com/quotes/authors/'
try:
author = author.split('; ')
title = author[0]
number = int(author[1])
if number > 5:
number = 5
await self.bot.reply("Heck naw brah. 5 is max. Any more and you get killed.")
url = url + title.lower()[0] + "/" + title.lower().replace(" ", "_") + ".html"
async with aiohttp.request("GET", url) as resp:
test = str(await resp.text())
quote_find = list(set(re.findall(regex, test)))
for i in range(number):
random_quote = choice(quote_find)
quote_find.remove(random_quote)
while random_quote == title:
random_quote = choice(quote_find)
random_quote = random_quote.replace("'", "'") if "'" in random_quote else random_quote
await self.bot.say(box(random_quote))
await asyncio.sleep(1)
except IndexError:
await self.bot.say("Your search is not valid, please follow the examples."
"Make sure the names are correctly written\n"
"[p]quotes Margaret Thatcher; 5\n[p]quotes Morgan Freeman; 5")
评论列表
文章目录