add discord membercount service & endpoint

a background worker is added that sends an approximate member count
request every 60 seconds, caches it into memory, and serves the cache on
a public endpoint
This commit is contained in:
2025-07-09 00:06:56 +02:00
parent fc458143a9
commit 6a12495686
5 changed files with 78 additions and 5 deletions

View File

@@ -1,5 +1,17 @@
use axum::{Router, routing::get};
use axum::{Router, http::StatusCode, routing::get};
pub fn init() -> Router {
Router::new().route("/", get(async || "root"))
Router::new()
.route("/", get(async || "root"))
.route("/discord/member-count", get(get_member_count))
}
async fn get_member_count() -> (StatusCode, String) {
match crate::discordbot::get_member_count().await {
Some(count) => (StatusCode::OK, format!("{count}")),
None => (
StatusCode::INTERNAL_SERVER_ERROR,
format!("An error occured - could not fetch discord member count."),
),
}
}