aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/fav.rs14
-rw-r--r--src/commands/follow.rs7
-rw-r--r--src/commands/look_up.rs7
-rw-r--r--src/commands/quit.rs2
-rw-r--r--src/commands/show_cache.rs18
-rw-r--r--src/commands/thread.rs15
-rw-r--r--src/commands/twete.rs67
-rw-r--r--src/commands/view.rs13
8 files changed, 76 insertions, 67 deletions
diff --git a/src/commands/fav.rs b/src/commands/fav.rs
index 89e1987..6109310 100644
--- a/src/commands/fav.rs
+++ b/src/commands/fav.rs
@@ -19,13 +19,16 @@ 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
- queryer.do_api_post(&format!("{}?id={}", UNFAV_TWEET_URL, twete.id));
+ match queryer.do_api_post(&format!("{}?id={}", UNFAV_TWEET_URL, twete.id)) {
+ Ok(_) => (),
+ Err(e) => tweeter.display_info.status(e)
+ }
} else {
tweeter.display_info.status(format!("No tweet for id: {:?}", twid));
}
}
Err(e) => {
- println!("Invalid id: {}", e);
+ tweeter.display_info.status(format!("Invalid id: {}", e));
}
}
}
@@ -42,13 +45,16 @@ 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
- queryer.do_api_post(&format!("{}?id={}", FAV_TWEET_URL, twete.id));
+ match queryer.do_api_post(&format!("{}?id={}", FAV_TWEET_URL, twete.id)) {
+ Ok(_) => (),
+ Err(e) => tweeter.display_info.status(e)
+ }
} else {
tweeter.display_info.status(format!("No tweet for id: {:?}", twid));
}
}
Err(e) => {
- println!("Invalid id: {}", e);
+ tweeter.display_info.status(format!("Invalid id: {}", e));
}
}
}
diff --git a/src/commands/follow.rs b/src/commands/follow.rs
index ad121e5..b0dc8a7 100644
--- a/src/commands/follow.rs
+++ b/src/commands/follow.rs
@@ -14,7 +14,10 @@ pub static UNFOLLOW: Command = Command {
fn unfl(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
let screen_name = line.trim();
- queryer.do_api_post(&format!("{}?screen_name={}", FOLLOW_URL, screen_name));
+ match queryer.do_api_post(&format!("{}?screen_name={}", FOLLOW_URL, screen_name)) {
+ Ok(_resp) => (),
+ Err(e) => tweeter.display_info.status(format!("unfl request error: {}", e))
+ }
}
pub static FOLLOW: Command = Command {
@@ -25,5 +28,5 @@ pub static FOLLOW: Command = Command {
fn fl(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
let screen_name = line.trim();
- println!("fl resp: {:?}", queryer.do_api_post(&format!("{}?screen_name={}", UNFOLLOW_URL, screen_name)));
+ tweeter.display_info.status(format!("fl resp: {:?}", queryer.do_api_post(&format!("{}?screen_name={}", UNFOLLOW_URL, screen_name))));
}
diff --git a/src/commands/look_up.rs b/src/commands/look_up.rs
index 701ce2d..dff56aa 100644
--- a/src/commands/look_up.rs
+++ b/src/commands/look_up.rs
@@ -12,10 +12,11 @@ pub static LOOK_UP_USER: Command = Command {
};
fn look_up_user(line: String, tweeter: &mut tw::TwitterCache, mut queryer: &mut Queryer) {
- if let Some(user) = tweeter.fetch_user(&line, &mut queryer) {
- println!("{:?}", user);
+ // should probably just pass the id?
+ if let Some(user) = tweeter.fetch_user(&line, &mut queryer).map(|x| x.clone()) {
+ tweeter.display_info.recv(display::Infos::User(user));
} else {
-// println!("Couldn't retrieve {}", userid);
+ tweeter.display_info.status(format!("Couldn't retrieve {}", line));
}
}
diff --git a/src/commands/quit.rs b/src/commands/quit.rs
index 982c48f..716c412 100644
--- a/src/commands/quit.rs
+++ b/src/commands/quit.rs
@@ -12,7 +12,7 @@ pub static QUIT: Command = Command {
};
fn quit(_line: String, tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer) {
- println!("Bye bye!");
+ tweeter.display_info.status("Bye bye!".to_owned());
tweeter.store_cache();
exit(0);
}
diff --git a/src/commands/show_cache.rs b/src/commands/show_cache.rs
index 3c31697..59ecfc2 100644
--- a/src/commands/show_cache.rs
+++ b/src/commands/show_cache.rs
@@ -9,23 +9,23 @@ pub static SHOW_CACHE: Command = Command {
exec: show_cache
};
-fn show_cache(line: String, tweeter: &mut tw::TwitterCache, mut queryer: &mut Queryer) {
- println!("----* USERS *----");
+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 {
- println!("User: {} -> {:?}", uid, user);
+ tweeter.display_info.status(format!("User: {} -> {:?}", uid, user));
}
- println!("----* TWEETS *----");
+ tweeter.display_info.status("----* TWEETS *----".to_owned());
for (tid, tweet) in &tweeter.tweets {
- println!("Tweet: {} -> {:?}", tid, tweet);
+ tweeter.display_info.status(format!("Tweet: {} -> {:?}", tid, tweet));
}
- println!("----* FOLLOWERS *----");
+ tweeter.display_info.status("----* FOLLOWERS *----".to_owned());
for uid in &tweeter.followers.clone() {
- let user_res = tweeter.fetch_user(uid, &mut queryer);
+ let user_res = tweeter.fetch_user(uid, &mut queryer).map(|x| x.clone());
match user_res {
Some(user) => {
- println!("Follower: {} - {:?}", uid, user);
+ tweeter.display_info.status(format!("Follower: {} - {:?}", uid, user));
}
- None => { println!(" ..."); }
+ None => { tweeter.display_info.status(" ...".to_owned()); }
}
}
}
diff --git a/src/commands/thread.rs b/src/commands/thread.rs
index 8880af7..6f05048 100644
--- a/src/commands/thread.rs
+++ b/src/commands/thread.rs
@@ -14,7 +14,7 @@ pub static FORGET_THREAD: Command = Command {
fn forget(line: String, tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer) {
tweeter.forget_thread(line.trim().to_string());
- println!("Ok! Forgot thread {}", line.trim().to_string());
+ tweeter.display_info.status(format!("Ok! Forgot thread {}", line.trim().to_string()));
}
pub static REMEMBER_THREAD: Command = Command {
@@ -55,20 +55,9 @@ pub static LIST_THREADS: Command = Command {
};
fn ls_threads(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
- println!("Threads: ");
let threads: Vec<String> = tweeter.threads().collect::<Vec<&String>>().into_iter().map(|x| x.to_owned()).collect::<Vec<String>>();
for k in threads {
- println!("Thread: {}", k);
let latest_inner_id = tweeter.latest_in_thread(k.to_owned()).unwrap().to_owned();
- // should be able to just directly render TweetId.. and threads should be Vec<TweetId>...
- let twete_id_TEMP = tweeter.retrieve_tweet(&TweetId::Bare(latest_inner_id)).map(|x| x.id.to_owned());
- if let Some(twete) = twete_id_TEMP {
- // gross..
- // and this ought to be a command to tweeter.display_info anyway...
- display::render_twete(&TweetId::Twitter(twete), tweeter);
- println!("");
- } else {
- println!("ERROR no tweet for remembered thread.");
- }
+ tweeter.display_info.recv(display::Infos::TweetWithContext(TweetId::Bare(latest_inner_id), format!("Thread: {}", k)))
}
}
diff --git a/src/commands/twete.rs b/src/commands/twete.rs
index eb21a15..f057e5f 100644
--- a/src/commands/twete.rs
+++ b/src/commands/twete.rs
@@ -5,8 +5,6 @@ use tw::TweetId;
use commands::Command;
-use std::str::FromStr;
-
static DEL_TWEET_URL: &str = "https://api.twitter.com/1.1/statuses/destroy";
static RT_TWEET_URL: &str = "https://api.twitter.com/1.1/statuses/retweet";
static CREATE_TWEET_URL: &str = "https://api.twitter.com/1.1/statuses/update.json";
@@ -22,13 +20,16 @@ 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()) {
- queryer.do_api_post(&format!("{}/{}.json", DEL_TWEET_URL, twitter_id));
+ match queryer.do_api_post(&format!("{}/{}.json", DEL_TWEET_URL, twitter_id)) {
+ Ok(_) => (),
+ Err(e) => tweeter.display_info.status(e)
+ }
} else {
tweeter.display_info.status(format!("No tweet for id {:?}", twid));
}
},
Err(e) => {
- tweeter.display_info.status(format!("Invalid id: {:?}", line));
+ tweeter.display_info.status(format!("Invalid id: {:?} ({})", line, e));
}
}
}
@@ -39,17 +40,19 @@ pub static TWETE: Command = Command {
exec: twete
};
-fn twete(line: String, _tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
+fn twete(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
let text = line.trim();
let substituted = ::url_encode(text);
- println!("msg len: {}", text.len());
- println!("excessively long? {}", text.len() > 140);
- if text.len() > 140 {
- queryer.do_api_post(&format!("{}?status={}", CREATE_TWEET_URL, substituted));
+ if text.len() <= 140 {
+ match queryer.do_api_post(&format!("{}?status={}", CREATE_TWEET_URL, substituted)) {
+ Ok(_) => (),
+ Err(e) => tweeter.display_info.status(e)
+ }
} else {
- queryer.do_api_post(&format!("{}?status={}&weighted_character_count=true", CREATE_TWEET_URL, substituted));
+ // TODO: this 140 is maybe sometimes 280.. :)
+ // and see if weighted_character_count still does things?
+ tweeter.display_info.status(format!("tweet is too long: {}/140 chars", text.len()));
}
-// println!("{}", &format!("{}?status={}", CREATE_TWEET_URL, substituted));
}
pub static THREAD: Command = Command {
@@ -69,13 +72,16 @@ fn thread(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 handle = &tweeter.retrieve_user(&twete.author_id).unwrap().handle;
+ 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 {
let substituted = ::url_encode(reply);
- queryer.do_api_post(&format!("{}?status={}&in_reply_to_status_id={}", CREATE_TWEET_URL, substituted, twete.id));
+ match queryer.do_api_post(&format!("{}?status={}&in_reply_to_status_id={}", CREATE_TWEET_URL, substituted, twete.id)) {
+ Ok(_) => (),
+ Err(e) => tweeter.display_info.status(e)
+ }
} else {
- println!("you can only thread your own tweets");
+ tweeter.display_info.status("you can only thread your own tweets".to_owned());
// ask if it should .@ instead?
}
}
@@ -85,10 +91,10 @@ fn thread(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
}
}
} else {
- println!("thread <id> your sik reply");
+ tweeter.display_info.status("thread <id> your sik reply".to_owned());
}
} else {
- println!("thread <id> your sik reply");
+ tweeter.display_info.status("thread <id> your sik reply".to_owned());
}
}
@@ -129,21 +135,23 @@ fn rep(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
let decorated_ats: Vec<String> = ats.into_iter().map(|x| format!("@{}", x)).collect();
let full_reply = format!("{} {}", decorated_ats.join(" "), reply);
let substituted = ::url_encode(&full_reply);
- // println!("{}", (&format!("{}?status={}&in_reply_to_status_id={}", CREATE_TWEET_URL, substituted, twete.id)));
- queryer.do_api_post(&format!("{}?status={}&in_reply_to_status_id={}", CREATE_TWEET_URL, substituted, twete.id));
+ match queryer.do_api_post(&format!("{}?status={}&in_reply_to_status_id={}", CREATE_TWEET_URL, substituted, twete.id)) {
+ Ok(_) => (),
+ Err(e) => tweeter.display_info.status(e)
+ }
} else {
tweeter.display_info.status(format!("No tweet for id: {:?}", twid));
}
},
Err(e) => {
- tweeter.display_info.status(format!("Cannot parse input: {:?}", id_str));
+ tweeter.display_info.status(format!("Cannot parse input: {:?} ({})", id_str, e));
}
}
} else {
- println!("rep <id> your sik reply");
+ tweeter.display_info.status("rep <id> your sik reply".to_owned());
}
} else {
- println!("rep <id> your sik reply");
+ tweeter.display_info.status("rep <id> your sik reply".to_owned());
}
}
@@ -172,14 +180,16 @@ fn quote(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
twete.id
)
);
- println!("{}", substituted);
- queryer.do_api_post(
+ match queryer.do_api_post(
&format!("{}?status={}&attachment_url={}",
CREATE_TWEET_URL,
substituted,
attachment_url
)
- );
+ ) {
+ Ok(_) => (),
+ Err(e) => tweeter.display_info.status(e)
+ }
} else {
tweeter.display_info.status(format!("No tweet found for id {:?}", twid));
}
@@ -189,10 +199,10 @@ fn quote(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
}
}
} else {
- println!("rep <id> your sik reply");
+ tweeter.display_info.status("rep <id> your sik reply".to_owned());
}
} else {
- println!("rep <id> your sik reply");
+ tweeter.display_info.status("rep <id> your sik reply".to_owned());
}
}
@@ -207,7 +217,10 @@ 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()) {
- queryer.do_api_post(&format!("{}/{}.json", RT_TWEET_URL, twitter_id));
+ match queryer.do_api_post(&format!("{}/{}.json", RT_TWEET_URL, twitter_id)) {
+ Ok(_) => (),
+ Err(e) => tweeter.display_info.status(e)
+ }
} else {
tweeter.display_info.status(format!("No tweet for id {:?}", twid));
}
diff --git a/src/commands/view.rs b/src/commands/view.rs
index a6ce647..0c9e974 100644
--- a/src/commands/view.rs
+++ b/src/commands/view.rs
@@ -5,8 +5,6 @@ use tw::TweetId;
use commands::Command;
-use std::str::FromStr;
-
use display;
pub static VIEW: Command = Command {
@@ -19,7 +17,10 @@ fn view(line: String, tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer) {
match TweetId::parse(line) {
Ok(twid) => {
if let Some(twete) = tweeter.retrieve_tweet(&twid).map(|x| x.clone()) {
- tweeter.display_info.recv(display::Infos::Tweet(TweetId::Twitter(twete.id.to_owned())));
+ tweeter.display_info.recv(display::Infos::TweetWithContext(
+ TweetId::Twitter(twete.id.to_owned()),
+ format!("link: https://twitter.com/i/web/status/{}", twete.id)
+ ));
} else {
tweeter.display_info.status(format!("No tweet for id {:?}", twid));
}
@@ -28,8 +29,6 @@ fn view(line: String, tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer) {
tweeter.display_info.status(format!("Invalid id {:?}", e));
}
}
-// display::render_twete(&twete.id, tweeter);
-// println!(" link: https://twitter.com/i/web/status/{}", twete.id);
}
pub static VIEW_THREAD: Command = Command {
@@ -60,8 +59,6 @@ fn view_tr(line: String, mut tweeter: &mut tw::TwitterCache, queryer: &mut Query
}
tweeter.display_info.recv(display::Infos::Thread(thread));
-// display::render_twete(&twete.id, tweeter);
-// println!("link: https://twitter.com/i/web/status/{}", twete.id);
}
pub static VIEW_THREAD_FORWARD: Command = Command {
@@ -70,7 +67,7 @@ pub static VIEW_THREAD_FORWARD: Command = Command {
exec: view_tr_forward
};
-fn view_tr_forward(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
+fn view_tr_forward(_line: String, _tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer) {
// first see if we have a thread for the tweet named
// if we do not, we'll have to mimic a request like
// curl 'https://twitter.com/jojonila/status/914383908090691584' \