add status automation service, unify event constituent update calls

This commit is contained in:
2025-06-21 00:23:25 +02:00
parent 904ff5a213
commit 6ec3c8e4cb
4 changed files with 75 additions and 16 deletions

View File

@@ -0,0 +1,34 @@
use serenity::all::ActivityData;
use std::sync::LazyLock;
pub static LIST: LazyLock<Vec<ActivityData>> = LazyLock::new(|| {
use ActivityData as ACT;
vec![
ACT::playing("Team Fortress 2"),
ACT::playing("Minecraft"),
ACT::playing("PGTF Dating Sim"),
ACT::playing("Hades"),
ACT::playing("Bloons TD 6"),
// // // // // // // // // // //
ACT::listening("Lin-Manuel Miranda"),
ACT::listening("Kendrick Lamar"),
ACT::listening("Pięć Dwa Dębiec"),
ACT::listening("Gimpson"),
// // // // // // // // // // //
ACT::watching("Scooby Doo"),
ACT::watching("Horimiya"),
ACT::watching("My Deer Friend Nokotan"),
ACT::watching("Lycoris Recoil"),
ACT::watching("Yuru Camp"),
ACT::watching("DARLING in the FRANXX"),
// // // // // // // // // // //
ACT::custom("Formalizuje stowarzyszenie"),
ACT::custom("Shipuje członków"),
ACT::custom("Spisuje cytaty"),
ACT::custom("Krzyczy na rozmówcę"),
ACT::custom("Montuje konwent"),
ACT::custom("Rozmontowuje konwent"),
ACT::custom("Głosi prelekcję"),
ACT::custom("Zmienia nicki innym"),
]
});

View File

@@ -0,0 +1,29 @@
use rand::{Rng, SeedableRng, seq::IndexedRandom};
use serenity::all::Context;
use std::time::Duration;
use tokio::time::sleep;
use tracing::info;
use crate::discordbot::status::list::LIST;
mod list;
pub fn init_service(ctx: &Context) {
info!("Initialising status automation service...");
let ctx = ctx.clone();
tokio::spawn(async move {
run_service(ctx).await;
});
}
pub async fn run_service(ctx: Context) {
loop {
let mut rng = rand::rngs::SmallRng::from_rng(&mut rand::rng());
let activity = (*LIST).choose(&mut rng).map(|a| a.to_owned());
ctx.set_activity(activity);
// sleep for randomly 15, 30 or 45 minutes between status changes
sleep(Duration::from_secs(60 * 15 * rng.random_range(1..=3))).await;
}
}