Commit 1e40b6d7 authored by Aljaž Srebrnič's avatar Aljaž Srebrnič

Add keymaster modifier

parent 8f268d16
......@@ -4,6 +4,7 @@ extern crate r2d2_redis;
use spaceapi_server::SpaceapiServerBuilder;
use spaceapi_server::api;
use spaceapi_server::api::Keymaster;
use spaceapi_server::modifiers::StatusModifier;
use std::env::var;
......@@ -38,6 +39,31 @@ impl StatusModifier for OpenStatusFromRedisModifier {
}
}
struct KeymastersFromRedisModifier {
pool: RedisPool
}
impl KeymastersFromRedisModifier {
fn new(pool: RedisPool) -> KeymastersFromRedisModifier {
KeymastersFromRedisModifier{pool}
}
}
impl StatusModifier for KeymastersFromRedisModifier {
fn modify(&self, status: &mut api::Status) {
let conn = self.pool.get().unwrap(); // XXX Remove unwrap
let km_redis : Vec<String> = conn.zrange("keys", 0, -1).unwrap();
let mut km : Vec<Keymaster> = Vec::new();
for k in km_redis {
let mut m = Keymaster::default();
m.irc_nick = Some(k);
km.push(m)
}
status.contact.keymasters = Some(km);
}
}
fn main() {
env_logger::init();
......@@ -77,7 +103,8 @@ fn main() {
let server = SpaceapiServerBuilder::new(status)
// .add_redis_pool(pool) waiting for
.redis_connection_info(&*redis_connstring)
.add_status_modifier(OpenStatusFromRedisModifier::new(pool))
.add_status_modifier(OpenStatusFromRedisModifier::new(pool.clone()))
.add_status_modifier(KeymastersFromRedisModifier::new(pool.clone()))
.build()
.expect("Could not initialize server");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment