Rustendo/src/util/user_util.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

2024-03-03 22:30:31 +00:00
use serenity::all::{ChannelId, Context, Guild, GuildId};
/// Get a guild by id
pub fn get_guild(ctx: &Context, guild_id: &GuildId) -> Option<Guild> {
let guild = ctx.cache.guild(guild_id)?;
Some(guild.clone())
}
/// Get the current channel id of the bot
pub fn get_channel_id(ctx: &Context, guild_id: &GuildId) -> Option<ChannelId> {
let guild = get_guild(ctx, guild_id)?;
let channel_id = guild
.voice_states
.get(&ctx.cache.current_user().id)
.and_then(|voice_state| voice_state.channel_id);
Some(channel_id.unwrap())
}
pub fn is_self_connected_to_vc(ctx: &Context, guild_id: &GuildId) -> bool {
2024-03-03 22:30:31 +00:00
let channel_id = get_channel_id(ctx, guild_id);
// TODO: There has to be a way to improve this. This is bad code and it should be optimized.
2024-03-03 22:30:31 +00:00
if channel_id.is_none() {
return false;
}
true
}
// This whole file is jank. I have to rewrite this once I know Rust better
2024-03-03 22:30:31 +00:00
pub fn get_self_vc_id(ctx: &Context, guild_id: &GuildId) -> Option<ChannelId> {
let channel_id = get_channel_id(ctx, guild_id)?;
Some(channel_id)
}