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