Skip to content

Commit 998fda3

Browse files
committed
add include spectator as option
1 parent 8d1d2fc commit 998fda3

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

.DS_Store

-2 KB
Binary file not shown.

map.jpg

1.24 KB
Loading

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl EventHandler for Handler {
6565
.unwrap_or_else(|_| "5".to_string())
6666
.parse::<i32>()
6767
.expect("prevrequestcount wasn't given an integer!"),
68+
include_spectators: env::var("include_spectators").unwrap_or_else(|_| "no".to_string()),
6869
};
6970

7071
log::info!("Started monitoring server {:#?}", statics.server_name);

src/message.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct Static {
2929
pub message_channel: u64,
3030
pub started_amount: i32,
3131
pub mins_between_avatar_change: i32,
32+
pub include_spectators: String,
3233
}
3334

3435
pub async fn check(
@@ -38,21 +39,21 @@ pub async fn check(
3839
statics: Static,
3940
) -> Result<Global> {
4041
if statics.message_channel != 40 {
41-
let mut server_info = format!(
42-
"{}/{} [{}] - {}",
42+
// in_spectator
43+
let server_info = format!(
44+
"{}/{}{}{} - {}",
4345
status.detailed.current_players,
4446
status.detailed.max_players,
45-
status.detailed.in_que.unwrap_or(0),
47+
match status.detailed.in_que.unwrap_or(0) > 0 {
48+
true => format!(" [{}]", status.detailed.in_que.unwrap_or(0)),
49+
false => "".to_string(),
50+
},
51+
match &statics.include_spectators[..] == "yes" {
52+
true => format!("({})", status.detailed.in_spectator.unwrap_or(0)),
53+
false => "".to_string(),
54+
},
4655
status.detailed.server_map
4756
);
48-
if status.detailed.in_que.unwrap_or(0) == 0 {
49-
server_info = format!(
50-
"{}/{} - {}",
51-
status.detailed.current_players,
52-
status.detailed.max_players,
53-
status.detailed.server_map
54-
);
55-
}
5657

5758
let mut image_url = "info_image.jpg";
5859
if status.detailed.server_name.contains("AMG") {

src/server_info.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub struct MainInfo {
1717
pub max_players: i32,
1818
#[serde(rename = "inQue")]
1919
pub in_que: Option<i32>,
20+
#[serde(rename = "inSpectator")]
21+
pub in_spectator: Option<i32>,
2022
#[serde(rename = "smallMode")]
2123
pub small_mode: String,
2224
#[serde(rename = "currentMap")]
@@ -49,6 +51,8 @@ pub struct DetailedInfo {
4951
pub max_players: i32,
5052
#[serde(rename = "inQueue")]
5153
pub in_que: Option<i32>,
54+
#[serde(rename = "inSpectator")]
55+
pub in_spectator: Option<i32>,
5256
#[serde(rename = "smallmode")]
5357
pub small_mode: String,
5458
#[serde(rename = "prefix")]
@@ -219,6 +223,7 @@ async fn get(statics: message::Static, game_id: &String) -> Result<ServerInfo> {
219223
DetailedInfo {
220224
current_players: payload.current_players,
221225
max_players: payload.max_players,
226+
in_spectator: payload.in_spectator,
222227
in_que: payload.in_que,
223228
small_mode: payload.small_mode,
224229
server_name: payload
@@ -255,23 +260,23 @@ pub async fn change_name(
255260
statics: message::Static,
256261
game_id: &String,
257262
) -> Result<ServerInfo> {
258-
let status = match get(statics, game_id).await {
263+
let status = match get(statics.clone(), game_id).await {
259264
Ok(status) => {
260-
let mut server_info = format!(
261-
"{}/{} [{}] - {}",
265+
let server_info = format!(
266+
"{}/{}{}{} - {}",
262267
status.detailed.current_players,
263268
status.detailed.max_players,
264-
status.detailed.in_que.unwrap_or(0),
265-
status.detailed.server_map,
269+
match status.detailed.in_que.unwrap_or(0) > 0 {
270+
true => format!(" [{}]", status.detailed.in_que.unwrap_or(0)),
271+
false => "".to_string(),
272+
},
273+
match &statics.include_spectators[..] == "yes" {
274+
true => format!(" ({})", status.detailed.in_spectator.unwrap_or(0)),
275+
false => "".to_string(),
276+
},
277+
status.detailed.server_map
266278
);
267-
if status.detailed.in_que.unwrap_or(0) == 0 {
268-
server_info = format!(
269-
"{}/{} - {}",
270-
status.detailed.current_players,
271-
status.detailed.max_players,
272-
status.detailed.server_map,
273-
);
274-
}
279+
275280
// change game activity
276281
ctx.set_activity(Some(ActivityData::playing(server_info)));
277282

0 commit comments

Comments
 (0)