Exemple #1
0
def urlparser(match, say = None, input=None, bot=None):
    inpo = input.params.replace(input.chan+" :","")
    url = match.group().encode('utf-8')
    regexs = re.compile(r"(.+?)(\'|\"|\(|\)|\{|\}|\]|\[|\<|\>)")
    matchs = regexs.search(url)
    if matchs:
        url = matchs.group(0).replace(matchs.group(0)[-1:],"")
    url = urlnorm.normalize(url)
    url2 = urltest(url,match)
    if (not input.conn.conf['autotitle']==False) and (not (perm.isignored(input) or perm.isbot(input))) and not (inpo.startswith(",t") or inpo.startswith(",title") or inpo.startswith(",shor")) and not ("@" in url):
        #print "[debug] URL found"
        if url.startswith("www."):
            url = "http://"+url
        for x in ignored_urls:
            if x in url:
                return
        title = parse(url)
        title = multiwordReplace(title, wordDic)
        try:
            realurl = http.get_url(url)
        except Exception, msg:
            return("(Link) %s" % msg)
        api_user = bot.config.get("api_keys", {}).get("bitly_user", None)
        api_key = bot.config.get("api_keys", {}).get("bitly_api", None)
        if api_key is None:
            return "error: no api key set"
        realurl = isgd(realurl)
        if realurl == url:
            return("(Link) %s" % title)
        else:
            return("(Link) %s <=> %s" % (realurl, title))
Exemple #2
0
def urlparser(match, say=None):
    url = urlnorm.normalize(match.group().encode('utf-8'))
    if url[:7] != "http://":
        if url[:8] != "https://":
            url = "http://" + url
    for x in ignored_urls:
        if x in url:
            return
    title = parse(url)
    if title == "fail":
        return
    title = http.unescape(title)
    realurl = http.get_url(url)
    if realurl == url:
        say("(Link) %s" % title)
        return
    else:
        say("(Link) %s [%s]" % (title, realurl))
        return
Exemple #3
0
def expand(inp, bot=None):
    ".expand <url> - Gets the original URL from a shortened link."
    try:
        url = http.get_url(inp)
    except HTTPError, e:
        return "Failed to expand URL."