forked from DiscordBots/Rustendo
feat: bot now plays songs, started to work on queue system
This commit is contained in:
parent
edc22a91f2
commit
a16d8a6b60
12 changed files with 289 additions and 130 deletions
|
@ -7,9 +7,9 @@ pub async fn run(_ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
|
|||
let username = command.user.name.as_str();
|
||||
|
||||
Embed::create(
|
||||
username,
|
||||
"",
|
||||
"Botendo v7\ndeveloped by [moonleay](https://moonleay.net)\n\nCheck out the repository: https://git.moonleay.net/DiscordBots/Rustendo",
|
||||
"Botendo v7",
|
||||
"developed by [moonleay](https://moonleay.net)\n\nCheck out the repository: https://git.moonleay.net/DiscordBots/Rustendo",
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
use serenity::all::{CommandDataOptionValue, CommandInteraction, Context};
|
||||
use serenity::builder::{CreateCommand, CreateCommandOption, CreateEmbed};
|
||||
use serenity::model::application::CommandOptionType;
|
||||
use crate::music::music_manager;
|
||||
|
||||
use crate::util::embed::Embed;
|
||||
use crate::util::user_util::{self, get_vc_id};
|
||||
|
||||
pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
|
||||
let username = command.user.name.as_str();
|
||||
let options = &command.data.options;
|
||||
|
||||
let query = command.data.options.first().and_then(|option| {
|
||||
|
||||
let query = options.first().and_then(|option| {
|
||||
if let CommandDataOptionValue::String(query) = &option.value {
|
||||
Some(query)
|
||||
} else {
|
||||
|
@ -28,40 +28,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
|
|||
}
|
||||
};
|
||||
|
||||
println!("Guild ID: {:?}", guild_id);
|
||||
|
||||
let connect_to = get_vc_id(ctx, &guild_id, &command.user.id).await.expect("Cannot get channel id");
|
||||
|
||||
let manager = &songbird::get(ctx)
|
||||
.await
|
||||
.expect("Cannot get Songbird.")
|
||||
.clone();
|
||||
|
||||
let self_channel = user_util::get_self_vc_id(ctx, &guild_id).await;
|
||||
if !user_util::is_self_connected_to_vc(ctx, &guild_id).await {
|
||||
// self is connected to vc, check if user is in same vc
|
||||
|
||||
if self_channel.is_none() {
|
||||
// Connect to VC
|
||||
manager
|
||||
.join(*guild_id, connect_to)
|
||||
.await
|
||||
.expect("Cannot connect>...");
|
||||
}
|
||||
|
||||
}
|
||||
let self_channel = self_channel.expect("Cannot get self channel");
|
||||
|
||||
// Check if user is in the same VC as the bot
|
||||
if self_channel != connect_to {
|
||||
return Embed::create(
|
||||
username,
|
||||
"You are not in my VC.",
|
||||
"Connect to my VC to control the music.",
|
||||
);
|
||||
}
|
||||
|
||||
Embed::create(username, "Searching...", format!("Looking for {:?}", query))
|
||||
music_manager::attempt_to_queue_song(&ctx, &guild_id, &command.user.id, &command.user.name, query.unwrap()).await
|
||||
}
|
||||
|
||||
pub fn register() -> CreateCommand {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use serenity::all::{CommandInteraction, Context};
|
||||
use serenity::builder::{CreateCommand, CreateEmbed};
|
||||
|
||||
use crate::music::music_manager;
|
||||
use crate::util::embed::Embed;
|
||||
use crate::util::user_util;
|
||||
|
||||
pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
|
||||
let username = command.user.name.as_str();
|
||||
|
@ -14,38 +13,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
|
|||
}
|
||||
};
|
||||
|
||||
if !user_util::is_self_connected_to_vc_cached(ctx, guild_id) {
|
||||
// Bot is not connectd to vc; no need to dc
|
||||
return Embed::create(
|
||||
username,
|
||||
"Bot is not connected",
|
||||
"And therefore I cannot stop playing.",
|
||||
);
|
||||
}
|
||||
|
||||
let manager = songbird::get(ctx)
|
||||
.await
|
||||
.expect("Cannot get Songbird")
|
||||
.clone();
|
||||
|
||||
let has_handler = manager.get(*guild_id).is_some();
|
||||
|
||||
if has_handler {
|
||||
if let Err(e) = manager.remove(*guild_id).await {
|
||||
return Embed::create(username, "There was an error", format!("Failed: {:?}", e));
|
||||
}
|
||||
return Embed::create(
|
||||
username,
|
||||
"I stopped and left\nJust like your girlfriend.",
|
||||
"",
|
||||
);
|
||||
}
|
||||
|
||||
Embed::create(
|
||||
username,
|
||||
"Bot is not connected",
|
||||
"And therefore I cannot stop playing.\nSomething happend, which shouldn't have.",
|
||||
)
|
||||
music_manager::attempt_to_stop(&ctx, &guild_id, &command.user.id, &command.user.name).await
|
||||
}
|
||||
|
||||
pub fn register() -> CreateCommand {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue