Logging better

This commit is contained in:
August 2026-05-07 00:22:32 -04:00
parent ffea97668a
commit d5f9c0ead6
Signed by: shibedrill
SSH Key Fingerprint: SHA256:M0m3JW1s38BgO2t0fG146Yxd9OJ2IOqkvCAsuRHQ6Pw
4 changed files with 21 additions and 4 deletions

15
Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM scratch
COPY --from=grandmaster/cacerts /etc/ssl/certs /etc/ssl/certs
ADD target/x86_64-unknown-linux-musl/release/playerbot /
ADD config.json /
ENV RUST_LOG="playerbot=info"
CMD ["/playerbot"]

View File

@ -63,20 +63,24 @@ pub async fn event_handler(
let http_response = request(data.server.api_address()) let http_response = request(data.server.api_address())
.await .await
.expect("Error executing request"); .expect("Error executing request");
trace!("Got HTTP response");
let results = data.server.parse( let results = data.server.parse(
http_response http_response
.text() .text()
.await .await
.expect("Response had no body text"), .expect("Response had no body text"),
); );
trace!("Parsed response");
match &results { match &results {
ServerResponse::Offline => { ServerResponse::Offline => {
info!("Got status: Offline");
ctx.set_presence( ctx.set_presence(
Some(ActivityData::custom("Server offline!")), Some(ActivityData::custom("Server offline!")),
serenity::OnlineStatus::DoNotDisturb, serenity::OnlineStatus::DoNotDisturb,
); );
} }
ServerResponse::Online(online_info) => { ServerResponse::Online(online_info) => {
info!("Got status: Online");
ctx.set_presence( ctx.set_presence(
Some(ActivityData::custom(format!( Some(ActivityData::custom(format!(
"{}/{} online, v{}", "{}/{} online, v{}",

View File

@ -13,6 +13,7 @@ use std::path::Path;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
env_logger::init(); env_logger::init();
info!("Starting up!");
let config = config_parser::parse_configs(Path::new("config.json")) let config = config_parser::parse_configs(Path::new("config.json"))
.expect("Could not parse config.json"); .expect("Could not parse config.json");
info!("Got config file"); info!("Got config file");

View File

@ -6,9 +6,6 @@ const USER_AGENT: &str = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36
pub async fn request(url: Url) -> Result<Response, reqwest::Error> { pub async fn request(url: Url) -> Result<Response, reqwest::Error> {
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let mut request = reqwest::Request::new(reqwest::Method::GET, url); let mut request = reqwest::Request::new(reqwest::Method::GET, url);
request.headers_mut().append( request.headers_mut().append("User-Agent", HeaderValue::from_str(USER_AGENT).expect("Could not build header"));
"User-Agent",
HeaderValue::from_str(USER_AGENT).expect("Could not build header"),
);
client.execute(request).await client.execute(request).await
} }