mirror of
https://github.com/matrix-construct/construct
synced 2024-09-26 18:38:52 +02:00
modules/console: Add redact last cmd to supplement the feature in E!ement.
This commit is contained in:
parent
11d0ab9eaf
commit
b906650946
1 changed files with 90 additions and 0 deletions
|
@ -18067,6 +18067,96 @@ console_cmd__redact(opt &out, const string_view &line)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
console_cmd__redact__last(opt &out, const string_view &line)
|
||||||
|
{
|
||||||
|
const params param{line, " ",
|
||||||
|
{
|
||||||
|
"room_id", "sender", "redactor", "count", "type", "reason"
|
||||||
|
}};
|
||||||
|
|
||||||
|
const m::room::id::buf room_id
|
||||||
|
{
|
||||||
|
m::room_id(param["room_id"])
|
||||||
|
};
|
||||||
|
|
||||||
|
const m::room room
|
||||||
|
{
|
||||||
|
room_id
|
||||||
|
};
|
||||||
|
|
||||||
|
const m::user::id sender
|
||||||
|
{
|
||||||
|
param["sender"]
|
||||||
|
};
|
||||||
|
|
||||||
|
const m::user::id redactor
|
||||||
|
{
|
||||||
|
param["redactor"]
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto type
|
||||||
|
{
|
||||||
|
param["type"]
|
||||||
|
};
|
||||||
|
|
||||||
|
auto count
|
||||||
|
{
|
||||||
|
param.at<uint>("count", 1)
|
||||||
|
};
|
||||||
|
|
||||||
|
m::room::iterate events
|
||||||
|
{
|
||||||
|
room, "sender"
|
||||||
|
};
|
||||||
|
|
||||||
|
size_t limit(10000);
|
||||||
|
events.for_each([&]
|
||||||
|
(const auto &_sender, const auto &depth, const auto &event_idx)
|
||||||
|
{
|
||||||
|
if(--limit <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(_sender != sender)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
const auto event_id
|
||||||
|
{
|
||||||
|
m::event_id(std::nothrow, event_idx)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(unlikely(!event_id))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
const auto type_equal{[&type]
|
||||||
|
(const auto &t)
|
||||||
|
{
|
||||||
|
return type == t;
|
||||||
|
}};
|
||||||
|
|
||||||
|
if(type && !m::query(event_idx, "type", type_equal))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
const auto redact_id
|
||||||
|
{
|
||||||
|
m::redact(room, redactor, event_id, param["reason"])
|
||||||
|
};
|
||||||
|
|
||||||
|
out
|
||||||
|
<< std::setw(3) << std::right << count
|
||||||
|
<< ' '
|
||||||
|
<< redact_id
|
||||||
|
<< " redacted "
|
||||||
|
<< event_id
|
||||||
|
;
|
||||||
|
|
||||||
|
return --count > 0;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// well-known
|
// well-known
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue