0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-28 11:48:54 +02:00

modules/console: Add room type count cmd.

This commit is contained in:
Jason Volk 2020-11-21 16:21:15 -08:00
parent 8e79fda31b
commit c97cc4ecb7

View file

@ -11280,6 +11280,61 @@ console_cmd__room__type(opt &out, const string_view &line)
return true;
}
bool
console_cmd__room__type__count(opt &out, const string_view &line)
{
const params param{line, " ",
{
"room_id", "type", "start_depth", "end_depth"
}};
const auto &room_id
{
m::room_id(param.at("room_id"))
};
const auto &type
{
param["type"]
};
const uint64_t start_depth
{
param.at<uint64_t>(2, -1UL)
};
const int64_t end_depth
{
param.at<int64_t>(3, -1L)
};
const bool prefix_match
{
endswith(type, "...")
};
const m::room::type events
{
room_id,
rstrip(type, "..."),
{ start_depth, end_depth },
prefix_match
};
size_t ret(0);
events.for_each([&ret]
(const string_view &type, const uint64_t &depth, const m::event::idx &event_idx)
{
++ret;
return true;
});
out
<< ret
<< std::endl;
return true;
}
bool
console_cmd__room__get(opt &out, const string_view &line)
{