]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/ircbot.py
Merge https://github.com/sixohsix/twitter into pr-rouxrc
[z_archive/twitter.git] / twitter / ircbot.py
index 9310d0c05278fcb0e81b02fc27663dd5917532f3..60914172d721af32aa88ec6c3eebf0d4bb16cdd6 100644 (file)
@@ -36,7 +36,7 @@ oauth_token_file: <oauth_token_filename>
 
 from __future__ import print_function
 
-BOT_VERSION = "TwitterBot 1.6.1 (http://mike.verdone.ca/twitter)"
+BOT_VERSION = "TwitterBot 1.9.1 (http://mike.verdone.ca/twitter)"
 
 CONSUMER_KEY = "XryIxN3J2ACaJs50EizfLQ"
 CONSUMER_SECRET = "j7IuDCNjftVY8DBauRdqXs4jDl5Fgk1IJRag8iE"
@@ -87,7 +87,7 @@ except ImportError:
         "This module requires python irclib available from "
         + "https://github.com/sixohsix/python-irclib/zipball/python-irclib3-0.4.8")
 
-OAUTH_FILE = os.environ.get('HOME', '') + os.sep + '.twitterbot_oauth'
+OAUTH_FILE = os.environ.get('HOME', os.environ.get('USERPROFILE', '')) + os.sep + '.twitterbot_oauth'
 
 def debug(msg):
     # uncomment this for debug text stuff
@@ -148,12 +148,12 @@ class TwitterBot(object):
         self.twitter = Twitter(
             auth=OAuth(
                 oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET),
-            api_version='1',
             domain='api.twitter.com')
 
         self.irc = irclib.IRC()
         self.irc.add_global_handler('privmsg', self.handle_privmsg)
         self.irc.add_global_handler('ctcp', self.handle_ctcp)
+        self.irc.add_global_handler('umode', self.handle_umode)
         self.ircServer = self.irc.server()
 
         self.sched = Scheduler(
@@ -164,7 +164,7 @@ class TwitterBot(object):
     def check_statuses(self):
         debug("In check_statuses")
         try:
-            updates = reversed(self.twitter.statuses.friends_timeline())
+            updates = reversed(self.twitter.statuses.home_timeline())
         except Exception as e:
             print("Exception while querying twitter:", file=sys.stderr)
             traceback.print_exc(file=sys.stderr)
@@ -226,6 +226,19 @@ class TwitterBot(object):
             elif args[0] == 'CLIENTINFO':
                 conn.ctcp_reply(source, "CLIENTINFO PING VERSION CLIENTINFO")
 
+    def handle_umode(self, conn, evt):
+        """
+        QuakeNet ignores all your commands until after the MOTD. This
+        handler defers joining until after it sees a magic line. It
+        also tries to join right after connect, but this will just
+        make it join again which should be safe.
+        """
+        args = evt.arguments()
+        if (args and args[0] == '+i'):
+            channels = self.config.get('irc', 'channel').split(',')
+            for channel in channels:
+                self.ircServer.join(channel)
+
     def privmsg_channels(self, msg):
         return_response=True
         channels=self.config.get('irc','channel').split(',')
@@ -241,7 +254,7 @@ class TwitterBot(object):
                 "%sI'm already following %s." %(get_prefix('error'), name))
         else:
             try:
-                self.twitter.friendships.create(id=name)
+                self.twitter.friendships.create(screen_name=name)
             except TwitterError:
                 conn.privmsg(
                     userNick,
@@ -265,7 +278,7 @@ class TwitterBot(object):
                 userNick,
                 "%sI'm not following %s." %(get_prefix('error'), name))
         else:
-            self.twitter.friendships.destroy(id=name)
+            self.twitter.friendships.destroy(screen_name=name)
             conn.privmsg(
                 userNick,
                 "%sOkay! I've stopped following %s." %(