err-elizabot

a classic electronic shrink for the chatbot err
git clone https://git.ce9e.org/err-elizabot.git

commit
dbb4f25ed75c7430a6d8ab13c0b326514f28e0eb
parent
e9905ac1e5ffae38c2bdb3acb098d6434c43c948
Author
Guillaume BINET <gbin@gootz.net>
Date
2012-06-09 12:05
added the command !complete

Diffstat

M elizaBot.py 20 +++++++++++++++++++-

1 files changed, 19 insertions, 1 deletions


diff --git a/elizaBot.py b/elizaBot.py

@@ -1,8 +1,10 @@
    1     1 import json
   -1     2 from random import choice
   -1     3 from lxml import objectify
    2     4 from errbot.botplugin import BotPlugin
    3     5 from eliza import Eliza
    4     6 from errbot.jabberbot import botcmd
    5    -1 from urllib2 import urlopen
   -1     7 from urllib2 import urlopen,quote
    6     8 
    7     9 __author__ = 'gbin'
    8    10 
@@ -17,8 +19,24 @@ class ElizaBot(BotPlugin):
   17    19     @botcmd
   18    20     def askus(self, mess, args):
   19    21         """ Give us a fun topic to talk about
   -1    22             thx to http://chatoms.com/
   20    23         """
   21    24         content = urlopen('http://chatoms.com/chatom.json?Normal=1&Fun=2&Philosophy=3&Out+There=4&Love=5&Personal=7').read()
   22    25         return json.loads(content)['text']
   23    26 
   -1    27     @botcmd
   -1    28     def complete(self, mess, args):
   -1    29         """ Complete the given sentence
   -1    30             thx to the awesome google completion
   -1    31         """
   -1    32         args = args.strip()
   -1    33         if not args:
   -1    34             return 'Complete what ?'
   -1    35 
   -1    36         content = urlopen('http://google.com/complete/search?q=%s&output=toolbar'%quote(args)).read()
   -1    37         xml = objectify.fromstring(content)
   -1    38         possibilities = xml.xpath("//toplevel/CompleteSuggestion/suggestion/@data")
   -1    39         if possibilities:
   -1    40             return choice(possibilities)
   -1    41         return 'Hmmm... no answer for that'
   24    42