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:
Fam Zheng
2026-04-10 22:58:39 +01:00
parent 9d2d2af33f
commit c2be8e6930
6 changed files with 311 additions and 116 deletions

View File

@@ -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;
});
}