2018-03-16 03:13:43 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
Checks if a website is up by sending a HEAD request to it.
|
|
|
|
"""
|
|
|
|
import requests
|
|
|
|
|
|
|
|
from module import commands, require_chanmsg
|
|
|
|
|
|
|
|
@require_chanmsg(message="It's not polite to whisper.")
|
|
|
|
@commands('isup')
|
|
|
|
def isup(bot, trigger):
|
|
|
|
"""Queries the given url to check if it's up or not."""
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("What URL do you want to check?")
|
2020-01-07 18:58:19 -05:00
|
|
|
url = trigger.args[1]
|
|
|
|
|
2018-03-16 03:13:43 -04:00
|
|
|
if url.startswith("192") and not trigger.owner:
|
|
|
|
return bot.reply("Do not violate the LAN.")
|
|
|
|
|
|
|
|
if not url.startswith("http"):
|
|
|
|
url = "http://" + url
|
|
|
|
|
|
|
|
try:
|
2018-04-24 20:07:25 -04:00
|
|
|
res = requests.head(url, timeout=10, verify=True)
|
2018-03-16 03:13:43 -04:00
|
|
|
except (requests.exceptions.MissingSchema,
|
|
|
|
requests.exceptions.InvalidSchema):
|
2018-05-25 15:21:18 -04:00
|
|
|
return bot.msg("Missing or invalid schema. Check the URL.")
|
2018-03-16 03:13:43 -04:00
|
|
|
|
|
|
|
except requests.exceptions.ConnectionError:
|
2018-06-02 13:42:19 -04:00
|
|
|
return bot.msg("\x0304Connection error\x03. Are you sure this is " + \
|
|
|
|
"a real website?")
|
2018-03-16 03:13:43 -04:00
|
|
|
|
|
|
|
except requests.exceptions.InvalidURL:
|
2018-05-25 15:21:18 -04:00
|
|
|
return bot.msg("Invalid URL.")
|
2018-03-16 03:13:43 -04:00
|
|
|
|
2018-06-02 13:42:19 -04:00
|
|
|
except requests.exceptions.ReadTimeout:
|
|
|
|
return bot.msg("\x0307" + url + "\x03 looks \x0304down\x03 from " + \
|
|
|
|
"here (\x0304Timed out [10s]\x03)")
|
|
|
|
|
2018-03-16 03:13:43 -04:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2018-06-02 13:42:19 -04:00
|
|
|
return bot.msg("Listen buddy. I don't know what you're doing, but " + \
|
|
|
|
"you're not doing it right.")
|
2018-03-16 03:13:43 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
res.raise_for_status()
|
2018-06-02 13:42:19 -04:00
|
|
|
return bot.msg("\x0307" + url + "\x03 looks \x0303up\x03 from here.")
|
2018-03-16 03:13:43 -04:00
|
|
|
except requests.exceptions.HTTPError:
|
2018-06-02 13:42:19 -04:00
|
|
|
return bot.msg("\x0307" + url + "\x03 looks \x0304down\x03 from here.")
|