use std::sync::Arc; use serenity::{all::{ChannelId, ChannelType, CreateMessage, GuildChannel, GuildId, GuildRef, Message}, http::Http}; use crate::types; use anyhow::Context; pub async fn get_system_channel(guild_id: GuildId, http: &Http) -> anyhow::Result { return http.get_guild(guild_id).await?.system_channel_id .context(format!("System channel of guild: {} not found", guild_id.get())); } pub async fn replace_msg(http: Arc, msg: Message, content: String) -> Result { msg.delete(http.clone()).await?; return ChannelId::new(msg.channel_id.get()).send_message(http.clone(), CreateMessage::new().content(content)).await; } pub fn get_vc_names(guild: GuildRef) -> Vec { let mut result: Vec = [].to_vec(); for (_, channel) in &guild.channels { if channel.kind == ChannelType::Voice { result.push(channel.name.clone()); } } result } pub fn get_channel_by_name(guild: GuildRef, name: String) -> Option { let mut result = None; for (_, channel) in &guild.channels { if channel.name == name { result = Some(channel.id); break; } } result }