Prep for final release

This commit is contained in:
August 2025-01-08 22:02:14 -05:00
parent 6f04e79965
commit 7257d93884
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
5 changed files with 416 additions and 356 deletions

726
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@ name = "shibe-bot"
description = "A Discord bot written in Rust, using Poise."
license = "MIT"
readme = "README.md"
version = "0.4.2"
version = "1.0.0"
edition = "2021"
build = "build.rs"
@ -29,3 +29,4 @@ tempfile = "3.15.0"
self-replace = "1.5.0"
zip = "2.2.2"
nix = { version = "0.29.0", features = ["process"] }
minreq = { version = "2.13.0", features = ["https"] }

BIN
artifact.zip Normal file

Binary file not shown.

BIN
shibe-bot Executable file

Binary file not shown.

View File

@ -10,6 +10,8 @@ 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> {
@ -55,7 +57,7 @@ pub async fn update(ctx: Context<'_>) -> Result<(), Error> {
info!("Update unnecessary: Commit ID of remote is same as compiled commit.");
} else {
info!("Update required, latest commit hash: {}", sha);
let Err(what) = self_update().await;
let Err(what) = self_update();
error!("Update failed: {}", what);
ctx.say(format!("Error occurred while updating: {}", what))
.await?;
@ -103,29 +105,24 @@ pub async fn say(
Ok(())
}
async fn self_update() -> Result<Infallible, Error> {
fn self_update() -> Result<Infallible, Error> {
let artifact_url = "https://nightly.link/shibedrill/shibe-bot/workflows/rust/main/artifact.zip";
let tempdir = tempfile::Builder::new().prefix("shibe-bot").tempdir()?;
let response = reqwest::get(artifact_url).await?;
trace!("Created tempdir successfully: {}", tempdir.path().display());
let response = minreq::get(artifact_url).send()?;
let mut dest = {
let fname = response
.url()
.path_segments()
.and_then(|segments| segments.last())
.and_then(|name| if name.is_empty() { None } else { Some(name) })
.unwrap_or("tmp");
let fname = tempdir.path().join(fname);
std::fs::File::create(fname)?
};
let content = response.bytes().await?;
let mut dest = std::fs::File::create_new(tempdir.path().join("artifact.zip"))?;
let content = response.as_bytes();
dest.write_all(&content)?;
trace!("Downloaded latest build artifact successfully");
let mut archive = zip::ZipArchive::new(dest)?;
trace!("Created zip archive reader");
let mut zipped_bin = archive.by_index(0)?;
let new_bin_path = tempdir.path().join("shibe-bot");
let mut new_bin = std::fs::File::create_new(&new_bin_path)?;
trace!("Created new file for binary");
std::io::copy(&mut zipped_bin, &mut new_bin)?;
trace!("Extracted binary successfully");
@ -135,6 +132,7 @@ async fn self_update() -> Result<Infallible, Error> {
let new_command_args: Vec<_> = std::env::args_os().skip(1).collect();
let new_command_path = std::env::current_exe()?;
trace!("Got current executable path successfully: {}", new_command_path.display());
Err(Box::new(
std::process::Command::new(new_command_path)
@ -142,3 +140,20 @@ async fn self_update() -> Result<Infallible, Error> {
.exec(),
))
}
mod test {
#[cfg(test)]
use std::convert::Infallible;
#[cfg(test)]
use crate::Error;
#[test]
fn test_self_update() -> Result<Infallible, Error> {
use pretty_env_logger;
use crate::command::devel::self_update;
pretty_env_logger::init();
self_update()
}
}