cleanup
All checks were successful
tests / build (push) Successful in 1m4s
tests / fmt (push) Successful in 2m17s
tests / clippy (push) Successful in 2m14s
tests / pre-commit (push) Successful in 2m12s
tests / test (push) Successful in 2m27s
deploy / release-image (push) Successful in 6m11s
All checks were successful
tests / build (push) Successful in 1m4s
tests / fmt (push) Successful in 2m17s
tests / clippy (push) Successful in 2m14s
tests / pre-commit (push) Successful in 2m12s
tests / test (push) Successful in 2m27s
deploy / release-image (push) Successful in 6m11s
This commit is contained in:
@@ -1,10 +1,40 @@
|
||||
use crate::state::{State, StateRef};
|
||||
use anyhow::Context;
|
||||
use std::{error::Error, sync::Arc};
|
||||
use twilight_model::{
|
||||
gateway::payload::incoming::InteractionCreate,
|
||||
id::{marker::GuildMarker, Id},
|
||||
};
|
||||
|
||||
pub(crate) async fn leave_if_alone(
|
||||
guild_id: Id<GuildMarker>,
|
||||
state: State,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
||||
let user = state
|
||||
.cache
|
||||
.current_user()
|
||||
.context("Cannot get current user")?;
|
||||
let user_voice_state = state
|
||||
.cache
|
||||
.voice_state(user.id, guild_id)
|
||||
.context("Cannot get voice state")?;
|
||||
let channel = state
|
||||
.cache
|
||||
.channel(user_voice_state.channel_id())
|
||||
.context("Cannot get channel")?;
|
||||
let channel_voice_states = state
|
||||
.cache
|
||||
.voice_channel_states(channel.id)
|
||||
.context("Cannot get voice channel")?;
|
||||
let count = channel_voice_states.count();
|
||||
|
||||
// count is 1 if the bot is the only one in the channel
|
||||
if count == 1 {
|
||||
leave_channel(guild_id, Arc::clone(&state)).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn leave_channel(
|
||||
guild_id: Id<GuildMarker>,
|
||||
state: Arc<StateRef>,
|
||||
|
||||
Reference in New Issue
Block a user