diff options
Diffstat (limited to 'src/filters.rs')
-rw-r--r-- | src/filters.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/filters.rs b/src/filters.rs index 02334bc..715e4e4 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -4,7 +4,7 @@ use evtclib::statistics::gamedata::Boss; use num_traits::FromPrimitive; -use super::{SearchField, LogResult, Opt}; +use super::{SearchField, LogResult, Opt, guilds}; use chrono::Datelike; @@ -30,7 +30,8 @@ pub fn filter_name(evtc: &PartialEvtc, opt: &Opt) -> bool { _ => (), } } - false + // Don't throw away the log yet if we are searching for guilds + opt.field.contains(&SearchField::Guild) } /// Do filtering based on the boss ID. @@ -64,3 +65,21 @@ pub fn filter_time(result: &LogResult, opt: &Opt) -> bool { after_ok && before_ok } + +/// Do filtering based on the guilds. +pub fn filter_guilds(result: &LogResult, opt: &Opt) -> bool { + if !opt.guilds { + return true; + } + if !opt.field.contains(&SearchField::Guild) { + return true; + } + result.players.iter().any(|player| { + let guild = player.guild_id.as_ref().and_then(|id| guilds::lookup(id)); + if let Some(guild) = guild { + opt.expression.is_match(guild.tag()) || opt.expression.is_match(guild.name()) + } else { + false + } + }) +} |