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 = "*"
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 = "*"

BIN
Penis1

Binary file not shown.

Binary file not shown.

View file

@ -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));

View file

@ -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::<String>()?;
for arg in args.iter::<String>() {
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::<String>()?;
for arg in args.iter::<String>() {
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(())
}