moover_rust/src/util/utilities.rs

41 lines
1.2 KiB
Rust
Raw Normal View History

use std::sync::Arc;
2024-12-09 14:40:46 +00:00
use serenity::{all::{ChannelId, ChannelType, CreateMessage, GuildChannel, GuildId, GuildRef, Message}, http::Http};
2024-12-09 14:40:46 +00:00
use crate::types;
use anyhow::Context;
2024-10-06 14:53:12 +00:00
pub async fn get_system_channel(guild_id: GuildId, http: &Http) -> anyhow::Result<ChannelId> {
return http.get_guild(guild_id).await?.system_channel_id
.context(format!("System channel of guild: {} not found", guild_id.get()));
2024-09-28 16:39:32 +00:00
}
pub async fn replace_msg(http: Arc<Http>, msg: Message, content: String) -> Result<Message, serenity::Error> {
msg.delete(http.clone()).await?;
return ChannelId::new(msg.channel_id.get()).send_message(http.clone(), CreateMessage::new().content(content)).await;
2024-12-09 14:40:46 +00:00
}
pub fn get_vc_names(guild: GuildRef) -> Vec<String> {
let mut result: Vec<String> = [].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<ChannelId> {
let mut result = None;
for (_, channel) in &guild.channels {
if channel.name == name {
result = Some(channel.id);
break;
}
}
result
}