add http API, channel-driven life loop, predefined diary timer
- Extract http.rs: unified HTTP server with /api/timers and gitea webhook - Life loop: select! on interval tick + mpsc channel for force-fire - Predefined diary timer (cron 22:55 daily), auto-registered on startup - BufferOutput for system timers (chat_id=0), no TG message - state: ensure_timer(), get_timer() - context.md: add blog and Hugo docs for AI
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -1,6 +1,7 @@
|
||||
mod config;
|
||||
mod display;
|
||||
mod gitea;
|
||||
mod http;
|
||||
mod life;
|
||||
mod output;
|
||||
mod state;
|
||||
@@ -92,16 +93,18 @@ async fn main() {
|
||||
|
||||
let config = Arc::new(config);
|
||||
|
||||
// start life loop
|
||||
tokio::spawn(life::life_loop(bot.clone(), state.clone(), config.clone()));
|
||||
// channel: http server → life loop
|
||||
let (life_tx, life_rx) = tokio::sync::mpsc::channel(16);
|
||||
|
||||
// start gitea webhook server
|
||||
if let Some(gitea_config) = &config.gitea {
|
||||
let gc = gitea_config.clone();
|
||||
// Use the gitea admin username as the bot user for @mention detection
|
||||
let bot_user = std::env::var("GITEA_ADMIN_USER").unwrap_or_else(|_| "noc".into());
|
||||
// start life loop
|
||||
tokio::spawn(life::life_loop(bot.clone(), state.clone(), config.clone(), life_rx));
|
||||
|
||||
// start http server (API + gitea webhook)
|
||||
{
|
||||
let srv_config = config.clone();
|
||||
let srv_state = state.clone();
|
||||
tokio::spawn(async move {
|
||||
gitea::start_webhook_server(&gc, bot_user).await;
|
||||
http::start_http_server(&srv_config, srv_state, life_tx).await;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user