diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index ba834ce..674d128 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use std::str::FromStr; use std::sync::atomic::{AtomicBool, Ordering}; use anyhow::{anyhow, Context, Error, Result}; -use chrono::{DateTime, TimeZone, Utc}; +use chrono::{DateTime, Duration, TimeZone, Utc}; use colored::Colorize; use log::debug; use regex::Regex; @@ -17,7 +17,7 @@ use structopt::StructOpt; use walkdir::{DirEntry, WalkDir}; use evtclib::raw::parser::PartialEvtc; -use evtclib::{Boss, EventKind, Log}; +use evtclib::{Boss, Event, EventKind, Log}; mod fexpr; mod filters; @@ -129,10 +129,16 @@ impl Opt { fn build_filter(&self) -> Result<Box<dyn LogFilter>> { // As a shortcut, we allow only the regular expression to be given, to retain the behaviour // before the filter changes. + + // Special characters that when present will prevent the filter to be interpreted as a + // regex. This is to ensure that errors are properly reported on invalid filterlines + // instead of being swallowed because the filter was taken as a (valid) regex: + const SPECIAL_CHARS: &[char] = &['-', '(', ')', ':', '<', '>', '=']; + if self.expression.len() == 1 { let line = &self.expression[0]; let maybe_filter = build_filter(line); - if maybe_filter.is_err() && !line.starts_with('-') { + if maybe_filter.is_err() && !line.contains(SPECIAL_CHARS) { let maybe_regex = Regex::new(line); if let Ok(rgx) = maybe_regex { let filter = filters::player::any( @@ -156,6 +162,8 @@ pub struct LogResult { log_file: PathBuf, /// The time of the recording. time: DateTime<Utc>, + /// The duration of the fight. + duration: Duration, /// The boss. boss: Option<Boss>, /// A vector of all participating players. @@ -553,6 +561,7 @@ fn extract_info(path: &Path, log: &Log) -> LogResult { LogResult { log_file: path.to_path_buf(), time: Utc.timestamp(i64::from(log.local_end_timestamp().unwrap_or(0)), 0), + duration: get_fight_duration(log), boss, players, outcome: get_fight_outcome(log), @@ -589,3 +598,10 @@ fn get_fight_outcome(log: &Log) -> FightOutcome { FightOutcome::Wipe } } + +/// Get the duration of the fight. +fn get_fight_duration(log: &Log) -> Duration { + let start = log.events().first().map(Event::time).unwrap_or(0) as i64; + let end = log.events().last().map(Event::time).unwrap_or(0) as i64; + Duration::milliseconds(end - start) +} |