From 58476f59c32a6960ed3f23b9b02d752073e2a299 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 19 Apr 2023 12:43:02 -0700 Subject: [PATCH] modules/console: Overload parameters of room events cmd to filter by type. --- modules/console.cc | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/modules/console.cc b/modules/console.cc index 91e4dfdfa..c8ea2ec15 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -11455,31 +11455,47 @@ console_cmd__room__count(opt &out, const string_view &line) bool console_cmd__room__events(opt &out, const string_view &line) { - const params param{line, " ", + const params param_any{line, " ", { "room_id", "depth|-limit", "order", "limit" }}; + const params param_type{line, " ", + { + "room_id", "type", "depth|-limit", "order", "limit" + }}; + + const bool use_type + { + param_type["type"] && !lex_castable(param_type["type"]) + }; + + // decide which argument overload to use + const params ¶m + { + use_type? param_type : param_any + }; + const auto &room_id { - m::room_id(param.at(0)) + m::room_id(param.at("room_id")) }; const int64_t depth { - param.at(1, std::numeric_limits::max()) + param.at("depth|-limit", std::numeric_limits::max()) }; const char order { - param.at(2, "b"_sv).at(0) + param.at("order", "b"_sv).at(0) }; ssize_t limit { depth < 0? std::abs(depth): - param.at(3, ssize_t(32)) + param.at("depth|-limit", ssize_t(32)) }; const m::room room @@ -11493,15 +11509,21 @@ console_cmd__room__events(opt &out, const string_view &line) }; m::event::fetch event; - for(; it && limit > 0; order == 'b'? --it : ++it, --limit) + for(; it && limit > 0; order == 'b'? --it : ++it) { if(!seek(std::nothrow, event, it.event_idx())) continue; + if(use_type) + if(!globular_imatch(param["type"])(json::get<"type"_>(event))) + continue; + out << std::left << std::setw(10) << it.event_idx() << " " << pretty_oneline(event) << std::endl; + + --limit; } return true;