From de71b5124ce8a9a6c5a6b6194e46728cec4f641e Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 14 Apr 2024 20:05:19 -0600 Subject: [PATCH] fixed restarts and long status messages --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- src/discord/mod.rs | 18 ++++++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d4c4ca..35dce65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -249,9 +249,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" dependencies = [ "android-tzdata", "iana-time-zone", @@ -406,7 +406,7 @@ dependencies = [ [[package]] name = "daemon" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bitflags 2.4.2", "config", diff --git a/Cargo.toml b/Cargo.toml index ab1a4b3..7a2ac38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "daemon" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/discord/mod.rs b/src/discord/mod.rs index 19158a4..3d09644 100644 --- a/src/discord/mod.rs +++ b/src/discord/mod.rs @@ -290,17 +290,27 @@ async fn service( .await?; } ServiceAction::Restart => { - systemctl::stop(&service_name)?; + systemctl::restart(&service_name)?; ctx.reply(format!("`{}` has been restarted", service_name)) .await?; } ServiceAction::Status => { let status = systemctl::status(&service.name)?; - let mut msg = MessageBuilder::new(); - msg.push_codeblock_safe(status, None); + if status.len() > serenity::MESSAGE_CODE_LIMIT { + let file_name = format!("{}_status.log", service_name); + ctx.send( + CreateReply::default() + .attachment(CreateAttachment::bytes(status.into_bytes(), &file_name)), + ) + .await?; + } else { + let mut msg = MessageBuilder::new(); - ctx.reply(msg.build()).await?; + msg.push_codeblock_safe(status, None); + + ctx.reply(msg.build()).await?; + } } } } else {