Skip to content

Commit

Permalink
add option to set banner image
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Jun 26, 2024
1 parent 4dcda0b commit 8e82c4b
Show file tree
Hide file tree
Showing 3 changed files with 25 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 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
Expand Down
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 22 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Handler;
pub struct Static {
pub token: String,
pub server_name: String,
pub set_banner_image: bool,
}

/// `MyConfig` implements `Default`
Expand All @@ -32,6 +33,7 @@ impl ::std::default::Default for Static {
Self {
token: "".into(),
server_name: "".into(),
set_banner_image: true,
}
}
}
Expand Down Expand Up @@ -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(());
}
Expand Down Expand Up @@ -193,10 +202,10 @@ pub async fn gen_img(server: BattlebitServer) -> 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 @@ -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
Expand Down

0 comments on commit 8e82c4b

Please sign in to comment.