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() {
|
Some(ActivityData::custom(match status.online() {
|
||||||
true => {
|
true => {
|
||||||
format!(
|
format!(
|
||||||
"{}/{} players online {}",
|
"{}/{} players online",
|
||||||
status.players().unwrap(),
|
status.players().unwrap(),
|
||||||
status.max().unwrap(),
|
status.max().unwrap()
|
||||||
if let Some(version) = status.version() {
|
|
||||||
format!("v{}", version)
|
|
||||||
} else {
|
|
||||||
"".into()
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
false => "Server offline!".to_string(),
|
false => "Server offline!".to_string(),
|
||||||
|
|||||||
@ -4,6 +4,7 @@ mod scpsl;
|
|||||||
mod types;
|
mod types;
|
||||||
use dotenvy::{self, dotenv};
|
use dotenvy::{self, dotenv};
|
||||||
use minecraft::Minecraft;
|
use minecraft::Minecraft;
|
||||||
|
use scpsl::Scpsl;
|
||||||
use tokio::join;
|
use tokio::join;
|
||||||
use url::{self, Url};
|
use url::{self, Url};
|
||||||
|
|
||||||
@ -24,10 +25,5 @@ async fn main() {
|
|||||||
std::env::var("TOKEN_BOT_MC_MCHPRS").unwrap(),
|
std::env::var("TOKEN_BOT_MC_MCHPRS").unwrap(),
|
||||||
"Project MCRV".into(),
|
"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());
|
join!(mchprs.run(), gamerzone.run());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,24 +3,12 @@ use reqwest::{Client, Request};
|
|||||||
use serenity::*;
|
use serenity::*;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{
|
use crate::{funcs, types::ServerResponse};
|
||||||
funcs,
|
|
||||||
types::{self, ServerResponse},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Debug)]
|
#[derive(serde::Deserialize, Debug)]
|
||||||
struct ServerSummary {
|
struct ServerSummary {
|
||||||
online: bool,
|
online: bool,
|
||||||
players: Option<Players>,
|
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)]
|
#[derive(serde::Deserialize, Debug)]
|
||||||
@ -61,10 +49,9 @@ impl Minecraft {
|
|||||||
data.online,
|
data.online,
|
||||||
Some(players.online as u32),
|
Some(players.online as u32),
|
||||||
Some(players.max as u32),
|
Some(players.max as u32),
|
||||||
Some(data.version.name_raw),
|
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(ServerResponse::new(data.online, None, None, None))
|
Ok(ServerResponse::new(data.online, None, None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub async fn run(&self) {
|
pub async fn run(&self) {
|
||||||
|
|||||||
@ -46,7 +46,6 @@ impl Scpsl {
|
|||||||
data.online,
|
data.online,
|
||||||
playercount_unwrapped.first().copied(),
|
playercount_unwrapped.first().copied(),
|
||||||
playercount_unwrapped.get(1).copied(),
|
playercount_unwrapped.get(1).copied(),
|
||||||
None,
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
38
src/types.rs
38
src/types.rs
@ -1,24 +1,15 @@
|
|||||||
use std::fmt::format;
|
|
||||||
|
|
||||||
pub struct ServerResponse {
|
pub struct ServerResponse {
|
||||||
online: bool,
|
online: bool,
|
||||||
players: Option<u32>,
|
players: Option<u32>,
|
||||||
max: Option<u32>,
|
max: Option<u32>,
|
||||||
version: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerResponse {
|
impl ServerResponse {
|
||||||
pub fn new(
|
pub fn new(online: bool, players: Option<u32>, max: Option<u32>) -> Self {
|
||||||
online: bool,
|
|
||||||
players: Option<u32>,
|
|
||||||
max: Option<u32>,
|
|
||||||
version: Option<String>,
|
|
||||||
) -> Self {
|
|
||||||
ServerResponse {
|
ServerResponse {
|
||||||
online,
|
online,
|
||||||
players,
|
players,
|
||||||
max,
|
max,
|
||||||
version,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,28 +29,11 @@ impl ServerResponse {
|
|||||||
self.players >= self.max
|
self.players >= self.max
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn version(&self) -> &Option<String> {
|
|
||||||
&self.version
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_string(&self) -> String {
|
pub fn to_string(&self) -> String {
|
||||||
format!(
|
if let (Some(players), Some(max)) = (self.players, self.max) {
|
||||||
"{} {} {}",
|
format!("{}/{} ({})", players, max, self.online)
|
||||||
if let Some(players) = self.players {
|
} else {
|
||||||
if let Some(max) = self.max {
|
format!("N/A ({})", self.online)
|
||||||
format!("{}/{}", players, max)
|
}
|
||||||
} else {
|
|
||||||
players.to_string()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
"N/A".into()
|
|
||||||
},
|
|
||||||
self.online,
|
|
||||||
if let Some(version) = &self.version {
|
|
||||||
version.to_string()
|
|
||||||
} else {
|
|
||||||
"N/A".into()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user