mirror of
https://github.com/matrix-construct/construct
synced 2025-01-13 08:23:56 +01:00
modules/m_command: Add control command w/ sigil'ed shortcut.
This commit is contained in:
parent
595c51e17e
commit
8e79fda31b
1 changed files with 71 additions and 0 deletions
|
@ -232,6 +232,12 @@ command__version(const mutable_buffer &buf,
|
|||
const m::room &room,
|
||||
const string_view &cmd);
|
||||
|
||||
static command_result
|
||||
command__control(const mutable_buffer &buf,
|
||||
const m::user &user,
|
||||
const m::room &room,
|
||||
const string_view &cmd);
|
||||
|
||||
command_result
|
||||
execute_command(const mutable_buffer &buf,
|
||||
const m::user &user,
|
||||
|
@ -239,6 +245,9 @@ execute_command(const mutable_buffer &buf,
|
|||
const string_view &cmd)
|
||||
try
|
||||
{
|
||||
if(startswith(cmd, '#'))
|
||||
return command__control(buf, user, room, lstrip(cmd, '#'));
|
||||
|
||||
switch(hash(token(cmd, ' ', 0)))
|
||||
{
|
||||
case "version"_:
|
||||
|
@ -259,6 +268,16 @@ try
|
|||
case "caption"_:
|
||||
return command__caption(buf, user, room, cmd);
|
||||
|
||||
case "control"_:
|
||||
{
|
||||
const auto subcmd
|
||||
{
|
||||
tokens_after(cmd, ' ', 0)
|
||||
};
|
||||
|
||||
return command__control(buf, user, room, subcmd);
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1119,3 +1138,55 @@ command__caption(const mutable_buffer &buf,
|
|||
html, caption
|
||||
};
|
||||
}
|
||||
|
||||
command_result
|
||||
command__control(const mutable_buffer &buf,
|
||||
const m::user &user,
|
||||
const m::room &room,
|
||||
const string_view &cmd)
|
||||
{
|
||||
if(!is_oper(user))
|
||||
throw m::ACCESS_DENIED
|
||||
{
|
||||
"You do not have access to the !control room."
|
||||
};
|
||||
|
||||
const ircd::module console_module
|
||||
{
|
||||
"console"
|
||||
};
|
||||
|
||||
using prototype = int (std::ostream &, const string_view &, const string_view &);
|
||||
mods::import<prototype> command
|
||||
{
|
||||
console_module, "console_command"s
|
||||
};
|
||||
|
||||
std::ostringstream out;
|
||||
out.exceptions(out.badbit | out.failbit | out.eofbit);
|
||||
pubsetbuf(out, buf);
|
||||
|
||||
static const string_view opts
|
||||
{
|
||||
"html"
|
||||
};
|
||||
|
||||
out << "<pre>";
|
||||
command(out, cmd, opts);
|
||||
out << "</pre>";
|
||||
|
||||
const string_view html
|
||||
{
|
||||
view(out, buf)
|
||||
};
|
||||
|
||||
const string_view alt //TODO: X
|
||||
{
|
||||
"no alt text"
|
||||
};
|
||||
|
||||
return
|
||||
{
|
||||
html, alt
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue