Add option for playing in separate channel
Play sounds in another channel even if not connected.
This commit is contained in:
parent
64e7eb4a53
commit
6307de331d
@ -1,4 +1,7 @@
|
|||||||
use poise::serenity::{builder::CreateActionRow, model::application::component::ButtonStyle};
|
use poise::{
|
||||||
|
serenity::{builder::CreateActionRow, model::application::component::ButtonStyle},
|
||||||
|
serenity_prelude::GuildChannel,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cmds::autocomplete_sound,
|
cmds::autocomplete_sound,
|
||||||
@ -14,23 +17,32 @@ pub async fn play(
|
|||||||
#[description = "Name or ID of sound to play"]
|
#[description = "Name or ID of sound to play"]
|
||||||
#[autocomplete = "autocomplete_sound"]
|
#[autocomplete = "autocomplete_sound"]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[description = "Channel to play in (default: your current voice channel)"] channel: Option<
|
||||||
|
GuildChannel,
|
||||||
|
>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
ctx.defer().await?;
|
ctx.defer().await?;
|
||||||
|
|
||||||
let guild = ctx.guild().unwrap();
|
let guild = ctx.guild().unwrap();
|
||||||
|
|
||||||
ctx.say(
|
if channel.as_ref().map_or(false, |c| c.is_text_based()) {
|
||||||
play_from_query(
|
ctx.say("The channel specified is not a voice channel.")
|
||||||
&ctx.discord(),
|
.await?;
|
||||||
&ctx.data(),
|
} else {
|
||||||
guild,
|
ctx.say(
|
||||||
ctx.author().id,
|
play_from_query(
|
||||||
&name,
|
&ctx.discord(),
|
||||||
false,
|
&ctx.data(),
|
||||||
|
guild,
|
||||||
|
ctx.author().id,
|
||||||
|
channel.map(|c| c.id),
|
||||||
|
&name,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await,
|
||||||
)
|
)
|
||||||
.await,
|
.await?;
|
||||||
)
|
}
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -224,6 +236,7 @@ pub async fn loop_play(
|
|||||||
&ctx.data(),
|
&ctx.data(),
|
||||||
guild,
|
guild,
|
||||||
ctx.author().id,
|
ctx.author().id,
|
||||||
|
None,
|
||||||
&name,
|
&name,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
|
@ -142,6 +142,7 @@ SELECT name, id, public, server_id, uploader_id
|
|||||||
&data,
|
&data,
|
||||||
guild_id.to_guild_cached(&ctx).unwrap(),
|
guild_id.to_guild_cached(&ctx).unwrap(),
|
||||||
component.user.id,
|
component.user.id,
|
||||||
|
None,
|
||||||
&component.data.custom_id,
|
&component.data.custom_id,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
11
src/utils.rs
11
src/utils.rs
@ -104,15 +104,18 @@ pub async fn play_from_query(
|
|||||||
data: &Data,
|
data: &Data,
|
||||||
guild: Guild,
|
guild: Guild,
|
||||||
user_id: UserId,
|
user_id: UserId,
|
||||||
|
channel: Option<ChannelId>,
|
||||||
query: &str,
|
query: &str,
|
||||||
loop_: bool,
|
loop_: bool,
|
||||||
) -> String {
|
) -> String {
|
||||||
let guild_id = guild.id;
|
let guild_id = guild.id;
|
||||||
|
|
||||||
let channel_to_join = guild
|
let channel_to_join = channel.or_else(|| {
|
||||||
.voice_states
|
guild
|
||||||
.get(&user_id)
|
.voice_states
|
||||||
.and_then(|voice_state| voice_state.channel_id);
|
.get(&user_id)
|
||||||
|
.and_then(|voice_state| voice_state.channel_id)
|
||||||
|
});
|
||||||
|
|
||||||
match channel_to_join {
|
match channel_to_join {
|
||||||
Some(user_channel) => {
|
Some(user_channel) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user