Forgot how to use regex apparently

ww_develop
bobloy 4 years ago
parent 221ca4074b
commit a5eda8ca2a

@ -10,9 +10,9 @@ log = logging.getLogger("red.fox_v3.isitdown")
class IsItDown(commands.Cog): class IsItDown(commands.Cog):
""" """
Cog Description Cog for checking whether a website is down or not.
Less important information about the cog Uses the `isitdown.site` API
""" """
def __init__(self, bot: Red): def __init__(self, bot: Red):
@ -36,23 +36,25 @@ class IsItDown(commands.Cog):
Alias: iid Alias: iid
""" """
try: try:
resp = await self._check_if_down(url_to_check) resp, url = await self._check_if_down(url_to_check)
except AssertionError: except AssertionError:
await ctx.maybe_send_embed("Invalid URL provided. Make sure not to include `http://`") await ctx.maybe_send_embed("Invalid URL provided. Make sure not to include `http://`")
return return
# log.debug(resp)
if resp["isitdown"]: if resp["isitdown"]:
await ctx.maybe_send_embed(f"{url_to_check} is DOWN!") await ctx.maybe_send_embed(f"{url} is DOWN!")
else: else:
await ctx.maybe_send_embed(f"{url_to_check} is UP!") await ctx.maybe_send_embed(f"{url} is UP!")
async def _check_if_down(self, url_to_check): async def _check_if_down(self, url_to_check):
url = re.compile(r"https?://(www\.)?") re_compiled = re.compile(r"https?://(www\.)?")
url.sub("", url_to_check).strip().strip("/") url = re_compiled.sub("", url_to_check).strip().strip("/")
url = f"https://isitdown.site/api/v3/{url}" url = f"https://isitdown.site/api/v3/{url}"
# log.debug(url)
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(url) as response: async with session.get(url) as response:
assert response.status == 200 assert response.status == 200
resp = await response.json() resp = await response.json()
return resp return resp, url

Loading…
Cancel
Save