Rustendo/src/util/user_util.rs

43 lines
1.3 KiB
Rust
Raw Normal View History

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()
}