Пример #1
0
def blame(connection, channel, nick, cmd, args):
    goats = zip(("spaceone" for a in range(23)), 42 * [ reduce(random, [], "spaceone") ])
    shuffle(goats)
    goats.sort(key=lambda x: random())
    shuffle(goats)
    scapegoat = goats[randint(0, len(goats) - 1)][int(1337 * random()) % 2]
    plugins.say(connection, channel, "I blame %s." % scapegoat)
Пример #2
0
def wcsolve(connection, channel, nick, cmd, args):
    #"""Usage: revsolve (chall nr | chall name) [user]"""
    """Shows how many solved a challenge. Usage: wcsolve (chall nr | chall name)"""
    print "wcsolve", args
    if time.time() - cache_ts > 1 * 60:
        print "time diff", (time.time() - cache_ts)
        build_cache()

    if not args:
        plugins.print_help(connection, channel, nick, None, cmd)
        return

    nr, name, url, solvers = None, None, None, None
    if args.isdigit():
        nr = args
        if nr_to_url.has_key(nr):
            name, url, solvers = nr_to_url[nr]
    else:
        for key, val in nr_to_url.items():
            if val[0].lower().startswith(args.lower()):
                nr = key
                name, url, solvers = val
                break
            if args.lower() in val[0].lower():
                nr = key
                name, url, solvers = val

    txt = "No such challenge."
    if solvers is not None:
        txt = "Challenge Nr. %s, %s, has been solved by %d user%s." % (nr, name, solvers, "" if solvers == 1 else "s")

    plugins.say(connection, channel, txt)
Пример #3
0
def print_info(connection, channel, nick, msg):
    match = None
    try:
        match = regex.search(msg)
    except:
        traceback.print_exc()
        
    if match is None:
        return
    
    vid = match.group(2)
    #vid = "nw-z_FAyIVc"
    if vid in info_cache:
        txt = info_cache[vid] + " (cached)"
    else:
        req = urllib2.Request(searchurl % (API_KEY, vid))
        req.add_header("Referer", REFERER)
        resp = urllib2.urlopen(req).read()
        print resp
        resp = json.loads(resp)
        entry = resp["items"][0]
        name = entry["snippet"]["title"]
        duration = entry['contentDetails']['duration'][2:].lower()

        txt = "\x02[YouTube]\x0f %s (%s)" % (name, duration)
        info_cache[vid] = txt
        
    plugins.say(connection, channel, txt)
Пример #4
0
def movie(connection, channel, nick, cmd, args):
    """Shows information about movie from themoviedb.org"""
    if not args or not args.strip():
        return plugins.print_help(connection, channel, nick, None, cmd)

    args = args.strip()
    id = -1
    res = tmdb.Search().movie(query=args)
    if res["total_results"] > 0:
        id = res["results"][0]["id"]

    if id < 0:
        return plugins.say(connection, channel, "No such movie.")

    movie = tmdb.Movies(id)
    movie_info = movie.info()
    txt = "\x02%s\x02" % movie_info["title"]
    if movie_info["title"] != movie_info["original_title"]:
        txt += " (%s)" % movie_info["original_title"]
    if movie_info["release_date"]:
        txt += " | \x02Released:\x02 %s" % movie_info["release_date"]
    if movie_info["vote_count"] > 0:
        txt += " | \x02Rating:\x02 %.1f/10" % movie_info["vote_average"]
    if movie_info["homepage"]:
        txt += " | \x02Homepage:\x02 %s" % movie_info["homepage"]

    plugins.say(connection, channel, txt)
    plugins.say(connection, channel, plugins.split(movie_info["overview"]))
Пример #5
0
def tv(connection, channel, nick, cmd, args):
    """Shows information about tv series from themoviedb.org"""
    if not args or not args.strip():
        return plugins.print_help(nick, channel, None, cmd)

    args = args.strip()
    id = -1
    res = tmdb.Search().tv(query=args)
    if res["total_results"] > 0:
        id = res["results"][0]["id"]

    if id < 0:
        return plugins.say(connection, channel, "No such tv series.")

    movie = tmdb.TV(id)
    movie_info = movie.info()
    txt = "\x02%s\x02" % movie_info["name"]
    if movie_info["name"] != movie_info["original_name"]:
        txt += " (%s)" % movie_info["original_name"]
    if movie_info["first_air_date"]:
        txt += " | \x02First Aired:\x02 %s" % movie_info["first_air_date"]
    if movie_info["number_of_seasons"]:
        txt += " | \x02Nr. of Seasons:\x02 %d" % movie_info["number_of_seasons"]
    if movie_info["vote_count"] > 0:
        txt += " | \x02Rating:\x02 %.1f/10" % movie_info["vote_average"]
    if movie_info["homepage"]:
        txt += " | \x02Homepage:\x02 %s" % movie_info["homepage"]

    plugins.say(connection, channel, txt)
    plugins.say(connection, channel, plugins.split(movie_info["overview"]))
Пример #6
0
def waquery(connection, channel, nick, cmd, args):
    if not args:
        return

    res = client.query(args)
    try:
        txt = next(res.results).text
    except StopIteration:
        txt = "No results"
    plugins.say(connection, channel, txt)
Пример #7
0
def jhype(connection, channel, nick, cmd, args):
    nr = random.randint(1, max)
    if args:
        what = args.split()[0].strip()
        if what == "bikini":
            nr = 2
        elif what == "latest":
            nr = max
        elif what == "naked":
            return plugins.say(connection, channel, "You're not old enough or have no age specified")
    plugins.say(connection, channel, "Picture of Jhype: https://www.sabrefilms.co.uk/store/j%d.jpg" % nr)
Пример #8
0
def translate(connection, channel, nick, cmd, args):
    if not args:
        return

    headers = { 'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1' }
    data = { 'sl' : 'auto', 'tl' : 'en', 'hl' : 'en', 'ie' : 'UTF-8', 'q' : args }
    req = urllib2.Request("https://translate.google.com/", urllib.urlencode(data), headers)
    tree = lxml.html.parse(urllib2.urlopen(req))

    trans = tree.xpath("//span[@id='result_box']")
    if len(trans) > 0:
        txt = trans[0].text_content().strip()
        plugins.say(connection, channel, "Translation: %s" % txt)
Пример #9
0
def vs(connection, channel, nick, cmd, args):
    """Usage: vs "search term 1" "search term 2" -- Compares the number of google results for both terms."""
    if not args:
        return plugins.print_help(connection, channel, nick, None, cmd)

    try:
        v = shlex.split(args)
    except Exception as e:
        return plugins.say(connection, channel, str(e))
    
    if len(v) != 2:
        return plugins.print_help(connection, channel, nick, None, cmd)
    
    term1, term2 = v
    hits1 = google_search(term1.encode("utf-8"))[0]
    hits2 = google_search(term2.encode("utf-8"))[0]
    h1 = locale.format("%d", hits1, 1)
    h2 = locale.format("%d", hits2, 1)
    plugins.say(connection, channel, "%s %s %s %s %s" % (term1, h1, create_bar(hits1, hits2, 21), h2, term2))
Пример #10
0
def tbssolve(connection, channel, nick, cmd, args):
    #"""Usage: tbssolve chall_name"""
    """Shows how many solved a challenge. Usage: tbssolve chall_name"""

    if not args:
        plugins.print_help(connection, channel, nick, None, cmd)
        return

    build_cache()
    print solved_cache
    name, url, solved = None, None, None
    for n, u, s in solved_cache:
        if n.lower().startswith(args.lower()):
            name = n
            url = u
            solved = s
            break

    txt = "No such challenge."
    if name:
        txt = "Challenge '%s' has been solved by %d user%s." % (name, solved, "" if solved == 1 else "s")

    plugins.say(connection, channel, txt)
Пример #11
0
def wtf(connection, channel, nick, cmd, args):
    index = 0
    try:
        pargs = parser.parse_args(shlex.split(args or ""))
        if parser.help_requested:
            return plugins.say(connection, channel, parser.format_help().strip())
        if pargs.nr:
            index = int(pargs.nr) - 1
    except plugins.ArgumentParserError as e:
        return plugins.say(connection, channel, "error: %s" % str(e))
    except (SystemExit, NameError, ValueError):
        return plugins.print_help(connection, channel, nick, None, cmd)
    
    page = index / 7 + 1
    index %= 7
    term = pargs.search_term

    """
    if term.lower() == "maddinw":
        return plugins.say(channel, "A guy commonly referred to as Strong Mad.")
    elif term.lower() == "dloser":
        return plugins.say(channel, "<Jhype> dloser: a thoughtful friend ")
    """

    tree = lxml.html.parse("http://www.urbandictionary.com/define.php?term=%s&page=%d" % (urllib.quote_plus(term.encode("utf-8")), page))
    entries = tree.xpath("//div[@class='def-panel' and @data-defid]")
    if not entries:
        return plugins.say(connection, channel, "'%s' has no definition at http://www.urbandictionary.com" % term)

    if index >= len(entries) or index < 0:
        return plugins.say(connection, channel, "No definition nr %d available" % (index + 1))

    count = "?"
    count_div = tree.xpath("//div[contains(@class, 'definition-count-panel')]")
    if count_div:
        try:
            count = str(1 + int(count_div[0].text_content().split()[0]))
        except Exception as e:
            print e
            pass

    txt = "\x02[Definition %d/%s]\x0f " % (index + 1, count)
    definition = extract_text(entries[index], ".//div[@class='meaning']")
    if len(definition) > 300:
        definition = definition[:300] + "..."
    txt += definition
    
    example = extract_text(entries[index], ".//div[@class='example']")
    if example:
        if len(example) > 300:
            example = example[:300] + "..."
        txt += "\n\x02Example:\x0f " + example

    plugins.say(connection, channel, txt)
Пример #12
0
def helper(connection, channel, nick, cmd, args, what):
    if not args:
        return plugins.print_help(connection, channel, nick, None, cmd)

    count, hits, searchurl = google_search(args, what)
    for h in hits:
        plugins.say(connection, channel, "%s | %s" % (html.unescape(h["titleNoFormatting"]), h["unescapedUrl"]))
    if hits:
        plugins.say(connection, channel, "For more results, see %s (%s hits)" % (searchurl, locale.format("%d", count, 1)))
    else:
        plugins.say(connection, channel, "Found no results. See for yourself: %s" % searchurl)
Пример #13
0
def _time(connection, channel, nick, cmd, args):
    """Print the seconds since last chall"""
    last = time.mktime(datetime.date(2013, 10, 11).timetuple())
    plugins.say(connection, channel, "%d seconds since last chall" % int(time.time() - last))
Пример #14
0
def meminfo(connection, channel, nick, cmd, args):
    if plugins.is_windows():
        minfo = meminfo_win()
    else:
        minfo = None
    plugins.say(connection, channel, "Current memory usage: %s" % minfo)
Пример #15
0
def fam(connection, channel, nick, cmd, args):
    """This help at fam"""
    plugins.say(connection, channel, ".quoet fom")
Пример #16
0
def roulette(connection, channel, nick, msg):
    if msg.find("BANG") > -1 or msg.find("BOOM") > -1:
        plugins.say(connection, channel, "!roulette")
Пример #17
0
def uname(connection, channel, nick, cmd, args):
    if plugins.is_windows():
        p = Popen(["ver"], stdout=PIPE, shell=True).communicate()[0].strip()
    else:
        p = Popen(["uname", "-a"], stdout=PIPE).communicate()[0].strip()
    plugins.say(connection, channel, "%s: %s" % (nick, p))
Пример #18
0
 def reload(self, connection, channel, nick, cmd, args):
     res = self.tehbot.reload()
     if res is None:
         plugins.say(connection, channel, "Okay")
     else:
         plugins.say(connection, channel, "Error: %s" % res)
Пример #19
0
def uptime(connection, channel, nick, cmd, args):
    """Prints the uptime of tehbot's host."""
    up = get_uptime()
    plugins.say(connection, channel, "%s: %s" % (nick, up))