Fix tps parsing

This commit is contained in:
Malte Tammena 2021-12-07 16:47:04 +01:00
parent 960a4447ce
commit 80055b2225

View file

@ -1,8 +1,9 @@
use nom::{
bytes::complete::tag,
combinator::{all_consuming, map, opt},
character::complete::one_of,
combinator::{all_consuming, map, opt, value},
number::complete::double,
sequence::{preceded, tuple},
sequence::{pair, preceded, tuple},
IResult,
};
@ -38,14 +39,14 @@ impl RconCommand for TpsCmd {
}
fn parse_tps_result(inp: &str) -> IResult<&str, Tps> {
let start = tag("§6TPS from last 1m, 5m, 15m: §a");
let start = tag("§6TPS from last 1m, 5m, 15m: ");
all_consuming(map(
tuple((
start,
tps_value,
tag(", §a"),
tag(", "),
tps_value,
tag(", §a"),
tag(", "),
tps_value,
tag("\n"),
)),
@ -54,5 +55,9 @@ fn parse_tps_result(inp: &str) -> IResult<&str, Tps> {
}
fn tps_value(inp: &str) -> IResult<&str, f64> {
preceded(opt(tag("*")), double)(inp)
preceded(pair(ignore_color, opt(tag("*"))), double)(inp)
}
fn ignore_color(inp: &str) -> IResult<&str, ()> {
value((), opt(pair(tag("§"), one_of("0123456789abcdef"))))(inp)
}