2017-07-04 13:22:20 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
|
|
|
import irc3
|
|
|
|
import requests
|
2017-08-22 13:57:57 +00:00
|
|
|
from docopt import Dict
|
2017-07-04 13:22:20 +00:00
|
|
|
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
|
2017-08-22 13:57:57 +00:00
|
|
|
def isup(self, mask: IrcString, target: IrcString, args: Dict):
|
2017-08-22 14:15:52 +00:00
|
|
|
"""Checks if a address is up or down
|
2017-07-04 13:22:20 +00:00
|
|
|
|
|
|
|
%%isup <address>
|
|
|
|
"""
|
|
|
|
address = args['<address>']
|
|
|
|
if not address.startswith('http://'):
|
|
|
|
address = 'https://{}'.format(address)
|
|
|
|
|
|
|
|
try:
|
|
|
|
requests.head(address)
|
|
|
|
state = 'up'
|
|
|
|
except requests.ConnectionError:
|
|
|
|
state = 'down'
|
2017-08-22 12:57:14 +00:00
|
|
|
|
|
|
|
parsed = urlparse(address)
|
|
|
|
return '\x02{}://{}\x02 seems to be \x02{}\x02'.format(parsed.scheme, parsed.netloc, state)
|