36 lines
916 B
Python
36 lines
916 B
Python
# -*- coding: utf-8 -*-
|
|
from urllib.parse import urlparse
|
|
|
|
import irc3
|
|
import requests
|
|
from docopt import Dict
|
|
from irc3.plugins.command import command
|
|
from irc3.utils import IrcString
|
|
|
|
from . import DatabasePlugin
|
|
|
|
|
|
@irc3.plugin
|
|
class Useless(DatabasePlugin):
|
|
requires = ['irc3.plugins.command',
|
|
'bot.plugins.storage']
|
|
|
|
@command
|
|
def isup(self, mask: IrcString, target: IrcString, args: Dict):
|
|
"""Checks if a address is up or down
|
|
|
|
%%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'
|
|
|
|
parsed = urlparse(address)
|
|
return '\x02{}://{}\x02 seems to be \x02{}\x02'.format(parsed.scheme, parsed.netloc, state)
|