diff --git a/Cargo.toml b/Cargo.toml index bc23239..639cb7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ typemap = "~0.3" serde_json = "*" utilities = { git = "http://dimov.cloud/hodasemi/utilities" } rusqlite = { version = "*", features = ["bundled"] } -serenity = { version = "0.7", default-features = false, features = [ "builder", "cache", "client", "framework", "gateway", "model", "standard_framework", "utils", "voice", "rustls_backend"]} +serenity = { version = "0.8", default-features = false, features = [ "builder", "cache", "client", "framework", "gateway", "model", "standard_framework", "utils", "voice", "rustls_backend"]} parking_lot = "*" failure = "*" hey_listen = "*" diff --git a/Penis1 b/Penis1 index dbaef54..a03d1e1 100644 Binary files a/Penis1 and b/Penis1 differ diff --git a/RUSSIAN VILLAGE BOYS - LOVE NETHERLANDS (MUSIC VIDEO) b/RUSSIAN VILLAGE BOYS - LOVE NETHERLANDS (MUSIC VIDEO) new file mode 100644 index 0000000..954f70c Binary files /dev/null and b/RUSSIAN VILLAGE BOYS - LOVE NETHERLANDS (MUSIC VIDEO) differ diff --git a/src/main.rs b/src/main.rs index 87a26bf..540b623 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,24 +11,16 @@ mod player; use serenity::{ framework::standard::{ help_commands, - macros::{check, command, group, help}, - Args, CheckResult, CommandGroup, CommandOptions, CommandResult, DispatchError, HelpOptions, - StandardFramework, + macros::{group, help}, + Args, CommandGroup, CommandResult, HelpOptions, StandardFramework, }, - model::{ - channel::{Channel, Message}, - gateway::Ready, - id::UserId, - }, - utils::{content_safe, ContentSafeOptions}, + model::{channel::Message, id::UserId}, }; // This imports `typemap`'s `Key` as `TypeMapKey`. use serenity::prelude::*; use std::sync::{Arc, Mutex}; -use std::thread; -use std::time::Duration; use player::prelude::*; use std::collections::HashSet; @@ -51,11 +43,9 @@ impl Default for Config { } } -group!({ - name: "general", - options: {}, - commands: [ip, list, pause, play, remove, skip, stop] -}); +#[group] +#[commands(ip, list, pause, play, remove, skip, stop)] +struct General; #[help] fn my_help( @@ -147,29 +137,6 @@ fn main() -> VerboseResult<()> { .help(&MY_HELP), ); - thread::spawn(move || loop { - { - let mut media_lock = media_data.lock().unwrap(); - - // check if there is a song currently being played - let mut is_playing = false; - - if let Some(song) = media_lock.song() { - let song_lock = song.lock(); - - if !song_lock.finished { - is_playing = true; - } - } - - if !is_playing { - MediaData::next_song(&mut media_lock).unwrap(); - } - } - - thread::sleep(Duration::from_millis(1500)); - }); - let _ = client .start() .map_err(|why| println!("Client ended: {:?}", why)); diff --git a/src/player/commands/play.rs b/src/player/commands/play.rs index a9530c0..64fc608 100644 --- a/src/player/commands/play.rs +++ b/src/player/commands/play.rs @@ -13,6 +13,12 @@ use serenity::{ use utilities::prelude::*; +use std::sync::Once; +use std::thread; +use std::time::Duration; + +static WATCHER: Once = Once::new(); + #[command] fn play(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult { if let Err(err) = channel_contains_author(ctx, msg) { @@ -29,31 +35,66 @@ fn play(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult { } }; - let mut media_lock = media.lock().unwrap(); + { + let mut media_lock = media.lock().unwrap(); - if args.len() == 0 { - if !check_for_continue(media_lock.song_mut()) { - msg.channel_id - .say(&ctx.http, "Must provide a URL to a video or audio")?; - } - } else { - let first_arg = args.current().unwrap(); - - if first_arg == "--local" { - handle_local_request(&mut media_lock, ctx, msg)?; - } else if first_arg.starts_with("http") { - handle_http_request(&mut media_lock, ctx, msg, first_arg)?; - } else { - let mut arg_list = args.single::()?; - - for arg in args.iter::() { - arg_list += &format!(" {}", arg?.trim()); + if args.len() == 0 { + if !check_for_continue(media_lock.song_mut()) { + msg.channel_id + .say(&ctx.http, "Must provide a URL to a video or audio")?; } + } else { + let first_arg = args.current().unwrap(); - handle_song_request(&mut media_lock, ctx, msg, &arg_list)? + if first_arg == "--local" { + handle_local_request(&mut media_lock, ctx, msg)?; + } else if first_arg.starts_with("http") { + handle_http_request(&mut media_lock, ctx, msg, first_arg)?; + } else { + let mut arg_list = args.single::()?; + + for arg in args.iter::() { + arg_list += &format!(" {}", arg?.trim()); + } + + handle_song_request(&mut media_lock, ctx, msg, &arg_list)? + } } } + WATCHER.call_once(|| { + let media_data = media.clone(); + let message_clone = msg.clone(); + let context_clone = ctx.clone(); + + thread::spawn(move || loop { + { + let mut media_lock = media_data.lock().unwrap(); + + // check if there is a song currently being played + let mut is_playing = false; + + if let Some(song) = media_lock.song() { + let song_lock = song.lock(); + + if !song_lock.finished { + is_playing = true; + } + } + + if !is_playing { + if let Err(err) = + MediaData::next_song(&context_clone, &mut media_lock, &message_clone) + { + println!("{}", err); + } + } + } + + thread::sleep(Duration::from_millis(1500)); + }); + }); + Ok(()) }