Fix update to newer version

This commit is contained in:
hodasemi 2020-02-09 16:36:33 +01:00
parent 8ecca44e76
commit 3f6fc4e4e0
5 changed files with 67 additions and 59 deletions

View file

@ -9,7 +9,7 @@ typemap = "~0.3"
serde_json = "*" serde_json = "*"
utilities = { git = "http://dimov.cloud/hodasemi/utilities" } utilities = { git = "http://dimov.cloud/hodasemi/utilities" }
rusqlite = { version = "*", features = ["bundled"] } 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 = "*" parking_lot = "*"
failure = "*" failure = "*"
hey_listen = "*" hey_listen = "*"

BIN
Penis1

Binary file not shown.

Binary file not shown.

View file

@ -11,24 +11,16 @@ mod player;
use serenity::{ use serenity::{
framework::standard::{ framework::standard::{
help_commands, help_commands,
macros::{check, command, group, help}, macros::{group, help},
Args, CheckResult, CommandGroup, CommandOptions, CommandResult, DispatchError, HelpOptions, Args, CommandGroup, CommandResult, HelpOptions, StandardFramework,
StandardFramework,
}, },
model::{ model::{channel::Message, id::UserId},
channel::{Channel, Message},
gateway::Ready,
id::UserId,
},
utils::{content_safe, ContentSafeOptions},
}; };
// This imports `typemap`'s `Key` as `TypeMapKey`. // This imports `typemap`'s `Key` as `TypeMapKey`.
use serenity::prelude::*; use serenity::prelude::*;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
use player::prelude::*; use player::prelude::*;
use std::collections::HashSet; use std::collections::HashSet;
@ -51,11 +43,9 @@ impl Default for Config {
} }
} }
group!({ #[group]
name: "general", #[commands(ip, list, pause, play, remove, skip, stop)]
options: {}, struct General;
commands: [ip, list, pause, play, remove, skip, stop]
});
#[help] #[help]
fn my_help( fn my_help(
@ -147,29 +137,6 @@ fn main() -> VerboseResult<()> {
.help(&MY_HELP), .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 let _ = client
.start() .start()
.map_err(|why| println!("Client ended: {:?}", why)); .map_err(|why| println!("Client ended: {:?}", why));

View file

@ -13,6 +13,12 @@ use serenity::{
use utilities::prelude::*; use utilities::prelude::*;
use std::sync::Once;
use std::thread;
use std::time::Duration;
static WATCHER: Once = Once::new();
#[command] #[command]
fn play(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult { fn play(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
if let Err(err) = channel_contains_author(ctx, msg) { if let Err(err) = channel_contains_author(ctx, msg) {
@ -29,6 +35,7 @@ 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 args.len() == 0 {
@ -53,6 +60,40 @@ fn play(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
handle_song_request(&mut media_lock, ctx, msg, &arg_list)? 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(()) Ok(())
} }