Skip to content

Commit

Permalink
add include spectator as option
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Jan 3, 2025
1 parent 8d1d2fc commit 998fda3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified map.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl EventHandler for Handler {
.unwrap_or_else(|_| "5".to_string())
.parse::<i32>()
.expect("prevrequestcount wasn't given an integer!"),
include_spectators: env::var("include_spectators").unwrap_or_else(|_| "no".to_string()),
};

log::info!("Started monitoring server {:#?}", statics.server_name);
Expand Down
23 changes: 12 additions & 11 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Static {
pub message_channel: u64,
pub started_amount: i32,
pub mins_between_avatar_change: i32,
pub include_spectators: String,
}

pub async fn check(
Expand All @@ -38,21 +39,21 @@ pub async fn check(
statics: Static,
) -> Result<Global> {
if statics.message_channel != 40 {
let mut server_info = format!(
"{}/{} [{}] - {}",
// in_spectator
let server_info = format!(
"{}/{}{}{} - {}",
status.detailed.current_players,
status.detailed.max_players,
status.detailed.in_que.unwrap_or(0),
match status.detailed.in_que.unwrap_or(0) > 0 {
true => format!(" [{}]", status.detailed.in_que.unwrap_or(0)),
false => "".to_string(),
},
match &statics.include_spectators[..] == "yes" {
true => format!("({})", status.detailed.in_spectator.unwrap_or(0)),
false => "".to_string(),
},
status.detailed.server_map
);
if status.detailed.in_que.unwrap_or(0) == 0 {
server_info = format!(
"{}/{} - {}",
status.detailed.current_players,
status.detailed.max_players,
status.detailed.server_map
);
}

let mut image_url = "info_image.jpg";
if status.detailed.server_name.contains("AMG") {
Expand Down
31 changes: 18 additions & 13 deletions src/server_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct MainInfo {
pub max_players: i32,
#[serde(rename = "inQue")]
pub in_que: Option<i32>,
#[serde(rename = "inSpectator")]
pub in_spectator: Option<i32>,
#[serde(rename = "smallMode")]
pub small_mode: String,
#[serde(rename = "currentMap")]
Expand Down Expand Up @@ -49,6 +51,8 @@ pub struct DetailedInfo {
pub max_players: i32,
#[serde(rename = "inQueue")]
pub in_que: Option<i32>,
#[serde(rename = "inSpectator")]
pub in_spectator: Option<i32>,
#[serde(rename = "smallmode")]
pub small_mode: String,
#[serde(rename = "prefix")]
Expand Down Expand Up @@ -219,6 +223,7 @@ async fn get(statics: message::Static, game_id: &String) -> Result<ServerInfo> {
DetailedInfo {
current_players: payload.current_players,
max_players: payload.max_players,
in_spectator: payload.in_spectator,
in_que: payload.in_que,
small_mode: payload.small_mode,
server_name: payload
Expand Down Expand Up @@ -255,23 +260,23 @@ pub async fn change_name(
statics: message::Static,
game_id: &String,
) -> Result<ServerInfo> {
let status = match get(statics, game_id).await {
let status = match get(statics.clone(), game_id).await {
Ok(status) => {
let mut server_info = format!(
"{}/{} [{}] - {}",
let server_info = format!(
"{}/{}{}{} - {}",
status.detailed.current_players,
status.detailed.max_players,
status.detailed.in_que.unwrap_or(0),
status.detailed.server_map,
match status.detailed.in_que.unwrap_or(0) > 0 {
true => format!(" [{}]", status.detailed.in_que.unwrap_or(0)),
false => "".to_string(),
},
match &statics.include_spectators[..] == "yes" {
true => format!(" ({})", status.detailed.in_spectator.unwrap_or(0)),
false => "".to_string(),
},
status.detailed.server_map
);
if status.detailed.in_que.unwrap_or(0) == 0 {
server_info = format!(
"{}/{} - {}",
status.detailed.current_players,
status.detailed.max_players,
status.detailed.server_map,
);
}

// change game activity
ctx.set_activity(Some(ActivityData::playing(server_info)));

Expand Down

0 comments on commit 998fda3

Please sign in to comment.