Add error handler and finally fix the query
All checks were successful
Build and push container image / build (push) Successful in 10m38s
All checks were successful
Build and push container image / build (push) Successful in 10m38s
This commit is contained in:
parent
85e0ffce71
commit
3da094eaa6
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -833,7 +833,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kon"
|
name = "kon"
|
||||||
version = "0.1.15"
|
version = "0.1.16"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo_toml",
|
"cargo_toml",
|
||||||
"gamedig",
|
"gamedig",
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kon"
|
name = "kon"
|
||||||
version = "0.1.15"
|
version = "0.1.16"
|
||||||
rust-version = "1.74"
|
rust-version = "1.74"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cargo_toml = "0.19.2"
|
cargo_toml = "0.19.2"
|
||||||
gamedig = "0.4.1"
|
gamedig = "0.4.1"
|
||||||
@ -31,3 +29,4 @@ debug = true
|
|||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
debug = false
|
debug = false
|
||||||
|
strip = true
|
||||||
|
@ -27,9 +27,9 @@ static PMS_BASE: Lazy<String> = Lazy::new(||
|
|||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct MinecraftQueryData {
|
struct MinecraftQueryData {
|
||||||
motd: MinecraftMotd,
|
motd: Option<MinecraftMotd>,
|
||||||
players: MinecraftPlayers,
|
players: Option<MinecraftPlayers>,
|
||||||
version: String,
|
version: Option<String>,
|
||||||
online: bool
|
online: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ struct MinecraftMotd {
|
|||||||
clean: Vec<String>
|
clean: Vec<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, Clone, Copy)]
|
||||||
struct MinecraftPlayers {
|
struct MinecraftPlayers {
|
||||||
online: i32,
|
online: i32,
|
||||||
max: i32
|
max: i32
|
||||||
@ -70,6 +70,8 @@ async fn gs_query_minecraft(server_ip: &str) -> Result<MinecraftQueryData, Error
|
|||||||
if req.status().is_success() {
|
if req.status().is_success() {
|
||||||
let data: MinecraftQueryData = req.json().await?;
|
let data: MinecraftQueryData = req.json().await?;
|
||||||
Ok(data)
|
Ok(data)
|
||||||
|
} else if req.status().is_server_error() {
|
||||||
|
Err(Error::from("Webserver returned a 5xx error."))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::from("Failed to query the server."))
|
Err(Error::from("Failed to query the server."))
|
||||||
}
|
}
|
||||||
@ -137,9 +139,9 @@ pub async fn gs(
|
|||||||
let mut embed_fields = Vec::new();
|
let mut embed_fields = Vec::new();
|
||||||
embed_fields.push(("Server IP".to_owned(), ip_address.to_owned(), true));
|
embed_fields.push(("Server IP".to_owned(), ip_address.to_owned(), true));
|
||||||
embed_fields.push((format!("\u{200b}"), format!("\u{200b}"), true));
|
embed_fields.push((format!("\u{200b}"), format!("\u{200b}"), true));
|
||||||
embed_fields.push(("MOTD".to_owned(), format!("{}", result.motd.clean[0]), true));
|
embed_fields.push(("MOTD".to_owned(), format!("{}", result.motd.unwrap().clean[0]), true));
|
||||||
embed_fields.push(("Players".to_owned(), format!("**{}**/**{}**", result.players.online, result.players.max), true));
|
embed_fields.push(("Players".to_owned(), format!("**{}**/**{}**", result.players.unwrap().online, result.players.clone().unwrap().max), true));
|
||||||
embed_fields.push(("Version".to_owned(), result.version, true));
|
embed_fields.push(("Version".to_owned(), result.version.unwrap(), true));
|
||||||
|
|
||||||
ctx.send(CreateReply::default()
|
ctx.send(CreateReply::default()
|
||||||
.embed(embed
|
.embed(embed
|
||||||
@ -149,7 +151,7 @@ pub async fn gs(
|
|||||||
).await?;
|
).await?;
|
||||||
} else {
|
} else {
|
||||||
ctx.send(CreateReply::default()
|
ctx.send(CreateReply::default()
|
||||||
.content(format!("Server **{}** (`{}`) is currently offline.", server_name, ip_address))
|
.content(format!("**{}** (`{}`) is currently offline or unreachable.", server_name, ip_address))
|
||||||
).await?;
|
).await?;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -76,6 +76,14 @@ async fn main() {
|
|||||||
};
|
};
|
||||||
println!("[{}] {} ran /{}", get_guild_name, ctx.author().name, ctx.command().qualified_name)
|
println!("[{}] {} ran /{}", get_guild_name, ctx.author().name, ctx.command().qualified_name)
|
||||||
}),
|
}),
|
||||||
|
on_error: |error| Box::pin(async move {
|
||||||
|
match error {
|
||||||
|
poise::FrameworkError::Command { error, ctx, .. } => {
|
||||||
|
println!("PoiseCommandError({}): {}", ctx.command().qualified_name, error);
|
||||||
|
}
|
||||||
|
other => println!("PoiseOtherError: {:?}", other)
|
||||||
|
}
|
||||||
|
}),
|
||||||
initialize_owners: true,
|
initialize_owners: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user