def mangleRandomTweet(): import tcfparty tweet = getRandomTweet() if tweet is None: logging.warn('No tweets found.') return 'I\'m sorry, I didn\'t find any tweets.' quit() text = tweet['text'] # Replace usernames with real names if '@' in text: import random logging.debug('Replacing usernames with real names') matches = re.findall(r'(?:^|\s)(@.+?)(?=$|\s)', text) matches = set(matches) for match in matches: logging.debug(' Name found: ' + match) text = text.replace(match, random.choice(names)) text = text.replace('#', '') text = tcfparty.tcfparty(text) return text
def mention(phenny, input): phrase = input.group(1).strip() selector = random.randint(1,2) logging.debug('lackbot mentioned, selector rolled a ' + str(selector)) if selector <= 1: logging.debug('Confused reply') reply = random.choice(["What's that?", "Too right!", "Say whaat?!?", "Hmm?", "Pardon?"]) phenny.reply(reply) elif selector <= 2: logging.debug('Replying with a party of the input') import tcfparty phrase = phrase.replace(phenny.nick, input.nick) phenny.reply(tcfparty.tcfparty(phrase))
def getFact(): global sentenceOnly sentenceOnly = True factoid = randomArticle() try: factoid = tcfparty.tcfparty(factoid) return factoid except UnicodeDecodeError: return "Robots are better than people!" # logging.debug('getFact failed, lackbot having a mood') # import lbtwitter # return lbtwitter.mangleRandomTweet() sentenceOnly = False
def chat(phenny, input): phrase = input.group(1).strip() selector = random.randint(1,6) logging.debug('Selector rolled a ' + str(selector)) if selector <= 1: logging.debug('Doing a Vincent reply') import vincent phenny.reply(vincent.question(phrase)) elif selector <= 2: logging.debug('I LIKE FOOD') phenny.reply("I LIKE FOOD") elif selector <= 3: logging.debug('Replying with a "fact"') import wikipedia phenny.reply(wikipedia.getFact()) else: logging.debug('Replying with a party of the input') import tcfparty phenny.reply(tcfparty.tcfparty(phrase))