feat: heatseeking

This commit is contained in:
2026-05-24 13:20:43 -04:00
parent e1aab0a8fb
commit b598adb498
12 changed files with 288 additions and 40 deletions

View File

@@ -1,7 +1,6 @@
use clap::Parser;
use fomo_reducer::{
BotDataManager, CommandRouter, GuildVoiceChannelToTextChannel, State, Storage, UserDataManager,
VCsWatcher, all_commands, command, initialize_vcs, update_vcs,
BotDataManager, CommandRouter, GuildVoiceChannelToTextChannel, State, Storage, UserDataManager, VCsSender, all_commands, command, heat_seek, initialize_vcs, update_vcs
};
use secrecy::{ExposeSecret, SecretString};
use snafu::{OptionExt, ResultExt, Snafu};
@@ -336,7 +335,7 @@ async fn main() -> Result<(), MainError> {
let discord_client = Arc::new(discord_client);
let songbird = Arc::new(songbird);
let vcs_watcher = VCsWatcher::new(vcs);
let vcs_sender = VCsSender::new(vcs);
let bot_data = bot_data.into_inner();
let recording_data = recording_data.into_inner();
@@ -380,9 +379,11 @@ async fn main() -> Result<(), MainError> {
recording_data,
songbird,
user_data_manager,
vcs_watcher,
vcs_sender,
};
let heat_seeking = tokio::spawn(heat_seek(state.clone()));
if let Some(discord_status) = discord_status {
shards.iter().for_each(|shard| {
shard.command(
@@ -409,7 +410,6 @@ async fn main() -> Result<(), MainError> {
.map(|shard| handle_events(command_router.clone(), state.clone(), shard));
let run_shards = JoinSet::from_iter(run_shards);
let run_shards = run_shards.join_all();
tokio::pin!(run_shards);
tokio::spawn({
let cancellation_token = cancellation_token.clone();
@@ -432,13 +432,19 @@ async fn main() -> Result<(), MainError> {
}
});
let finished_naturally = async move {
heat_seeking.await.unwrap();
run_shards.await;
};
tokio::pin!(finished_naturally);
select! {
_ = &mut run_shards => {
_ = &mut finished_naturally => {
Ok(())
}
() = cancellation_token.cancelled() => {
tracing::warn!("waiting for tasks to gracefully shut down");
run_shards.await;
finished_naturally.await;
Err(MainError::Cancelled)
}
@@ -496,7 +502,7 @@ async fn handle_event(command_router: Arc<CommandRouter>, state: State, event: E
match event {
Event::VoiceStateUpdate(voice_state_update) => {
state
.vcs_watcher
.vcs_sender
.send_modify(|vcs| update_vcs(&voice_state_update, vcs));
}
Event::InteractionCreate(interaction_create) => {