2024-02-16 20:54:07 +00:00
|
|
|
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-02-16 20:54:07 +00:00
|
|
|
|
2024-12-09 14:40:46 +00:00
|
|
|
use crate::types;
|
2024-02-16 20:54:07 +00:00
|
|
|
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> {
|
2024-02-16 20:54:07 +00:00
|
|
|
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
|
2024-02-16 20:54:07 +00:00
|
|
|
}
|