Ignore:
Timestamp:
2010-08-07T19:39:01Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
203a2d2
Parents:
daae10f
Message:

Add commands to the Twitter module, starting with undo (which deletes
either your most recent tweet, or a specific id (pass it as an argument)).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    rdaae10f r7b87539  
    189189        s->flags |= ACC_SET_OFFLINE_ONLY;
    190190       
     191        s = set_add( &acc->set, "commands", "true", set_eval_bool, acc );
     192       
    191193        s = set_add( &acc->set, "message_length", "140", set_eval_int, acc );
    192194       
     
    273275        twitter_connections = g_slist_remove( twitter_connections, ic );
    274276}
     277
     278static void twitter_handle_command( struct im_connection *ic, char *message );
    275279
    276280/**
     
    302306                        }
    303307                }
    304                 else if( twitter_length_check(ic, message) )
    305                         twitter_post_status(ic, message);
     308                else
     309                        twitter_handle_command(ic, message);
    306310        }
    307311        else
     
    335339static void twitter_chat_msg( struct groupchat *c, char *message, int flags )
    336340{
    337         if( c && message && twitter_length_check( c->ic, message ) )
    338         {
    339                 char *s, *new = NULL;
    340                
    341                 if( ( s = strchr( message, ':' ) ) ||
    342                     ( s = strchr( message, ',' ) ) )
    343                 {
    344                         bee_user_t *bu;
    345                        
    346                         new = g_strdup( message );
    347                         new[s-message] = '\0';
    348                         if( ( bu = bee_user_by_handle( c->ic->bee, c->ic, new ) ) )
    349                         {
    350                                 sprintf( new, "@%s", bu->handle );
    351                                 new[s-message+1] = ' ';
    352                                 message = new;
    353                         }
    354                 }
    355                
    356                 twitter_post_status( c->ic, message );
    357                 g_free( new );
    358         }
     341        if( c && message )
     342                twitter_handle_command( c->ic, message );
    359343}
    360344
     
    410394//      return value;
    411395//}
     396
     397static void twitter_handle_command( struct im_connection *ic, char *message )
     398{
     399        struct twitter_data *td = ic->proto_data;
     400        char *cmds, **cmd;
     401       
     402        cmds = g_strdup( message );
     403        cmd = split_command_parts( cmds );
     404       
     405        if( cmd[0] == NULL )
     406        {
     407                g_free( cmds );
     408                return;
     409        }
     410        else if( !set_getbool( &ic->set, "commands" ) )
     411        {
     412                /* Not supporting commands. */
     413        }
     414        else if( g_strcasecmp( cmd[0], "undo" ) == 0 )
     415        {
     416                guint64 id;
     417               
     418                if( cmd[1] )
     419                {
     420                        char *end = NULL;
     421                       
     422                        id = g_ascii_strtoull( cmd[1], &end, 10 );
     423                        if( end == NULL )
     424                                id = 0;
     425                }
     426                else
     427                        id = td->last_status_id;
     428               
     429                /* TODO: User feedback. */
     430                if( id )
     431                        twitter_status_destroy( ic, id );
     432               
     433                g_free( cmds );
     434                return;
     435        }
     436        else if( g_strcasecmp( cmd[0], "post" ) == 0 )
     437        {
     438                message += 5;
     439        }
     440       
     441        {
     442                char *s, *new = NULL;
     443                bee_user_t *bu;
     444               
     445                if( !twitter_length_check( ic, message ) )
     446                {
     447                        g_free( cmds );
     448                        return;
     449                }
     450               
     451                s = cmd[0] + strlen( cmd[0] ) - 1;
     452                if( s > cmd[0] && ( *s == ':' || *s == ',' ) )
     453                {
     454                        *s = '\0';
     455                       
     456                        if( ( bu = bee_user_by_handle( ic->bee, ic, cmd[0] ) ) )
     457                        {
     458                                new = g_strdup_printf( "@%s %s", bu->handle,
     459                                                       message + ( s - cmd[0] ) + 2 );
     460                                message = new;
     461                        }
     462                }
     463               
     464                twitter_post_status( ic, message );
     465                g_free( new );
     466        }
     467        g_free( cmds );
     468}
    412469
    413470void twitter_initmodule()
Note: See TracChangeset for help on using the changeset viewer.