- Timestamp:
- 2012-09-15T16:24:52Z (12 years ago)
- Branches:
- master
- Children:
- ddca104
- Parents:
- b3d99e3
- Location:
- protocols/twitter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
rb3d99e3 rb61c74c 490 490 } 491 491 492 /** Convert the given bitlbee tweet ID, bitlbee username, or twitter tweet ID 493 * into a twitter tweet ID. 494 * 495 * Returns 0 if the user provides garbage. 496 */ 497 static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, struct twitter_data *td, char *arg) { 498 struct twitter_user_data *tud; 499 bee_user_t *bu; 500 guint64 id = 0; 501 if (g_str_has_prefix(arg, "#") && 502 sscanf(arg + 1, "%" G_GUINT64_FORMAT, &id) == 1) { 503 if (id < TWITTER_LOG_LENGTH && td->log) 504 id = td->log[id].id; 505 } else if ((bu = bee_user_by_handle(ic->bee, ic, arg)) && 506 (tud = bu->data) && tud->last_id) 507 id = tud->last_id; 508 else if (sscanf(arg, "%" G_GUINT64_FORMAT, &id) == 1){ 509 if (id < TWITTER_LOG_LENGTH && td->log) 510 id = td->log[id].id; 511 } 512 return id; 513 } 514 492 515 static void twitter_handle_command(struct im_connection *ic, char *message) 493 516 { … … 517 540 twitter_msg(ic, "Could not undo last action"); 518 541 542 g_free(cmds); 543 return; 544 } else if (g_strcasecmp(cmd[0], "favourite") == 0 && cmd[1]) { 545 guint64 id; 546 if ((id = twitter_message_id_from_command_arg(ic, td, cmd[1]))) { 547 twitter_favourite_tweet(ic, id); 548 } else { 549 twitter_msg(ic, "Please provide a message ID or username."); 550 } 519 551 g_free(cmds); 520 552 return; … … 546 578 return; 547 579 } else if (g_strcasecmp(cmd[0], "rt") == 0 && cmd[1]) { 548 struct twitter_user_data *tud; 549 bee_user_t *bu; 550 guint64 id; 551 552 if (g_str_has_prefix(cmd[1], "#") && 553 sscanf(cmd[1] + 1, "%" G_GUINT64_FORMAT, &id) == 1) { 554 if (id < TWITTER_LOG_LENGTH && td->log) 555 id = td->log[id].id; 556 } else if ((bu = bee_user_by_handle(ic->bee, ic, cmd[1])) && 557 (tud = bu->data) && tud->last_id) 558 id = tud->last_id; 559 else if (sscanf(cmd[1], "%" G_GUINT64_FORMAT, &id) == 1){ 560 if (id < TWITTER_LOG_LENGTH && td->log) 561 id = td->log[id].id; 562 } 580 guint64 id = twitter_message_id_from_command_arg(ic, td, cmd[1]); 563 581 564 582 td->last_status_id = 0; -
protocols/twitter/twitter_lib.c
rb3d99e3 rb61c74c 1083 1083 ic, 1, args, 2); 1084 1084 } 1085 1086 /** 1087 * Favourite a tweet. 1088 */ 1089 void twitter_favourite_tweet(struct im_connection *ic, guint64 id) 1090 { 1091 char *url; 1092 url = g_strdup_printf("%s%llu%s", TWITTER_FAVORITE_CREATE_URL, 1093 (unsigned long long) id, ".xml"); 1094 twitter_http(ic, url, twitter_http_post, ic, 1, NULL, 0); 1095 g_free(url); 1096 } -
protocols/twitter/twitter_lib.h
rb3d99e3 rb61c74c 91 91 void twitter_status_retweet(struct im_connection *ic, guint64 id); 92 92 void twitter_report_spam(struct im_connection *ic, char *screen_name); 93 void twitter_favourite_tweet(struct im_connection *ic, guint64 id); 93 94 94 95 #endif //_TWITTER_LIB_H
Note: See TracChangeset
for help on using the changeset viewer.