treewide: allow for running w/o storage

This commit is contained in:
seth 2024-03-27 18:55:31 -04:00
parent 827b5a4bd7
commit a9a63f36ad
14 changed files with 174 additions and 90 deletions

28
src/config/bot.rs Normal file
View file

@ -0,0 +1,28 @@
use log::{info, warn};
#[derive(Clone, Debug, Default)]
pub struct Config {
redis_url: Option<String>,
}
impl Config {
pub fn new(redis_url: Option<String>) -> Self {
Self { redis_url }
}
pub fn new_from_env() -> Self {
let redis_url = std::env::var("BOT_REDIS_URL").ok();
if let Some(url) = &redis_url {
info!("Redis URL is {url}");
} else {
warn!("BOT_REDIS_URL is empty; features requiring storage will be disabled.");
}
Self::new(redis_url)
}
pub fn redis_url(self) -> Option<String> {
self.redis_url
}
}