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

modules/console: Add a room command suite.

This commit is contained in:
Jason Volk 2018-02-08 21:00:50 -08:00
parent 39fed550cd
commit 7f25e368bc

View file

@ -23,6 +23,7 @@ IRCD_EXCEPTION_HIDENAME(ircd::error, bad_command)
// the console to be reused easily inside the application (like a matrix room).
std::stringstream out;
static bool console_cmd__room(const string_view &line);
static bool console_cmd__state(const string_view &line);
static bool console_cmd__event(const string_view &line);
static bool console_cmd__exec(const string_view &line);
@ -68,6 +69,9 @@ try
case hash("state"):
return console_cmd__state(args);
case hash("room"):
return console_cmd__room(args);
}
return -1;
@ -757,3 +761,95 @@ console_cmd__exec_file(const string_view &line)
return true;
}
//
// room
//
static bool console_cmd__room__members(const string_view &line);
static bool console_cmd__room__depth(const string_view &line);
static bool console_cmd__room__head(const string_view &line);
bool
console_cmd__room(const string_view &line)
{
const auto args
{
tokens_after(line, ' ', 0)
};
switch(hash(token(line, " ", 0)))
{
case hash("depth"):
return console_cmd__room__depth(args);
case hash("head"):
return console_cmd__room__head(args);
case hash("members"):
return console_cmd__room__members(args);
}
return true;
}
bool
console_cmd__room__head(const string_view &line)
{
const m::room::id room_id
{
token(line, ' ', 0)
};
const m::room room
{
room_id
};
out << head(room_id) << std::endl;
return true;
}
bool
console_cmd__room__depth(const string_view &line)
{
const m::room::id room_id
{
token(line, ' ', 0)
};
const m::room room
{
room_id
};
out << depth(room_id) << std::endl;
return true;
}
bool
console_cmd__room__members(const string_view &line)
{
const m::room::id room_id
{
token(line, ' ', 0)
};
const m::room room
{
room_id
};
const m::room::members members
{
room
};
members.until([](const m::event &event)
{
out << pretty_oneline(event) << std::endl;
return true;
});
return true;
}