mirror of
https://github.com/matrix-construct/construct
synced 2024-09-29 20:28:52 +02:00
modules: Export conf item get/set in s_conf; import for s_control interface.
This commit is contained in:
parent
a68d97d22d
commit
9d69e5a405
2 changed files with 54 additions and 13 deletions
|
@ -16,7 +16,7 @@ IRCD_MODULE
|
||||||
"Server Configuration"
|
"Server Configuration"
|
||||||
};
|
};
|
||||||
|
|
||||||
const ircd::m::room::id::buf
|
const m::room::id::buf
|
||||||
conf_room_id
|
conf_room_id
|
||||||
{
|
{
|
||||||
"conf", ircd::my_host()
|
"conf", ircd::my_host()
|
||||||
|
@ -28,6 +28,33 @@ conf_room
|
||||||
conf_room_id
|
conf_room_id
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern "C" m::event::id::buf
|
||||||
|
set_conf_item(const m::user::id &sender,
|
||||||
|
const string_view &key,
|
||||||
|
const string_view &val)
|
||||||
|
{
|
||||||
|
return send(conf_room, sender, "ircd.conf.item", key,
|
||||||
|
{
|
||||||
|
{ "value", val }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void
|
||||||
|
get_conf_item(const string_view &key,
|
||||||
|
const std::function<void (const string_view &)> &closure)
|
||||||
|
{
|
||||||
|
conf_room.get("ircd.conf.item", key, [&closure]
|
||||||
|
(const m::event &event)
|
||||||
|
{
|
||||||
|
const auto &value
|
||||||
|
{
|
||||||
|
unquote(at<"content"_>(event).at("value"))
|
||||||
|
};
|
||||||
|
|
||||||
|
closure(value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_conf(const m::event &event)
|
update_conf(const m::event &event)
|
||||||
noexcept
|
noexcept
|
||||||
|
|
|
@ -40,12 +40,23 @@ _conf_set(const m::event &event,
|
||||||
const string_view &val)
|
const string_view &val)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const auto &sender
|
||||||
|
{
|
||||||
|
at<"sender"_>(event)
|
||||||
|
};
|
||||||
|
|
||||||
|
using prototype = m::event::id::buf (const m::user::id &,
|
||||||
|
const string_view &key,
|
||||||
|
const string_view &val);
|
||||||
|
|
||||||
|
static import<prototype> set_conf_item
|
||||||
|
{
|
||||||
|
"s_conf", "set_conf_item"
|
||||||
|
};
|
||||||
|
|
||||||
const auto event_id
|
const auto event_id
|
||||||
{
|
{
|
||||||
send(conf_room_id, at<"sender"_>(event), "ircd.conf.item", key,
|
set_conf_item(sender, key, val)
|
||||||
{
|
|
||||||
{ "value", val }
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
char kvbuf[768];
|
char kvbuf[768];
|
||||||
|
@ -64,15 +75,18 @@ _conf_get(const m::event &event,
|
||||||
const string_view &key)
|
const string_view &key)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const m::room conf_room{conf_room_id};
|
using closure = std::function<void (const string_view &val)>;
|
||||||
conf_room.get("ircd.conf.item", key, [&key]
|
using prototype = void (const string_view &key,
|
||||||
(const m::event &event)
|
const closure &);
|
||||||
{
|
|
||||||
const auto &value
|
|
||||||
{
|
|
||||||
unquote(at<"content"_>(event).at("value"))
|
|
||||||
};
|
|
||||||
|
|
||||||
|
static import<prototype> get_conf_item
|
||||||
|
{
|
||||||
|
"s_conf", "get_conf_item"
|
||||||
|
};
|
||||||
|
|
||||||
|
get_conf_item(key, [&key]
|
||||||
|
(const string_view &value)
|
||||||
|
{
|
||||||
char kvbuf[256];
|
char kvbuf[256];
|
||||||
notice(control_room, fmt::sprintf
|
notice(control_room, fmt::sprintf
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue