aboutsummaryrefslogtreecommitdiff
path: root/src/filters.rs
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2020-04-06 14:43:28 +0200
committerDaniel <kingdread@gmx.de>2020-04-06 14:43:28 +0200
commita304370df4f998f7054731bac173113f91bf5cb1 (patch)
treeaab806f530e8871dbc35368e021485dc02265c54 /src/filters.rs
parentf7a0f17ce47e15f4cb39b49fecf4e252ce7897c3 (diff)
downloadraidgrep-a304370df4f998f7054731bac173113f91bf5cb1.tar.gz
raidgrep-a304370df4f998f7054731bac173113f91bf5cb1.tar.bz2
raidgrep-a304370df4f998f7054731bac173113f91bf5cb1.zip
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.
Diffstat (limited to 'src/filters.rs')
-rw-r--r--src/filters.rs23
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
+ }
+ })
+}