Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions sopel/modules/isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,33 @@ def handle_isup(bot, trigger, secure=True):
"""
try:
site = get_site_url(trigger.group(2))
response = requests.head(site, verify=secure)
response = requests.head(site, verify=secure, timeout=(10.0, 5.0))
response.raise_for_status()
response = response.headers
except ValueError as error:
bot.reply(str(error))
except requests.exceptions.SSLError:
bot.say(
'%s looks down from here. Try using %sisupinsecure'
% (site, bot.config.core.help_prefix))
except requests.RequestException:
bot.say('%s looks down from here.' % site)
else:
if response:
bot.say(site + ' looks fine to me.')
else:
bot.say(site + ' is down from here.')
'{} looks down to me (SSL error). Try using `{}isupinsecure`.'
.format(site, bot.config.core.help_prefix))
except requests.HTTPError:
bot.say(
'{} looks down to me (HTTP {} "{}").'
.format(site, response.status_code, response.reason))
except requests.ConnectTimeout:
bot.say(
'{} looks down to me (timed out while connecting).'
.format(site))
except requests.ReadTimeout:
bot.say(
'{} looks down to me (timed out waiting for reply).'
.format(site))
except requests.ConnectionError:
bot.say(
'{} looks down to me (connection error).'
.format(site))

# If no exception happened, the request succeeded.
bot.say(site + ' looks fine to me.')


@plugin.command('isupinsecure')
Expand Down
1 change: 1 addition & 0 deletions test/modules/test_modules_isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_get_site_url(site, expected):


INVALID_SITE_URLS = (
None, # missing
'', # empty
' ', # empty once stripped
'steam://browsemedia', # invalid protocol
Expand Down