From fe79f444cf3c83b7c9060ece50d1cdc9ed167933 Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Tue, 20 Jul 2021 21:39:39 +0000 Subject: [PATCH] isup: show state as 'down' if response is an HTTPError --- bot/isup.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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)