From 70cf5cc0d6e60706019f60dcda6bfa4baa959bf4 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 21 Oct 2017 14:02:37 -0700 Subject: fix bug with @s not going through in conversations split included @, meaning no handle started with @, so get_mentions() returned empty vec --- src/commands/twete.rs | 2 +- src/tw/tweet.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/commands/twete.rs b/src/commands/twete.rs index a66d5eb..c399df1 100644 --- a/src/commands/twete.rs +++ b/src/commands/twete.rs @@ -95,7 +95,7 @@ fn rep(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { if let Some(twete) = tweeter.retrieve_tweet(&TweetId::Bare(inner_twid)) { // get handles to reply to... let author_handle = tweeter.retrieve_user(&twete.author_id).unwrap().handle.to_owned(); - let mut ats: Vec = twete.get_mentions().into_iter().map(|x| x.to_owned()).collect(); //std::collections::HashSet::new(); + let mut ats: Vec = twete.get_mentions(); //std::collections::HashSet::new(); /* for handle in twete.get_mentions() { ats.insert(handle); diff --git a/src/tw/tweet.rs b/src/tw/tweet.rs index 72802ca..a3fdde3 100644 --- a/src/tw/tweet.rs +++ b/src/tw/tweet.rs @@ -22,17 +22,19 @@ pub struct Tweet { } impl Tweet { - pub fn get_mentions(&self) -> Vec<&str> { + pub fn get_mentions(&self) -> Vec { self.text.split(&[ ',', '.', '/', ';', '\'', '[', ']', '\\', '~', '!', - '@', '#', '$', '%', '^', + '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', '{', '}', '|', ':', '"', '<', '>', '?', '`', ' ' // forgot this initially. awkward. ][..]) - .filter(|x| x.starts_with("@") && x.len() > 1) + .filter(|x| x.starts_with("@") && x.len() > 1 && x.chars().skip(1).all(|c| c != '@')) + // discard @, mentions are just the usernames. + .map(|handle| handle.chars().skip(1).collect()) .collect() } -- cgit v1.1