From 8e82c4b0023b3856646aff5644ada211b7797f4f Mon Sep 17 00:00:00 2001 From: iiTzArcur Date: Wed, 26 Jun 2024 12:36:00 +0200 Subject: [PATCH] add option to set banner image --- Dockerfile | 1 + Readme.md | 3 ++- src/main.rs | 25 ++++++++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6babc6c..2260c55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ FROM debian:bookworm-slim ENV token default_token_value ENV server_name default_server_name_value +ENV set_banner_image true HEALTHCHECK --interval=5m --timeout=3s --start-period=5s \ CMD curl -f http://127.0.0.1:3030/ || exit 1 diff --git a/Readme.md b/Readme.md index 794185e..e547af6 100644 --- a/Readme.md +++ b/Readme.md @@ -7,7 +7,8 @@ You can use the bot with multiple methods, a config file, environment variable o ```yaml token: discord bot token -name: servername to track +server_name: servername to track +set_banner_image: (optional) if it has to set the banner image of the bot (defaults to true) ``` ## Using the bot diff --git a/src/main.rs b/src/main.rs index 3002b0d..52a2876 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ struct Handler; pub struct Static { pub token: String, pub server_name: String, + pub set_banner_image: bool, } /// `MyConfig` implements `Default` @@ -32,6 +33,7 @@ impl ::std::default::Default for Static { Self { token: "".into(), server_name: "".into(), + set_banner_image: true, } } } @@ -163,7 +165,14 @@ async fn status(ctx: Context, statics: Static) -> Result<()> { .await .expect("Failed to read image"); let mut user = ctx.cache.current_user().clone(); - let _ = user.edit(ctx, EditProfile::new().avatar(&avatar)).await; + let mut new_profile = EditProfile::new().avatar(&avatar); + if statics.set_banner_image { + let banner = CreateAttachment::path("./info_image.jpg") + .await + .expect("Failed to read banner image"); + new_profile = new_profile.banner(&banner); + } + let _ = user.edit(ctx, new_profile.clone()).await; return Ok(()); } @@ -193,10 +202,10 @@ pub async fn gen_img(server: BattlebitServer) -> Result { let mut img2 = ImageReader::new(Cursor::new(img)) .with_guessed_format()? - .decode()? - .brighten(-25); + .decode()?; img2.save("./info_image.jpg")?; + img2.brighten(-25); let scale = PxScale { x: (img2.width() / 3) as f32, @@ -264,6 +273,16 @@ async fn main() -> anyhow::Result<()> { Ok(res) => res, Err(_) => cfg.server_name, }; + cfg.set_banner_image = match env::var("set_banner_image") { + Ok(res) => match res.as_str() { + "true" => true, + "t" => true, + "false" => false, + "f" => false, + _ => true, + }, + Err(_) => cfg.set_banner_image, + }; confy::store_path("config.txt", cfg.clone()).unwrap(); // Login with a bot token from the environment