Skip to content

Commit

Permalink
manage operator attached to alias
Browse files Browse the repository at this point in the history
  • Loading branch information
Geobert Quach committed Aug 25, 2020
1 parent 6a05a35 commit e5d6aa7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,23 @@ impl AllData {
}

pub(crate) async fn get_alias(&self, alias: &str, chat_id: u64) -> Option<String> {
// TODO: check for + - / *
let (alias, rest) =
if let Some(idx) = alias.find(|c| c == '+' || c == '-' || c == '*' || c == '/') {
(&alias[..idx], Some(&alias[idx..]))
} else {
(alias, None)
};
match self.get(&chat_id) {
Some(data) => data.aliases.get(alias).cloned(),
Some(data) => match data.aliases.get(alias) {
Some(alias) => {
if let Some(rest) = rest {
Some(format!("{} {}", alias, rest))
} else {
Some(alias.clone())
}
}
None => None,
},
None => None,
}
}
Expand Down

0 comments on commit e5d6aa7

Please sign in to comment.