可算加上我心心念念的 uptime 了,目前记录是9d不崩

当然实际上我估计能更长, 如果不怎么更新我估计一个月都没问题(不是)
This commit is contained in:
shenjack 2024-07-23 23:27:08 +08:00
parent 18df7d1a89
commit 8dd5c0b7d4
Signed by: shenjack
GPG Key ID: 7B1134A979775551
12 changed files with 65 additions and 18 deletions

26
Cargo.lock generated
View File

@ -522,9 +522,9 @@ checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "heck"
version = "0.4.1"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hermit-abi"
@ -1061,15 +1061,15 @@ dependencies = [
[[package]]
name = "pyo3"
version = "0.21.2"
version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8"
checksum = "831e8e819a138c36e212f3af3fd9eeffed6bf1510a805af35b0edee5ffa59433"
dependencies = [
"cfg-if",
"indoc",
"libc",
"memoffset",
"parking_lot",
"once_cell",
"portable-atomic",
"pyo3-build-config",
"pyo3-ffi",
@ -1079,9 +1079,9 @@ dependencies = [
[[package]]
name = "pyo3-build-config"
version = "0.21.2"
version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50"
checksum = "1e8730e591b14492a8945cdff32f089250b05f5accecf74aeddf9e8272ce1fa8"
dependencies = [
"once_cell",
"target-lexicon",
@ -1089,9 +1089,9 @@ dependencies = [
[[package]]
name = "pyo3-ffi"
version = "0.21.2"
version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403"
checksum = "5e97e919d2df92eb88ca80a037969f44e5e70356559654962cbb3316d00300c6"
dependencies = [
"libc",
"pyo3-build-config",
@ -1099,9 +1099,9 @@ dependencies = [
[[package]]
name = "pyo3-macros"
version = "0.21.2"
version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c"
checksum = "eb57983022ad41f9e683a599f2fd13c3664d7063a3ac5714cae4b7bee7d3f206"
dependencies = [
"proc-macro2",
"pyo3-macros-backend",
@ -1111,9 +1111,9 @@ dependencies = [
[[package]]
name = "pyo3-macros-backend"
version = "0.21.2"
version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c"
checksum = "ec480c0c51ddec81019531705acac51bcdbeae563557c982aa8263bb96880372"
dependencies = [
"heck",
"proc-macro2",

View File

@ -41,7 +41,7 @@ colored = "2.1"
# runtime
tokio = { version = "1.37", features = ["full"] }
futures-util = "0.3.30"
pyo3 = { version = "0.21.2", features = ["experimental-async"] }
pyo3 = { version = "0.22.2", features = ["experimental-async", "py-clone"] }
anyhow = { version = "1.0", features = ["backtrace"] }
# async 这玩意以后在搞
# pyo3-async = "0.3.2"

View File

@ -1,6 +1,7 @@
# Python 兼容版本 3.8+
from typing import Callable, Tuple, NewType, Optional, Union
from datetime import datetime
"""
ica.rs
@ -161,6 +162,10 @@ class IcaClient:
def version(self) -> str:
...
@property
def startup_time(self) -> datetime:
"""请注意, 此时刻为 UTC 时刻"""
...
@property
def ica_version(self) -> str:
"""shenbot ica 的版本号"""
...
@ -261,6 +266,10 @@ class TailchatClient:
def tailchat_version(self) -> str:
"""tailchat 的版本号"""
...
@property
def startup_time(self) -> datetime:
"""请注意, 此时刻为 UTC 时刻"""
...
def debug(self, message: str) -> None:
"""向日志中输出调试信息"""
def info(self, message: str) -> None:

View File

@ -1,6 +1,7 @@
import io
import psutil
import platform
from datetime import datetime, timezone
from typing import TYPE_CHECKING, TypeVar
from PIL import (Image, ImageDraw, ImageFont)
@ -57,6 +58,11 @@ def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
reply = msg.reply_with(datas)
reply.set_img(local_env_image(), "image/png", False)
client.send_message(reply)
elif msg.content == "/bot-uptime":
uptime = client.startup_time
up_delta = datetime.now(timezone.utc) - uptime
reply = msg.reply_with(f"Bot 运行时间: {up_delta}")
client.send_message(reply)
def on_tailchat_message(msg: TailchatReciveMessage, client: TailchatClient) -> None:
@ -69,3 +75,8 @@ def on_tailchat_message(msg: TailchatReciveMessage, client: TailchatClient) -> N
reply = msg.reply_with(datas)
reply.set_img(local_env_image(), "just_img.png")
client.send_message(reply)
elif msg.content == "/bot-uptime":
uptime = client.startup_time
up_delta = datetime.now(timezone.utc) - uptime
reply = msg.reply_with(f"Bot 运行时间: {up_delta}")
client.send_message(reply)

View File

@ -10,7 +10,7 @@ use crate::config::IcaConfig;
use crate::error::{ClientResult, IcaError};
use crate::StopGetter;
const ICA_PROTOCOL_VERSION: &str = "2.12.6";
const ICA_PROTOCOL_VERSION: &str = "2.12.9";
pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> {
let span = span!(Level::INFO, "Icalingua Client");

View File

@ -123,6 +123,7 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
"messageSuccess",
"messageFailed",
"setAllChatGroups",
"handleRequest", // 处理验证消息 (加入请求之类的)
// 忽略的
"notify",
"syncRead", // 同步已读

View File

@ -18,6 +18,7 @@ pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus {
config: None,
ica_status: None,
tailchat_status: None,
startup_time: None,
};
pub type MainStatus = status::BotStatus;
@ -25,8 +26,8 @@ pub type MainStatus = status::BotStatus;
pub type StopGetter = tokio::sync::oneshot::Receiver<()>;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const ICA_VERSION: &str = "1.6.0";
pub const TAILCHAT_VERSION: &str = "1.2.0";
pub const ICA_VERSION: &str = "1.6.1";
pub const TAILCHAT_VERSION: &str = "1.2.1";
#[macro_export]
macro_rules! async_callback_with_state {

View File

@ -1,3 +1,5 @@
use std::time::SystemTime;
use pyo3::prelude::*;
use rust_socketio::asynchronous::Client;
use tokio::runtime::Runtime;
@ -215,6 +217,8 @@ impl IcaClientPy {
pub fn get_version(&self) -> String { crate::VERSION.to_string() }
#[getter]
pub fn get_ica_version(&self) -> String { crate::ICA_VERSION.to_string() }
#[getter]
pub fn get_startup_time(&self) -> SystemTime { crate::MainStatus::get_startup_time() }
pub fn debug(&self, content: String) {
debug!("{}", content);

View File

@ -1,3 +1,5 @@
use std::time::SystemTime;
use pyo3::prelude::*;
use rust_socketio::asynchronous::Client;
@ -64,6 +66,8 @@ impl TailchatClientPy {
pub fn get_version(&self) -> String { crate::VERSION.to_string() }
#[getter]
pub fn get_tailchat_version(&self) -> String { crate::TAILCHAT_VERSION.to_string() }
#[getter]
pub fn get_startup_time(&self) -> SystemTime { crate::MainStatus::get_startup_time() }
pub fn debug(&self, content: String) {
debug!("{}", content);
}

View File

@ -6,6 +6,7 @@ pub struct BotStatus {
pub config: Option<BotConfig>,
pub ica_status: Option<ica::MainStatus>,
pub tailchat_status: Option<tailchat::MainStatus>,
pub startup_time: Option<std::time::SystemTime>,
}
impl BotStatus {
@ -35,9 +36,14 @@ impl BotStatus {
online_status: ica::OnlineData::default(),
});
MAIN_STATUS.config = Some(config);
MAIN_STATUS.startup_time = Some(std::time::SystemTime::now());
}
}
pub fn get_startup_time() -> std::time::SystemTime {
unsafe { MAIN_STATUS.startup_time.unwrap() }
}
pub fn global_config() -> &'static BotConfig { unsafe { MAIN_STATUS.config.as_ref().unwrap() } }
pub fn global_ica_status() -> &'static ica::MainStatus {

View File

@ -37,7 +37,7 @@ pub async fn start_tailchat(
let client = reqwest_ClientBuilder::new().default_headers(header_map.clone()).build()?;
let status = match client
.post(&format!("{}/api/openapi/bot/login", config.host))
.post(format!("{}/api/openapi/bot/login", config.host))
.body(json! {{"appId": config.app_id, "token": token}}.to_string())
.send()
.await

11
news.md
View File

@ -1,5 +1,16 @@
# 更新日志
## 0.6.9
我决定立即发布 0.6.9
- 添加了 `Client.startup_time() -> datetime` 方法
- 用于获取 bot 启动时间
- 这样就可以经常吹我 bot 跑了多久了 ( ˘•ω•˘ )
- 顺手加上了 `/bot-uptime` 命令
- 可以获取 bot 运行时间
- 谢谢 GitHub Copilot 的帮助
## 0.6.8
- 修复了一堆拼写错误