0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 15:04:10 +01:00

modules/m_command: Add caption command.

This commit is contained in:
Jason Volk 2020-11-09 09:19:10 -08:00
parent 172c192df2
commit 1be8eda7f1

View file

@ -196,6 +196,12 @@ catch(const std::exception &e)
};
}
static command_result
command__caption(const mutable_buffer &buf,
const m::user &user,
const m::room &room,
const string_view &cmd);
static command_result
command__ping(const mutable_buffer &buf,
const m::user &user,
@ -241,6 +247,9 @@ try
case "ping"_:
return command__ping(buf, user, room, cmd);
case "caption"_:
return command__caption(buf, user, room, cmd);
default:
break;
}
@ -814,3 +823,43 @@ command__dash(const mutable_buffer &buf,
return { view(out, buf), alt };
}
command_result
command__caption(const mutable_buffer &buf,
const m::user &user,
const m::room &room,
const string_view &cmd)
{
const params param{tokens_after(cmd, ' ', 0), " ",
{
"url",
}};
const string_view caption
{
tokens_after(cmd, ' ', 1)
};
std::ostringstream out;
pubsetbuf(out, buf);
out
<< "<img"
<< " src=\"" << param.at("url") << "\""
<< " height=\"100%\""
<< " width=\"100%\""
<< " />"
<< "<caption>"
<< caption
<< "</caption>"
;
const string_view html
{
view(out, buf)
};
return
{
html, caption
};
}