From ae10b786fee6dec598362460e1176f34ada67e68 Mon Sep 17 00:00:00 2001 From: August Date: Wed, 27 Aug 2025 21:20:13 -0400 Subject: [PATCH] Featurize self update --- Cargo.lock | 2 +- Cargo.toml | 18 +++++++++++------- README.md | 2 +- src/command/devel.rs | 20 +++++++------------- src/main.rs | 1 + 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d534cc6..42051d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2378,7 +2378,7 @@ dependencies = [ [[package]] name = "shibe-bot" -version = "1.0.2" +version = "1.1.0" dependencies = [ "anyhow", "dotenvy", diff --git a/Cargo.toml b/Cargo.toml index 1c403ae..1f3b5f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "shibe-bot" description = "A Discord bot written in Rust, using Poise." license = "MIT" readme = "README.md" -version = "1.0.2" +version = "1.1.0" edition = "2021" build = "build.rs" @@ -24,9 +24,13 @@ serde_json = "1.0.140" roux = "2.2.13" structstruck = "0.5.0" reqwest = { version = "0.12.15", features = ["json"] } -octocrab = "0.44.1" -tempfile = "3.20.0" -self-replace = "1.5.0" -zip = "4.2.0" -nix = { version = "0.30.1", features = ["process"] } -minreq = { version = "2.14.0", features = ["https"] } +octocrab = { version = "0.44.1", optional = true } +tempfile = { version = "3.20.0", optional = true } +self-replace = { version = "1.5.0", optional = true } +zip = { version = "4.2.0", optional = true } +nix = { version = "0.30.1", features = ["process"], optional = true } +minreq = { version = "2.14.0", features = ["https"], optional = true } + + +[features] +self-update=["octocrab", "tempfile", "self-replace", "zip", "nix", "minreq"] \ No newline at end of file diff --git a/README.md b/README.md index 6fe435b..b74e19f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Shibe Bot 1.0.2 +# Shibe Bot 1.1.0 [![Rust](https://github.com/shibedrill/shibe-bot/actions/workflows/rust.yml/badge.svg)](https://github.com/shibedrill/shibe-bot/actions/workflows/rust.yml) [![GitHub License](https://img.shields.io/github/license/shibedrill/shibe-bot)](LICENSE.txt) diff --git a/src/command/devel.rs b/src/command/devel.rs index 1949e2f..71031c9 100644 --- a/src/command/devel.rs +++ b/src/command/devel.rs @@ -1,17 +1,9 @@ -use std::convert::Infallible; -use std::os::unix::process::CommandExt; +#[cfg(feature="self-update")] +use {std::convert::Infallible, std::os::unix::process::CommandExt, octocrab, std::io::Write, self_replace, zip, minreq}; use crate::Context; use crate::Error; -use octocrab; -use std::io::Write; - -use self_replace; -use zip; - -use minreq; - /// Print version and build information #[poise::command(slash_command)] pub async fn version(ctx: Context<'_>) -> Result<(), Error> { @@ -42,6 +34,7 @@ pub async fn version(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +#[cfg(feature="self-update")] /// Update the bot remotely (requires Github CI) #[poise::command(slash_command, owners_only, hide_in_help)] pub async fn update( @@ -121,6 +114,7 @@ pub async fn say( Ok(()) } +#[cfg(feature="self-update")] fn self_update() -> Result { let artifact_url = "https://nightly.link/shibedrill/shibe-bot/workflows/rust/main/artifact.zip"; let tempdir = tempfile::Builder::new().prefix("shibe-bot").tempdir()?; @@ -173,11 +167,11 @@ fn self_update() -> Result { mod test { #[cfg(test)] - use crate::Error; - #[cfg(test)] - use std::convert::Infallible; + #[cfg(feature="self-update")] + use {crate::Error, std::convert::Infallible}; #[test] + #[cfg(feature="self-update")] fn test_self_update() -> Result { use crate::command::devel::self_update; use pretty_env_logger; diff --git a/src/main.rs b/src/main.rs index f299e1b..575fa97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,6 +85,7 @@ async fn main() { shutdown(), restart(), say(), + #[cfg(feature="self-update")] update(), version(), // Fun