Exemple #1
0
def handle_confluence_search(bot, ievent):

    if "channels" not in cfg.data or ievent.channel not in cfg.data["channels"]:
        ievent.reply("Confluence wiki search not enabled for this channel")
        return

    serverName = cfg.data["channels"][ievent.channel]
    server = cfg.data["servers"][serverName]

    if len(ievent.args) == 0:
        ievent.reply("The wiki is located at %s" % server["url"])
        return
    args = ievent.args
    if args[0][0] == "#":
        maxResults = int(args[0].strip("#"))
        args = args[1:]
    else:
        maxResults = 5

    query = " ".join(args)

    try:
        client, auth = getRpcClient(server)
        results = client.search(auth, query, maxResults)
    except Exception as ex: ievent.reply("an error occured: %s" % str(ex)) ; return

    ievent.reply("Displaying %s result(s) :" % min(maxResults, len(results)))
    for page in results[:maxResults]:
        tinyurl = get_tinyurl(page["url"])
        tinyurl = tinyurl[0] if tinyurl else page["url"]
        ievent.reply('"%s": %s' % (page["title"], tinyurl))
Exemple #2
0
def getUrlInfo(text):
    """ get info of urls in given txt. """
    from tl.utils.url import enabled
    if not enabled: raise URLNotEnabled
    out = ''
    text = sanitize(text)
    urls = getUrls(text)
    if urls:
        idx = 1
        for i in urls:
            o = ''
            try:
                server = xmlrpc.client.ServerProxy("http://whatisthisfile.appspot.com/xmlrpc")
                logging.info('urlinfo - XMLRPC query: %s' % i)
                urlinfo = server.app.query(i)
                if 'html' in urlinfo:
                     if 'title' in urlinfo['html']: o += 'Title: "%s" ' % urlinfo['html']['title'].strip()
                elif 'image' in urlinfo: o += 'Image: %dx%d ' % (urlinfo['image']['width'], urlinfo['image']['height'])
                if not o: continue
                if len(o):
                    if len(urls) > 1: out += ' ' + str(idx) + '. ' ; idx += 1
                out += o
                if "tinyurl" in i: out = out.strip() ; out += " - %s" % i
                elif not "http://" in out: out = out.strip() ; out += " - %s" % get_tinyurl(i)[0]
            except Exception: pass
    return out.strip()
Exemple #3
0
def doLookup(bot, ievent):
    fnd = gitHashRule.match(ievent.txt)
    for project in cfg.data[ievent.channel]:
        try:
            res = gh.commits.show(project, sha=fnd.group(1))
            logging.info('response from github: %s' % res)
            bot.say(ievent.channel, "%s- %s by %s: %s %s" % (project, res.id[:7], res.author["name"], res.message[:60], get_tinyurl("https://github.com" + res.url)[0]))
            return
        except:
            print("Couldn't find %s" % fnd.group(1))
Exemple #4
0
def doLookup(bot, ievent):
    logging.info("Doing lookup for fisheye changeset")
    fnd = gitHashRule.match(ievent.txt)
    for pname in cfg.data[ievent.channel]:
        project = cfg.data["projects"][pname]
        try:
            server, auth = getRpcClient(project)
            res = server.getChangeset(auth, pname, fnd.group(1))
            logging.info('response from fisheye: %s' % res)
            cs_url = "%s/changelog/%s?cs=%s" % (project["url"], pname, res["csid"])
            bot.say(ievent.channel, "%s- %s by %s: %s %s" % (pname, res["csid"][:7], res["author"], res["log"].strip()[:60], get_tinyurl(cs_url)[0]))
            return
        except:
            print("Couldn't find %s" % fnd.group(1))