35 lines
1.0 KiB
D

module api;
import util, asdf, api_data;
void send(T)(T content, string roomid, string type = "m.room.message") {
import std.random: uniform;
mkhsrq("/_matrix/client/v3/rooms/" ~ roomid ~ "/send/" ~ type ~
"/skunky-" ~ intToStr(uniform(1111_1111, 9999_9999)), "PUT", content.serializeToJson);
}
void rawState(string room, string name, string content) {
mkhsrq (
"/_matrix/client/v3/rooms/" ~ room ~ "/state/" ~ name,
"PUT",
content
);
}
void state(T)(string room, string name, T content) {
rawState(room, name, content.serializeToJson);
}
T getState(T)(string room, string name) {
return mkhsrq("/_matrix/client/v3/rooms/" ~ room ~ "/state/" ~ name).body.deserialize!T;
}
MSG event(string id, string room) {
struct Evt { MSG content; }
return (mkhsrq("/_matrix/client/v3/rooms/" ~ room ~ "/event/" ~ id).body.deserialize!Evt).content;
}
string upload(T)(T file) {
struct Upload { string content_uri; }
return (mkhsrq("/_matrix/media/v3/upload", "POST", cast(string)file)
.body.deserialize!Upload).content_uri;
}