use std::{sync::Arc, time::Duration}; use axum::Router; use clap::Parser; use crate::{cache::Cache, state::State}; pub mod cache; mod handlers; mod state; /// Simple program to greet a person #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Args { /// IP and port to bind the server #[arg(short, long, default_value_t = String::from("0.0.0.0:8000"), env = "BIND")] bind: String, /// Discord bot token #[arg(long, env = "DISCORD_TOKEN")] discord_token: String, /// GitHub PAT with `read:user` scope #[arg(long, env = "GITHUB_TOKEN")] github_token: String, } #[tokio::main] async fn main() { dotenvy::dotenv().ok(); let args = Args::parse(); let state = Arc::new(State { cache: Cache::default(), discord_token: args.discord_token, github_token: args.github_token, }); let eviction_state = state.clone(); tokio::spawn(async move { loop { tokio::time::sleep(Duration::from_secs(10)).await; eviction_state.cache.evict().await; } }); let app = Router::new().merge(handlers::router()).with_state(state); let listener = tokio::net::TcpListener::bind(args.bind).await.unwrap(); axum::serve(listener, app).await.unwrap(); }