diff --git a/bot/isup.py b/bot/isup.py index d317b65..02cb9d8 100644 --- a/bot/isup.py +++ b/bot/isup.py @@ -12,19 +12,22 @@ from . import Plugin class Useless(Plugin): @command def isup(self, mask: IrcString, target: IrcString, args: Dict): - """Checks if a address is up or down + """Checks if an address is up or down %%isup
""" address = args['
'] - if not address.startswith('http://'): + if not address.startswith('http://') and not address.startswith('https://'): address = 'https://{}'.format(address) try: - requests.head(address) + res = requests.head(address) + res.raise_for_status() state = 'up' except requests.ConnectionError: - state = 'down' + state = 'down (timeout)' + except requests.HTTPError as e: + state = f'down ({e.response.status_code} {e.response.reason})' parsed = urlparse(address) return '\x02{}://{}\x02 seems to be \x02{}\x02'.format(parsed.scheme, parsed.netloc, state)