fix: fixed import errors
feat: removed unneeded functions, added logging to user_util
This commit is contained in:
parent
57e9bca8f0
commit
4d6e665a3b
3 changed files with 43 additions and 56 deletions
|
@ -1,38 +1,50 @@
|
|||
use serenity::all::{ChannelId, Context, Guild, GuildId};
|
||||
use serenity::all::{ChannelId, Context, Guild, GuildId, UserId};
|
||||
|
||||
/// Get a guild by id
|
||||
pub fn get_guild(ctx: &Context, guild_id: &GuildId) -> Option<Guild> {
|
||||
let guild = ctx.cache.guild(guild_id)?;
|
||||
let guild = match ctx.cache.guild(guild_id) {
|
||||
Some(guild) => guild,
|
||||
None => {
|
||||
println!("Cannot get guild!");
|
||||
return None
|
||||
}
|
||||
}; // TODO This is always None for some reason
|
||||
|
||||
println!("Got guild: {:?}", guild.name);
|
||||
|
||||
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)?;
|
||||
pub fn get_vc_id(ctx: &Context, guild_id: &GuildId, user_id: &UserId) -> Option<ChannelId> {
|
||||
let guild = match get_guild(&ctx, guild_id){
|
||||
Some(guild) => guild,
|
||||
None => {
|
||||
println!("Cannot get guild while getting channel id!");
|
||||
return None
|
||||
}
|
||||
};
|
||||
|
||||
let channel_id = guild
|
||||
.voice_states
|
||||
.get(&ctx.cache.current_user().id)
|
||||
.and_then(|voice_state| voice_state.channel_id);
|
||||
.get(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 {
|
||||
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.
|
||||
if channel_id.is_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) -> Option<ChannelId> {
|
||||
let channel_id = get_channel_id(ctx, guild_id)?;
|
||||
println!("Got vc with id: {:?}", channel_id);
|
||||
|
||||
Some(channel_id)
|
||||
}
|
||||
|
||||
/// Check if the bot is connected to a voice channel
|
||||
pub fn is_self_connected_to_vc(ctx: &Context, guild_id: &GuildId) -> bool {
|
||||
let channel_id = get_self_vc_id(ctx, guild_id);
|
||||
|
||||
!channel_id.is_none()
|
||||
}
|
||||
|
||||
/// Get the current channel id of the bot
|
||||
pub fn get_self_vc_id(ctx: &Context, guild_id: &GuildId) -> Option<ChannelId> {
|
||||
let channel_id = get_vc_id(ctx, guild_id, &ctx.cache.current_user().id)?;
|
||||
|
||||
Some(channel_id)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue