Skip to content

Commit

Permalink
Fix breaking due to removal of channel cache
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Mar 13, 2024
1 parent a365e8a commit f436415
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 85 deletions.
107 changes: 38 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions tts_commands/src/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,11 @@ pub async fn invite(ctx: Context<'_>) -> CommandResult {
.replace("{channel_mention}", &invite_channel.mention().to_string())
.replace("{bot_mention}", &bot_mention)
} else {
cache
.channel(invite_channel)
let guild = cache.guild(config.main_server).try_unwrap()?;

guild
.channels
.get(&invite_channel)
.map(|c| {
ctx.gettext(
"Join {server_invite} and look in #{channel_name} to invite {bot_mention}",
Expand Down
33 changes: 19 additions & 14 deletions tts_events/src/voice_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,26 @@ pub async fn voice_state_update(
return Ok(());
}

let channel_members = ctx
.cache
.channel(old.channel_id.try_unwrap()?)
.try_unwrap()?
.members(&ctx.cache)?;

// Bot is in the voice channel being left from
if channel_members.iter().all(|m| m.user.id != bot_id) {
return Ok(());
{
let channel_id = old.channel_id.try_unwrap()?;
let guild = ctx.cache.guild(guild_id).try_unwrap()?;
let mut channel_members = guild.members.iter().filter(|(m, _)| {
guild
.voice_states
.get(m)
.is_some_and(|v| v.channel_id == Some(channel_id))
});

// Bot is in the voice channel being left from
if channel_members.clone().all(|(_, m)| m.user.id != bot_id) {
return Ok(());
}

// All the users in the vc are now bots
if channel_members.any(|(_, m)| !m.user.bot()) {
return Ok(());
};
}

// All the users in the vc are now bots
if channel_members.into_iter().any(|m| !m.user.bot()) {
return Ok(());
};

data.songbird.remove(guild_id).await.map_err(Into::into)
}

0 comments on commit f436415

Please sign in to comment.