Skip to content

Commit 8a76dd4

Browse files
committed
add server banner as option
1 parent 0d43a04 commit 8a76dd4

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

Readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ guid: serverid (optional)
1010
game: game name (tunguska, casablanca, kingston, bf4)
1111
ownerId: server owner playerid (optional for casablanca and kingston)
1212
fakeplayers: removes bots on bf4's playercount if set to yes (optional, default no)
13+
serverbanner: (optional) if it has to set the banner image of the bot (defaults to yes)
1314
name: servername
1415
lang: language (default en-us)
1516
platform: from which platform is the server (default pc)

map.jpg

30 KB
Loading

src/main.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl EventHandler for Handler {
3939
owner_id: env::var("ownerId").unwrap_or_else(|_| "none".to_string()),
4040
platform: env::var("platform").unwrap_or_else(|_| "pc".to_string()),
4141
fake_players: env::var("fakeplayers").unwrap_or_else(|_| "no".to_string()),
42+
set_banner_image: env::var("serverbanner").unwrap_or_else(|_| "yes".to_string()),
4243
server_name: env::var("name")
4344
.expect("name wasn't given an argument!")
4445
.replace('`', "#")
@@ -140,10 +141,14 @@ async fn status(
140141
.expect("Failed to read image");
141142
let mut user = ctx.cache.current_user().clone();
142143

143-
if let Err(e) = user
144-
.edit(ctx.clone(), EditProfile::new().avatar(&avatar))
145-
.await
146-
{
144+
let mut new_profile = EditProfile::new().avatar(&avatar);
145+
if &statics.set_banner_image[..] == "yes" {
146+
let banner = CreateAttachment::path("./map.jpg")
147+
.await
148+
.expect("Failed to read banner image");
149+
new_profile = new_profile.banner(&banner);
150+
}
151+
if let Err(e) = user.edit(ctx.clone(), new_profile).await {
147152
log::error!(
148153
"Failed to set new avatar: {:?}\n adding timeout before retrying",
149154
e

src/message.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Static {
2121
pub platform: String,
2222
pub owner_id: String,
2323
pub fake_players: String,
24+
pub set_banner_image: String,
2425
pub server_name: String,
2526
pub lang: String,
2627
pub min_player_amount: i32,

src/server_info.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,10 @@ pub async fn gen_img(status: ServerInfo, statics: message::Static) -> Result<Str
301301
.await?;
302302
let mut img2 = ImageReader::new(Cursor::new(img))
303303
.with_guessed_format()?
304-
.decode()?
305-
.brighten(-25);
304+
.decode()?;
305+
306+
img2.save("./map.jpg")?;
307+
img2.brighten(-25);
306308

307309
let font: FontRef = if &statics.game[..] == "kingston" || &statics.game[..] == "bf2042" {
308310
FontRef::try_from_slice(include_bytes!("BF_Modernista-Regular.ttf") as &[u8]).unwrap()

0 commit comments

Comments
 (0)