Index: protocols/twitter/twitter.c
===================================================================
--- protocols/twitter/twitter.c	(revision 203a2d2e8857e4c83f8f5e1a89de03ea08538cb2)
+++ protocols/twitter/twitter.c	(revision f32c14c649e854fbfb7b8e495e2ebc8459ee5b6f)
@@ -186,4 +186,6 @@
 	}
 	
+	s = set_add( &acc->set, "auto_reply_timeout", "10800", set_eval_int, acc );
+	
 	s = set_add( &acc->set, "base_url", def_url, NULL, acc );
 	s->flags |= ACC_SET_OFFLINE_ONLY;
@@ -427,11 +429,5 @@
 		
 		if( cmd[1] )
-		{
-			char *end = NULL;
-			
-			id = g_ascii_strtoull( cmd[1], &end, 10 );
-			if( end == NULL )
-				id = 0;
-		}
+			id = g_ascii_strtoull( cmd[1], NULL, 10 );
 		else
 			id = td->last_status_id;
@@ -444,4 +440,35 @@
 		return;
 	}
+	else if( g_strcasecmp( cmd[0], "follow" ) == 0 && cmd[1] )
+	{
+		twitter_add_buddy( ic, cmd[1], NULL );
+		g_free( cmds );
+		return;
+	}
+	else if( g_strcasecmp( cmd[0], "unfollow" ) == 0 && cmd[1] )
+	{
+		twitter_remove_buddy( ic, cmd[1], NULL );
+		g_free( cmds );
+		return;
+	}
+	else if( g_strcasecmp( cmd[0], "rt" ) == 0 && cmd[1] )
+	{
+		struct twitter_user_data *tud;
+		bee_user_t *bu;
+		guint64 id;
+		
+		if( ( bu = bee_user_by_handle( ic->bee, ic, cmd[1] ) ) &&
+		    ( tud = bu->data ) && tud->last_id )
+			id = tud->last_id;
+		else
+			id = g_ascii_strtoull( cmd[1], NULL, 10 );
+		
+		td->last_status_id = 0;
+		if( id )
+			twitter_status_retweet( ic, id );
+		
+		g_free( cmds );
+		return;
+	}
 	else if( g_strcasecmp( cmd[0], "post" ) == 0 )
 	{
@@ -450,4 +477,5 @@
 	
 	{
+		guint64 in_reply_to = 0;
 		char *s, *new = NULL;
 		bee_user_t *bu;
@@ -466,11 +494,20 @@
 			if( ( bu = bee_user_by_handle( ic->bee, ic, cmd[0] ) ) )
 			{
+				struct twitter_user_data *tud = bu->data;
+				
 				new = g_strdup_printf( "@%s %s", bu->handle,
 				                       message + ( s - cmd[0] ) + 2 );
 				message = new;
+				
+				if( time( NULL ) < tud->last_time +
+				    set_getint( &ic->acc->set, "auto_reply_timeout" ) )
+					in_reply_to = tud->last_id;
 			}
 		}
 		
-		twitter_post_status( ic, message );
+		/* If the user runs undo between this request and its response
+		   this would delete the second-last Tweet. Prevent that. */
+		td->last_status_id = 0;
+		twitter_post_status( ic, message, in_reply_to );
 		g_free( new );
 	}
Index: protocols/twitter/twitter_lib.c
===================================================================
--- protocols/twitter/twitter_lib.c	(revision 203a2d2e8857e4c83f8f5e1a89de03ea08538cb2)
+++ protocols/twitter/twitter_lib.c	(revision f32c14c649e854fbfb7b8e495e2ebc8459ee5b6f)
@@ -784,11 +784,14 @@
  * Function to POST a new status to twitter.
  */ 
-void twitter_post_status(struct im_connection *ic, char* msg)
-{
-	char* args[2];
-	args[0] = "status";
-	args[1] = msg;
-	twitter_http(ic, TWITTER_STATUS_UPDATE_URL, twitter_http_post, ic, 1, args, 2);
-//	g_free(args[1]);
+void twitter_post_status(struct im_connection *ic, char *msg, guint64 in_reply_to)
+{
+	char* args[4] = {
+		"status", msg,
+		"in_reply_to_status_id",
+		g_strdup_printf("%llu", (unsigned long long) in_reply_to)
+	};
+	twitter_http(ic, TWITTER_STATUS_UPDATE_URL, twitter_http_post, ic, 1,
+	             args, in_reply_to ? 4 : 2);
+	g_free(args[3]);
 }
 
@@ -825,2 +828,10 @@
 	g_free(url);
 }
+
+void twitter_status_retweet(struct im_connection *ic, guint64 id)
+{
+	char *url;
+	url = g_strdup_printf("%s%llu%s", TWITTER_STATUS_RETWEET_URL, (unsigned long long) id, ".xml");
+	twitter_http(ic, url, twitter_http_post, ic, 1, NULL, 0);
+	g_free(url);
+}
Index: protocols/twitter/twitter_lib.h
===================================================================
--- protocols/twitter/twitter_lib.h	(revision 203a2d2e8857e4c83f8f5e1a89de03ea08538cb2)
+++ protocols/twitter/twitter_lib.h	(revision f32c14c649e854fbfb7b8e495e2ebc8459ee5b6f)
@@ -36,4 +36,5 @@
 #define TWITTER_STATUS_SHOW_URL "/statuses/show/"
 #define TWITTER_STATUS_DESTROY_URL "/statuses/destroy/"
+#define TWITTER_STATUS_RETWEET_URL "/statuses/retweet/"
 
 /* Timeline URLs */
@@ -81,8 +82,9 @@
 void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor);
 
-void twitter_post_status(struct im_connection *ic, char *msg);
+void twitter_post_status(struct im_connection *ic, char *msg, guint64 in_reply_to);
 void twitter_direct_messages_new(struct im_connection *ic, char *who, char *message);
 void twitter_friendships_create_destroy(struct im_connection *ic, char *who, int create);
 void twitter_status_destroy(struct im_connection *ic, guint64 id);
+void twitter_status_retweet(struct im_connection *ic, guint64 id);
 
 #endif //_TWITTER_LIB_H
