Skip to content

Commit

Permalink
add the same banner image code as the other bots
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Jun 26, 2024
1 parent e35e040 commit 5c9fe26
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FROM debian:bookworm-slim

ENV token default_token_value
ENV game bf1
ENV set_banner_image true

HEALTHCHECK --interval=5m --timeout=3s --start-period=5s \
CMD curl -f http://127.0.0.1:3030/ || exit 1
Expand Down
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ token: discord bot token
game: (optional) game could be bf1 or bfv, defaults to bf1
server_name: servername to track
server_id: server id to track
set_banner_image: (optional) if it has to set the banner image of the bot (defaults to true)
```
## Using the bot
Expand Down
Binary file modified info_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified map_mode.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 22 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct Static {
pub server_name: Option<String>,
pub server_id: Option<i64>,
pub game: Option<String>,
pub set_banner_image: bool,
}

/// `MyConfig` implements `Default`
Expand All @@ -37,6 +38,7 @@ impl ::std::default::Default for Static {
server_name: None,
server_id: None,
game: Some("bf1".into()),
set_banner_image: true,
}
}
}
Expand Down Expand Up @@ -367,7 +369,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).await;

return Ok(());
}
Expand All @@ -389,10 +398,10 @@ pub async fn gen_img(small_mode: &str, map_image: &str) -> Result<String> {

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,
Expand Down Expand Up @@ -442,6 +451,16 @@ async fn main() -> anyhow::Result<()> {
Ok(res) => Some(res),
Err(_) => cfg.game,
};
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,
};
if env::var("server_name").is_ok() || env::var("server_id").is_ok() {
cfg.server_name = match env::var("server_name") {
Ok(res) => Some(res),
Expand All @@ -454,7 +473,6 @@ async fn main() -> anyhow::Result<()> {
}
};
}
println!("{:#?}", cfg);
confy::store_path("config.txt", cfg.clone()).unwrap();

// Login with a bot token from the environment
Expand Down

0 comments on commit 5c9fe26

Please sign in to comment.