Compare commits
No commits in common. "c2491f45425c41a70d3539df29899f612abff8e9" and "8d1bdbc055e9c66422fbe81cfea6798d56c0749c" have entirely different histories.
c2491f4542
...
8d1bdbc055
@ -7,14 +7,9 @@ pub fn set_presence(ctx: &poise::serenity_prelude::Context, status: ServerRespon
|
||||
Some(ActivityData::custom(match status.online() {
|
||||
true => {
|
||||
format!(
|
||||
"{}/{} players online {}",
|
||||
"{}/{} players online",
|
||||
status.players().unwrap(),
|
||||
status.max().unwrap(),
|
||||
if let Some(version) = status.version() {
|
||||
format!("v{}", version)
|
||||
} else {
|
||||
"".into()
|
||||
}
|
||||
status.max().unwrap()
|
||||
)
|
||||
}
|
||||
false => "Server offline!".to_string(),
|
||||
|
||||
@ -4,6 +4,7 @@ mod scpsl;
|
||||
mod types;
|
||||
use dotenvy::{self, dotenv};
|
||||
use minecraft::Minecraft;
|
||||
use scpsl::Scpsl;
|
||||
use tokio::join;
|
||||
use url::{self, Url};
|
||||
|
||||
@ -24,10 +25,5 @@ async fn main() {
|
||||
std::env::var("TOKEN_BOT_MC_MCHPRS").unwrap(),
|
||||
"Project MCRV".into(),
|
||||
);
|
||||
let dawn = Minecraft::new(
|
||||
Url::try_from("https://api.mcstatus.io/v2/status/java/mchprs.shibedrill.site").unwrap(),
|
||||
std::env::var("TOKEN_BOT_MC_DAWN").unwrap(),
|
||||
"Dawn Group".into(),
|
||||
);
|
||||
join!(mchprs.run(), gamerzone.run());
|
||||
}
|
||||
|
||||
@ -3,24 +3,12 @@ use reqwest::{Client, Request};
|
||||
use serenity::*;
|
||||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
funcs,
|
||||
types::{self, ServerResponse},
|
||||
};
|
||||
use crate::{funcs, types::ServerResponse};
|
||||
|
||||
#[derive(serde::Deserialize, Debug)]
|
||||
struct ServerSummary {
|
||||
online: bool,
|
||||
players: Option<Players>,
|
||||
version: Version,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug)]
|
||||
struct Version {
|
||||
name_raw: String,
|
||||
name_clean: String,
|
||||
name_html: String,
|
||||
protocol: u32,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug)]
|
||||
@ -61,10 +49,9 @@ impl Minecraft {
|
||||
data.online,
|
||||
Some(players.online as u32),
|
||||
Some(players.max as u32),
|
||||
Some(data.version.name_raw),
|
||||
))
|
||||
} else {
|
||||
Ok(ServerResponse::new(data.online, None, None, None))
|
||||
Ok(ServerResponse::new(data.online, None, None))
|
||||
}
|
||||
}
|
||||
pub async fn run(&self) {
|
||||
|
||||
@ -46,7 +46,6 @@ impl Scpsl {
|
||||
data.online,
|
||||
playercount_unwrapped.first().copied(),
|
||||
playercount_unwrapped.get(1).copied(),
|
||||
None,
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
36
src/types.rs
36
src/types.rs
@ -1,24 +1,15 @@
|
||||
use std::fmt::format;
|
||||
|
||||
pub struct ServerResponse {
|
||||
online: bool,
|
||||
players: Option<u32>,
|
||||
max: Option<u32>,
|
||||
version: Option<String>,
|
||||
}
|
||||
|
||||
impl ServerResponse {
|
||||
pub fn new(
|
||||
online: bool,
|
||||
players: Option<u32>,
|
||||
max: Option<u32>,
|
||||
version: Option<String>,
|
||||
) -> Self {
|
||||
pub fn new(online: bool, players: Option<u32>, max: Option<u32>) -> Self {
|
||||
ServerResponse {
|
||||
online,
|
||||
players,
|
||||
max,
|
||||
version,
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,28 +29,11 @@ impl ServerResponse {
|
||||
self.players >= self.max
|
||||
}
|
||||
|
||||
pub fn version(&self) -> &Option<String> {
|
||||
&self.version
|
||||
}
|
||||
|
||||
pub fn to_string(&self) -> String {
|
||||
format!(
|
||||
"{} {} {}",
|
||||
if let Some(players) = self.players {
|
||||
if let Some(max) = self.max {
|
||||
format!("{}/{}", players, max)
|
||||
if let (Some(players), Some(max)) = (self.players, self.max) {
|
||||
format!("{}/{} ({})", players, max, self.online)
|
||||
} else {
|
||||
players.to_string()
|
||||
}
|
||||
} else {
|
||||
"N/A".into()
|
||||
},
|
||||
self.online,
|
||||
if let Some(version) = &self.version {
|
||||
version.to_string()
|
||||
} else {
|
||||
"N/A".into()
|
||||
}
|
||||
)
|
||||
format!("N/A ({})", self.online)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user