diff options
| author | seth <[email protected]> | 2023-12-05 05:17:49 -0500 |
|---|---|---|
| committer | seth <[email protected]> | 2023-12-15 16:41:13 -0500 |
| commit | 815cb0df3b3e3f9dd2078b00f85754da87b1d55e (patch) | |
| tree | 85099483f8ebb0586bc097b65f6c5a2b5997150e /src/main.rs | |
| parent | 0ca61ddff6ec7404f0aeabc1c8c785bbc8db7fd5 (diff) | |
refactor: centralize storage handlers
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/main.rs b/src/main.rs index afedd1a..d355307 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,32 +5,31 @@ use log::*; use poise::{ serenity_prelude as serenity, EditTracker, Framework, FrameworkOptions, PrefixFrameworkOptions, }; -use redis::AsyncCommands; -use settings::Settings; +use storage::Storage; mod api; mod colors; mod commands; mod consts; mod handlers; -mod settings; +mod storage; mod utils; type Context<'a> = poise::Context<'a, Data, Report>; #[derive(Clone)] pub struct Data { - redis: redis::Client, + storage: Storage, } impl Data { pub fn new() -> Result<Self> { let redis_url = std::env::var("REDIS_URL") - .wrap_err_with(|| eyre!("Couldn't find Redis URL in environment!"))?; + .wrap_err_with(|| "Couldn't find Redis URL in environment!")?; - let redis = redis::Client::open(redis_url)?; + let storage = Storage::new(&redis_url)?; - Ok(Self { redis }) + Ok(Self { storage }) } } @@ -75,25 +74,18 @@ async fn main() -> Result<()> { info!("Registered global commands!"); // register "extra" commands in guilds that allow it - let mut con = data.redis.get_async_connection().await?; - - info!("Fetching all guild settings from Redis...this might take a while"); - let guilds: Vec<String> = con.keys(format!("{}:*", settings::ROOT_KEY)).await?; + info!("Fetching opted guilds"); + let guilds = data.storage.get_opted_guilds().await?; for guild in guilds { - let settings: Settings = con.get(guild).await?; - - if settings.optional_commands_enabled { - poise::builtins::register_in_guild( - ctx, - &commands::to_guild_commands(), - settings.guild_id, - ) - .await?; - info!("Registered guild commands to {}", settings.guild_id); - } else { - debug!("Not registering guild commands to {} since optional_commands_enabled is False", settings.guild_id); - } + poise::builtins::register_in_guild( + ctx, + &commands::to_optional_commands(), + guild, + ) + .await?; + + info!("Registered guild commands to {}", guild); } Ok(data) |
