Пример #1
0
import plugins
import urllib
import urllib2
import lxml.html

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)

plugins.register_pub_cmd("translate", translate)
Пример #2
0
import plugins

def fam(connection, channel, nick, cmd, args):
    """This help at fam"""
    plugins.say(connection, channel, ".quoet fom")

plugins.register_pub_cmd("fam", fam)
Пример #3
0
    if not args: return
    args = args.encode("utf-8")
    args = map(str.strip, args.strip().split())
    cmd = args[0]

    if cmd[0] != "/":
        cmd = normpath(join("/bin", cmd))
        cmd = cmd.replace("\\", "/")

    res = "-tehsh: %s: Command not found" % args[0]
    if cmd == "/bin/ls":
        res = ls(args[1:])
    elif cmd == "/bin/head":
        res = head(args[1:])
    elif cmd == "/bin/cat":
        res = cat(args[1:])
    elif cmd == "/bin/uptime":
        res = execute(["uptime"])
    elif cmd == "/bin/uname":
        res = execute(["uname"] + args[1:])
    elif cmd == "/bin/free":
        res = execute(["free"])
    elif cmd == "/bin/tehsh":
        res = "-tehsh: No cando"
    elif cmd == "/bin/bash":
        res = "-tehsh: No, I like tehsh."

    plugins.say_nick(connection, channel, nick, res)

plugins.register_pub_cmd("exec", exec_)
Пример #4
0
    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)

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)

plugins.register_pub_cmd("wcsolve", wcsolve)
plugins.register_pub_cmd("blame", blame)
Пример #5
0
import plugins
import random

max = 25

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)

plugins.register_pub_cmd("jhype", jhype)
Пример #6
0
import plugins

shotmap = {}

def shots(connection, channel, nick, cmd, args):
    plugins.say_nick(connection, channel, nick, "|~|")
    plugins.say_nick(connection, channel, nick, "+-+  Cheers, %s!" % nick)
    if not shotmap.has_key(nick):
        shotmap[nick] = 0
    shotmap[nick] += 1

def shoot(connection, channel, nick, cmd, args):
    if not shotmap.has_key(nick) or shotmap[nick] == 0:
        return plugins.say_nick(connection, channel, nick, "Your glass is empty!")

    shotmap[nick] -= 1
    plugins.say_nick(connection, channel, nick, "| |  AH!")
    plugins.say_nick(connection, channel, nick, "+-+  Want another one, %s?" % nick)

plugins.register_pub_cmd("shots", shots)
plugins.register_pub_cmd("shoot", shoot)
Пример #7
0
import plugins

def get_uptime():
    if plugins.is_windows():
        import ctypes
        import time
        millis = ctypes.WinDLL("kernel32").GetTickCount64()
        days = millis / 86400000
        millis -= 86400000 * days
        hours = millis / 3600000
        millis -= 3600000 * hours
        mins = millis / 60000
        upstr = "%02d:%02d" % (hours, mins)
        if days != 0:
            upstr = "%d days, %s" % (days, upstr)
        return "%s up %s" % (time.strftime("%H:%M:%S"), upstr)
    else:
        from subprocess import Popen, PIPE
        return Popen(["uptime"], stdout=PIPE).communicate()[0].strip()

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))

plugins.register_pub_cmd("uptime", uptime)
Пример #8
0
        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)

plugins.register_pub_cmd("wtf", wtf)
plugins.register_pub_cmd("define", wtf)
Пример #9
0
    else:
        v = int(float(width) * v2 / (v1 + v2))
        if v < 0: v = 0
        if v > width - 1: v = width - 1
        bar[v] = "#"
    return "|" + "".join(bar) + "|"

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))

plugins.register_pub_cmd("vs", vs)
plugins.register_pub_cmd("google", google)
plugins.register_pub_cmd("images", images)
Пример #10
0
        return
    plugins.say_nick(connection, channel, nick, plugins.myfilter(args))

def solve(connection, channel, nick, cmd, args):
    if not args:
        return
    if args == "https://www.sabrefilms.co.uk/revolutionelite/chall-for-tehron.php":
        plugins.say_nick(connection, channel, nick, "muffins")
    else:
        seq = ["nice try :P", "you wish", "haha", "ok. ...wait, aren't you %s?" % nick]
        plugins.say_nick(connection, channel, nick, random.choice(seq))

beers = 100
def beer(connection, channel, nick, cmd, args):
    global beers
    if beers == 0:
        return plugins.me(connection, channel, "has no beer left :(")

    if not args or not args.strip():
        plugins.me(connection, channel, "passes 1 of %d bottles of cold beer around to %s" % (beers, nick))
    else:
        recv = args.split()[0].strip()
        plugins.me(connection, channel, "and %s pass 1 of %d bottles of cold beer around to %s" % (nick, beers, recv))
    beers -= 1

plugins.register_pub_cmd("reverse", reverse)
plugins.register_pub_cmd("say", say)
plugins.register_pub_cmd("doublereverse", say)
plugins.register_pub_cmd("solve", solve)
plugins.register_pub_cmd("beer", beer)
Пример #11
0
import plugins
import wolframalpha

APP_ID = "your api id here"

client = wolframalpha.Client(APP_ID)


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)


plugins.register_pub_cmd("wa", waquery)
Пример #12
0
import plugins
from subprocess import Popen, PIPE

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))

plugins.register_pub_cmd("uname", uname)
Пример #13
0
import plugins
import os
from subprocess import Popen, PIPE

def meminfo_win():
    info = Popen('tasklist /fo list /fi "pid eq %d"' % os.getpid(), shell=True, stdout=PIPE).communicate()[0]
    info = info.strip()
    minfo = info.splitlines()[-1]
    return minfo.split(":", 1)[-1].strip()

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)

plugins.register_pub_cmd("meminfo", meminfo)
Пример #14
0
import plugins
import datetime, time


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))


plugins.register_pub_cmd("time", _time)
Пример #15
0
    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)

plugins.register_channel_handler(print_info)
plugins.register_pub_cmd("youtube", yt_search)
Пример #16
0
    init = False
    puns = []
    currpun = []
    for line in page.splitlines():
        if line.startswith('<p class="emph2">'):
            init = True
            if currpun:
                puns.append("\n".join(currpun))
                currpun = []
            continue
        if init and line.find("</div>") > -1:
            init = False
            break
        if init:
            if line.startswith("<br />"):
                if currpun:
                    puns.append("\n".join(currpun))
                    currpun = []
            else:
                currpun.append(line.replace("<br />", ""))
    if currpun:
        puns.append("\n".join(currpun))
        
    print puns

    random.shuffle(puns)
    if puns:
        plugins.say_nick(connection, channel, nick, puns[0])

plugins.register_pub_cmd("pun", pun)
Пример #17
0
            continue
        solvers = int(e2[0].text_content())

        solved_cache.append((name, url, solvers))

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)

plugins.register_pub_cmd("tbssolve", tbssolve)
Пример #18
0
        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"]))

plugins.register_pub_cmd("movie", movie)
plugins.register_pub_cmd("tv", tv)