aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Kronifer <[email protected]>2021-03-03 20:20:22 +0000
committerGravatar Kronifer <[email protected]>2021-03-03 20:20:22 +0000
commitb2ee1b9e79766b8cfe7b45670f6c86e7166ee84f (patch)
treee56402220181db34f13a275c242b3d200f8bf0ce
parentpossible final update (diff)
fstrings, colours, and self.bot
-rw-r--r--Pipfile2
-rw-r--r--bot/constants.py1
-rw-r--r--bot/exts/easter/earth_photos.py48
3 files changed, 25 insertions, 26 deletions
diff --git a/Pipfile b/Pipfile
index 1d1df3d7..e7e01a31 100644
--- a/Pipfile
+++ b/Pipfile
@@ -15,8 +15,6 @@ PyYAML = "~=5.3.1"
"discord.py" = {extras = ["voice"], version = "~=1.5.1"}
async-rediscache = {extras = ["fakeredis"], version = "~=0.1.4"}
emojis = "~=0.6.0"
-requests = "~=2.25.1"
-pre-commit = "*"
[dev-packages]
flake8 = "~=3.8"
diff --git a/bot/constants.py b/bot/constants.py
index f8ea5743..c570b17f 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -158,6 +158,7 @@ class Colours:
soft_orange = 0xf9cb54
soft_red = 0xcd6d6d
yellow = 0xf9f586
+ grass_green = 0x66ff00
class Emojis:
diff --git a/bot/exts/easter/earth_photos.py b/bot/exts/easter/earth_photos.py
index 0ac470ce..a49e666c 100644
--- a/bot/exts/easter/earth_photos.py
+++ b/bot/exts/easter/earth_photos.py
@@ -1,8 +1,8 @@
-import aiohttp
import discord
from discord.ext import commands
from bot.constants import Tokens
+from bot.constants import Colours
UnClient_id = Tokens.unsplash_key
@@ -10,35 +10,35 @@ UnClient_id = Tokens.unsplash_key
class EarthPhotos(commands.Cog):
"""This cog contains the command for earth photos."""
- def __init__(self, bot: commands.Bot) -> None:
+ def __init__(self, bot: commands.Bot):
self.bot = bot
- self.current_channel = None
@commands.command(aliases=["earth"])
async def earth_photos(self, ctx: commands.Context) -> None:
"""Returns a random photo of earth, sourced from Unsplash."""
async with ctx.typing():
- async with aiohttp.ClientSession() as session:
- async with session.get(
- 'https://api.unsplash.com/photos/random?query=earth&client_id=' + UnClient_id) as r:
- jsondata = await r.json()
- linksdata = jsondata.get("urls")
- embedlink = linksdata.get("full")
- downloadlinksdata = jsondata.get("links")
- userdata = jsondata.get("user")
- username = userdata.get("name")
- userlinks = userdata.get("links")
- profile = userlinks.get("html")
- async with session.get(
- downloadlinksdata.get("download_location") + "?client_id=" + UnClient_id) as er:
- er.status
- embed = discord.Embed(
- title="Earth Photo",
- description="A photo of earth from Unsplash.",
- color=0x66ff00)
- embed.set_image(url=embedlink)
- embed.add_field(title="Author", value="Made by [" + username + "](" + profile + ") on Unsplash.")
- await ctx.send(embed=embed)
+ async with self.bot.http_session.get(
+ 'https://api.unsplash.com/photos/random',
+ params={"query": "planet_earth", "client_id": UnClient_id}) as r:
+ jsondata = await r.json()
+ linksdata = jsondata.get("urls")
+ embedlink = linksdata.get("full")
+ downloadlinksdata = jsondata.get("links")
+ userdata = jsondata.get("user")
+ username = userdata.get("name")
+ userlinks = userdata.get("links")
+ profile = userlinks.get("html")
+ async with self.bot.http_session.get(
+ downloadlinksdata.get("download_location"),
+ params={"client_id": UnClient_id}) as er:
+ er.status
+ embed = discord.Embed(
+ title="Earth Photo",
+ description="A photo of earth from Unsplash.",
+ color=Colours.grass_green)
+ embed.set_image(url=embedlink)
+ embed.add_field(name="Author", value=f"Made by [{username}]({profile}) on Unsplash.")
+ await ctx.send(embed=embed)
def setup(bot: commands.Bot) -> None: