41 lines
No EOL
1.2 KiB
Rust
41 lines
No EOL
1.2 KiB
Rust
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<ChannelId> {
|
|
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<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;
|
|
}
|
|
|
|
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
|
|
} |