Added names to objects
This commit is contained in:
parent
72af8c91fc
commit
c9318d7261
@ -18,14 +18,17 @@ async fn main() {
|
||||
let gamerzone = Minecraft::new(
|
||||
Url::try_from("https://api.mcstatus.io/v2/status/java/gamer.shibedrill.site").unwrap(),
|
||||
std::env::var("TOKEN_BOT_MC_GAMER").unwrap(),
|
||||
"Gamer SMP".into(),
|
||||
);
|
||||
let mchprs = Minecraft::new(
|
||||
Url::try_from("https://api.mcstatus.io/v2/status/java/mchprs.shibedrill.site").unwrap(),
|
||||
std::env::var("TOKEN_BOT_MC_MCHPRS").unwrap(),
|
||||
"Project MCRV".into(),
|
||||
);
|
||||
let scpsl = Scpsl::new(
|
||||
Url::try_from("https://api.scplist.kr/api/servers/81460").unwrap(),
|
||||
std::env::var("TOKEN_BOT_SCPSL").unwrap(),
|
||||
"SCP: SL".into(),
|
||||
);
|
||||
join!(scpsl.run(), mchprs.run(), gamerzone.run());
|
||||
}
|
||||
|
@ -25,11 +25,12 @@ pub struct Data {
|
||||
pub struct Minecraft {
|
||||
url: Url,
|
||||
token: String,
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl Minecraft {
|
||||
pub fn new(url: Url, token: String) -> Self {
|
||||
Self { url, token }
|
||||
pub fn new(url: Url, token: String, name: String) -> Self {
|
||||
Self { url, token, name }
|
||||
}
|
||||
|
||||
pub async fn get_status(&self) -> Result<ServerResponse, anyhow::Error> {
|
||||
@ -94,9 +95,13 @@ pub async fn event_handler(
|
||||
.controller
|
||||
.get_status()
|
||||
.await
|
||||
.inspect_err(|e| error!("Failed to get status: {}", e))
|
||||
.inspect_err(|e| error!("{}: Failed to get status: {}", data.controller.name, e))
|
||||
.unwrap();
|
||||
info!("Got status: {}", status.to_string());
|
||||
info!(
|
||||
"{}: Got status: {}",
|
||||
data.controller.name,
|
||||
status.to_string()
|
||||
);
|
||||
|
||||
funcs::set_presence(ctx, status);
|
||||
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
|
||||
|
13
src/scpsl.rs
13
src/scpsl.rs
@ -17,13 +17,14 @@ pub struct Data {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Scpsl {
|
||||
name: String,
|
||||
url: Url,
|
||||
token: String,
|
||||
}
|
||||
|
||||
impl Scpsl {
|
||||
pub fn new(url: Url, token: String) -> Self {
|
||||
Self { url, token }
|
||||
pub fn new(url: Url, token: String, name: String) -> Self {
|
||||
Self { url, token, name }
|
||||
}
|
||||
async fn get_status(&self) -> Result<ServerResponse, anyhow::Error> {
|
||||
let http_client = Client::new();
|
||||
@ -91,9 +92,13 @@ pub async fn event_handler(
|
||||
.controller
|
||||
.get_status()
|
||||
.await
|
||||
.inspect_err(|e| error!("Failed to get status: {}", e))
|
||||
.inspect_err(|e| error!("{}: Failed to get status: {}", data.controller.name, e))
|
||||
.unwrap();
|
||||
info!("Got status: {}", status.to_string());
|
||||
info!(
|
||||
"{}: Got status: {}",
|
||||
data.controller.name,
|
||||
status.to_string()
|
||||
);
|
||||
|
||||
funcs::set_presence(ctx, status);
|
||||
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
|
||||
|
Loading…
Reference in New Issue
Block a user