diff --git a/Cargo.toml b/Cargo.toml index c8e6d2c..0bd9bcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] resolver = "3" -members = ["types", "master", "worker"] +members = ["master", "types", "worker"] diff --git a/Dockerfile b/Dockerfile index 029747f..b469510 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,21 @@ FROM rust:1.93.1-alpine3.23 AS builder +RUN --mount=type=cache,target=/root/.cargo \ + rustup component add clippy && \ + rustup component add rustfmt --toolchain nightly + +RUN \ + cargo install cargo-sort + WORKDIR /build COPY . . +RUN --mount=type=cache,target=/build/target \ + cargo sort ./**/Cargo.toml --check && \ + cargo clippy && \ + cargo +nightly fmt --check + RUN --mount=type=cache,target=/build/target \ mkdir release && \ cargo build --workspace --release && \ diff --git a/master/Cargo.toml b/master/Cargo.toml index ff541a2..4ce2e52 100644 --- a/master/Cargo.toml +++ b/master/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2024" [dependencies] -types = { path = "../types" } async-nats = { version = "0.46.0" } +postcard = { version = "1.1.3", features = ["use-std"] } serenity = { version = "0.12.5", default-features = false, features = [ "client", "gateway", @@ -14,5 +14,5 @@ serenity = { version = "0.12.5", default-features = false, features = [ "collector", ] } tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] } -postcard = { version = "1.1.3", features = ["use-std"] } +types = { path = "../types" } uuid = { version = "1.21.0" } diff --git a/master/src/commands/modal.rs b/master/src/commands/modal.rs index 1f3e7f9..baca275 100644 --- a/master/src/commands/modal.rs +++ b/master/src/commands/modal.rs @@ -1,7 +1,4 @@ -use serenity::builder::*; -use serenity::model::prelude::*; -use serenity::prelude::*; -use serenity::utils::CreateQuickModal; +use serenity::{builder::*, model::prelude::*, prelude::*, utils::CreateQuickModal}; pub async fn run(ctx: &Context, interaction: &CommandInteraction) -> Result<(), serenity::Error> { let modal = CreateQuickModal::new("About you") diff --git a/master/src/commands/ping.rs b/master/src/commands/ping.rs index cd92b87..31c28d0 100644 --- a/master/src/commands/ping.rs +++ b/master/src/commands/ping.rs @@ -1,5 +1,4 @@ -use serenity::builder::CreateCommand; -use serenity::model::application::ResolvedOption; +use serenity::{builder::CreateCommand, model::application::ResolvedOption}; pub fn run(_options: &[ResolvedOption]) -> String { "Hey, I'm alive!".to_string() diff --git a/master/src/commands/testnats.rs b/master/src/commands/testnats.rs index 4985fd7..3985c9a 100644 --- a/master/src/commands/testnats.rs +++ b/master/src/commands/testnats.rs @@ -1,14 +1,19 @@ -use serenity::all::{ - CommandInteraction, Context, CreateCommandOption, CreateInteractionResponse, - CreateInteractionResponseMessage, -}; -use serenity::builder::CreateCommand; -use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue}; - use postcard::to_stdvec; - -use types::jobs::{InnerStruct, Job, JobKind}; -use types::misc::new_uuid_v4; +use serenity::{ + all::{ + CommandInteraction, + Context, + CreateCommandOption, + CreateInteractionResponse, + CreateInteractionResponseMessage, + }, + builder::CreateCommand, + model::application::{CommandOptionType, ResolvedOption, ResolvedValue}, +}; +use types::{ + jobs::{InnerStruct, Job, JobKind}, + misc::new_uuid_v4, +}; pub async fn run( ctx: &Context, diff --git a/master/src/main.rs b/master/src/main.rs index 695244e..5d8aa4f 100644 --- a/master/src/main.rs +++ b/master/src/main.rs @@ -2,11 +2,16 @@ mod commands; use std::env; -use serenity::async_trait; -use serenity::builder::{CreateInteractionResponse, CreateInteractionResponseMessage}; -use serenity::model::application::{Command, Interaction}; -use serenity::model::gateway::Ready; -use serenity::prelude::*; +use serenity::{ + Client, + all::{Context, EventHandler, GatewayIntents}, + async_trait, + builder::{CreateInteractionResponse, CreateInteractionResponseMessage}, + model::{ + application::{Command, Interaction}, + gateway::Ready, + }, +}; struct Handler { nats_client: async_nats::Client, diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..a083f01 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,4 @@ +imports_granularity = "Crate" +imports_layout = "HorizontalVertical" +group_imports = "StdExternalCrate" +reorder_imports = true diff --git a/types/Cargo.toml b/types/Cargo.toml index 61adecb..4884189 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -5,4 +5,4 @@ edition = "2024" [dependencies] serde = { version = "1.0.228" } -uuid = { version = "1.21.0", features = ["serde", "v4"]} +uuid = { version = "1.21.0", features = ["serde", "v4"] } diff --git a/types/src/lib.rs b/types/src/lib.rs index d250810..c1b809e 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -1,2 +1,2 @@ pub mod jobs; -pub mod misc; \ No newline at end of file +pub mod misc; diff --git a/types/src/misc.rs b/types/src/misc.rs index cb52a62..48ea9a0 100644 --- a/types/src/misc.rs +++ b/types/src/misc.rs @@ -1,5 +1,5 @@ use uuid::Uuid; -pub fn new_uuid_v4() -> Uuid{ +pub fn new_uuid_v4() -> Uuid { Uuid::new_v4() } diff --git a/worker/Cargo.toml b/worker/Cargo.toml index 7603e58..33b39cb 100644 --- a/worker/Cargo.toml +++ b/worker/Cargo.toml @@ -4,11 +4,11 @@ version = "0.1.0" edition = "2024" [dependencies] -types = { path = "../types" } async-nats = { version = "0.46.0" } futures = { version = "0.3.32" } futures-executor = { version = "0.3.32" } -tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] } postcard = { version = "1.1.3", features = ["use-std"] } -yt-dlp = { version = "2.1.0" } +tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] } +types = { path = "../types" } which = { version = "8.0.0" } +yt-dlp = { version = "2.1.0" } diff --git a/worker/src/main.rs b/worker/src/main.rs index 9fd86bc..cb0887f 100644 --- a/worker/src/main.rs +++ b/worker/src/main.rs @@ -1,12 +1,9 @@ use core::ops::Deref; -use std::path::PathBuf; -use which::which; use futures::StreamExt; - use postcard::from_bytes; - use types::jobs::Job; +use which::which; use yt_dlp::{Downloader, client::Libraries}; #[tokio::main] @@ -19,10 +16,7 @@ async fn main() { .await .unwrap(); - let libraries = Libraries::new( - PathBuf::from(which("yt-dlp").unwrap()), - PathBuf::from(which("ffmpeg").unwrap()), - ); + let libraries = Libraries::new(which("yt-dlp").unwrap(), which("ffmpeg").unwrap()); let downloader = Downloader::builder(libraries, "output") .build() .await