use discord embeds in messages
All checks were successful
tests / fmt (push) Successful in 3m17s
tests / fmt (pull_request) Successful in 2m35s
tests / test (push) Successful in 3m17s
tests / test (pull_request) Successful in 2m39s
tests / build (push) Successful in 3m26s
tests / clippy (push) Successful in 3m33s
tests / clippy (pull_request) Successful in 2m57s
tests / build (pull_request) Successful in 3m5s
tests / pre-commit (push) Successful in 4m16s
tests / pre-commit (pull_request) Successful in 1m29s
All checks were successful
tests / fmt (push) Successful in 3m17s
tests / fmt (pull_request) Successful in 2m35s
tests / test (push) Successful in 3m17s
tests / test (pull_request) Successful in 2m39s
tests / build (push) Successful in 3m26s
tests / clippy (push) Successful in 3m33s
tests / clippy (pull_request) Successful in 2m57s
tests / build (pull_request) Successful in 3m5s
tests / pre-commit (push) Successful in 4m16s
tests / pre-commit (pull_request) Successful in 1m29s
This commit is contained in:
@@ -9,6 +9,7 @@ use tokio::process::Command;
|
|||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
use twilight_model::application::interaction::Interaction;
|
use twilight_model::application::interaction::Interaction;
|
||||||
use twilight_model::http::interaction::{InteractionResponse, InteractionResponseType};
|
use twilight_model::http::interaction::{InteractionResponse, InteractionResponseType};
|
||||||
|
use twilight_util::builder::embed::EmbedBuilder;
|
||||||
use twilight_util::builder::InteractionResponseDataBuilder;
|
use twilight_util::builder::InteractionResponseDataBuilder;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
@@ -23,9 +24,13 @@ pub(crate) async fn play(
|
|||||||
interaction.author(),
|
interaction.author(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let interaction_response_data = InteractionResponseDataBuilder::new()
|
let content = format!("Adding track(s) to the queue: {}", query);
|
||||||
.content(format!("Adding track(s) to queue: {}", query))
|
let yellow = 0xFE_E7_5C;
|
||||||
.build();
|
let embeds = vec![EmbedBuilder::new()
|
||||||
|
.description(content)
|
||||||
|
.color(yellow)
|
||||||
|
.build()];
|
||||||
|
let interaction_response_data = InteractionResponseDataBuilder::new().embeds(embeds).build();
|
||||||
let response = InteractionResponse {
|
let response = InteractionResponse {
|
||||||
kind: InteractionResponseType::ChannelMessageWithSource,
|
kind: InteractionResponseType::ChannelMessageWithSource,
|
||||||
data: Some(interaction_response_data),
|
data: Some(interaction_response_data),
|
||||||
@@ -54,12 +59,7 @@ pub(crate) async fn play(
|
|||||||
|
|
||||||
debug!("query: {:?}", query);
|
debug!("query: {:?}", query);
|
||||||
|
|
||||||
// handle playlist links
|
let urls = get_playlist_urls(query).await?;
|
||||||
let urls = if query.contains("list=") {
|
|
||||||
get_playlist_urls(query).await?
|
|
||||||
} else {
|
|
||||||
vec![query]
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(call_lock) = state.songbird.get(guild_id) {
|
if let Some(call_lock) = state.songbird.get(guild_id) {
|
||||||
let call = call_lock.lock().await;
|
let call = call_lock.lock().await;
|
||||||
@@ -71,7 +71,7 @@ pub(crate) async fn play(
|
|||||||
let mut src = YoutubeDl::new(reqwest::Client::new(), url.to_string());
|
let mut src = YoutubeDl::new(reqwest::Client::new(), url.to_string());
|
||||||
if let Ok(metadata) = src.aux_metadata().await {
|
if let Ok(metadata) = src.aux_metadata().await {
|
||||||
debug!("metadata: {:?}", metadata);
|
debug!("metadata: {:?}", metadata);
|
||||||
tracks_added.push(metadata.title.clone());
|
tracks_added.push((url.clone(), metadata.title.clone()));
|
||||||
|
|
||||||
if let Some(call_lock) = state.songbird.get(guild_id) {
|
if let Some(call_lock) = state.songbird.get(guild_id) {
|
||||||
let mut call = call_lock.lock().await;
|
let mut call = call_lock.lock().await;
|
||||||
@@ -89,6 +89,7 @@ pub(crate) async fn play(
|
|||||||
x.insert::<MetadataMap>(Metadata {
|
x.insert::<MetadataMap>(Metadata {
|
||||||
title: metadata.title,
|
title: metadata.title,
|
||||||
duration: metadata.duration,
|
duration: metadata.duration,
|
||||||
|
url,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,23 +99,31 @@ pub(crate) async fn play(
|
|||||||
match num_tracks_added {
|
match num_tracks_added {
|
||||||
0 => {}
|
0 => {}
|
||||||
1 => {
|
1 => {
|
||||||
content = format!(
|
let track = tracks_added.first().unwrap().clone();
|
||||||
"Added \"{}\" to queue",
|
let title = track.1.unwrap();
|
||||||
tracks_added.first().unwrap().clone().unwrap()
|
let url = track.0;
|
||||||
);
|
content = format!("Added [{}]({}) to the queue", title, url);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
content = format!("Added {} tracks to queue:\n", num_tracks_added);
|
content = format!("Added {} tracks to the queue:\n", num_tracks_added);
|
||||||
for track in tracks_added.into_iter().take(num_tracks_added.min(3)) {
|
for track in tracks_added.into_iter().take(num_tracks_added.min(3)) {
|
||||||
content.push_str(&format!(" \"{}\"\n", track.unwrap()));
|
let title = track.1.unwrap();
|
||||||
|
let url = track.0;
|
||||||
|
content.push_str(&format!(" \"[{}]({})\"\n", title, url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let blurple = 0x58_65_F2;
|
||||||
|
let embeds = vec![EmbedBuilder::new()
|
||||||
|
.description(content)
|
||||||
|
.color(blurple)
|
||||||
|
.build()];
|
||||||
state
|
state
|
||||||
.http
|
.http
|
||||||
.interaction(interaction.application_id)
|
.interaction(interaction.application_id)
|
||||||
.update_response(&interaction.token)
|
.update_response(&interaction.token)
|
||||||
.content(Some(&content))
|
.embeds(Some(&embeds))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use twilight_model::{
|
|||||||
application::interaction::Interaction, channel::message::MessageFlags,
|
application::interaction::Interaction, channel::message::MessageFlags,
|
||||||
http::interaction::InteractionResponse,
|
http::interaction::InteractionResponse,
|
||||||
};
|
};
|
||||||
|
use twilight_util::builder::embed::EmbedBuilder;
|
||||||
use twilight_util::builder::InteractionResponseDataBuilder;
|
use twilight_util::builder::InteractionResponseDataBuilder;
|
||||||
|
|
||||||
use crate::{metadata::MetadataMap, state::State};
|
use crate::{metadata::MetadataMap, state::State};
|
||||||
@@ -35,8 +36,9 @@ pub(crate) async fn queue(
|
|||||||
let metadata = map.get::<MetadataMap>().unwrap();
|
let metadata = map.get::<MetadataMap>().unwrap();
|
||||||
message.push_str(
|
message.push_str(
|
||||||
format!(
|
format!(
|
||||||
"* `{}",
|
"* [{}]({})",
|
||||||
metadata.title.clone().unwrap_or("Unknown".to_string()),
|
metadata.title.clone().unwrap_or("Unknown".to_string()),
|
||||||
|
metadata.url,
|
||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
);
|
);
|
||||||
@@ -54,12 +56,13 @@ pub(crate) async fn queue(
|
|||||||
message.push_str(format!("{:02}:{:02}", minutes, seconds).as_str());
|
message.push_str(format!("{:02}:{:02}", minutes, seconds).as_str());
|
||||||
message.push(')');
|
message.push(')');
|
||||||
}
|
}
|
||||||
message.push_str("`\n");
|
message.push('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let embeds = vec![EmbedBuilder::new().description(&message).build()];
|
||||||
let interaction_response_data = InteractionResponseDataBuilder::new()
|
let interaction_response_data = InteractionResponseDataBuilder::new()
|
||||||
.content(&message)
|
|
||||||
.flags(MessageFlags::EPHEMERAL)
|
.flags(MessageFlags::EPHEMERAL)
|
||||||
|
.embeds(embeds)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let response = InteractionResponse {
|
let response = InteractionResponse {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::time::Duration;
|
|||||||
pub(crate) struct Metadata {
|
pub(crate) struct Metadata {
|
||||||
pub(crate) title: Option<String>,
|
pub(crate) title: Option<String>,
|
||||||
pub(crate) duration: Option<Duration>,
|
pub(crate) duration: Option<Duration>,
|
||||||
|
pub(crate) url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct MetadataMap;
|
pub(crate) struct MetadataMap;
|
||||||
|
|||||||
Reference in New Issue
Block a user