From ba42e009f4ea6e43f417d3eda2efed84f0869bf3 Mon Sep 17 00:00:00 2001 From: Miguel da Mota Date: Fri, 23 Feb 2024 19:22:19 +0100 Subject: [PATCH 1/2] fix: `interaction_create` event --- src/main.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 725a7a0..a65cf25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,12 +41,12 @@ struct Handler; impl EventHandler for Handler { async fn interaction_create(&self, ctx: Context, interaction: Interaction) { if let Interaction::Command(command) = interaction { - let content = match command.data.name.as_str() { - "info" => Some(commands::info::run(&ctx, &command)), - "play" => Some(commands::play::run(&ctx, &command)), - "stop" => Some(commands::stop::run(&ctx, &command)), - _ => Some(respond_with_error(&ctx, &command)), - }; + let content = Some(match command.data.name.as_str() { + "info" => commands::info::run(&ctx, &command).await, + "play" => commands::play::run(&ctx, &command).await, + "stop" => commands::stop::run(&ctx, &command).await, + _ => respond_with_error(&ctx, &command).await, + }); if let Some(embed) = content { let data = CreateInteractionResponseMessage::new().embed(embed); @@ -72,25 +72,24 @@ impl EventHandler for Handler { pub async fn respond_with_error(_ctx: &Context, command: &CommandInteraction) -> CreateEmbed { let username = &command.user.name.as_str(); let current_time = Local::now().format("%Y-%m-%d @ %H:%M:%S"); - + CreateEmbed::new() .author(CreateEmbedAuthor::new("Rustendo")) .title("Command not found") .description("Cannot find the executed command") - .footer(CreateEmbedFooter::new(format!("> {} | {}", current_time, username))) + .footer(CreateEmbedFooter::new(format!( + "> {} | {}", + current_time, username } #[tokio::main] async fn main() { - println!(r"__________ __ .___ -\______ \__ __ _______/ |_ ____ ____ __| _/____ - | _/ | | ___/\ __\_/ __ \ / \ / __ |/ _ \ + println!( | | \ | |___ \ | | \ ___/ | | | /_/ ( <_> ) |____|_ /____/____ > |__| \___ >|___| |____ |\____/ \/ \/ \/ \/ \/ "); - // Load config let config = config::load().unwrap(); // Set status @@ -111,9 +110,7 @@ async fn main() { // // Shards will automatically attempt to reconnect, and will perform exponential backoff until // it reconnects. - if let Err(why) = client - .start() - .await { + if let Err(why) = client.start().await { println!("Client error: {why:?}"); } } -- 2.45.2 From 1fd1bc893c10f5929c8abb477d4b6c0068ce10a6 Mon Sep 17 00:00:00 2001 From: Miguel da Mota Date: Fri, 23 Feb 2024 19:25:19 +0100 Subject: [PATCH 2/2] chore: formatting --- src/main.rs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index a65cf25..6f003ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,14 @@ mod commands; -mod util; mod handler; +mod util; -use std::thread::current; use chrono::Local; use serenity::all::{CommandInteraction, OnlineStatus}; use serenity::async_trait; -use serenity::builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter, CreateInteractionResponse, CreateInteractionResponseMessage}; +use serenity::builder::{ + CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter, CreateInteractionResponse, + CreateInteractionResponseMessage, +}; use serenity::gateway::ActivityData; use serenity::model::application::{Command, Interaction}; use serenity::model::gateway::Ready; @@ -18,18 +20,9 @@ use util::config; // The voice client can be retrieved in any command using `songbird::get(ctx).await`. use songbird::SerenityInit; -// Event related imports to detect track creation failures. -use songbird::events::{Event, EventContext, EventHandler as VoiceEventHandler, TrackEvent}; - -// To turn user URLs into playable audio, we'll use yt-dlp. -use songbird::input::YoutubeDl; - // YtDl requests need an HTTP client to operate -- we'll create and store our own. use reqwest::Client as HttpClient; -// Import the `Context` to handle commands. -use serenity::client::Context; - struct HttpKey; impl TypeMapKey for HttpKey { type Value = HttpClient; @@ -80,15 +73,20 @@ pub async fn respond_with_error(_ctx: &Context, command: &CommandInteraction) -> .footer(CreateEmbedFooter::new(format!( "> {} | {}", current_time, username + ))) } #[tokio::main] async fn main() { println!( + r"__________ __ .___ +\______ \__ __ _______/ |_ ____ ____ __| _/____ + | _/ | | ___/\ __\_/ __ \ / \ / __ |/ _ \ | | \ | |___ \ | | \ ___/ | | | /_/ ( <_> ) - |____|_ /____/____ > |__| \___ >|___| |____ |\____/ - \/ \/ \/ \/ \/ -"); + |____|_ /____/____ > |__| \___ >|___| |____ |\____/ + \/ \/ \/ \/ \/ +" + ); // Load config let config = config::load().unwrap(); -- 2.45.2