aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/twitter/twitter.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2011-03-29 23:47:00 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2011-03-29 23:47:00 +0100
commit15bc063f3b8cf99f5fdc7983192a521ac115e465 (patch)
tree4c7f55e704e2b169d41bf9be5d13b4a29e13d1bf /protocols/twitter/twitter.c
parent4f50ea5db021b6f627332592a7e43a06f3188172 (diff)
Also use the short IDs for a new reply command. Couldn't think of a sane way
to support "xx:" or "@xx" since it would also become too ambiguous. Only thing left to do now is documenting it.
Diffstat (limited to 'protocols/twitter/twitter.c')
-rw-r--r--protocols/twitter/twitter.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c
index ce702f9c..f655731b 100644
--- a/protocols/twitter/twitter.c
+++ b/protocols/twitter/twitter.c
@@ -453,7 +453,8 @@ static void twitter_buddy_data_free( struct bee_user *bu )
static void twitter_handle_command( struct im_connection *ic, char *message )
{
struct twitter_data *td = ic->proto_data;
- char *cmds, **cmd;
+ char *cmds, **cmd, *new = NULL;
+ guint64 in_reply_to = 0;
cmds = g_strdup( message );
cmd = split_command_parts( cmds );
@@ -523,24 +524,54 @@ static void twitter_handle_command( struct im_connection *ic, char *message )
g_free( cmds );
return;
}
+ else if( g_strcasecmp( cmd[0], "reply" ) == 0 && cmd[1] && cmd[2] )
+ {
+ struct twitter_user_data *tud;
+ bee_user_t *bu = NULL;
+ guint64 id = 0;
+
+ if( ( bu = bee_user_by_handle( ic->bee, ic, cmd[1] ) ) &&
+ ( tud = bu->data ) && tud->last_id )
+ {
+ id = tud->last_id;
+ }
+ else if( ( id = g_ascii_strtoull( cmd[1], NULL, 10 ) ) &&
+ ( id < TWITTER_LOG_LENGTH ) )
+ {
+ bu = td->log[id].bu;
+ if( g_slist_find( ic->bee->users, bu ) )
+ id = td->log[id].id;
+ else
+ bu = NULL;
+ }
+ if( !id || !bu )
+ {
+ twitter_msg( ic, "User `%s' does not exist or didn't "
+ "post any statuses recently", cmd[1] );
+ return;
+ }
+ message = new = g_strdup_printf( "@%s %s", bu->handle,
+ message + ( cmd[2] - cmd[0] ) );
+ in_reply_to = id;
+ }
else if( g_strcasecmp( cmd[0], "post" ) == 0 )
{
message += 5;
}
{
- guint64 in_reply_to = 0;
- char *s, *new = NULL;
+ char *s;
bee_user_t *bu;
if( !twitter_length_check( ic, message ) )
{
+ g_free( new );
g_free( cmds );
return;
}
s = cmd[0] + strlen( cmd[0] ) - 1;
- if( s > cmd[0] && ( *s == ':' || *s == ',' ) )
+ if( !new && s > cmd[0] && ( *s == ':' || *s == ',' ) )
{
*s = '\0';