Commits

Benoit C committed 7150ecc

dynamically create follow_list

  • Participants
  • Parent commits 6bb6916

Comments (0)

Files changed (2)

File autiste/modules/logger.py

     def __init__(self, conf, irc):
         IrcModule.__init__(self, conf, irc)
         self.logger = None
+        self.nickname = irc.nickname
+        print "i'm %s"%self.nickname
         print conf
 
     def name(self):
         return 'IrcLogger'
 
     def connectionMade(self):
-        print self.conf
         self.logger = MessageLogger(self.conf)
 
     def connectionLost(self, reason):
         self.logger.log(channel,
                 "-!- %s has joined %s" % (user, channel))
 
+    def random_sentence(self, channel, nick):
+        try:
+            msg = self.logger.random(channel)
+            if not self.nickname in msg:
+                self.irc.say(channel, "%s: %s" % (nick, msg))
+        except Exception, e:
+            print e
+            pass
+
+
     def privmsg(self, user, channel, msg):
         user = user.split('!', 1)[0]
         self.logger.log(channel, "(%s) %s" % (user, msg))
         self.logger.live(channel, msg)
+        if msg.startswith(self.nickname + ":"):
+            words = msg.split(' ')
+            if len(words) > 1:
+                self.random_sentence(channel, user)
+
 
     def action(self, user, channel, msg):
         """This will get called when the bot sees someone do an action."""

File autiste/modules/twitter.py

 STREAM_URL="http://stream.twitter.com/1/statuses/filter.json"
 
 import unicodedata
-
-def asciize(s):
-    return str(unicodedata.normalize('NFKD', s).encode('ascii','ignore'))
+def strip_accents(s):
+       return unicodedata.normalize('NFKD', s).encode('ascii','ignore')
 
 
 class Module(AsyncModule):
         self.pyc = None
 
     def run(self):
+        follow = "follow=" + ",".join([str(x) for x in self.conf.get('follow')])
         self.pyc = pycurl.Curl()
         self.pyc.setopt(pycurl.USERPWD, "%s:%s" % (self.conf.get("user"), self.conf.get("pass")))
         self.pyc.setopt(pycurl.URL, STREAM_URL)
         self.pyc.setopt(pycurl.WRITEFUNCTION, self.on_receive)
-        self.pyc.setopt(pycurl.POSTFIELDS, "follow=24299195,116523453,15687408,15180881")
+        self.pyc.setopt(pycurl.POSTFIELDS, follow)
         self.pyc.setopt(pycurl.POST, 1)
         self.pyc.perform()
 
             if text.startswith("RT") or text.startswith("@"):
                 return
             if "text" in content:
-                self.irc.say("#dzen", asciize(u"@{0[user][screen_name]}: {0[text]}".format(content)))
+                self.irc.say("#dzen", strip_accents(u"@{0[user][screen_name]}: {0[text]}".format(content)))
 
     def name(self):
         return 'TwitterFeed'