Use the /etc/os-release
instead for OS info
All checks were successful
Build and push container image / build (push) Successful in 14m53s
All checks were successful
Build and push container image / build (push) Successful in 14m53s
This commit is contained in:
parent
f936c29814
commit
de13b472bb
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -972,7 +972,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kon"
|
name = "kon"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bb8",
|
"bb8",
|
||||||
"bb8-postgres",
|
"bb8-postgres",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kon"
|
name = "kon"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -9,12 +9,43 @@ use crate::{
|
|||||||
|
|
||||||
use sysinfo::System;
|
use sysinfo::System;
|
||||||
use uptime_lib::get;
|
use uptime_lib::get;
|
||||||
use std::time::{
|
use std::{
|
||||||
Duration,
|
fs::File,
|
||||||
SystemTime,
|
path::Path,
|
||||||
UNIX_EPOCH
|
time::{
|
||||||
|
Duration,
|
||||||
|
SystemTime,
|
||||||
|
UNIX_EPOCH
|
||||||
|
},
|
||||||
|
io::{
|
||||||
|
BufRead,
|
||||||
|
BufReader
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fn get_os_info() -> String {
|
||||||
|
let path = Path::new("/etc/os-release");
|
||||||
|
let mut name = "BoringOS".to_string();
|
||||||
|
let mut version = "v0.0".to_string();
|
||||||
|
|
||||||
|
if let Ok(file) = File::open(&path) {
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
for line in reader.lines() {
|
||||||
|
if let Ok(line) = line {
|
||||||
|
if line.starts_with("NAME=") {
|
||||||
|
name = line.split('=').nth(1).unwrap_or_default().trim_matches('"').to_string();
|
||||||
|
} else if line.starts_with("VERSION=") {
|
||||||
|
version = line.split('=').nth(1).unwrap_or_default().trim_matches('"').to_string();
|
||||||
|
} else if line.starts_with("VERSION_ID=") {
|
||||||
|
version = line.split('=').nth(1).unwrap_or_default().trim_matches('"').to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
format!("{} {}", name, version)
|
||||||
|
}
|
||||||
|
|
||||||
/// Retrieve host and bot uptimes
|
/// Retrieve host and bot uptimes
|
||||||
#[poise::command(slash_command)]
|
#[poise::command(slash_command)]
|
||||||
pub async fn uptime(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
pub async fn uptime(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
||||||
@ -22,13 +53,12 @@ pub async fn uptime(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
|||||||
let mut sys = System::new_all();
|
let mut sys = System::new_all();
|
||||||
sys.refresh_all();
|
sys.refresh_all();
|
||||||
|
|
||||||
// Fetch system's operating system
|
|
||||||
let sys_os_info = os_info::get();
|
|
||||||
let sys_os = format!("{} {}", sys_os_info.os_type(), sys_os_info.version());
|
|
||||||
|
|
||||||
// Fetch system's uptime
|
// Fetch system's uptime
|
||||||
let sys_uptime = get().unwrap().as_secs();
|
let sys_uptime = get().unwrap().as_secs();
|
||||||
|
|
||||||
|
// Fetch system's processor
|
||||||
|
let cpu = sys.cpus();
|
||||||
|
|
||||||
// Fetch bot's process uptime
|
// Fetch bot's process uptime
|
||||||
let curr_pid = sysinfo::get_current_pid().unwrap();
|
let curr_pid = sysinfo::get_current_pid().unwrap();
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
@ -42,7 +72,8 @@ pub async fn uptime(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
|||||||
format!("**{} {}**", _bot.name, BOT_VERSION.as_str()),
|
format!("**{} {}**", _bot.name, BOT_VERSION.as_str()),
|
||||||
format!(">>> System: `{}`", format_duration(sys_uptime)),
|
format!(">>> System: `{}`", format_duration(sys_uptime)),
|
||||||
format!("Process: `{}`", format_duration(proc_uptime)),
|
format!("Process: `{}`", format_duration(proc_uptime)),
|
||||||
format!("OS: `{}`", sys_os)
|
format!("CPU: `{}`", format!("{}", cpu[0].brand())),
|
||||||
|
format!("OS: `{}`", get_os_info())
|
||||||
];
|
];
|
||||||
ctx.reply(concat_message(stat_msg)).await?;
|
ctx.reply(concat_message(stat_msg)).await?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user