spiffbot/src/tasks.rs
deepCurse 1afa975c6a
laying the groundwork for the new argument system
cleaning up the source tree
work towards dynamic loading of command plugins
2024-08-04 21:46:42 -03:00

34 lines
1 KiB
Rust

use crate::constants;
use std::{sync::Arc, time::Duration};
use ::std::collections::hash_map::HashMap;
use rand::{distributions::uniform::SampleRange, rngs::OsRng};
use serenity::all::{ActivityData, Cache, ShardId, ShardRunnerInfo};
use tokio::sync::Mutex;
pub async fn status_timer(
shard_runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>,
cache: Arc<Cache>,
) {
let mut rand = OsRng::default();
let activity_list = [
ActivityData::watching("my developer eat a watermelon whole."),
ActivityData::watching(format!(
"{} users in {} guilds.",
cache.user_count(),
cache.guild_count()
)),
ActivityData::watching(format!("for {}help", constants::COMMAND_PREFIX)),
ActivityData::listening("Infected Mushroom"),
];
loop {
for (_shard_id, shard_info) in shard_runners.lock().await.iter() {
shard_info.runner_tx.set_activity(Some(
activity_list[SampleRange::sample_single(0..activity_list.len() - 1, &mut rand)]
.clone(),
));
}
tokio::time::sleep(Duration::from_secs(20 * 60)).await;
}
}