update twilight, songbird and reqwest

This commit is contained in:
2025-03-05 03:27:03 +01:00
parent c6e34cf000
commit b1d6069d81
10 changed files with 887 additions and 345 deletions

View File

@@ -26,7 +26,7 @@ pub(crate) async fn delete(
.http
.channel_messages(msg.channel_id)
.before(msg.id)
.limit(n)?
.limit(n)
.await?
.model()
.await?;

View File

@@ -1,4 +1,4 @@
use crate::metadata::MetadataMap;
use crate::metadata::Metadata;
use crate::state::{State, StateRef};
use async_trait::async_trait;
use songbird::{Event, EventContext, EventHandler, TrackEvent};
@@ -99,9 +99,7 @@ impl EventHandler for TrackEndNotifier {
let mut call = call_lock.lock().await;
// get metadata from finished track
let old_typemap_lock = track_handle.typemap().read().await;
let old_metadata = old_typemap_lock.get::<MetadataMap>().unwrap();
let old_metadata = track_handle.data::<Metadata>();
// enqueue track
let handle = call.enqueue_with_preload(
old_metadata.src.clone().into(),
@@ -115,8 +113,8 @@ impl EventHandler for TrackEndNotifier {
);
// insert metadata into new track
let mut new_typemap = handle.typemap().write().await;
new_typemap.insert::<MetadataMap>(old_metadata.clone());
let mut _new_metadata = handle.data::<Metadata>();
_new_metadata = old_metadata.clone();
}
None
}

View File

@@ -1,5 +1,5 @@
use crate::commands::join::join_channel;
use crate::metadata::{Metadata, MetadataMap};
use crate::metadata::Metadata;
use crate::state::State;
use crate::{colors, db};
@@ -266,7 +266,7 @@ pub(crate) async fn play(
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.embeds(Some(&embeds))?
.embeds(Some(&embeds))
.await?;
Ok(())
}
@@ -348,7 +348,7 @@ pub(crate) async fn play_inner(
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.embeds(Some(&embeds))?
.embeds(Some(&embeds))
.await
.context("Could not send playlist loading message")?;
}
@@ -401,8 +401,8 @@ pub(crate) async fn play_inner(
}
}),
);
let mut x = handle.typemap().write().await;
x.insert::<MetadataMap>(Metadata {
let mut _x = handle.data::<Metadata>();
_x = Arc::new(Metadata {
title: metadata.title,
duration: metadata.duration,
url,
@@ -427,7 +427,7 @@ pub(crate) async fn play_inner(
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.embeds(Some(&embeds))?
.embeds(Some(&embeds))
.await?;
return Ok(());
}
@@ -440,7 +440,7 @@ pub(crate) async fn play_inner(
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.embeds(Some(&embeds))?
.embeds(Some(&embeds))
.await
.context("Could not send final play message")?;

View File

@@ -1,6 +1,6 @@
use songbird::tracks::TrackHandle;
use twilight_model::channel::message::component::{ActionRow, Button, ButtonStyle};
use twilight_model::channel::message::{Component, Embed, MessageFlags, ReactionType};
use twilight_model::channel::message::{Component, Embed, EmojiReactionType, MessageFlags};
use twilight_model::gateway::payload::incoming::InteractionCreate;
use twilight_model::http::interaction::InteractionResponse;
use twilight_model::http::interaction::InteractionResponseType;
@@ -8,7 +8,8 @@ use twilight_util::builder::embed::EmbedBuilder;
use twilight_util::builder::InteractionResponseDataBuilder;
use crate::colors;
use crate::{metadata::MetadataMap, state::State};
use crate::metadata::Metadata;
use crate::state::State;
use std::error::Error;
pub(crate) const TRACKS_PER_PAGE: usize = 5;
@@ -38,10 +39,7 @@ pub(crate) async fn build_queue_embeds(queue: &[TrackHandle], page: usize) -> Ve
.skip(TRACKS_PER_PAGE * page)
.take(TRACKS_PER_PAGE)
{
let map = track.typemap().read().await;
let metadata = map
.get::<MetadataMap>()
.expect("Could not get metadata map");
let metadata = track.data::<Metadata>();
message.push_str(
format!(
"* [{}]({})",
@@ -76,31 +74,34 @@ pub(crate) fn build_action_row(page: usize, n_pages: usize) -> Vec<Component> {
custom_id: Some(format!("page:{}", page as i32 - 1)),
style: ButtonStyle::Primary,
label: Some("Previous page".to_string()),
emoji: Some(ReactionType::Unicode {
emoji: Some(EmojiReactionType::Unicode {
name: "⬅️".to_string(),
}),
url: None,
disabled: page == 0,
sku_id: None,
}),
Component::Button(Button {
custom_id: Some(format!("page:{}", page)),
style: ButtonStyle::Primary,
label: Some("Refresh".to_string()),
emoji: Some(ReactionType::Unicode {
emoji: Some(EmojiReactionType::Unicode {
name: "🔄".to_string(),
}),
url: None,
disabled: false,
sku_id: None,
}),
Component::Button(Button {
custom_id: Some(format!("page:{}", page + 1)),
style: ButtonStyle::Primary,
label: Some("Next page".to_string()),
emoji: Some(ReactionType::Unicode {
emoji: Some(EmojiReactionType::Unicode {
name: "➡️".to_string(),
}),
url: None,
disabled: page >= n_pages - 1,
sku_id: None,
}),
],
})]
@@ -153,8 +154,8 @@ pub(crate) async fn queue(
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.embeds(Some(&embeds))?
.components(Some(&action_row))?
.embeds(Some(&embeds))
.components(Some(&action_row))
.await?;
Ok(())