nxy/bot/plugins/isup.py

35 lines
912 B
Python
Raw Normal View History

2017-07-04 13:22:20 +00:00
# -*- coding: utf-8 -*-
from urllib.parse import urlparse
import irc3
import requests
from docopt import Dict as DocOptDict
from irc3.plugins.command import command
from irc3.utils import IrcString
from . import DatabasePlugin
@irc3.plugin
class Useless(DatabasePlugin):
requires = ['irc3.plugins.command',
2017-07-07 00:11:20 +00:00
'bot.plugins.storage']
2017-07-04 13:22:20 +00:00
@command
def isup(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Checks if a address is up.
%%isup <address>
"""
address = args['<address>']
if not address.startswith('http://'):
address = 'https://{}'.format(address)
parsed = urlparse(address)
try:
requests.head(address)
state = 'up'
except requests.ConnectionError:
state = 'down'
2017-07-07 00:11:20 +00:00
return '{}://{} seems to be {}'.format(parsed.scheme, parsed.netloc, state)