Example #1
0
def wik(jenni, input):
    if blacklist.user(input.nick):
        return
    
    origterm = input.groups()[1]
    if not origterm:
        return jenni.say('Perhaps you meant ".wik Zen"?')
    origterm = origterm.encode('utf-8')
    origterm = origterm.strip()

    term = urllib.unquote(origterm)

    if blacklist.term(term, input.nick):
        return

    language = 'en'
    if term.startswith(':') and (' ' in term):
        a, b = term.split(' ', 1)
        a = a.lstrip(':')
        if a.isalpha():
            language, term = a, b
    term = term[0].upper() + term[1:]
    term = term.replace(' ', '_')

    try: result = wikipedia(term, language)
    except IOError:
        args = (language, wikiuri % (language, term))
        error = "Can't connect to %s.wikipedia.org (%s)" % args
        return jenni.say(error)

    if result is not None:
        jenni.say(result)
    else: jenni.say('Can\'t find anything in Wikipedia for "%s".' % origterm)
Example #2
0
def translate(jenni, input):
    alphabet = {
        "a": "4",
        "b": "b",
        "c": "c",
        "d": "d",
        "e": "3",
        "f": "ph",
        "g": "9",
        "h": "h",
        "i": "1",
        "k": "k",
        "l": "l",
        "m": "m",
        "n": "n",
        "o": "0",
        "p": "p",
        "q": "q",
        "r": "r",
        "s": "5",
        "t": "7",
        "u": "u",
        "v": "v",
        "w": "w",
        "x": "x",
        "y": "y",
        "z": "z"
    }

    words = {
        "am": "m",
        "are": "r",
        "at": "@",
        "thanks": "thx",
        "your": "ur",
        "cool": "kewl",
        "defeated": "pwned",
        "dude": "d00d",
        "fear": "ph33r",
        "fool": "f00",
        "freak": "phreak",
        "hacker": "h4x0r",
        "lamer": "l4m3r",
        "mad": "m4d",
        "newbie": "n00b",
        "own": "pwn",
        "phone": "fone",
        "p**n": "pr0n",
        "rocks": "roxxorz",
        "skill": "sk1llz",
        "sucks": "sux0rz",
        "the": "t3h",
        "uber": "ub3r",
        "yay": "w00t",
        "yo": "j0",
        "you": "j00"
    }

    fixes = {
        'phph': 'ph'
    }

    if not (input.group(2)):
        return
    
    query = input.group(2)

    if not is_ascii(query):
        return

    if blacklist.term(query, input.nick):
        return
    
    for word in str(query).split():
        if word in words:
            query = query.replace(word, words[word])
        else:
            new_word = []
            for letter in word:
                if letter in alphabet:
                    new_word.append(letter.replace(letter, alphabet[letter]))
                else:
                    new_word.append(letter)
            query = query.replace(word, ''.join(new_word))

    for word in query.split():
        for fix in fixes:
            query = query.replace(fix, fixes[fix])
            
    jenni.say(query)