mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 12:26:10 +01:00
music commands plus activity
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
use serenity::framework::standard::Args;
|
||||
use serenity::framework::standard::{
|
||||
macros::command,
|
||||
CommandResult,
|
||||
};
|
||||
use serenity::framework::standard::{macros::command, CommandResult};
|
||||
|
||||
use reqwest::Client as HttpClient;
|
||||
|
||||
@@ -13,8 +10,10 @@ use serenity::prelude::TypeMapKey;
|
||||
use serenity::model::prelude::*;
|
||||
|
||||
use songbird::input::YoutubeDl;
|
||||
use songbird::TrackEvent;
|
||||
|
||||
use crate::commands::misc::check_msg;
|
||||
use crate::commands::music::misc::TrackErrorNotifier;
|
||||
|
||||
pub struct HttpKey;
|
||||
|
||||
@@ -25,6 +24,25 @@ impl TypeMapKey for HttpKey {
|
||||
#[command]
|
||||
#[only_in(guilds)]
|
||||
async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
let (guild_id, channel_id) = {
|
||||
let guild = msg.guild(&ctx.cache).unwrap();
|
||||
let channel_id = guild
|
||||
.voice_states
|
||||
.get(&msg.author.id)
|
||||
.and_then(|voice_state| voice_state.channel_id);
|
||||
|
||||
(guild.id, channel_id)
|
||||
};
|
||||
|
||||
let connect_to = match channel_id {
|
||||
Some(channel) => channel,
|
||||
None => {
|
||||
check_msg(msg.reply(ctx, "Not in a voice channel").await);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let url = match args.single::<String>() {
|
||||
Ok(url) => url,
|
||||
Err(_) => {
|
||||
@@ -40,8 +58,6 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
|
||||
let do_search = !url.starts_with("http");
|
||||
|
||||
let guild_id = msg.guild_id.unwrap();
|
||||
|
||||
let http_client = {
|
||||
let data = ctx.data.read().await;
|
||||
data.get::<HttpKey>()
|
||||
@@ -54,6 +70,11 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
.expect("Client placed at init")
|
||||
.clone();
|
||||
|
||||
if let Ok(handler_lock) = manager.join(guild_id, connect_to).await {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||
}
|
||||
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user