diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/auth.rs | 7 | ||||
-rw-r--r-- | src/commands/fav.rs | 8 | ||||
-rw-r--r-- | src/commands/follow.rs | 12 | ||||
-rw-r--r-- | src/commands/help.rs | 2 | ||||
-rw-r--r-- | src/commands/quit.rs | 2 | ||||
-rw-r--r-- | src/commands/show_cache.rs | 2 | ||||
-rw-r--r-- | src/commands/twete.rs | 50 |
7 files changed, 47 insertions, 36 deletions
diff --git a/src/commands/auth.rs b/src/commands/auth.rs index 7d01451..65dcaf5 100644 --- a/src/commands/auth.rs +++ b/src/commands/auth.rs @@ -4,8 +4,6 @@ use std::collections::HashMap; use hyper; use ::Queryer; -use tw::TweetId; - use commands::Command; static FAV_TWEET_URL: &str = "https://api.twitter.com/1.1/favorites/create.json"; @@ -79,10 +77,11 @@ fn pin(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { as_map.insert(part[0], part[1]); } // turns out the "actual" oauth creds are different - tweeter.add_profile(tw::Credential { + // TODO: profile names? + tweeter.add_profile(tw::TwitterProfile::new(tw::Credential { key: as_map["oauth_token"].to_owned(), secret: as_map["oauth_token_secret"].to_owned() - }); + }, tw::user::User::default()), Some("iximeow".to_owned())); tweeter.WIP_auth = None; tweeter.state = tw::AppState::Reconnect; tweeter.display_info.status("Looks like you authed! Connecting...".to_owned()); diff --git a/src/commands/fav.rs b/src/commands/fav.rs index 7a4852e..5c12535 100644 --- a/src/commands/fav.rs +++ b/src/commands/fav.rs @@ -21,8 +21,8 @@ fn unfav(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { match maybe_id { Ok(twid) => { if let Some(twete) = tweeter.retrieve_tweet(&twid).map(|x| x.clone()) { // TODO: no clone when this stops taking &mut self - let result = match tweeter.profile.clone() { - Some(user_creds) => queryer.do_api_post(&format!("{}?id={}", UNFAV_TWEET_URL, twete.id), &tweeter.app_key, &user_creds), + let result = match tweeter.current_profile() { + Some(user_profile) => queryer.do_api_post(&format!("{}?id={}", UNFAV_TWEET_URL, twete.id), &tweeter.app_key, &user_profile.creds), None => Err("No logged in user to unfav from".to_owned()) }; match result { @@ -53,8 +53,8 @@ fn fav(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { Ok(twid) => { // tweeter.to_twitter_tweet_id(twid)... if let Some(twete) = tweeter.retrieve_tweet(&twid).map(|x| x.clone()) { // TODO: no clone when this stops taking &mut self - let result = match tweeter.profile.clone() { - Some(user_creds) => queryer.do_api_post(&format!("{}?id={}", FAV_TWEET_URL, twete.id), &tweeter.app_key, &user_creds), + let result = match tweeter.current_profile() { + Some(user_profile) => queryer.do_api_post(&format!("{}?id={}", FAV_TWEET_URL, twete.id), &tweeter.app_key, &user_profile.creds), None => Err("No logged in user to fav from".to_owned()) }; match result { diff --git a/src/commands/follow.rs b/src/commands/follow.rs index 3a29252..6e29788 100644 --- a/src/commands/follow.rs +++ b/src/commands/follow.rs @@ -16,9 +16,9 @@ pub static UNFOLLOW: Command = Command { fn unfl(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { let screen_name = line.trim(); - let result = match tweeter.profile.clone() { - Some(user_creds) => { - queryer.do_api_post(&format!("{}?screen_name={}", FOLLOW_URL, screen_name), &tweeter.app_key, &user_creds) + let result = match tweeter.current_profile() { + Some(user_profile) => { + queryer.do_api_post(&format!("{}?screen_name={}", FOLLOW_URL, screen_name), &tweeter.app_key, &user_profile.creds) }, None => Err("No logged in user to unfollow from".to_owned()) }; @@ -38,15 +38,15 @@ pub static FOLLOW: Command = Command { fn fl(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { let screen_name = line.trim(); - match tweeter.profile.clone() { - Some(user_creds) => { + match tweeter.current_profile().map(|profile| profile.to_owned()) { + Some(user_profile) => { tweeter.display_info.status( format!( "fl resp: {:?}", queryer.do_api_post( &format!("{}?screen_name={}", UNFOLLOW_URL, screen_name), &tweeter.app_key, - &user_creds + &user_profile.creds ) ) ) diff --git a/src/commands/help.rs b/src/commands/help.rs index c99681e..445684b 100644 --- a/src/commands/help.rs +++ b/src/commands/help.rs @@ -1,8 +1,6 @@ use tw; use ::Queryer; -use tw::TweetId; - use commands::Command; pub static HELP: Command = Command { diff --git a/src/commands/quit.rs b/src/commands/quit.rs index 6638299..0f5c582 100644 --- a/src/commands/quit.rs +++ b/src/commands/quit.rs @@ -3,8 +3,6 @@ use ::Queryer; use commands::Command; -use std::process::exit; - pub static QUIT: Command = Command { keyword: "q", params: 0, diff --git a/src/commands/show_cache.rs b/src/commands/show_cache.rs index fffcdb6..6dda8dc 100644 --- a/src/commands/show_cache.rs +++ b/src/commands/show_cache.rs @@ -12,6 +12,7 @@ pub static SHOW_CACHE: Command = Command { }; fn show_cache(_line: String, tweeter: &mut tw::TwitterCache, mut queryer: &mut Queryer) { + /* tweeter.display_info.status("----* USERS *----".to_owned()); for (uid, user) in &tweeter.users { tweeter.display_info.status(format!("User: {} -> {:?}", uid, user)); @@ -30,4 +31,5 @@ fn show_cache(_line: String, tweeter: &mut tw::TwitterCache, mut queryer: &mut Q None => { tweeter.display_info.status(" ...".to_owned()); } } } + */ } diff --git a/src/commands/twete.rs b/src/commands/twete.rs index c5c0c1a..0d82b76 100644 --- a/src/commands/twete.rs +++ b/src/commands/twete.rs @@ -22,8 +22,8 @@ fn del(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { Ok(twid) => { // TODO this really converts twid to a TweetId::Twitter if let Some(twitter_id) = tweeter.retrieve_tweet(&twid).map(|x| x.id.to_owned()) { - let result = match tweeter.profile.clone() { - Some(user_creds) => queryer.do_api_post(&format!("{}/{}.json", DEL_TWEET_URL, twitter_id), &tweeter.app_key, &user_creds), + let result = match tweeter.current_profile() { + Some(user_profile) => queryer.do_api_post(&format!("{}/{}.json", DEL_TWEET_URL, twitter_id), &tweeter.app_key, &user_profile.creds), None => Err("No logged in user to delete as".to_owned()) }; match result { @@ -61,8 +61,8 @@ fn twete(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { pub fn send_twete(text: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { let substituted = ::url_encode(&text); - let result = match tweeter.profile.clone() { - Some(user_creds) => queryer.do_api_post(&format!("{}?status={}", CREATE_TWEET_URL, substituted), &tweeter.app_key, &user_creds), + let result = match tweeter.current_profile() { + Some(user_profile) => queryer.do_api_post(&format!("{}?status={}", CREATE_TWEET_URL, substituted), &tweeter.app_key, &user_profile.creds), None => Err("No logged in user to tweet as".to_owned()) }; match result { @@ -83,6 +83,13 @@ pub static THREAD: Command = Command { // the difference between threading and replying is not including // yourself in th @'s. fn thread(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { + let user_profile = match tweeter.current_profile().map(|profile| profile.to_owned()) { + Some(profile) => profile, + None => { + tweeter.display_info.status("To reply you must be authenticated as a user.".to_owned()); + return; + } + }; let mut text: String = line.trim().to_string(); if let Some(id_end_idx) = text.find(" ") { let reply_bare = text.split_off(id_end_idx + 1); @@ -95,8 +102,8 @@ fn thread(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { if let Some(twete) = tweeter.retrieve_tweet(&twid).map(|x| x.clone()) { // TODO: no clone when this stops taking &mut self let handle = &tweeter.retrieve_user(&twete.author_id).unwrap().handle.to_owned(); // TODO: definitely breaks if you change your handle right now - if handle == &tweeter.current_user.handle { - send_reply(reply.to_owned(), twid, tweeter, queryer); + if handle == &user_profile.user.handle { + send_reply(reply.to_owned(), twid, tweeter, queryer, user_profile.creds); } else { tweeter.display_info.status("you can only thread your own tweets".to_owned()); // ask if it should .@ instead? @@ -125,6 +132,13 @@ pub static REP: Command = Command { }; fn rep(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { + let user_profile = match tweeter.current_profile().map(|profile| profile.to_owned()) { + Some(profile) => profile, + None => { + tweeter.display_info.status("To reply you must be authenticated as a user.".to_owned()); + return; + } + }; let mut text: String = line.trim().to_string(); let reply_bare = match text.find(" ") { None => "".to_owned(), @@ -152,8 +166,8 @@ fn rep(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { // if you're directly replying to yourself, i trust you know what you're doing and // want to @ yourself again (this keeps self-replies from showing up on your // profile as threaded tweets, f.ex) - if !(ats.len() > 0 && &ats[0] == &tweeter.current_user.handle) { - ats.remove_item(&tweeter.current_user.handle); + if !(ats.len() > 0 && &ats[0] == &user_profile.user.handle) { + ats.remove_item(&user_profile.user.handle); } //let ats_vec: Vec<&str> = ats.into_iter().collect(); //let full_reply = format!("{} {}", ats_vec.join(" "), reply); @@ -161,7 +175,7 @@ fn rep(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { let full_reply = format!("{} {}", decorated_ats.join(" "), reply); if reply.len() > 0 { - send_reply(full_reply, twid, tweeter, queryer); + send_reply(full_reply, twid, tweeter, queryer, user_profile.creds); } else { tweeter.display_info.mode = Some(::display::DisplayMode::Reply(twid, full_reply)); } @@ -175,11 +189,11 @@ fn rep(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { } } -pub fn send_reply(text: String, twid: TweetId, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { +pub fn send_reply(text: String, twid: TweetId, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, user_creds: tw::Credential) { if let Some(twete) = tweeter.retrieve_tweet(&twid).map(|x| x.clone()) { // TODO: no clone when this stops taking &mut self let substituted = ::url_encode(&text); - let result = match tweeter.profile.clone() { - Some(user_creds) => { + let result = match tweeter.current_profile() { + Some(user_profile) => { queryer.do_api_post(&format!("{}?status={}&in_reply_to_status_id={}", CREATE_TWEET_URL, substituted, twete.id), &tweeter.app_key, &user_creds) }, None => Err("No logged in user to tweet as".to_owned()) @@ -220,8 +234,8 @@ fn quote(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { twete.id ) ); - let result = match tweeter.profile.clone() { - Some(user_creds) => { + let result = match tweeter.current_profile() { + Some(user_profile) => { queryer.do_api_post( &format!("{}?status={}&attachment_url={}", CREATE_TWEET_URL, @@ -229,7 +243,7 @@ fn quote(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { attachment_url ), &tweeter.app_key, - &user_creds + &user_profile.creds ) }, None => Err("No logged in user to tweet as".to_owned()) @@ -267,9 +281,9 @@ fn retwete(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) Ok(twid) => { // TODO this really converts twid to a TweetId::Twitter if let Some(twitter_id) = tweeter.retrieve_tweet(&twid).map(|x| x.id.to_owned()) { - let result = match tweeter.profile.clone() { - Some(user_creds) => { - queryer.do_api_post(&format!("{}/{}.json", RT_TWEET_URL, twitter_id), &tweeter.app_key, &user_creds) + let result = match tweeter.current_profile() { + Some(user_profile) => { + queryer.do_api_post(&format!("{}/{}.json", RT_TWEET_URL, twitter_id), &tweeter.app_key, &user_profile.creds) }, None => Err("No logged in user to retweet as".to_owned()) }; |