diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1116676..54db0bb 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,9 +3,9 @@ updates: - package-ecosystem: "cargo" directory: "/" schedule: - interval: "daily" + interval: "weekly" - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "daily" + interval: "weekly" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index efa8551..03eb0f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,15 @@ --- name: CI +permissions: + actions: write + checks: write + contents: write + id-token: write + pull-requests: write + security-events: write + statuses: write + on: push: branches: [ master ] @@ -16,7 +25,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup rust uses: ./.github/actions/setup-rust @@ -32,7 +41,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup rust uses: ./.github/actions/setup-rust @@ -51,7 +60,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup rust uses: ./.github/actions/setup-rust @@ -67,11 +76,15 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + with: + # super-linter needs the full git history to get the + # list of files that changed across commits + fetch-depth: 0 - name: Lint Code Base - uses: github/super-linter/slim@v4 + uses: github/super-linter@v4 env: VALIDATE_ALL_CODEBASE: false GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - VALIDATE_EDITORCONFIG: false + VALIDATE_EDITORCONFIG: false \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 78e0499..807b426 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,15 @@ --- name: Release +permissions: + actions: write + checks: write + contents: write + id-token: write + pull-requests: write + security-events: write + statuses: write + on: release: types: [ published ] @@ -10,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.sha }} @@ -31,4 +40,4 @@ jobs: upload_url: ${{ github.event.release.upload_url }} asset_path: ./x86_64-linux.zip asset_content_type: application/zip - asset_name: x86_64-linux.zip + asset_name: x86_64-linux.zip \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 9681fc0..d2d647a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,6 @@ panic = "abort" incremental = true [dependencies] -tokio = { version = "*", features = ["macros", "rt-multi-thread", "time"] } -serenity = { version = "*", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] } -clap = { version = "*", features = ["derive"] } \ No newline at end of file +tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread", "time"] } +serenity = { default-features = false, features = ["http", "model", "utils", "rustls_backend", "client", "gateway"], version = "0.12.1" } +clap = { version = "4.5.4", features = ["derive"] } \ No newline at end of file diff --git a/rust-toolchain b/rust-toolchain index 5889a27..6f41e7f 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "1.65.0" +channel = "1.78.0" components = ["rustfmt", "clippy"] -targets = ["x86_64-unknown-linux-gnu"] +targets = ["x86_64-unknown-linux-gnu"] \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 0000000..ddc7a78 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +RUSTFLAGS="-C link-arg=-s" cargo build --release --target "$1" \ No newline at end of file diff --git a/scripts/pack.sh b/scripts/pack.sh new file mode 100644 index 0000000..b867b33 --- /dev/null +++ b/scripts/pack.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +./scripts/publish-x86-64-Linux.sh && cp LICENSE output/ && zip -9 -r x86_64-linux.zip output/ \ No newline at end of file diff --git a/scripts/publish-x86-64-Linux.sh b/scripts/publish-x86-64-Linux.sh new file mode 100644 index 0000000..850654d --- /dev/null +++ b/scripts/publish-x86-64-Linux.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +./scripts/publish.sh x86_64-unknown-linux-gnu \ No newline at end of file diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100644 index 0000000..384bd73 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +./scripts/build.sh "$1" && mkdir -p "./output/" && cp "./target/$1/release/dstub" "./output/dstub" && cp LICENSE "./output/" && mkdir -p "./output/" \ No newline at end of file diff --git a/scripts/run-clippy.sh b/scripts/run-clippy.sh new file mode 100644 index 0000000..183f478 --- /dev/null +++ b/scripts/run-clippy.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +cargo clippy --release -- -D warnings \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 33c74f5..dc1ef5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,54 +1,62 @@ use clap::{Parser, ValueEnum}; -use tokio::time::sleep; -use std::time::Duration; -use serenity::model::user::OnlineStatus; use serenity::model::gateway::{Activity, GatewayIntents}; +use serenity::model::user::OnlineStatus; use serenity::prelude::*; +use std::time::Duration; +use tokio::time::sleep; #[derive(Parser, Debug, Clone)] #[command(author, version, about, long_about = None)] struct Args { - #[arg(short, long)] - token: String, + #[arg(short, long)] + token: String, - #[arg(short, long)] - status_message: String, + #[arg(short, long)] + status_message: String, - #[arg(value_enum)] - status_type: Status, + #[arg(value_enum)] + status_type: Status, } #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)] enum Status { - /// Show online status - Online, + /// Show online status + Online, - /// Show Do Not Disturb status - DoNotDisturb, + /// Show Do Not Disturb status + DoNotDisturb, - /// Show Idle status - Idle, + /// Show Idle status + Idle, } #[tokio::main] async fn main() { - let args = Args::parse(); - - let mut client = Client::builder(&args.token, GatewayIntents::empty()).await.unwrap(); - let manager = client.shard_manager.clone(); - tokio::spawn(async move { - let status = match args.status_type { - Status::Online => OnlineStatus::Online, - Status::DoNotDisturb => OnlineStatus::DoNotDisturb, - Status::Idle => OnlineStatus::Idle - }; - sleep(Duration::from_secs(15)).await; - - for shard in manager.lock().await.runners.lock().await.iter_mut() { - shard.1.runner_tx.set_presence(Some(Activity::playing(args.status_message.clone())), status); - } - }); - if let Err(why) = client.start_autosharded().await { - println!("Client error: {:?}", why); - } + let args = Args::parse(); + + let mut client = Client::builder(&args.token, GatewayIntents::empty()) + .await + .unwrap(); + + let manager = client.shard_manager.clone(); + + tokio::spawn(async move { + let status = match args.status_type { + Status::Online => OnlineStatus::Online, + Status::DoNotDisturb => OnlineStatus::DoNotDisturb, + Status::Idle => OnlineStatus::Idle, + }; + sleep(Duration::from_secs(15)).await; + + for shard in manager.runners.lock().await.iter_mut() { + shard + .1 + .runner_tx + .set_presence(Some(ActivityData::playing(args.status_message.clone())), status); + } + }); + + if let Err(why) = client.start_autosharded().await { + println!("Client error: {:?}", why); + } }