added quotes.....

This commit is contained in:
Robert 2020-01-09 02:36:45 +01:00
parent 08cc01ca70
commit f786f29141
2 changed files with 38 additions and 0 deletions

14
api/quote.py Normal file
View file

@ -0,0 +1,14 @@
import requests
import random
from util import logging
def fetch_quote() -> tuple:
url = "https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en"
response = requests.get(url)
if not response.ok:
logging.error(f"Failed to access Quotes API: {response.status_code} [{url}]")
return ()
data = response.json()
return (data["quoteText"], data["quoteAuthor"])

24
cogs/api/quote.py Normal file
View file

@ -0,0 +1,24 @@
import discord
from discord.ext import commands
from util import embed, config
from api import quote
class Quote(commands.Cog):
def __init__(self, client: discord.Client):
self.client = client
@commands.command(name="quote", description="Sends a random quote", usage="quote", aliases=["q"])
@commands.cooldown(1, 2)
async def quote(self, ctx: commands.Context):
please_kill_me = quote.fetch_quote()
if len(please_kill_me) == 0:
await ctx.send(embed=embed.make_error_embed("Something went wrong while fetching a random quote"))
return
end_my_life = discord.Embed(title=f'"{please_kill_me[0]}"', colour=int(config.settings["color"], 16))
end_my_life.set_footer(text=please_kill_me[1])
await ctx.send(embed=end_my_life)
def setup(client: discord.Client):
client.add_cog(Quote(client))