mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 04:31:05 +08:00
可算加上我心心念念的 uptime 了,目前记录是9d不崩
当然实际上我估计能更长, 如果不怎么更新我估计一个月都没问题(不是)
This commit is contained in:
parent
18df7d1a89
commit
8dd5c0b7d4
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -522,9 +522,9 @@ checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.4.1"
|
version = "0.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
|
@ -1061,15 +1061,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3"
|
name = "pyo3"
|
||||||
version = "0.21.2"
|
version = "0.22.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8"
|
checksum = "831e8e819a138c36e212f3af3fd9eeffed6bf1510a805af35b0edee5ffa59433"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"indoc",
|
"indoc",
|
||||||
"libc",
|
"libc",
|
||||||
"memoffset",
|
"memoffset",
|
||||||
"parking_lot",
|
"once_cell",
|
||||||
"portable-atomic",
|
"portable-atomic",
|
||||||
"pyo3-build-config",
|
"pyo3-build-config",
|
||||||
"pyo3-ffi",
|
"pyo3-ffi",
|
||||||
|
@ -1079,9 +1079,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-build-config"
|
name = "pyo3-build-config"
|
||||||
version = "0.21.2"
|
version = "0.22.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50"
|
checksum = "1e8730e591b14492a8945cdff32f089250b05f5accecf74aeddf9e8272ce1fa8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
|
@ -1089,9 +1089,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-ffi"
|
name = "pyo3-ffi"
|
||||||
version = "0.21.2"
|
version = "0.22.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403"
|
checksum = "5e97e919d2df92eb88ca80a037969f44e5e70356559654962cbb3316d00300c6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"pyo3-build-config",
|
"pyo3-build-config",
|
||||||
|
@ -1099,9 +1099,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-macros"
|
name = "pyo3-macros"
|
||||||
version = "0.21.2"
|
version = "0.22.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c"
|
checksum = "eb57983022ad41f9e683a599f2fd13c3664d7063a3ac5714cae4b7bee7d3f206"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"pyo3-macros-backend",
|
"pyo3-macros-backend",
|
||||||
|
@ -1111,9 +1111,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-macros-backend"
|
name = "pyo3-macros-backend"
|
||||||
version = "0.21.2"
|
version = "0.22.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c"
|
checksum = "ec480c0c51ddec81019531705acac51bcdbeae563557c982aa8263bb96880372"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
|
|
|
@ -41,7 +41,7 @@ colored = "2.1"
|
||||||
# runtime
|
# runtime
|
||||||
tokio = { version = "1.37", features = ["full"] }
|
tokio = { version = "1.37", features = ["full"] }
|
||||||
futures-util = "0.3.30"
|
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"] }
|
anyhow = { version = "1.0", features = ["backtrace"] }
|
||||||
# async 这玩意以后在搞
|
# async 这玩意以后在搞
|
||||||
# pyo3-async = "0.3.2"
|
# pyo3-async = "0.3.2"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# Python 兼容版本 3.8+
|
# Python 兼容版本 3.8+
|
||||||
|
|
||||||
from typing import Callable, Tuple, NewType, Optional, Union
|
from typing import Callable, Tuple, NewType, Optional, Union
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
"""
|
"""
|
||||||
ica.rs
|
ica.rs
|
||||||
|
@ -161,6 +162,10 @@ class IcaClient:
|
||||||
def version(self) -> str:
|
def version(self) -> str:
|
||||||
...
|
...
|
||||||
@property
|
@property
|
||||||
|
def startup_time(self) -> datetime:
|
||||||
|
"""请注意, 此时刻为 UTC 时刻"""
|
||||||
|
...
|
||||||
|
@property
|
||||||
def ica_version(self) -> str:
|
def ica_version(self) -> str:
|
||||||
"""shenbot ica 的版本号"""
|
"""shenbot ica 的版本号"""
|
||||||
...
|
...
|
||||||
|
@ -261,6 +266,10 @@ class TailchatClient:
|
||||||
def tailchat_version(self) -> str:
|
def tailchat_version(self) -> str:
|
||||||
"""tailchat 的版本号"""
|
"""tailchat 的版本号"""
|
||||||
...
|
...
|
||||||
|
@property
|
||||||
|
def startup_time(self) -> datetime:
|
||||||
|
"""请注意, 此时刻为 UTC 时刻"""
|
||||||
|
...
|
||||||
def debug(self, message: str) -> None:
|
def debug(self, message: str) -> None:
|
||||||
"""向日志中输出调试信息"""
|
"""向日志中输出调试信息"""
|
||||||
def info(self, message: str) -> None:
|
def info(self, message: str) -> None:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import io
|
import io
|
||||||
import psutil
|
import psutil
|
||||||
import platform
|
import platform
|
||||||
|
from datetime import datetime, timezone
|
||||||
from typing import TYPE_CHECKING, TypeVar
|
from typing import TYPE_CHECKING, TypeVar
|
||||||
from PIL import (Image, ImageDraw, ImageFont)
|
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 = msg.reply_with(datas)
|
||||||
reply.set_img(local_env_image(), "image/png", False)
|
reply.set_img(local_env_image(), "image/png", False)
|
||||||
client.send_message(reply)
|
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:
|
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 = msg.reply_with(datas)
|
||||||
reply.set_img(local_env_image(), "just_img.png")
|
reply.set_img(local_env_image(), "just_img.png")
|
||||||
client.send_message(reply)
|
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)
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::config::IcaConfig;
|
||||||
use crate::error::{ClientResult, IcaError};
|
use crate::error::{ClientResult, IcaError};
|
||||||
use crate::StopGetter;
|
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> {
|
pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> {
|
||||||
let span = span!(Level::INFO, "Icalingua Client");
|
let span = span!(Level::INFO, "Icalingua Client");
|
||||||
|
|
|
@ -123,6 +123,7 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
||||||
"messageSuccess",
|
"messageSuccess",
|
||||||
"messageFailed",
|
"messageFailed",
|
||||||
"setAllChatGroups",
|
"setAllChatGroups",
|
||||||
|
"handleRequest", // 处理验证消息 (加入请求之类的)
|
||||||
// 忽略的
|
// 忽略的
|
||||||
"notify",
|
"notify",
|
||||||
"syncRead", // 同步已读
|
"syncRead", // 同步已读
|
||||||
|
|
|
@ -18,6 +18,7 @@ pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus {
|
||||||
config: None,
|
config: None,
|
||||||
ica_status: None,
|
ica_status: None,
|
||||||
tailchat_status: None,
|
tailchat_status: None,
|
||||||
|
startup_time: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type MainStatus = status::BotStatus;
|
pub type MainStatus = status::BotStatus;
|
||||||
|
@ -25,8 +26,8 @@ pub type MainStatus = status::BotStatus;
|
||||||
pub type StopGetter = tokio::sync::oneshot::Receiver<()>;
|
pub type StopGetter = tokio::sync::oneshot::Receiver<()>;
|
||||||
|
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
pub const ICA_VERSION: &str = "1.6.0";
|
pub const ICA_VERSION: &str = "1.6.1";
|
||||||
pub const TAILCHAT_VERSION: &str = "1.2.0";
|
pub const TAILCHAT_VERSION: &str = "1.2.1";
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! async_callback_with_state {
|
macro_rules! async_callback_with_state {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use rust_socketio::asynchronous::Client;
|
use rust_socketio::asynchronous::Client;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
@ -215,6 +217,8 @@ impl IcaClientPy {
|
||||||
pub fn get_version(&self) -> String { crate::VERSION.to_string() }
|
pub fn get_version(&self) -> String { crate::VERSION.to_string() }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_ica_version(&self) -> String { crate::ICA_VERSION.to_string() }
|
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) {
|
pub fn debug(&self, content: String) {
|
||||||
debug!("{}", content);
|
debug!("{}", content);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
use rust_socketio::asynchronous::Client;
|
use rust_socketio::asynchronous::Client;
|
||||||
|
@ -64,6 +66,8 @@ impl TailchatClientPy {
|
||||||
pub fn get_version(&self) -> String { crate::VERSION.to_string() }
|
pub fn get_version(&self) -> String { crate::VERSION.to_string() }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_tailchat_version(&self) -> String { crate::TAILCHAT_VERSION.to_string() }
|
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) {
|
pub fn debug(&self, content: String) {
|
||||||
debug!("{}", content);
|
debug!("{}", content);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub struct BotStatus {
|
||||||
pub config: Option<BotConfig>,
|
pub config: Option<BotConfig>,
|
||||||
pub ica_status: Option<ica::MainStatus>,
|
pub ica_status: Option<ica::MainStatus>,
|
||||||
pub tailchat_status: Option<tailchat::MainStatus>,
|
pub tailchat_status: Option<tailchat::MainStatus>,
|
||||||
|
pub startup_time: Option<std::time::SystemTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BotStatus {
|
impl BotStatus {
|
||||||
|
@ -35,9 +36,14 @@ impl BotStatus {
|
||||||
online_status: ica::OnlineData::default(),
|
online_status: ica::OnlineData::default(),
|
||||||
});
|
});
|
||||||
MAIN_STATUS.config = Some(config);
|
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_config() -> &'static BotConfig { unsafe { MAIN_STATUS.config.as_ref().unwrap() } }
|
||||||
|
|
||||||
pub fn global_ica_status() -> &'static ica::MainStatus {
|
pub fn global_ica_status() -> &'static ica::MainStatus {
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub async fn start_tailchat(
|
||||||
|
|
||||||
let client = reqwest_ClientBuilder::new().default_headers(header_map.clone()).build()?;
|
let client = reqwest_ClientBuilder::new().default_headers(header_map.clone()).build()?;
|
||||||
let status = match client
|
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())
|
.body(json! {{"appId": config.app_id, "token": token}}.to_string())
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in New Issue
Block a user