diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-04-16 01:10:10 +0200 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-04-16 01:10:10 +0200 |
commit | e88fbe272c097066e538d670fe8fa907e9847321 (patch) | |
tree | 3869ead829b68c358823a1daded8ee45e093bfd0 | |
parent | f9ed3113c4bc5110171295abef9c140e1328aeb1 (diff) |
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.
-rw-r--r-- | doc/user-guide/commands.xml | 36 | ||||
-rw-r--r-- | protocols/twitter/twitter.c | 28 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.c | 35 |
3 files changed, 75 insertions, 24 deletions
diff --git a/doc/user-guide/commands.xml b/doc/user-guide/commands.xml index 0664aaab..7dd23d0c 100644 --- a/doc/user-guide/commands.xml +++ b/doc/user-guide/commands.xml @@ -20,7 +20,7 @@ <description> <para> - 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 <protocol></emphasis>. + 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 <protocol></emphasis>. </para> </description> @@ -72,11 +72,11 @@ </para> <para> - By default all your Twitter contacts will show up in your contact list and their tweets will show up as private messages or in &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>). + 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>). </para> <para> - 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. + To send tweets yourself, send them to the twitter_(yourusername) contact, or just write in the groupchat channel if you enabled that option. </para> </description> </bitlbee-command> @@ -658,6 +658,26 @@ </bitlbee-setting> + <bitlbee-setting name="mode" type="string" scope="account"> + <possible-values>one, many, chat</possible-values> + <default>one</default> + + <description> + <para> + 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. + </para> + + <para> + If you prefer to have all your Twitter things in a separate channel, you can set this setting to "chat". + </para> + + <para> + 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. + </para> + </description> + + </bitlbee-setting> + <bitlbee-setting name="nick" type="string" scope="chat"> <description> @@ -919,16 +939,6 @@ </description> </bitlbee-setting> - <bitlbee-setting name="use_groupchat" type="boolean" scope="account"> - <default>false</default> - - <description> - <para> - By default the Twitter module shows all Twitter contacts and their Tweet in &bitlbee and/or private messages. With this setting enabled the module will show all contacts and their Tweets in a separate channel. - </para> - </description> - </bitlbee-setting> - <bitlbee-setting name="web_aware" type="string" scope="account"> <default>false</default> diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 727eff91..29be8a96 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -40,7 +40,7 @@ gboolean twitter_main_loop(gpointer data, gint fd, b_input_condition cond) // If the user uses multiple private message windows we need to get the // users buddies. - if (!set_getbool( &ic->acc->set, "use_groupchat" )) + if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "many") == 0) twitter_get_statuses_friends(ic, -1); // Do stuff.. @@ -50,11 +50,21 @@ gboolean twitter_main_loop(gpointer data, gint fd, b_input_condition cond) return (ic->flags & OPT_LOGGED_IN) == OPT_LOGGED_IN; } +static char *set_eval_mode( set_t *set, char *value ) +{ + if( g_strcasecmp( value, "one" ) == 0 || + g_strcasecmp( value, "many" ) == 0 || + g_strcasecmp( value, "char" ) == 0 ) + return value; + else + return NULL; +} static void twitter_init( account_t *acc ) { set_t *s; - s = set_add( &acc->set, "use_groupchat", "false", set_eval_bool, acc ); + + s = set_add( &acc->set, "mode", "one", set_eval_mode, acc ); s->flags |= ACC_SET_OFFLINE_ONLY; } @@ -66,6 +76,7 @@ static void twitter_login( account_t *acc ) { struct im_connection *ic = imcb_new( acc ); struct twitter_data *td = g_new0( struct twitter_data, 1 ); + char name[strlen(acc->user)+9]; twitter_connections = g_slist_append( twitter_connections, ic ); @@ -83,6 +94,10 @@ static void twitter_login( account_t *acc ) // Queue the main_loop // Save the return value, so we can remove the timeout on logout. td->main_loop_id = b_timeout_add(60000, twitter_main_loop, ic); + + sprintf( name, "twitter_%s", acc->user ); + imcb_add_buddy( ic, name, NULL ); + imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); } /** @@ -114,11 +129,12 @@ static void twitter_logout( struct im_connection *ic ) */ static int twitter_buddy_msg( struct im_connection *ic, char *who, char *message, int away ) { - // Let's just update the status. -// if ( g_strcasecmp(who, ic->acc->user) == 0 ) + if (g_strncasecmp(who, "twitter_", 8) == 0 && + g_strcasecmp(who + 8, ic->acc->user) == 0) twitter_post_status(ic, message); -// else -// twitter_direct_messages_new(ic, who, message); + else + twitter_direct_messages_new(ic, who, message); + return( 0 ); } diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index 081612ac..04e8ef95 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -104,12 +104,14 @@ static void twitter_add_buddy(struct im_connection *ic, char *name, const char * // Check if the buddy is allready in the buddy list. if (!imcb_find_buddy( ic, name )) { + char *mode = set_getstr(&ic->acc->set, "mode"); + // The buddy is not in the list, add the buddy and set the status to logged in. imcb_add_buddy( ic, name, NULL ); imcb_rename_buddy( ic, name, fullname ); - if (set_getbool( &ic->acc->set, "use_groupchat" )) + if (g_strcasecmp(mode, "chat") == 0) imcb_chat_add_buddy( td->home_timeline_gc, name ); - else + else if (g_strcasecmp(mode, "many") == 0) imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); } } @@ -451,14 +453,37 @@ static void twitter_private_message_chat(struct im_connection *ic, GSList *list) struct twitter_data *td = ic->proto_data; GSList *l = NULL; struct twitter_xml_status *status; + char from[MAX_STRING]; + gboolean mode_one; + + mode_one = g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "one" ) == 0; + if( mode_one ) + { + g_snprintf( from, sizeof( from ) - 1, "twitter_%s", ic->acc->user ); + from[MAX_STRING-1] = '\0'; + } + for ( l = list; l ; l = g_slist_next(l) ) { + char *text = NULL; + status = l->data; - imcb_buddy_msg( ic, status->user->screen_name, status->text, 0, status->created_at ); + + if( mode_one ) + text = g_strdup_printf( "\002<\002%s\002>\002 %s", + status->user->screen_name, status->text ); + + imcb_buddy_msg( ic, + mode_one ? from : status->user->screen_name, + mode_one ? text : status->text, + 0, status->created_at ); + // Update the home_timeline_id to hold the highest id, so that by the next request // we won't pick up the updates allready in the list. td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id; + + g_free( text ); } } @@ -511,7 +536,7 @@ static void twitter_http_get_home_timeline(struct http_request *req) xt_free( parser ); // See if the user wants to see the messages in a groupchat window or as private messages. - if (set_getbool( &ic->acc->set, "use_groupchat" )) + if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "chat") == 0) twitter_groupchat(ic, txl->list); else twitter_private_message_chat(ic, txl->list); @@ -611,7 +636,7 @@ static void twitter_http_post_status(struct http_request *req) // Check if the HTTP request went well. if (req->status_code != 200) { // It didn't go well, output the error and return. - imcb_error(ic, "Could not post tweet... HTTP STATUS: %d", req->status_code); + imcb_error(ic, "Could not post message... HTTP STATUS: %d", req->status_code); return; } } |