Josh VanderLinden avatar Josh VanderLinden committed d2905a7

Bumped the version a little. Fixed some problems related to tweets that contain ampersands. Implemented a feature inspired by @Brycedan, which allows you to insert someone's Twitter username mid-tweet by doing something like 'I want to tweet to ./5' where 5 is the internal ID for a tweet that you have received in the current session. Along with this change, you can now use the internal ID for various other commands, such as follow, unfollow, and whois.

Comments (0)

Files changed (2)

 
         sys.exit(0)
 
+    def GetUsernameByID(self, id):
+        """
+        Attempts to retrieve a Twitter user's username based on a numeric ID
+        that refers to a tweet in your IM
+        """
+
+        try:
+            number = int(id)
+            tweet = cache.by_id(number)
+            if tweet:
+                return tweet.user.screen_name
+        except ValueError:
+            pass
+        return id
+
     def OnHelpCommand(self, user, body, remaining):
         """
         Describes the commands a user can use and how to use them
         # follow a new friend
         args = re.search('^([^ $]+)', remaining)
         if args:
-            username = args.group(1)
+            username = self.GetUsernameByID(args.group(1))
             try:
                 log.info('Attempting to follow %s' % username)
                 user.api.CreateFriendship(username)
         # unfollow someone
         args = re.search('^([^ $]+)', remaining)
         if args:
-            username = args.group(1)
+            username = self.GetUsernameByID(args.group(1))
             try:
                 user.api.DestroyFriendship(username)
                 self.TellUser('You are no longer following %s' % username)
         """
         args = re.search('^([^ $]+)', remaining)
         if args:
-            username = args.group(1)
+            username = self.GetUsernameByID(args.group(1))
             try:
                 info = user.api.GetUser(username)
 
 
         args = re.search('^([^ ]+) (.*)$', remaining)
         if args:
-            username = args.group(1)
+            username = self.GetUsernameByID(args.group(1))
             message = args.group(2)
             try:
                 log.info('Sending DM to %s (%s)' % (username, message))
                                                           info['shortcut'],
                                                           info['compression'])
 
+        # see if there is anything such as "I am talking to ./5" and, if so
+        # replace the "./5" with the username for that tweet in the cache
+        get_username = lambda mo: '@' + self.GetUsernameByID(mo.group(1))
+        body = re.sub('\./(\d+)', get_username, body)
+
         posted = user.api.PostUpdates(body,
                                       in_reply_to_status_id=in_reply_to_status_id)
         if posted:
             text)
 
         replacements = (
-            ('&', '&'),
             ('—', '--'),
             ('–', '-'),
         )
             text = text.replace(needle, rep)
         text = clean(text)
 
+        # take care of any lingering ampersands
+        text = re.sub('&(?!\w+;)', '&', text)
+
         return uhref + ': ' + text
 
     def TellUser(self, message):
 # -*- coding: utf-8 -*-
 
 """
-Twim is a simple program which regularly checks your Twitter account(s) for
+Twibber is a simple program which regularly checks your Twitter account(s) for
 updates.  Upon finding an update, it will send it to you via Instant Message
 using any Jabber-compatible client.
 """
 
 APP_TITLE = 'Twibber'
 __url__ = 'http://bitbucket.org/codekoala/twibber'
-__version__ = '0.0.3.9'
+__version__ = '0.0.4.0'
 
 if __name__ == '__main__':
     # configure logging
                         level=logging.DEBUG,
                         format=format)
 
-    twim = Twibber('--no-gui' not in sys.argv)
+    twibber = Twibber('--no-gui' not in sys.argv)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.