# Path: core/moduletemplate.py
# class BotModule:
#     PRIV_NONE = "none"
#     PRIV_MOD = "mod"
#     PRIV_MODERATOR = "mod"
#     PRIV_ADMIN = "admin"
#     PRIV_ADMINISTRATOR = "admin"
#     def __init__(self, conn, logger, module_name):
#     def on_module_load(self):
#     def on_module_unload(self):
#     def on_connect(self):
#     def on_disconnect(self):
#     def on_privmsg(self, target, nick, message):
#     def on_action(self, target, nick, action):
#     def on_join(self, nick, channel):
#     def on_part(self, nick, channel, message):
#     def on_self_join(self, channel):
#     def on_self_part(self, channel):
#     def on_kick(self, nick, channel, knick, reason):
#     def on_quit(self, nick, message):
#     def on_command(self, target, nick, command, commandtext, mod, admin):
#     def on_numeric(self, numeric, data):
#     def message(self, target, nick, message, parse=False):
#     def notice(self, nick, message, parse=False):
#     def action(self, target, action, parse=False):
#     def mode(self, target, modes):
#     def ban(self, nick, channel, quiet=False):
#     def getMask(self, nick):
#     def send_raw(self, raw_message):
#     def debug(self, message, format=False):
#     def log(self, message):
#     def log_verbose(self, message):
#     def warning(self, message):
#     def notice_verbose(self, message):
#     def warning_verbose(self, message):
#     def error(self, message):
#     def isOp(self, nick, channel):
#     def isVoice(self, nick, channel):
#     def isOn(self, nick, channel):
#     def isIdentified(self, nick):
#     def isOper(self, nick):
#     def getUserData(self, nick):
#     def getChannelData(self, channel):
#     def isBotAdministrator(self, nick):
#     def isBotModerator(self, nick):
#     def ratelimit(self, command, confName="rate_limit_delay", delay=10):
#     def register_command(self, command, params, help, priv, aliases=None):
#     def unregister_command(self, command):
#     def getConfigMetadata(self, metadata):
#     def requireApiKey(self, api_name):
#     def _getApiKey(self, api_name):
#     def _unregister_commands(self):
#     def _getModuleData(self):
# 
# Path: tools/urlparse.py
# RE_PROTOCOL = r"(?:([\w\-_]+?)(?::\/\/))?"  # (1) match the protocol, strip :// e.g. https or ssh
# RE_DOMAIN = r"([\w\-_\.]+)"  # (2) match the domain, and any subdomains. e.g. www.google, google, or maps.google
# RE_TLD = r"\.([a-z]{2,16})"  # (3) The top level domain, does not account for unicode. e.g. com, info, org
# RE_PORT = r"(?::(\+?[1-9]\d{1,4}))?"  # (4) The port. e.g. google.com:100 extracts 100
# RE_PATH = r"(\/[^ ]+)?"  # (5) Get everything after the top level domain / port starting with a slash. e.g. /hi.html
# URL_REGEX = re.compile(RE_PROTOCOL + RE_DOMAIN + RE_TLD + RE_PORT + RE_PATH, re.I)
#     CERTAINTY_CAP = 100
# class Url:
#     def __init__(self, url, min_certainty=50):
#     def getCertainty(self):
#     def getMinCertainty(self):
#     def getUrl(self):
#     def getProtocol(self):
#     def getSubdomains(self):
#     def getDomain(self):
#     def getPort(self):
#     def getTld(self):
#     def getPath(self):
#     def getFactors(self):
#     def getAsDict(self):
#     def find(string):
#     def findAll(string):
#     def isUrl(self):
#     def encode(self):
#     def decode(self):
#     def _parse(self):
#     def _calculateCertainty(self):
#     def _addCertainty(self, amount, factor):
# 
# Path: tools/urltools.py
# class UrlTools:
#     SHORTEN_SERVICES = ["isgd", "googl", "scenesat"]
#     def isUrl(url):
#     def shorten(url, service, api_key=None, logger=None, ret_false=False):
#     def getAvailableServices():
#     def getDefaultShortenService():
#     def getTitle(url, ret_false=False):
#     def htmlEntityEncode(string):
#     def htmlEntityDecode(string):


from core import moduletemplate
from tools import urlparse
from tools import urltools
import re
import requests
                    title = self.get_title(url.getUrl(), True)
                    if title and title != self.last_title:
                        self.last_title = title
                        self.message(target, None, ("({}) '{}' at {}.{}"
                                                    .format(nick, title, url.getDomain(), url.getTld())))

    def on_command(self, target, nick, command, commandtext, mod, admin):
        if command == "title" or command == "gettitle":
            if not commandtext:
                return self.notice(nick, "Usage: title <website>")
            return self.message(target, nick, self.get_title(commandtext, False))
        if command == "xkcd":
            if not commandtext or not commandtext.isdigit():
                return self.notice(nick, "Usage: xkcd <id>")
            return self.message(target, nick, self.get_xkcd_info("http://xkcd.com/{}/".format(commandtext)), True)
        if command == "wiki" or command == "wikipedia":
            if not commandtext:
                return self.notice(nick, "Usage: wiki <article> [language = en]")

            cmdtext = commandtext.split()
            article = cmdtext[0]

            language = "en"
            if len(cmdtext) > 1 and len(cmdtext[1]) == 2:
                language = cmdtext[1]

            return self.message(target, nick, self.get_wiki_info(language, article), True)
        return False

    def get_title(self, url, ret_false=False):

# Path: core/moduletemplate.py
# class BotModule:
#     PRIV_NONE = "none"
#     PRIV_MOD = "mod"
#     PRIV_MODERATOR = "mod"
#     PRIV_ADMIN = "admin"
#     PRIV_ADMINISTRATOR = "admin"
#     def __init__(self, conn, logger, module_name):
#     def on_module_load(self):
#     def on_module_unload(self):
#     def on_connect(self):
#     def on_disconnect(self):
#     def on_privmsg(self, target, nick, message):
#     def on_action(self, target, nick, action):
#     def on_join(self, nick, channel):
#     def on_part(self, nick, channel, message):
#     def on_self_join(self, channel):
#     def on_self_part(self, channel):
#     def on_kick(self, nick, channel, knick, reason):
#     def on_quit(self, nick, message):
#     def on_command(self, target, nick, command, commandtext, mod, admin):
#     def on_numeric(self, numeric, data):
#     def message(self, target, nick, message, parse=False):
#     def notice(self, nick, message, parse=False):
#     def action(self, target, action, parse=False):
#     def mode(self, target, modes):
#     def ban(self, nick, channel, quiet=False):
#     def getMask(self, nick):
#     def send_raw(self, raw_message):
#     def debug(self, message, format=False):
#     def log(self, message):
#     def log_verbose(self, message):
#     def warning(self, message):
#     def notice_verbose(self, message):
#     def warning_verbose(self, message):
#     def error(self, message):
#     def isOp(self, nick, channel):
#     def isVoice(self, nick, channel):
#     def isOn(self, nick, channel):
#     def isIdentified(self, nick):
#     def isOper(self, nick):
#     def getUserData(self, nick):
#     def getChannelData(self, channel):
#     def isBotAdministrator(self, nick):
#     def isBotModerator(self, nick):
#     def ratelimit(self, command, confName="rate_limit_delay", delay=10):
#     def register_command(self, command, params, help, priv, aliases=None):
#     def unregister_command(self, command):
#     def getConfigMetadata(self, metadata):
#     def requireApiKey(self, api_name):
#     def _getApiKey(self, api_name):
#     def _unregister_commands(self):
#     def _getModuleData(self):
# 
# Path: tools/urlparse.py
# RE_PROTOCOL = r"(?:([\w\-_]+?)(?::\/\/))?"  # (1) match the protocol, strip :// e.g. https or ssh
# RE_DOMAIN = r"([\w\-_\.]+)"  # (2) match the domain, and any subdomains. e.g. www.google, google, or maps.google
# RE_TLD = r"\.([a-z]{2,16})"  # (3) The top level domain, does not account for unicode. e.g. com, info, org
# RE_PORT = r"(?::(\+?[1-9]\d{1,4}))?"  # (4) The port. e.g. google.com:100 extracts 100
# RE_PATH = r"(\/[^ ]+)?"  # (5) Get everything after the top level domain / port starting with a slash. e.g. /hi.html
# URL_REGEX = re.compile(RE_PROTOCOL + RE_DOMAIN + RE_TLD + RE_PORT + RE_PATH, re.I)
#     CERTAINTY_CAP = 100
# class Url:
#     def __init__(self, url, min_certainty=50):
#     def getCertainty(self):
#     def getMinCertainty(self):
#     def getUrl(self):
#     def getProtocol(self):
#     def getSubdomains(self):
#     def getDomain(self):
#     def getPort(self):
#     def getTld(self):
#     def getPath(self):
#     def getFactors(self):
#     def getAsDict(self):
#     def find(string):
#     def findAll(string):
#     def isUrl(self):
#     def encode(self):
#     def decode(self):
#     def _parse(self):
#     def _calculateCertainty(self):
#     def _addCertainty(self, amount, factor):
# 
# Path: tools/urltools.py
# class UrlTools:
#     SHORTEN_SERVICES = ["isgd", "googl", "scenesat"]
#     def isUrl(url):
#     def shorten(url, service, api_key=None, logger=None, ret_false=False):
#     def getAvailableServices():
#     def getDefaultShortenService():
#     def getTitle(url, ret_false=False):
#     def htmlEntityEncode(string):
#     def htmlEntityDecode(string):


# Path: modules/title.py
from core import moduletemplate
from tools import urlparse
from tools import urltools
import re
import requests

                    title = self.get_title(url.getUrl(), True)
                    if title and title != self.last_title:
                        self.last_title = title
                        self.message(target, None, ("({}) '{}' at {}.{}"
                                                    .format(nick, title, url.getDomain(), url.getTld())))

    def on_command(self, target, nick, command, commandtext, mod, admin):
        if command == "title" or command == "gettitle":
            if not commandtext:
                return self.notice(nick, "Usage: title <website>")
            return self.message(target, nick, self.get_title(commandtext, False))
        if command == "xkcd":
            if not commandtext or not commandtext.isdigit():
                return self.notice(nick, "Usage: xkcd <id>")
            return self.message(target, nick, self.get_xkcd_info("http://xkcd.com/{}/".format(commandtext)), True)
        if command == "wiki" or command == "wikipedia":
            if not commandtext:
                return self.notice(nick, "Usage: wiki <article> [language = en]")

            cmdtext = commandtext.split()
            article = cmdtext[0]

            language = "en"
            if len(cmdtext) > 1 and len(cmdtext[1]) == 2:
                language = cmdtext[1]

            return self.message(target, nick, self.get_wiki_info(language, article), True)
        return False

    def get_title(self, url, ret_false=False):

        return urltools.UrlTools.getTitle(url, ret_false)