diff options
author | iximeow <me@iximeow.net> | 2018-01-15 14:33:10 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-15 14:33:10 -0800 |
commit | ba66e351757c2b1a1efae8be294313d0806d48b4 (patch) | |
tree | 8a4e0117e8f2bb7754c512360ce97a6765d1a24f /src/commands | |
parent | deb7dff15aaef57a6fb1ecefeba9bfd3d895d84d (diff) | |
parent | 5ecfb0b6204481e9ca4ed1af09ce22ff4591c1e3 (diff) |
Merge pull request #10 from iximeow/hm-translation
add flag to translate emoji to/from a description
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/twete.rs | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/src/commands/twete.rs b/src/commands/twete.rs index 0f3b6a5..8bcfdbd 100644 --- a/src/commands/twete.rs +++ b/src/commands/twete.rs @@ -1,4 +1,5 @@ use display::DisplayInfo; +use serde_json; use tw; use ::Queryer; @@ -61,15 +62,7 @@ fn twete(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, di } pub fn send_twete(text: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, display_info: &mut DisplayInfo) { - let result = match tweeter.current_profile() { - Some(user_profile) => queryer.do_api_post( - CREATE_TWEET_URL, - &vec![("status", &text)], - &tweeter.app_key, - &user_profile.creds - ), - None => Err("No logged in user to tweet as".to_owned()) - }; + let result = make_tweet(&text, vec![("status", &text)], queryer, tweeter); match result { Ok(_) => (), Err(e) => display_info.status(e) @@ -201,19 +194,26 @@ fn rep(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, disp } } +pub fn make_tweet(text: &str, params: Vec<(&str, &str)>, queryer: &mut Queryer, tweeter: &tw::TwitterCache) -> Result<serde_json::Value, String> { + let updated_text = if tweeter.translate_emoji { + text + .replace(":thinking:", "🤔") + .replace(":clap:", "👏") + } else { + text.to_owned() + }; + let mut all_params = params; + all_params.push(("status", &updated_text)); + + match tweeter.current_profile() { + Some(user_profile) => queryer.do_api_post(CREATE_TWEET_URL, &all_params, &tweeter.app_key, &user_profile.creds), + None => Err("No logged in user to tweet as".to_owned()) + } +} + pub fn send_reply(text: String, twid: TweetId, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, user_creds: tw::Credential, display_info: &mut DisplayInfo) { if let Some(twete) = tweeter.retrieve_tweet(&twid) { - let result = match tweeter.current_profile() { - Some(user_profile) => { - queryer.do_api_post( - CREATE_TWEET_URL, - &vec![("status", &text), ("in_reply_to_status_id", &twete.id)], - &tweeter.app_key, - &user_creds - ) - }, - None => Err("No logged in user to tweet as".to_owned()) - }; + let result = make_tweet(&text, vec![("in_reply_to_status_id", &twete.id)], queryer, tweeter); match result { Ok(_) => (), Err(e) => display_info.status(e) @@ -248,18 +248,7 @@ fn quote(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, di tweeter.retrieve_user(&twete.author_id).unwrap().handle, // TODO: for now this is ok ish, if we got the tweet we have the author twete.id ); - let result = match tweeter.current_profile() { - Some(user_profile) => { - queryer.do_api_post( - CREATE_TWEET_URL, - &vec![("status", reply), ("attachment_url", attachment_url)], - - &tweeter.app_key, - &user_profile.creds - ) - }, - None => Err("No logged in user to tweet as".to_owned()) - }; + let result = make_tweet(reply, vec![("attachment_url", attachment_url)], queryer, tweeter); match result { Ok(_) => (), Err(e) => display_info.status(e) |