aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Shivansh-007 <[email protected]>2021-02-04 05:23:54 +0530
committerGravatar Shivansh-007 <[email protected]>2021-02-04 05:23:54 +0530
commit5e55ea1dbfd652c10999c88d1c32aebd1be768f0 (patch)
tree9c2404e34744378f774608f464f7278e0c812a5e
parentAdd not Implemented error handler for .status cat command (diff)
Make use of constants in the url
-rw-r--r--bot/exts/evergreen/status_codes.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py
index ff2ac9e1..874c87eb 100644
--- a/bot/exts/evergreen/status_codes.py
+++ b/bot/exts/evergreen/status_codes.py
@@ -3,6 +3,9 @@ from http import HTTPStatus
import discord
from discord.ext import commands
+HTTP_DOG_URL = "https://httpstatusdogs.com/img/{code}.jpg"
+HTTP_CAT_URL = "https://http.cat/{code}.jpg"
+
class HTTPStatusCodes(commands.Cog):
"""Commands that give HTTP statuses described and visualized by cats and dogs."""
@@ -16,19 +19,17 @@ class HTTPStatusCodes(commands.Cog):
if not ctx.invoked_subcommand:
await ctx.send_help(ctx.command)
- @http_status_group.command(aliases=['cat'])
+ @http_status_group.command(name='cat')
async def http_cat(self, ctx: commands.Context, code: int) -> None:
"""Sends an embed with an image of a cat, portraying the status code."""
embed = discord.Embed(title=f'**Status: {code}**')
+ url = HTTP_CAT_URL.format(code=code)
try:
HTTPStatus(code)
- async with self.bot.http_session.get(
- f'https://http.cat/{code}.jpg',
- allow_redirects=False
- ) as response:
+ async with self.bot.http_session.get(url, allow_redirects=False) as response:
if response.status != 404:
- embed.set_image(url=f'https://http.cat/{code}.jpg')
+ embed.set_image(url=url)
else:
raise NotImplementedError
@@ -41,19 +42,17 @@ class HTTPStatusCodes(commands.Cog):
finally:
await ctx.send(embed=embed)
- @http_status_group.command(aliases=['dog'])
+ @http_status_group.command(name='dog')
async def http_dog(self, ctx: commands.Context, code: int) -> None:
"""Sends an embed with an image of a dog, portraying the status code."""
embed = discord.Embed(title=f'**Status: {code}**')
+ url = HTTP_DOG_URL.format(code=code)
try:
HTTPStatus(code)
- async with self.bot.http_session.get(
- f'https://httpstatusdogs.com/img/{code}.jpg',
- allow_redirects=False
- ) as response:
+ async with self.bot.http_session.get(url, allow_redirects=False) as response:
if response.status != 302:
- embed.set_image(url=f'https://httpstatusdogs.com/img/{code}.jpg')
+ embed.set_image(url=url)
else:
raise NotImplementedError