module commands.slaves; enum Parallel; import util; import api; import api_data; import main: db; void apod_slave() @Parallel { import core.thread; import commands.apod; import core.stdc.time: time; db.exec("create table if not exists apod ( subscribed_room string, mxc string unique, body string, title string, mimetype string, size integer, width integer, height integer, untill integer )"); for (;;) { int v; auto q = db.query("select untill from apod where subscribed_room = 'CACHE'"); if (q.step) v = q.get!int; for (q = db.query("select subscribed_room from apod where subscribed_room != 'CACHE'"); q.step;) { if (v == 0 || v < time(null)) { send(cached_apod, q.get!string); db.exec("delete from apod where subscribed_room = 'CACHE'"); } } Thread.sleep(30.seconds); } } void nctl_slave() @Parallel { import core.thread: Thread; import core.time: Duration, dur; import core.stdc.time: time; import asdf: serializeToJson; static Duration tms = dur!"msecs"(10); struct udr { string room; string user; string type; string nc; int unt; } for (;;) { auto q = db.query("select * from nctl"); while (q.step) { try { udr z = q.get!udr; if (time(null) >= z.unt) { if (z.type == null) { mkhsrq( "/_matrix/client/v3/rooms/"~z.room~"/unban", "POST", Moderate(z.user, "Its time to unban!").serializeToJson ); } else rawState(z.room, z.type, z.nc); db.exec("delete from nctl where user = ? and room = ?", z.user, z.room); } } catch (Exception e) { import core.stdc.stdio; printf("[nctl_slave] ERROR: %s\n", cast(char*)e.msg); } } Thread.sleep(tms); } }