Changeset e88fbe27


Ignore:
Timestamp:
2010-04-15T23:10:10Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
55b1e69
Parents:
f9ed311
Message:

Added a meta-contact twitter_$username and replaced the "use_groupchat"
setting with a "mode" setting which also allows for a mode where everything
just comes from the meta-contact. Tweets should now go to that user or to
the channel (if available). Messages to others become DMs.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • doc/user-guide/commands.xml

    rf9ed311 re88fbe27  
    2121                        <description>
    2222                                <para>
    23                                         Adds an account on the given server with the specified protocol, username and password to the account list. Supported protocols right now are: Jabber, MSN, OSCAR (AIM/ICQ) and Yahoo. For more information about adding an account, see <emphasis>help account add &lt;protocol&gt;</emphasis>.
     23                                        Adds an account on the given server with the specified protocol, username and password to the account list. Supported protocols right now are: Jabber, MSN, OSCAR (AIM/ICQ), Yahoo and Twitter. For more information about adding an account, see <emphasis>help account add &lt;protocol&gt;</emphasis>.
    2424                                </para>
    2525                        </description>
     
    7373                                       
    7474                                        <para>
    75                                                 By default all your Twitter contacts will show up in your contact list and their tweets will show up as private messages or in &amp;bitlbee depending on your settings. If you want them in a separate channel, use the use_groupchat setting (see <emphasis>help set use_groupchat</emphasis>).
     75                                                By default all your Twitter contacts will come from a contact called twitter_(yourusername). You can change this behaviour using the <emphasis>mode</emphasis> setting (see <emphasis>help set mode</emphasis>).
    7676                                        </para>
    7777                                       
    7878                                        <para>
    79                                                 To send tweets yourself, send them to any of your Twitter contacts via /query (doesn't matter who), or just write in the groupchat channel if you enabled that option.
     79                                                To send tweets yourself, send them to the twitter_(yourusername) contact, or just write in the groupchat channel if you enabled that option.
    8080                                        </para>
    8181                                </description>
     
    659659        </bitlbee-setting>
    660660
     661        <bitlbee-setting name="mode" type="string" scope="account">
     662                <possible-values>one, many, chat</possible-values>
     663                <default>one</default>
     664
     665                <description>
     666                        <para>
     667                                By default, everything from the Twitter module will come from one nick, twitter_(yourusername). If you prefer to have individual nicks for everyone, you can set this setting to "many" instead.
     668                        </para>
     669                       
     670                        <para>
     671                                If you prefer to have all your Twitter things in a separate channel, you can set this setting to "chat".
     672                        </para>
     673                       
     674                        <para>
     675                                In the last two modes, you can send direct messages by /msg'ing your contacts directly. Note, however, that incoming DMs are not fetched yet.
     676                        </para>
     677                </description>
     678
     679        </bitlbee-setting>
     680
    661681        <bitlbee-setting name="nick" type="string" scope="chat">
    662682
     
    916936                        <para>
    917937                                Sends you a /notice when a user starts typing a message (if supported by the IM protocol and the user's client). To use this, you most likely want to use a script in your IRC client to show this information in a more sensible way.
    918                         </para>
    919                 </description>
    920         </bitlbee-setting>
    921 
    922         <bitlbee-setting name="use_groupchat" type="boolean" scope="account">
    923                 <default>false</default>
    924 
    925                 <description>
    926                         <para>
    927                                 By default the Twitter module shows all Twitter contacts and their Tweet in &amp;bitlbee and/or private messages. With this setting enabled the module will show all contacts and their Tweets in a separate channel.
    928938                        </para>
    929939                </description>
  • protocols/twitter/twitter.c

    rf9ed311 re88fbe27  
    4141        // If the user uses multiple private message windows we need to get the
    4242        // users buddies.
    43         if (!set_getbool( &ic->acc->set, "use_groupchat" ))
     43        if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "many") == 0)
    4444                twitter_get_statuses_friends(ic, -1);
    4545
     
    5151}
    5252
     53static char *set_eval_mode( set_t *set, char *value )
     54{
     55        if( g_strcasecmp( value, "one" ) == 0 ||
     56            g_strcasecmp( value, "many" ) == 0 ||
     57            g_strcasecmp( value, "char" ) == 0 )
     58                return value;
     59        else
     60                return NULL;
     61}
    5362
    5463static void twitter_init( account_t *acc )
    5564{
    5665        set_t *s;
    57         s = set_add( &acc->set, "use_groupchat", "false", set_eval_bool, acc );
     66       
     67        s = set_add( &acc->set, "mode", "one", set_eval_mode, acc );
    5868        s->flags |= ACC_SET_OFFLINE_ONLY;
    5969}
     
    6777        struct im_connection *ic = imcb_new( acc );
    6878        struct twitter_data *td = g_new0( struct twitter_data, 1 );
     79        char name[strlen(acc->user)+9];
    6980
    7081        twitter_connections = g_slist_append( twitter_connections, ic );
     
    8495        // Save the return value, so we can remove the timeout on logout.
    8596        td->main_loop_id = b_timeout_add(60000, twitter_main_loop, ic);
     97       
     98        sprintf( name, "twitter_%s", acc->user );
     99        imcb_add_buddy( ic, name, NULL );
     100        imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL );
    86101}
    87102
     
    115130static int twitter_buddy_msg( struct im_connection *ic, char *who, char *message, int away )
    116131{
    117         // Let's just update the status.
    118 //      if ( g_strcasecmp(who, ic->acc->user) == 0 )
     132        if (g_strncasecmp(who, "twitter_", 8) == 0 &&
     133            g_strcasecmp(who + 8, ic->acc->user) == 0)
    119134                twitter_post_status(ic, message);
    120 //      else
    121 //              twitter_direct_messages_new(ic, who, message);
     135        else
     136                twitter_direct_messages_new(ic, who, message);
     137       
    122138        return( 0 );
    123139}
  • protocols/twitter/twitter_lib.c

    rf9ed311 re88fbe27  
    105105        if (!imcb_find_buddy( ic, name ))
    106106        {
     107                char *mode = set_getstr(&ic->acc->set, "mode");
     108               
    107109                // The buddy is not in the list, add the buddy and set the status to logged in.
    108110                imcb_add_buddy( ic, name, NULL );
    109111                imcb_rename_buddy( ic, name, fullname );
    110                 if (set_getbool( &ic->acc->set, "use_groupchat" ))
     112                if (g_strcasecmp(mode, "chat") == 0)
    111113                        imcb_chat_add_buddy( td->home_timeline_gc, name );
    112                 else
     114                else if (g_strcasecmp(mode, "many") == 0)
    113115                        imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL );
    114116        }
     
    452454        GSList *l = NULL;
    453455        struct twitter_xml_status *status;
    454 
     456        char from[MAX_STRING];
     457        gboolean mode_one;
     458       
     459        mode_one = g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "one" ) == 0;
     460
     461        if( mode_one )
     462        {
     463                g_snprintf( from, sizeof( from ) - 1, "twitter_%s", ic->acc->user );
     464                from[MAX_STRING-1] = '\0';
     465        }
     466       
    455467        for ( l = list; l ; l = g_slist_next(l) )
    456468        {
     469                char *text = NULL;
     470               
    457471                status = l->data;
    458                 imcb_buddy_msg( ic, status->user->screen_name, status->text, 0, status->created_at );
     472               
     473                if( mode_one )
     474                        text = g_strdup_printf( "\002<\002%s\002>\002 %s",
     475                                                status->user->screen_name, status->text );
     476               
     477                imcb_buddy_msg( ic,
     478                                mode_one ? from : status->user->screen_name,
     479                                mode_one ? text : status->text,
     480                                0, status->created_at );
     481               
    459482                // Update the home_timeline_id to hold the highest id, so that by the next request
    460483                // we won't pick up the updates allready in the list.
    461484                td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id;
     485               
     486                g_free( text );
    462487        }
    463488}
     
    512537
    513538        // See if the user wants to see the messages in a groupchat window or as private messages.
    514         if (set_getbool( &ic->acc->set, "use_groupchat" ))
     539        if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "chat") == 0)
    515540                twitter_groupchat(ic, txl->list);
    516541        else
     
    612637        if (req->status_code != 200) {
    613638                // It didn't go well, output the error and return.
    614                 imcb_error(ic, "Could not post tweet... HTTP STATUS: %d", req->status_code);
     639                imcb_error(ic, "Could not post message... HTTP STATUS: %d", req->status_code);
    615640                return;
    616641        }
Note: See TracChangeset for help on using the changeset viewer.