47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
|
#! /usr/bin/env python3
|
||
|
# -*- coding: utf-8 -*-
|
||
|
"""
|
||
|
Checks if a website is up by sending a HEAD request to it.
|
||
|
"""
|
||
|
import requests
|
||
|
|
||
|
from module import commands, require_chanmsg
|
||
|
from tools import web
|
||
|
|
||
|
@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."""
|
||
|
url = trigger.group(2)
|
||
|
|
||
|
if not url:
|
||
|
return bot.reply("What URL do you want to check?")
|
||
|
if url.startswith("192") and not trigger.owner:
|
||
|
return bot.reply("Do not violate the LAN.")
|
||
|
|
||
|
if not web.secCheck(bot, url):
|
||
|
return bot.reply("Known malicious url. Ignoring.")
|
||
|
|
||
|
if not url.startswith("http"):
|
||
|
url = "http://" + url
|
||
|
|
||
|
try:
|
||
|
res = requests.head(url, verify=True)
|
||
|
except (requests.exceptions.MissingSchema,
|
||
|
requests.exceptions.InvalidSchema):
|
||
|
return bot.say("Missing or invalid schema. Check the URL.")
|
||
|
except requests.exceptions.ConnectionError:
|
||
|
return bot.say("Connection error. Are you sure this is a real website?")
|
||
|
except requests.exceptions.InvalidURL:
|
||
|
return bot.say("Invalid URL.")
|
||
|
except Exception as e:
|
||
|
print(e)
|
||
|
return bot.say("Listen buddy. I don't know what you're doing, but \
|
||
|
you're not doing it right.")
|
||
|
|
||
|
try:
|
||
|
res.raise_for_status()
|
||
|
return bot.say(url + " appears to be working from here.")
|
||
|
except requests.exceptions.HTTPError:
|
||
|
return bot.say(url + " looks down from here.")
|