From a304370df4f998f7054731bac173113f91bf5cb1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 6 Apr 2020 14:43:28 +0200 Subject: implement guild display & filtering options Filtering based on guilds is slow, as it will have to retrieve every guild name from the GW2 API, and it has to parse every log file instead of bailing early. Therefore, guilds are not searched by default, and have to be explicitely turned on with --guilds. In addition, this means that raidgrep will now need network access when --guilds is passed, which was not the case before. --- src/filters.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/filters.rs') 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 + } + }) +} -- cgit v1.2.3