aboutsummaryrefslogtreecommitdiffstats
path: root/mumd
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2020-10-17 21:12:31 +0200
committerEskil Queseth <eskilq@kth.se>2020-10-17 21:12:31 +0200
commit39b13833187e4331fa32c1601f1bf1b1d6fa036a (patch)
treed587852b7873afa49f0f0af7feb32a2f8478689c /mumd
parent74a64c249e0371890f4bb03ee8cd17b5059ddc4c (diff)
downloadmum-39b13833187e4331fa32c1601f1bf1b1d6fa036a.tar.gz
add soft matching for channel joining
Diffstat (limited to 'mumd')
-rw-r--r--mumd/src/state.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/mumd/src/state.rs b/mumd/src/state.rs
index 62ba865..2c48955 100644
--- a/mumd/src/state.rs
+++ b/mumd/src/state.rs
@@ -67,7 +67,17 @@ impl State {
.filter(|e| e.1.ends_with(&channel_identifier))
.collect::<Vec<_>>();
let id = match matches.len() {
- 0 => return (false, Err(Error::ChannelIdentifierError(channel_identifier, ChannelIdentifierError::Invalid))),
+ 0 => {
+ let soft_matches = channels.iter()
+ .map(|e| (e.0, e.1.path(channels).to_lowercase()))
+ .filter(|e| e.1.ends_with(&channel_identifier.to_lowercase()))
+ .collect::<Vec<_>>();
+ match soft_matches.len() {
+ 0 => return (false, Err(Error::ChannelIdentifierError(channel_identifier, ChannelIdentifierError::Invalid))),
+ 1 => *soft_matches.get(0).unwrap().0,
+ _ => return (false, Err(Error::ChannelIdentifierError(channel_identifier, ChannelIdentifierError::Invalid))),
+ }
+ },
1 => *matches.get(0).unwrap().0,
_ => return (false, Err(Error::ChannelIdentifierError(channel_identifier, ChannelIdentifierError::Ambiguous))),
};