diff --git a/Dockerfile b/Dockerfile index f3fbf3f..410649e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.75 as builder +FROM rust:1.75 AS builder WORKDIR /usr/src/myapp COPY . . ARG github_token @@ -8,11 +8,18 @@ RUN git config --global credential.helper store && echo "https://zefanjajobse:${ FROM debian:bookworm-slim ENV token default_token_value +ENV game bf1 ENV server_name default_server_name_value +ENV server_id default_server_id_value HEALTHCHECK --interval=5m --timeout=3s --start-period=5s \ CMD curl -f http://127.0.0.1:3030/ || exit 1 COPY --from=builder /usr/local/cargo/bin/discord_bot /usr/local/bin/discord_bot RUN apt-get update && apt-get install --assume-yes curl && apt-get clean -CMD echo "token = '$token'\nserver_name = '$server_name'" > config.txt && discord_bot +CMD if [ "$server_name" = "default_server_name_value" ]; then\ + export INFO="token = '$token'\ngame = '$game'\nserver_id = $server_id"; \ + else \ + export INFO="token = '$token'\ngame = '$game'\nserver_name = '$server_name'"; \ + fi; \ + echo $INFO > config.txt && discord_bot \ No newline at end of file diff --git a/Readme.md b/Readme.md index aa0cbf6..c0219ad 100644 --- a/Readme.md +++ b/Readme.md @@ -5,6 +5,12 @@ set the config to the correct info in a config.txt next to this executable to us ```yaml # discord bot token token = '' +# (optional) game could be bf1 or bfv, defaults to bf1 +game = '' + +## use one of the options below # servername to track server_name = '' +# server id to track +server_id = '' ``` diff --git a/info_image.jpg b/info_image.jpg index e4a4856..2274491 100644 Binary files a/info_image.jpg and b/info_image.jpg differ diff --git a/map_mode.jpg b/map_mode.jpg index 806a0d4..a1235d6 100644 Binary files a/map_mode.jpg and b/map_mode.jpg differ diff --git a/src/main.rs b/src/main.rs index 6b6ba23..b585ede 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,9 @@ struct Handler; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Static { pub token: String, - pub server_name: String, + pub server_name: Option, + pub server_id: Option, + pub game: Option, } /// `MyConfig` implements `Default` @@ -31,7 +33,9 @@ impl ::std::default::Default for Static { fn default() -> Self { Self { token: "".into(), - server_name: "".into(), + server_name: None, + server_id: None, + game: Some("bf1".into()), } } } @@ -87,10 +91,6 @@ pub struct MarneServerInfo { pub need_same_mods: i64, #[serde(rename = "allowMoreMods")] pub allow_more_mods: i64, - #[serde(rename = "modList")] - pub mod_list: ModType, - #[serde(rename = "playerList")] - pub player_list: PlayerType, #[serde(rename = "currentPlayers")] pub current_players: i64, pub region: String, @@ -108,7 +108,13 @@ impl EventHandler for Handler { let cfg: Static = confy::load_path("config.txt").unwrap(); - log::info!("Started monitoring server {}", cfg.server_name); + if let Some(ref server_name) = cfg.server_name { + log::info!("Started monitoring server with name: {}", server_name); + } else if let Some(server_id) = cfg.server_id { + log::info!("Started monitoring server with id: {}", server_id); + } else { + log::error!("No server name of id set!"); + } tokio::spawn(async move { let hello = warp::any().map(move || { @@ -132,7 +138,7 @@ impl EventHandler for Handler { // loop in seperate async tokio::spawn(async move { loop { - match status(ctx.clone(), cfg.clone()).await { + match status(&ctx, &cfg).await { Ok(item) => item, Err(e) => { log::error!("cant get new stats: {}", e); @@ -146,9 +152,12 @@ impl EventHandler for Handler { } } -async fn get() -> Result { +async fn get(game: &String) -> Result { let client = reqwest::Client::new(); - let url = "https://marne.io/api/srvlst/"; + let url = match game.as_str() { + "bfv" => "https://marne.io/api/v/srvlst/", + _ => "https://marne.io/api/srvlst/", + }; match client.get(url).send().await { Ok(resp) => { @@ -172,100 +181,108 @@ async fn get() -> Result { } } -async fn status(ctx: Context, statics: Static) -> Result<()> { - match get().await { +async fn status(ctx: &Context, statics: &Static) -> Result<()> { + match get(&statics.game.clone().unwrap_or("bf1".into())).await { Ok(status) => { + let maps = HashMap::from([ + ("Levels/MP/MP_Amiens/MP_Amiens", "Amiens"), + ("Levels/MP/MP_Chateau/MP_Chateau", "Ballroom Blitz"), + ("Levels/MP/MP_Desert/MP_Desert", "Sinai Desert"), + ("Levels/MP/MP_FaoFortress/MP_FaoFortress", "Fao Fortress"), + ("Levels/MP/MP_Forest/MP_Forest", "Argonne Forest"), + ("Levels/MP/MP_ItalianCoast/MP_ItalianCoast", "Empire's Edge"), + ("Levels/MP/MP_MountainFort/MP_MountainFort", "Monte Grappa"), + ("Levels/MP/MP_Scar/MP_Scar", "St Quentin Scar"), + ("Levels/MP/MP_Suez/MP_Suez", "Suez"), + ("Xpack0/Levels/MP/MP_Giant/MP_Giant", "Giant's Shadow"), + ("Xpack1/Levels/MP_Fields/MP_Fields", "Soissons"), + ("Xpack1/Levels/MP_Graveyard/MP_Graveyard", "Rupture"), + ("Xpack1/Levels/MP_Underworld/MP_Underworld", "Fort De Vaux"), + ("Xpack1/Levels/MP_Verdun/MP_Verdun", "Verdun Heights"), + ( + "Xpack1-3/Levels/MP_ShovelTown/MP_ShovelTown", + "Prise de Tahure", + ), + ("Xpack1-3/Levels/MP_Trench/MP_Trench", "Nivelle Nights"), + ("Xpack2/Levels/MP/MP_Bridge/MP_Bridge", "Brusilov Keep"), + ("Xpack2/Levels/MP/MP_Islands/MP_Islands", "Albion"), + ("Xpack2/Levels/MP/MP_Ravines/MP_Ravines", "Łupków Pass"), + ("Xpack2/Levels/MP/MP_Tsaritsyn/MP_Tsaritsyn", "Tsaritsyn"), + ("Xpack2/Levels/MP/MP_Valley/MP_Valley", "Galicia"), + ("Xpack2/Levels/MP/MP_Volga/MP_Volga", "Volga River"), + ("Xpack3/Levels/MP/MP_Beachhead/MP_Beachhead", "Cape Helles"), + ("Xpack3/Levels/MP/MP_Harbor/MP_Harbor", "Zeebrugge"), + ("Xpack3/Levels/MP/MP_Naval/MP_Naval", "Heligoland Bight"), + ("Xpack3/Levels/MP/MP_Ridge/MP_Ridge", "Achi Baba"), + ("Xpack4/Levels/MP/MP_Alps/MP_Alps", "Razor's Edge"), + ("Xpack4/Levels/MP/MP_Blitz/MP_Blitz", "London Calling"), + ("Xpack4/Levels/MP/MP_Hell/MP_Hell", "Passchendaele"), + ( + "Xpack4/Levels/MP/MP_London/MP_London", + "London Calling: Scourge", + ), + ("Xpack4/Levels/MP/MP_Offensive/MP_Offensive", "River Somme"), + ("Xpack4/Levels/MP/MP_River/MP_River", "Caporetto"), + ]); + + let images = HashMap::from([ + ("Levels/MP/MP_Amiens/MP_Amiens", "https://cdn.gametools.network/maps/bf1/MP_Amiens_LandscapeLarge-e195589d.jpg"), + ("Levels/MP/MP_Chateau/MP_Chateau", "https://cdn.gametools.network/maps/bf1/MP_Chateau_LandscapeLarge-244d5987.jpg"), + ("Levels/MP/MP_Desert/MP_Desert", "https://cdn.gametools.network/maps/bf1/MP_Desert_LandscapeLarge-d8f749da.jpg"), + ("Levels/MP/MP_FaoFortress/MP_FaoFortress", "https://cdn.gametools.network/maps/bf1/MP_FaoFortress_LandscapeLarge-cad1748e.jpg"), + ("Levels/MP/MP_Forest/MP_Forest", "https://cdn.gametools.network/maps/bf1/MP_Forest_LandscapeLarge-dfbbe910.jpg"), + ("Levels/MP/MP_ItalianCoast/MP_ItalianCoast", "https://cdn.gametools.network/maps/bf1/MP_ItalianCoast_LandscapeLarge-1503eec7.jpg"), + ("Levels/MP/MP_MountainFort/MP_MountainFort", "https://cdn.gametools.network/maps/bf1/MP_MountainFort_LandscapeLarge-8a517533.jpg"), + ("Levels/MP/MP_Scar/MP_Scar", "https://cdn.gametools.network/maps/bf1/MP_Scar_LandscapeLarge-ee25fbd6.jpg"), + ("Levels/MP/MP_Suez/MP_Suez", "https://cdn.gametools.network/maps/bf1/MP_Suez_LandscapeLarge-f630fc76.jpg"), + ("Xpack0/Levels/MP/MP_Giant/MP_Giant", "https://cdn.gametools.network/maps/bf1/MP_Giant_LandscapeLarge-dd0b93ef.jpg"), + ("Xpack1/Levels/MP_Fields/MP_Fields", "https://cdn.gametools.network/maps/bf1/MP_Fields_LandscapeLarge-5f53ddc4.jpg"), + ("Xpack1/Levels/MP_Graveyard/MP_Graveyard", "https://cdn.gametools.network/maps/bf1/MP_Graveyard_LandscapeLarge-bd1012e6.jpg"), + ("Xpack1/Levels/MP_Underworld/MP_Underworld", "https://cdn.gametools.network/maps/bf1/MP_Underworld_LandscapeLarge-b6c5c7e7.jpg"), + ("Xpack1/Levels/MP_Verdun/MP_Verdun", "https://cdn.gametools.network/maps/bf1/MP_Verdun_LandscapeLarge-1a364063.jpg"), + ("Xpack1-3/Levels/MP_ShovelTown/MP_ShovelTown", "https://cdn.gametools.network/maps/bf1/MP_Shoveltown_LandscapeLarge-d0aa5920.jpg"), + ("Xpack1-3/Levels/MP_Trench/MP_Trench", "https://cdn.gametools.network/maps/bf1/MP_Trench_LandscapeLarge-dbd1248f.jpg"), + ("Xpack2/Levels/MP/MP_Bridge/MP_Bridge", "https://cdn.gametools.network/maps/bf1/MP_Bridge_LandscapeLarge-5b7f1b62.jpg"), + ("Xpack2/Levels/MP/MP_Islands/MP_Islands", "https://cdn.gametools.network/maps/bf1/MP_Islands_LandscapeLarge-c9d8272b.jpg"), + ("Xpack2/Levels/MP/MP_Ravines/MP_Ravines", "https://cdn.gametools.network/maps/bf1/MP_Ravines_LandscapeLarge-1fe0d3f6.jpg"), + ("Xpack2/Levels/MP/MP_Tsaritsyn/MP_Tsaritsyn", "https://cdn.gametools.network/maps/bf1/MP_Tsaritsyn_LandscapeLarge-2dbd3bf5.jpg"), + ("Xpack2/Levels/MP/MP_Valley/MP_Valley", "https://cdn.gametools.network/maps/bf1/MP_Valley_LandscapeLarge-8dc1c7ca.jpg"), + ("Xpack2/Levels/MP/MP_Volga/MP_Volga", "https://cdn.gametools.network/maps/bf1/MP_Volga_LandscapeLarge-6ac49c25.jpg"), + ("Xpack3/Levels/MP/MP_Beachhead/MP_Beachhead", "https://cdn.gametools.network/maps/bf1/MP_Beachhead_LandscapeLarge-5a13c655.jpg"), + ("Xpack3/Levels/MP/MP_Harbor/MP_Harbor", "https://cdn.gametools.network/maps/bf1/MP_Harbor_LandscapeLarge-d382c7ea.jpg"), + ("Xpack3/Levels/MP/MP_Naval/MP_Naval", "https://cdn.gametools.network/maps/bf1/MP_Naval_LandscapeLarge-dc2e8daf.jpg"), + ("Xpack3/Levels/MP/MP_Ridge/MP_Ridge", "https://cdn.gametools.network/maps/bf1/MP_Ridge_LandscapeLarge-8c057a19.jpg"), + ("Xpack4/Levels/MP/MP_Alps/MP_Alps", "https://cdn.gametools.network/maps/bf1/MP_Alps_LandscapeLarge-7ab30e3e.jpg"), + ("Xpack4/Levels/MP/MP_Blitz/MP_Blitz", "https://cdn.gametools.network/maps/bf1/MP_Blitz_LandscapeLarge-5e26212f.jpg"), + ("Xpack4/Levels/MP/MP_Hell/MP_Hell", "https://cdn.gametools.network/maps/bf1/MP_Hell_LandscapeLarge-7176911c.jpg"), + ("Xpack4/Levels/MP/MP_London/MP_London", "https://cdn.gametools.network/maps/bf1/MP_London_LandscapeLarge-0b51fe46.jpg"), + ("Xpack4/Levels/MP/MP_Offensive/MP_Offensive", "https://cdn.gametools.network/maps/bf1/MP_Offensive_LandscapeLarge-6dabdea3.jpg"), + ("Xpack4/Levels/MP/MP_River/MP_River", "https://cdn.gametools.network/maps/bf1/MP_River_LandscapeLarge-21443ae9.jpg"), + ]); + + let small_modes = HashMap::from([ + ("Conquest0", "CQ"), + ("Rush0", "RS"), + ("BreakThrough0", "SO"), + ("BreakThroughLarge0", "OP"), + ("Possession0", "WP"), + ("TugOfWar0", "FL"), + ("AirAssault0", "AA"), + ("Domination0", "DM"), + ("TeamDeathMatch0", "TM"), + ("ZoneControl0", "RS"), + ]); + for server in status.servers { - if server.name == statics.server_name { - let maps = HashMap::from([ - ("Levels/MP/MP_Amiens/MP_Amiens", "Amiens"), - ("Levels/MP/MP_Chateau/MP_Chateau", "Ballroom Blitz"), - ("Levels/MP/MP_Desert/MP_Desert", "Sinai Desert"), - ("Levels/MP/MP_FaoFortress/MP_FaoFortress", "Fao Fortress"), - ("Levels/MP/MP_Forest/MP_Forest", "Argonne Forest"), - ("Levels/MP/MP_ItalianCoast/MP_ItalianCoast", "Empire's Edge"), - ("Levels/MP/MP_MountainFort/MP_MountainFort", "Monte Grappa"), - ("Levels/MP/MP_Scar/MP_Scar", "St Quentin Scar"), - ("Levels/MP/MP_Suez/MP_Suez", "Suez"), - ("Xpack0/Levels/MP/MP_Giant/MP_Giant", "Giant's Shadow"), - ("Xpack1/Levels/MP_Fields/MP_Fields", "Soissons"), - ("Xpack1/Levels/MP_Graveyard/MP_Graveyard", "Rupture"), - ("Xpack1/Levels/MP_Underworld/MP_Underworld", "Fort De Vaux"), - ("Xpack1/Levels/MP_Verdun/MP_Verdun", "Verdun Heights"), - ( - "Xpack1-3/Levels/MP_ShovelTown/MP_ShovelTown", - "Prise de Tahure", - ), - ("Xpack1-3/Levels/MP_Trench/MP_Trench", "Nivelle Nights"), - ("Xpack2/Levels/MP/MP_Bridge/MP_Bridge", "Brusilov Keep"), - ("Xpack2/Levels/MP/MP_Islands/MP_Islands", "Albion"), - ("Xpack2/Levels/MP/MP_Ravines/MP_Ravines", "Łupków Pass"), - ("Xpack2/Levels/MP/MP_Tsaritsyn/MP_Tsaritsyn", "Tsaritsyn"), - ("Xpack2/Levels/MP/MP_Valley/MP_Valley", "Galicia"), - ("Xpack2/Levels/MP/MP_Volga/MP_Volga", "Volga River"), - ("Xpack3/Levels/MP/MP_Beachhead/MP_Beachhead", "Cape Helles"), - ("Xpack3/Levels/MP/MP_Harbor/MP_Harbor", "Zeebrugge"), - ("Xpack3/Levels/MP/MP_Naval/MP_Naval", "Heligoland Bight"), - ("Xpack3/Levels/MP/MP_Ridge/MP_Ridge", "Achi Baba"), - ("Xpack4/Levels/MP/MP_Alps/MP_Alps", "Razor's Edge"), - ("Xpack4/Levels/MP/MP_Blitz/MP_Blitz", "London Calling"), - ("Xpack4/Levels/MP/MP_Hell/MP_Hell", "Passchendaele"), - ( - "Xpack4/Levels/MP/MP_London/MP_London", - "London Calling: Scourge", - ), - ("Xpack4/Levels/MP/MP_Offensive/MP_Offensive", "River Somme"), - ("Xpack4/Levels/MP/MP_River/MP_River", "Caporetto"), - ]); - - let images = HashMap::from([ - ("Levels/MP/MP_Amiens/MP_Amiens", "https://cdn.gametools.network/maps/bf1/MP_Amiens_LandscapeLarge-e195589d.jpg"), - ("Levels/MP/MP_Chateau/MP_Chateau", "https://cdn.gametools.network/maps/bf1/MP_Chateau_LandscapeLarge-244d5987.jpg"), - ("Levels/MP/MP_Desert/MP_Desert", "https://cdn.gametools.network/maps/bf1/MP_Desert_LandscapeLarge-d8f749da.jpg"), - ("Levels/MP/MP_FaoFortress/MP_FaoFortress", "https://cdn.gametools.network/maps/bf1/MP_FaoFortress_LandscapeLarge-cad1748e.jpg"), - ("Levels/MP/MP_Forest/MP_Forest", "https://cdn.gametools.network/maps/bf1/MP_Forest_LandscapeLarge-dfbbe910.jpg"), - ("Levels/MP/MP_ItalianCoast/MP_ItalianCoast", "https://cdn.gametools.network/maps/bf1/MP_ItalianCoast_LandscapeLarge-1503eec7.jpg"), - ("Levels/MP/MP_MountainFort/MP_MountainFort", "https://cdn.gametools.network/maps/bf1/MP_MountainFort_LandscapeLarge-8a517533.jpg"), - ("Levels/MP/MP_Scar/MP_Scar", "https://cdn.gametools.network/maps/bf1/MP_Scar_LandscapeLarge-ee25fbd6.jpg"), - ("Levels/MP/MP_Suez/MP_Suez", "https://cdn.gametools.network/maps/bf1/MP_Suez_LandscapeLarge-f630fc76.jpg"), - ("Xpack0/Levels/MP/MP_Giant/MP_Giant", "https://cdn.gametools.network/maps/bf1/MP_Giant_LandscapeLarge-dd0b93ef.jpg"), - ("Xpack1/Levels/MP_Fields/MP_Fields", "https://cdn.gametools.network/maps/bf1/MP_Fields_LandscapeLarge-5f53ddc4.jpg"), - ("Xpack1/Levels/MP_Graveyard/MP_Graveyard", "https://cdn.gametools.network/maps/bf1/MP_Graveyard_LandscapeLarge-bd1012e6.jpg"), - ("Xpack1/Levels/MP_Underworld/MP_Underworld", "https://cdn.gametools.network/maps/bf1/MP_Underworld_LandscapeLarge-b6c5c7e7.jpg"), - ("Xpack1/Levels/MP_Verdun/MP_Verdun", "https://cdn.gametools.network/maps/bf1/MP_Verdun_LandscapeLarge-1a364063.jpg"), - ("Xpack1-3/Levels/MP_ShovelTown/MP_ShovelTown", "https://cdn.gametools.network/maps/bf1/MP_Shoveltown_LandscapeLarge-d0aa5920.jpg"), - ("Xpack1-3/Levels/MP_Trench/MP_Trench", "https://cdn.gametools.network/maps/bf1/MP_Trench_LandscapeLarge-dbd1248f.jpg"), - ("Xpack2/Levels/MP/MP_Bridge/MP_Bridge", "https://cdn.gametools.network/maps/bf1/MP_Bridge_LandscapeLarge-5b7f1b62.jpg"), - ("Xpack2/Levels/MP/MP_Islands/MP_Islands", "https://cdn.gametools.network/maps/bf1/MP_Islands_LandscapeLarge-c9d8272b.jpg"), - ("Xpack2/Levels/MP/MP_Ravines/MP_Ravines", "https://cdn.gametools.network/maps/bf1/MP_Ravines_LandscapeLarge-1fe0d3f6.jpg"), - ("Xpack2/Levels/MP/MP_Tsaritsyn/MP_Tsaritsyn", "https://cdn.gametools.network/maps/bf1/MP_Tsaritsyn_LandscapeLarge-2dbd3bf5.jpg"), - ("Xpack2/Levels/MP/MP_Valley/MP_Valley", "https://cdn.gametools.network/maps/bf1/MP_Valley_LandscapeLarge-8dc1c7ca.jpg"), - ("Xpack2/Levels/MP/MP_Volga/MP_Volga", "https://cdn.gametools.network/maps/bf1/MP_Volga_LandscapeLarge-6ac49c25.jpg"), - ("Xpack3/Levels/MP/MP_Beachhead/MP_Beachhead", "https://cdn.gametools.network/maps/bf1/MP_Beachhead_LandscapeLarge-5a13c655.jpg"), - ("Xpack3/Levels/MP/MP_Harbor/MP_Harbor", "https://cdn.gametools.network/maps/bf1/MP_Harbor_LandscapeLarge-d382c7ea.jpg"), - ("Xpack3/Levels/MP/MP_Naval/MP_Naval", "https://cdn.gametools.network/maps/bf1/MP_Naval_LandscapeLarge-dc2e8daf.jpg"), - ("Xpack3/Levels/MP/MP_Ridge/MP_Ridge", "https://cdn.gametools.network/maps/bf1/MP_Ridge_LandscapeLarge-8c057a19.jpg"), - ("Xpack4/Levels/MP/MP_Alps/MP_Alps", "https://cdn.gametools.network/maps/bf1/MP_Alps_LandscapeLarge-7ab30e3e.jpg"), - ("Xpack4/Levels/MP/MP_Blitz/MP_Blitz", "https://cdn.gametools.network/maps/bf1/MP_Blitz_LandscapeLarge-5e26212f.jpg"), - ("Xpack4/Levels/MP/MP_Hell/MP_Hell", "https://cdn.gametools.network/maps/bf1/MP_Hell_LandscapeLarge-7176911c.jpg"), - ("Xpack4/Levels/MP/MP_London/MP_London", "https://cdn.gametools.network/maps/bf1/MP_London_LandscapeLarge-0b51fe46.jpg"), - ("Xpack4/Levels/MP/MP_Offensive/MP_Offensive", "https://cdn.gametools.network/maps/bf1/MP_Offensive_LandscapeLarge-6dabdea3.jpg"), - ("Xpack4/Levels/MP/MP_River/MP_River", "https://cdn.gametools.network/maps/bf1/MP_River_LandscapeLarge-21443ae9.jpg"), - ]); - - let small_modes = HashMap::from([ - ("Conquest0", "CQ"), - ("Rush0", "RS"), - ("BreakThrough0", "SO"), - ("BreakThroughLarge0", "OP"), - ("Possession0", "WP"), - ("TugOfWar0", "FL"), - ("AirAssault0", "AA"), - ("Domination0", "DM"), - ("TeamDeathMatch0", "TM"), - ("ZoneControl0", "RS"), - ]); + let right_server = match &statics.server_name { + Some(server_name) => &server.name == server_name, + None => match &statics.server_id { + Some(server_id) => &server.id == server_id, + None => false, + }, + }; + if right_server { let server_info = format!( "{}/{} - {}", server.current_players, @@ -356,7 +373,9 @@ async fn main() -> anyhow::Result<()> { log::warn!("changing back to default.."); Static { token: "".into(), - server_name: "".into(), + server_name: None, + server_id: Some(0), + game: Some("bf1".into()), } } };