format and restructure, began working on schedule

This commit is contained in:
2024-09-05 17:10:56 -04:00
parent 0f1a97770a
commit 794d8cc34e
34 changed files with 561 additions and 212 deletions

View File

@@ -1,7 +1,10 @@
use std::sync::Arc;
use reqwest::Url;
use serenity::all::{CommandInteraction, CreateInteractionResponse, CreateInteractionResponseMessage, EditInteractionResponse};
use serenity::all::{
CommandInteraction, CreateInteractionResponse, CreateInteractionResponseMessage,
EditInteractionResponse,
};
use serenity::client::Cache;
use serenity::model::prelude::{GuildId, ChannelId};
use serenity::model::user::User;
@@ -34,17 +37,16 @@ pub async fn join_voice_channel(
) -> SirenResult<ChannelId> {
let channel_id = find_voice_channel(cache, guild_id, user)?;
log::debug!("<{}> Joining channel {}", guild_id.get(), channel_id.get());
manager.join(guild_id.to_owned(), channel_id.to_owned()).await?;
manager
.join(guild_id.to_owned(), channel_id.to_owned())
.await?;
Ok(channel_id)
}
/**
* Leaves a voice channel.
*/
pub async fn leave_voice_channel(
manager: &Arc<Songbird>,
guild_id: &GuildId,
) -> SirenResult<()> {
pub async fn leave_voice_channel(manager: &Arc<Songbird>, guild_id: &GuildId) -> SirenResult<()> {
if manager.get(guild_id.to_owned()).is_some() {
log::debug!("<{}> Disconnecting from channel", guild_id.get());
manager.remove(*guild_id).await?;
@@ -52,11 +54,7 @@ pub async fn leave_voice_channel(
Ok(())
}
pub async fn create_response(
ctx: &Context,
command: &CommandInteraction,
content: String,
) {
pub async fn create_response(ctx: &Context, command: &CommandInteraction, content: String) {
let data = CreateInteractionResponseMessage::new().content(content.to_owned());
let builder = CreateInteractionResponse::Message(data);
match command.create_response(&ctx.http, builder).await {
@@ -67,11 +65,7 @@ pub async fn create_response(
};
}
pub async fn edit_response(
ctx: &Context,
command: &CommandInteraction,
content: String,
) {
pub async fn edit_response(ctx: &Context, command: &CommandInteraction, content: String) {
let builder = EditInteractionResponse::new().content(content.to_owned());
match command.edit_response(&ctx.http, builder).await {
Ok(_) => {}
@@ -115,6 +109,11 @@ fn find_voice_channel(
.and_then(|voice_state| voice_state.channel_id)
{
Some(channel) => Ok(channel),
None => return Err(SirenError::new(401, "User is not in a voice channel".to_string())),
None => {
return Err(SirenError::new(
401,
"User is not in a voice channel".to_string(),
))
}
}
}