feat: being moved between voice channels

This commit is contained in:
Zomatree
2025-03-01 22:09:40 +00:00
parent 9c2cc8736c
commit 8b5e085232
13 changed files with 106 additions and 49 deletions

View File

@@ -258,11 +258,16 @@ pub enum EventV1 {
user: String,
from: String,
to: String,
state: UserVoiceState
},
UserVoiceStateUpdate {
id: String,
channel_id: String,
data: PartialUserVoiceState,
},
UserMoveVoiceChannel {
node: String,
token: String
}
}

View File

@@ -29,7 +29,7 @@ pub async fn raise_if_in_voice(user: &User, target: &str) -> Result<()> {
.to_internal_error()?
> 0
{
Err(create_error!(AlreadyInVoiceChannel))
Err(create_error!(NotConnected))
} else {
Ok(())
}
@@ -45,7 +45,7 @@ pub async fn set_channel_node(channel: &str, node: &str) -> Result<()> {
Ok(())
}
pub async fn get_channel_node(channel: &str) -> Result<String> {
pub async fn get_channel_node(channel: &str) -> Result<Option<String>> {
get_connection()
.await?
.get(format!("node:{channel}"))
@@ -61,6 +61,22 @@ pub async fn get_user_voice_channels(user_id: &str) -> Result<Vec<String>> {
.to_internal_error()
}
pub async fn set_user_moved_from_voice(old_channel: &str, new_channel: &str, user_id: &str) -> Result<()> {
get_connection()
.await?
.set_ex(format!("moved_to:{user_id}:{new_channel}"), old_channel, 10)
.await
.to_internal_error()
}
pub async fn get_user_moved_from_voice(channel_id: &str, user_id: &str) -> Result<Option<String>> {
get_connection()
.await?
.get(format!("moved_to:{user_id}:{channel_id}"))
.await
.to_internal_error()
}
pub async fn is_in_voice_channel(user_id: &str, channel_id: &str) -> Result<bool> {
get_connection()
.await?
@@ -275,7 +291,7 @@ pub async fn get_channel_voice_state(channel: &Channel) -> Result<Option<v0::Cha
if let Some(members) = members {
let mut participants = Vec::with_capacity(members.len());
let node = get_channel_node(channel.id()).await?;
let node = get_channel_node(channel.id()).await?.unwrap();
for user_id in members {
if let Some(voice_state) = get_voice_state(channel.id(), server, &user_id).await? {
@@ -312,7 +328,7 @@ pub async fn move_user(user: &str, from: &str, to: &str) -> Result<()> {
}
pub async fn sync_voice_permissions(db: &Database, voice_client: &VoiceClient, channel: &Channel, server: Option<&Server>, role_id: Option<&str>) -> Result<()> {
let node = get_channel_node(channel.id()).await?;
let node = get_channel_node(channel.id()).await?.unwrap();
for user_id in get_voice_channel_members(channel.id()).await?.iter().flatten() {
let user = Reference::from_unchecked(user_id.clone()).as_user(db).await?;

View File

@@ -97,7 +97,7 @@ impl VoiceClient {
channel.id(),
CreateRoomOptions {
max_participants: voice.max_users.unwrap_or(u32::MAX),
empty_timeout: 5 * 60, // 5 minutes
empty_timeout: 5 * 60, // 5 minutes,
..Default::default()
},
)