From f786f291410ad25902bde01af48ad7676511a06b Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 9 Jan 2020 02:36:45 +0100 Subject: [PATCH] added quotes..... --- api/quote.py | 14 ++++++++++++++ cogs/api/quote.py | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 api/quote.py create mode 100644 cogs/api/quote.py diff --git a/api/quote.py b/api/quote.py new file mode 100644 index 0000000..cd2ee81 --- /dev/null +++ b/api/quote.py @@ -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"]) \ No newline at end of file diff --git a/cogs/api/quote.py b/cogs/api/quote.py new file mode 100644 index 0000000..8e66342 --- /dev/null +++ b/cogs/api/quote.py @@ -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)) \ No newline at end of file