added quotes.....
This commit is contained in:
parent
08cc01ca70
commit
f786f29141
14
api/quote.py
Normal file
14
api/quote.py
Normal 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
24
cogs/api/quote.py
Normal 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))
|
Loading…
Reference in a new issue