Skip to content

Commit

Permalink
Merge pull request #134 from jontze/fix/update-songbird-serenity
Browse files Browse the repository at this point in the history
Update Songbird to v0.4.0 and serenity to v0.12.0
  • Loading branch information
jontze authored Dec 1, 2023
2 parents dd17a8a + e70e482 commit f0a75c3
Show file tree
Hide file tree
Showing 28 changed files with 365 additions and 310 deletions.
2 changes: 1 addition & 1 deletion .yt-dlprc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023.07.06
2023.11.16
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"cadency",
"examples/*"
]
resolver = "2"

[workspace.dependencies]
env_logger = "0.10.0"
Expand All @@ -16,13 +17,13 @@ serde_json = "1.0.99"
derive_builder = "0.12.0"

[workspace.dependencies.serenity]
version = "0.11.6"
version = "0.12.0"
default-features = false
features = ["client", "gateway", "rustls_backend", "model", "voice", "cache"]

[workspace.dependencies.songbird]
version = "0.3.2"
features = ["builtin-queue", "yt-dlp"]
version = "0.4.0"
features = ["builtin-queue"]

[workspace.dependencies.tokio]
version = "1.29.0"
Expand All @@ -35,4 +36,8 @@ features = ["derive"]
[workspace.dependencies.reqwest]
version = "0.11.18"
default-features = false
features = ["rustls-tls"]
features = ["rustls-tls", "json"]

[workspace.dependencies.symphonia]
version = "0.5"
features = ["all-formats"]
18 changes: 3 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM lukemathwalker/cargo-chef:latest-rust-1.68-slim-bullseye as build_base
FROM lukemathwalker/cargo-chef:latest-rust-1.74-slim-bullseye as build_base

FROM build_base as planner
WORKDIR /cadency
Expand Down Expand Up @@ -28,28 +28,16 @@ ENV CARGO_TERM_COLOR=always
# Build and cache only the cadency app with the previously builded dependencies
RUN cargo build --release --bin cadency

# Downloads yt-dlp
FROM bitnami/minideb:bullseye as packages
# Downloads both ffmpeg and yt-dlp
WORKDIR /packages
COPY --from=builder /cadency/.yt-dlprc .
# tar: (x) extract, (J) from .xz, (f) a file. (--wildcards */bin/ffmpeg) any path with /bin/ffmpeg, (--transform) remove all previous paths
# FFMPEG is staticly compiled, so platform specific
# If statement: converts architecture from docker to a correct link. Default is amd64 = desktop 64 bit
ARG TARGETARCH
RUN if [ "$TARGETARCH" = "arm64" ]; then \
export LINK="https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linuxarm64-gpl.tar.xz"; \
else \
export LINK="https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz"; \
fi && \
apt-get update && apt-get install -y curl tar xz-utils && \
curl -L $LINK > ffmpeg.tar.xz && \
tar -xJf ffmpeg.tar.xz --wildcards */bin/ffmpeg --transform='s/^.*\///' && rm ffmpeg.tar.xz
RUN YTDLP_VERSION=$(cat .yt-dlprc) && \
curl -L https://github.com/yt-dlp/yt-dlp/releases/download/$YTDLP_VERSION/yt-dlp_linux > yt-dlp && chmod +x yt-dlp

FROM bitnami/minideb:bullseye as python-builder
# Based on: https://github.com/zarmory/docker-python-minimal/blob/master/Dockerfile
# Removes Python build and developmenttools like pip.
FROM bitnami/minideb:bullseye as python-builder
RUN apt-get update && apt-get install -y python3-minimal binutils && \
rm -rf /usr/local/lib/python*/ensurepip && \
rm -rf /usr/local/lib/python*/idlelib && \
Expand Down
2 changes: 1 addition & 1 deletion cadency_codegen/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub(crate) fn impl_command_baseline(derive_input: DeriveInput) -> TokenStream {
let deferred = command.deferred;
quote! {
use cadency_core::{CadencyCommandBaseline as __CadencyCommandBaseline, CadencyCommandOption as __CadencyCommandOption};
use serenity::model::application::command::CommandOptionType as __CommandOptionType;
use serenity::model::application::CommandOptionType as __CommandOptionType;
impl __CadencyCommandBaseline for #struct_name {
fn name(&self) -> String {
String::from(#command_name)
Expand Down
6 changes: 2 additions & 4 deletions cadency_commands/src/fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use cadency_core::{
use serenity::{
async_trait,
client::Context,
model::application::interaction::application_command::{
ApplicationCommandInteraction, CommandDataOptionValue,
},
model::application::{CommandDataOptionValue, CommandInteraction},
};

#[derive(CommandBaseline, Default)]
Expand All @@ -34,7 +32,7 @@ impl CadencyCommand for Fib {
async fn execute<'a>(
&self,
_ctx: &Context,
command: &'a mut ApplicationCommandInteraction,
command: &'a mut CommandInteraction,
response_builder: &'a mut ResponseBuilder,
) -> Result<Response, CadencyError> {
let number = utils::get_option_value_at_position(command.data.options.as_ref(), 0)
Expand Down
7 changes: 2 additions & 5 deletions cadency_commands/src/inspire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use cadency_core::{
response::{Response, ResponseBuilder},
CadencyCommand, CadencyError,
};
use serenity::{
async_trait, client::Context,
model::application::interaction::application_command::ApplicationCommandInteraction,
};
use serenity::{async_trait, client::Context, model::application::CommandInteraction};

#[derive(CommandBaseline, Default)]
#[description = "Say something really inspiring!"]
Expand All @@ -26,7 +23,7 @@ impl CadencyCommand for Inspire {
async fn execute<'a>(
&self,
_ctx: &Context,
_command: &'a mut ApplicationCommandInteraction,
_command: &'a mut CommandInteraction,
response_builder: &'a mut ResponseBuilder,
) -> Result<Response, CadencyError> {
let inspire_url = Self::request_inspire_image_url().await.map_err(|err| {
Expand Down
12 changes: 5 additions & 7 deletions cadency_commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ mod test {
fn impl_commandbaseline_trait_with_macro() {
#[derive(cadency_codegen::CommandBaseline)]
struct Test {}
assert!(true)
}

#[test]
Expand Down Expand Up @@ -97,9 +96,8 @@ mod test {
#[description = "123"]
struct Test {}
let test = Test {};
assert_eq!(
test.deferred(),
false,
assert!(
!test.deferred(),
"Test command should not be deferred by default"
)
}
Expand Down Expand Up @@ -128,7 +126,7 @@ mod test {

#[test]
fn return_derived_option() {
use serenity::model::application::command::CommandOptionType;
use serenity::model::application::CommandOptionType;
#[derive(cadency_codegen::CommandBaseline)]
#[argument(
name = "say",
Expand All @@ -144,7 +142,7 @@ mod test {
assert_eq!(argument.name, "say");
assert_eq!(argument.description, "Word to say");
assert_eq!(argument.kind, CommandOptionType::String);
assert_eq!(argument.required, false);
assert!(!argument.required);
}

#[test]
Expand All @@ -166,7 +164,7 @@ mod test {

#[test]
fn return_multiple_options() {
use serenity::model::application::command::CommandOptionType;
use serenity::model::application::CommandOptionType;

#[derive(cadency_codegen::CommandBaseline)]
#[argument(name = "say", description = "Word to say", kind = "String")]
Expand Down
47 changes: 36 additions & 11 deletions cadency_commands/src/now.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use cadency_core::{
response::{Response, ResponseBuilder},
utils, CadencyCommand, CadencyError,
};
use serenity::{
async_trait, client::Context,
model::application::interaction::application_command::ApplicationCommandInteraction,
utils::{self, voice::TrackMetaKey},
CadencyCommand, CadencyError,
};
use serenity::{async_trait, client::Context, model::application::CommandInteraction};
use songbird::tracks::LoopState;

#[derive(CommandBaseline, Default)]
#[description = "Shows current song"]
Expand All @@ -16,7 +15,7 @@ impl CadencyCommand for Now {
async fn execute<'a>(
&self,
ctx: &Context,
command: &'a mut ApplicationCommandInteraction,
command: &'a mut CommandInteraction,
response_builder: &'a mut ResponseBuilder,
) -> Result<Response, CadencyError> {
let guild_id = command.guild_id.ok_or(CadencyError::Command {
Expand All @@ -30,11 +29,37 @@ impl CadencyCommand for Now {
let track = handler.queue().current().ok_or(CadencyError::Command {
message: ":x: **No song is playing**".to_string(),
})?;
Ok(response_builder
.message(Some(track.metadata().title.as_ref().map_or(

// Extract Loop State from Track
let loop_state = track.get_info().await.unwrap().loops;

// Create message from track metadata. This is scoped to drop the read lock on the
// trackmeta as soon as possible.
let message = {
let track_map = track.typemap().read().await;
let metadata = track_map
.get::<TrackMetaKey>()
.expect("Metadata to be present in track map");

metadata.title.as_ref().map_or(
String::from(":x: **Could not add audio source to the queue!**"),
|title| format!(":newspaper: `{title}`"),
)))
.build()?)
|title| {
let mut track_info = format!(":newspaper: `{title}`");
match loop_state {
LoopState::Infinite => {
track_info.push_str("\n:repeat: `Infinite`");
}
LoopState::Finite(loop_amount) => {
if loop_amount > 0 {
track_info.push_str(&format!("\n:repeat: `{}`", loop_amount));
}
}
}
track_info
},
)
};

Ok(response_builder.message(Some(message)).build()?)
}
}
7 changes: 2 additions & 5 deletions cadency_commands/src/pause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use cadency_core::{
response::{Response, ResponseBuilder},
utils, CadencyCommand, CadencyError,
};
use serenity::{
async_trait, client::Context,
model::application::interaction::application_command::ApplicationCommandInteraction,
};
use serenity::{async_trait, client::Context, model::application::CommandInteraction};

#[derive(CommandBaseline, Default)]
#[description = "Pause the current song"]
Expand All @@ -17,7 +14,7 @@ impl CadencyCommand for Pause {
async fn execute<'a>(
&self,
ctx: &Context,
command: &'a mut ApplicationCommandInteraction,
command: &'a mut CommandInteraction,
response_builder: &'a mut ResponseBuilder,
) -> Result<Response, CadencyError> {
let guild_id = command.guild_id.ok_or(CadencyError::Command {
Expand Down
7 changes: 2 additions & 5 deletions cadency_commands/src/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use cadency_core::{
response::{Response, ResponseBuilder},
CadencyCommand, CadencyError,
};
use serenity::{
async_trait, client::Context,
model::application::interaction::application_command::ApplicationCommandInteraction,
};
use serenity::{async_trait, client::Context, model::application::CommandInteraction};

#[derive(CommandBaseline, Default)]
#[description = "Play Ping-Pong"]
Expand All @@ -16,7 +13,7 @@ impl CadencyCommand for Ping {
async fn execute<'a>(
&self,
_ctx: &Context,
_command: &'a mut ApplicationCommandInteraction,
_command: &'a mut CommandInteraction,
response_builder: &'a mut ResponseBuilder,
) -> Result<Response, CadencyError> {
Ok(response_builder
Expand Down
Loading

0 comments on commit f0a75c3

Please sign in to comment.