diff options
| author | 2021-03-03 20:20:22 +0000 | |
|---|---|---|
| committer | 2021-03-03 20:20:22 +0000 | |
| commit | b2ee1b9e79766b8cfe7b45670f6c86e7166ee84f (patch) | |
| tree | e56402220181db34f13a275c242b3d200f8bf0ce /bot | |
| parent | possible final update (diff) | |
fstrings, colours, and self.bot
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/constants.py | 1 | ||||
| -rw-r--r-- | bot/exts/easter/earth_photos.py | 48 | 
2 files changed, 25 insertions, 24 deletions
| 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: | 
