WIP: continued working on play and stop command, there are still errors and it does not work, it does compile though

This commit is contained in:
moonleay 2024-02-24 03:05:27 +01:00
parent a1a78d6598
commit 50202dfdf5
Signed by: moonleay
GPG key ID: 82667543CCD715FB
5 changed files with 132 additions and 27 deletions

View file

@ -1 +1,2 @@
pub mod config;
pub mod config;
pub mod user_util;

42
src/util/user_util.rs Normal file
View file

@ -0,0 +1,42 @@
use serenity::all::{ChannelId, Context, CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter, GuildId};
pub fn is_self_connected_to_vc(ctx: &Context, guild_id: &GuildId) -> bool {
let self_id = &ctx.cache.current_user().id;
let (_guild_id, channel_id) = {
let guild = &ctx.cache.guild(guild_id).unwrap();
// This may be unsafe, idk not sure yet
let channel_id = guild
.voice_states
.get(self_id)
.and_then(|voice_state| voice_state.channel_id);
(guild.id, channel_id)
};
// TODO: There has to be a way to improve this. This is bad code and it should be optimized.
let connect_to = match channel_id {
Some(channel) => channel,
None => {
return false
},
};
true
}
// This whole file is jank. I have to rewrite this once I know Rust better
pub fn get_self_vc_id(ctx: &Context, guild_id: &GuildId) -> ChannelId {
let self_id = &ctx.cache.current_user().id;
let (guild_id, channel_id) = {
let guild = &ctx.cache.guild(guild_id).unwrap();
// This may be unsafe, idk not sure yet
let channel_id = guild
.voice_states
.get(&self_id)
.and_then(|voice_state| voice_state.channel_id);
(guild.id, channel_id)
};
channel_id.unwrap()
}