From 806f2dcd50c7bd759a01a19685eaaaceb7e81dd8 Mon Sep 17 00:00:00 2001 From: Benjamin Sherriff Date: Sun, 3 Nov 2024 11:52:24 -0500 Subject: [PATCH] Removed audio gitignore --- .gitignore | 1 - .vscode/extensions.json | 6 ++++ .vscode/settings.json | 5 +--- Cargo.toml | 13 +++++---- src/api/mod.rs | 5 ++++ src/bot/commands/audio/mute.rs | 52 ++++++++++++++++++++++++++++++++++ src/main.rs | 22 +++++++++++++- 7 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 .vscode/extensions.json create mode 100644 src/api/mod.rs create mode 100644 src/bot/commands/audio/mute.rs diff --git a/.gitignore b/.gitignore index 0d5d013..3e73231 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ target/ **/Cargo.lock -audio/ logs/ settings.json .env*.local diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..0c59eef --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "rust-lang.rust-analyzer", + "ms-vscode.makefile-tools" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 86e7de6..6418298 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,3 @@ { - "rust-analyzer.linkedProjects": [ - "./Cargo.toml" - ], - "rust-analyzer.showUnlinkedFileNotification": false + "makefile.configureOnOpen": false } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 950486a..47f0e4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "siren" -version = "0.2.8" +version = "0.2.9" edition = "2021" authors = ["Ben Sherriff "] description = "A Discord bot for playing music" @@ -12,8 +12,8 @@ license = "GPL-3.0-or-later" dotenv = "0.15.0" log = "0.4.22" env_logger = "0.11.5" -serde = { version = "1.0.209", features = ["derive"] } -serde_json = "1.0.127" +serde = { version = "1.0.210", features = ["derive"] } +serde_json = "1.0.128" serenity = { version = "0.12.2", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "voice", "cache", "framework", "standard_framework"] } songbird = { version = "0.4.3", features = ["builtin-queue"] } symphonia = { version = "0.5.4", features = ["all"] } @@ -21,8 +21,9 @@ sqlx = { version = "0.8.2", features = ["runtime-tokio", "postgres", "chrono", " chrono = { version = "0.4.38", features = ["serde"] } reqwest = { version = "0.11", default-features = false, features = ["json"] } lazy_static = "1.5.0" -uuid = { version = "1.10.0", features = ["serde", "v4"] } -redis = { version = "0.26.1", features = ["tokio-comp", "connection-manager", "r2d2"] } +uuid = { version = "1.11.0", features = ["serde", "v4"] } +redis = { version = "0.27.4", features = ["tokio-comp", "connection-manager", "r2d2"] } rand = "0.8.5" tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread"] } -regex = "1.10.6" +regex = "1.11.0" +axum = "0.7.7" diff --git a/src/api/mod.rs b/src/api/mod.rs new file mode 100644 index 0000000..429f314 --- /dev/null +++ b/src/api/mod.rs @@ -0,0 +1,5 @@ +use axum::Router; + +pub fn get_routes() -> Router { + Router::new() +} diff --git a/src/bot/commands/audio/mute.rs b/src/bot/commands/audio/mute.rs new file mode 100644 index 0000000..ddb1550 --- /dev/null +++ b/src/bot/commands/audio/mute.rs @@ -0,0 +1,52 @@ +use serenity::{ + all::{CommandInteraction, CreateCommand}, + prelude::*, +}; + +use super::{edit_response, get_songbird, process_message}; + +pub async fn run(ctx: &Context, command: &CommandInteraction) { + // Create the initial response + process_message(&ctx, &command).await; + + // Get the songbird manager + let manager = get_songbird(ctx).await; + + // Extract the guild ID + let guild_id = match &command.guild_id { + Some(guild_id) => guild_id, + None => { + edit_response( + &ctx, + &command, + "Unable to find the current server ID".to_string(), + ) + .await; + return; + } + }; + + // Mute the track + if let Some(handler_lock) = manager.get(guild_id.to_owned()) { + let mut handler = handler_lock.lock().await; + let is_muted = handler.is_mute(); + match handler.mute(!is_muted).await { + Ok(_) => { + if is_muted { + log::debug!("<{guild_id}> Unmuted"); + edit_response(&ctx, &command, format!("Unmuted")).await; + } else { + log::debug!("<{guild_id}> Muted"); + edit_response(&ctx, &command, format!("Muted")).await; + } + } + Err(err) => { + edit_response(&ctx, &command, format!("Failed to mute: {}", err)).await; + } + } + } +} + +pub fn register() -> CreateCommand { + CreateCommand::new("mute").description("Mute/unmute Siren") +} diff --git a/src/main.rs b/src/main.rs index b61b039..984e601 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,16 @@ use std::env; use std::collections::HashSet; use std::sync::Arc; +use axum::Router; use serenity::http::Http; use serenity::prelude::*; use songbird::{SerenityInit, Songbird}; use reqwest::Client as HttpClient; +use tokio::net::TcpListener; use crate::bot::handler::Handler; +mod api; mod bot; mod data; mod error; @@ -27,6 +30,23 @@ async fn main() { return; }; + // Start API server + tokio::spawn(async move { + start_api().await; + }); + + // Start Discord bot + // start_bot().await; +} + +async fn start_api() { + let app = Router::new(); + let listener = TcpListener::bind("127.0.0.1:3000").await.unwrap(); + log::debug!("listening on {}", listener.local_addr().unwrap()); + axum::serve(listener, app).await.unwrap(); +} + +async fn start_bot() { let token: String = env::var("DISCORD_TOKEN").expect("Expected a token in the environment"); let intents: GatewayIntents = GatewayIntents::all(); @@ -86,7 +106,7 @@ async fn main() { shard_manager.shutdown_all().await; }); - // Start listening for events by starting a single shard + // Start Discord bot if let Err(why) = client.start_autosharded().await { log::error!("Client error: {why:?}"); }