mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-04-12 19:49:55 +08:00
Compare commits
6 Commits
9d74853d1e
...
75832bfa2e
Author | SHA1 | Date | |
---|---|---|---|
75832bfa2e | |||
c5de63f02e | |||
686291755d | |||
38cfd2dce7 | |||
98633aa5cc | |||
4aa969adc5 |
88
Cargo.lock
generated
88
Cargo.lock
generated
|
@ -171,9 +171,9 @@ checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da"
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.1.36"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baee610e9452a8f6f0a1b6194ec09ff9e2d85dea54432acdae41aa0761c95d70"
|
||||
checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47"
|
||||
dependencies = [
|
||||
"shlex",
|
||||
]
|
||||
|
@ -232,9 +232,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
|||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.14"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0"
|
||||
checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
@ -698,7 +698,7 @@ dependencies = [
|
|||
"rust_socketio",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.0",
|
||||
"thiserror 2.0.3",
|
||||
"tokio",
|
||||
"toml",
|
||||
"toml_edit",
|
||||
|
@ -899,9 +899,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.162"
|
||||
version = "0.2.164"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398"
|
||||
checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
|
@ -1189,9 +1189,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pyo3"
|
||||
version = "0.22.6"
|
||||
version = "0.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884"
|
||||
checksum = "7ebb0c0cc0de9678e53be9ccf8a2ab53045e6e3a8be03393ceccc5e7396ccb40"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"indoc",
|
||||
|
@ -1207,9 +1207,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pyo3-build-config"
|
||||
version = "0.22.6"
|
||||
version = "0.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38"
|
||||
checksum = "80e3ce69c4ec34476534b490e412b871ba03a82e35604c3dfb95fcb6bfb60c09"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"target-lexicon",
|
||||
|
@ -1217,9 +1217,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pyo3-ffi"
|
||||
version = "0.22.6"
|
||||
version = "0.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636"
|
||||
checksum = "3b09f311c76b36dfd6dd6f7fa6f9f18e7e46a1c937110d283e80b12ba2468a75"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"pyo3-build-config",
|
||||
|
@ -1227,9 +1227,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pyo3-macros"
|
||||
version = "0.22.6"
|
||||
version = "0.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453"
|
||||
checksum = "fd4f74086536d1e1deaff99ec0387481fb3325c82e4e48be0e75ab3d3fcb487a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"pyo3-macros-backend",
|
||||
|
@ -1239,9 +1239,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pyo3-macros-backend"
|
||||
version = "0.22.6"
|
||||
version = "0.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe"
|
||||
checksum = "9e77dfeb76b32bbf069144a5ea0a36176ab59c8db9ce28732d0f06f096bbfbc8"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
|
@ -1377,7 +1377,7 @@ dependencies = [
|
|||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 1.0.68",
|
||||
"thiserror 1.0.69",
|
||||
"tokio",
|
||||
"tokio-tungstenite",
|
||||
"tungstenite",
|
||||
|
@ -1402,7 +1402,7 @@ dependencies = [
|
|||
"rust_engineio",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 1.0.68",
|
||||
"thiserror 1.0.69",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
@ -1424,9 +1424,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.39"
|
||||
version = "0.38.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee"
|
||||
checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
|
@ -1437,9 +1437,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.23.16"
|
||||
version = "0.23.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e"
|
||||
checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"rustls-pki-types",
|
||||
|
@ -1482,9 +1482,9 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
|||
|
||||
[[package]]
|
||||
name = "schannel"
|
||||
version = "0.1.26"
|
||||
version = "0.1.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1"
|
||||
checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
@ -1510,9 +1510,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "security-framework-sys"
|
||||
version = "2.12.0"
|
||||
version = "2.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6"
|
||||
checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
|
@ -1526,18 +1526,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.214"
|
||||
version = "1.0.215"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5"
|
||||
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.214"
|
||||
version = "1.0.215"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766"
|
||||
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1546,9 +1546,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.132"
|
||||
version = "1.0.133"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03"
|
||||
checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
|
@ -1758,27 +1758,27 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.68"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892"
|
||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||
dependencies = [
|
||||
"thiserror-impl 1.0.68",
|
||||
"thiserror-impl 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.0"
|
||||
version = "2.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15291287e9bff1bc6f9ff3409ed9af665bec7a5fc8ac079ea96be07bca0e2668"
|
||||
checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa"
|
||||
dependencies = [
|
||||
"thiserror-impl 2.0.0",
|
||||
"thiserror-impl 2.0.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.68"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e"
|
||||
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1787,9 +1787,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.0"
|
||||
version = "2.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22efd00f33f93fa62848a7cab956c3d38c8d43095efda1decfc2b3a5dc0b8972"
|
||||
checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -2043,7 +2043,7 @@ dependencies = [
|
|||
"native-tls",
|
||||
"rand",
|
||||
"sha1",
|
||||
"thiserror 1.0.68",
|
||||
"thiserror 1.0.69",
|
||||
"url",
|
||||
"utf-8",
|
||||
]
|
||||
|
|
|
@ -40,9 +40,9 @@ toml_edit = "0.22.20"
|
|||
colored = "2.1"
|
||||
|
||||
# runtime
|
||||
tokio = { version = "1.37", features = ["full"] }
|
||||
tokio = { version = "1.41", features = ["full"] }
|
||||
futures-util = "0.3.30"
|
||||
pyo3 = { version = "0.22", features = ["experimental-async", "py-clone"] }
|
||||
pyo3 = { version = "0.23", features = ["experimental-async", "py-clone"] }
|
||||
anyhow = { version = "1.0", features = ["backtrace"] }
|
||||
# async 这玩意以后在搞
|
||||
# pyo3-async = "0.3.2"
|
||||
|
|
|
@ -43,6 +43,8 @@ impl Room {
|
|||
// 手动 patch 一下 roomId
|
||||
// ica issue: https://github.com/Icalingua-plus-plus/Icalingua-plus-plus/issues/793
|
||||
if parse_json.get("roomId").is_none_or(|id| id.is_null()) {
|
||||
use tracing::warn;
|
||||
warn!("Room::new_from_json roomId is None, patching it to -1, raw: {:#?}", raw_json);
|
||||
parse_json["roomId"] = JsonValue::Number(Number::from(-1));
|
||||
}
|
||||
let inner = match serde_json::from_value::<InnerRoom>(parse_json) {
|
||||
|
@ -67,9 +69,7 @@ impl Room {
|
|||
}
|
||||
}
|
||||
|
||||
fn room_id_default() -> RoomId {
|
||||
-1
|
||||
}
|
||||
fn room_id_default() -> RoomId { -1 }
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
struct InnerRoom {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::{
|
||||
hash::{DefaultHasher, Hash, Hasher},
|
||||
time::Duration,
|
||||
sync::OnceLock,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
mod config;
|
||||
|
@ -21,7 +22,6 @@ 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;
|
||||
|
@ -48,11 +48,15 @@ by shenjackyuanjie"#;
|
|||
/// 获取帮助信息
|
||||
pub fn help_msg() -> String { format!("{}\n{}", version_str(), HELP_MSG) }
|
||||
|
||||
static STARTUP_TIME: OnceLock<SystemTime> = OnceLock::new();
|
||||
|
||||
pub fn start_up_time() -> SystemTime { *STARTUP_TIME.get().expect("WTF, why did you panic?") }
|
||||
|
||||
/// 获得当前客户端的 id
|
||||
/// 防止串号
|
||||
pub fn client_id() -> String {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
MainStatus::get_startup_time().hash(&mut hasher);
|
||||
start_up_time().hash(&mut hasher);
|
||||
let data = hasher.finish();
|
||||
// 取后6位
|
||||
format!("{:06}", data % 1_000_000)
|
||||
|
@ -73,7 +77,7 @@ pub fn version_str() -> String {
|
|||
|
||||
/// 是否为稳定版本
|
||||
/// 会在 release 的时候设置为 true
|
||||
pub const STABLE: bool = true;
|
||||
pub const STABLE: bool = false;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! async_callback_with_state {
|
||||
|
@ -96,6 +100,9 @@ macro_rules! async_any_callback_with_state {
|
|||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let start_up_time = SystemTime::now();
|
||||
STARTUP_TIME.set(start_up_time).expect("WTF, why did you panic?");
|
||||
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.thread_name("shenbot-rs")
|
||||
|
|
|
@ -127,7 +127,7 @@ macro_rules! call_py_func {
|
|||
e,
|
||||
// 获取 traceback
|
||||
match &e {
|
||||
PyPluginError::FuncCallError(py_err, _, _) => match py_err.traceback_bound(py) {
|
||||
PyPluginError::FuncCallError(py_err, _, _) => match py_err.traceback(py) {
|
||||
Some(traceback) => match traceback.format() {
|
||||
Ok(trace) => trace,
|
||||
Err(trace_e) => format!("failed to format traceback: {:?}", trace_e),
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
pub mod ica;
|
||||
pub mod tailchat;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::{
|
||||
pyclass, pymethods, IntoPyObject, Bound,
|
||||
PyAny, PyRef,
|
||||
types::{PyBool, PyString},
|
||||
};
|
||||
use toml::Value as TomlValue;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -26,21 +30,25 @@ pub struct ConfigDataPy {
|
|||
|
||||
#[pymethods]
|
||||
impl ConfigDataPy {
|
||||
pub fn __getitem__(self_: PyRef<'_, Self>, key: String) -> Option<Py<PyAny>> {
|
||||
pub fn __getitem__(self_: PyRef<'_, Self>, key: String) -> Option<Bound<PyAny>> {
|
||||
match self_.data.get(&key) {
|
||||
Some(value) => match value {
|
||||
TomlValue::String(s) => Some(s.into_py(self_.py())),
|
||||
TomlValue::Integer(i) => Some(i.into_py(self_.py())),
|
||||
TomlValue::Float(f) => Some(f.into_py(self_.py())),
|
||||
TomlValue::Boolean(b) => Some(b.into_py(self_.py())),
|
||||
// TomlValue::String(s) => Some(s.into_pyobject(self_.py()).unwrap().as_any().as_unbound().to_owned()),
|
||||
TomlValue::String(s) => Some(PyString::new(self_.py(), s).into_any()),
|
||||
TomlValue::Integer(i) => Some(i.into_pyobject(self_.py()).unwrap().into_any()),
|
||||
TomlValue::Float(f) => Some(f.into_pyobject(self_.py()).unwrap().into_any()),
|
||||
TomlValue::Boolean(b) => {
|
||||
let py_value = PyBool::new(self_.py(), *b);
|
||||
Some(py_value.as_any().clone())
|
||||
}
|
||||
TomlValue::Array(a) => {
|
||||
let new_self = Self::new(TomlValue::Array(a.clone()));
|
||||
let py_value = new_self.into_py(self_.py());
|
||||
let py_value = new_self.into_pyobject(self_.py()).unwrap().into_any();
|
||||
Some(py_value)
|
||||
}
|
||||
TomlValue::Table(t) => {
|
||||
let new_self = Self::new(TomlValue::Table(t.clone()));
|
||||
let py_value = new_self.into_py(self_.py());
|
||||
let py_value = new_self.into_pyobject(self_.py()).unwrap().into_any();
|
||||
Some(py_value)
|
||||
}
|
||||
_ => None,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use std::time::SystemTime;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::{pyclass, pymethods};
|
||||
use rust_socketio::asynchronous::Client;
|
||||
use tokio::runtime::Runtime;
|
||||
use tracing::{debug, info, warn};
|
||||
use tracing::{event, Level};
|
||||
|
||||
use crate::data_struct::ica::messages::{
|
||||
DeleteMessage, MessageTrait, NewMessage, ReplyMessage, SendMessage,
|
||||
|
@ -192,7 +192,7 @@ impl IcaClientPy {
|
|||
}
|
||||
|
||||
pub fn send_and_warn(&self, message: SendMessagePy) -> bool {
|
||||
warn!(message.msg.content);
|
||||
event!(Level::WARN, message.msg.content);
|
||||
self.send_message(message)
|
||||
}
|
||||
|
||||
|
@ -228,16 +228,16 @@ impl IcaClientPy {
|
|||
#[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 get_startup_time(&self) -> SystemTime { crate::start_up_time() }
|
||||
|
||||
pub fn debug(&self, content: String) {
|
||||
debug!("{}", content);
|
||||
event!(Level::DEBUG, "{}", content);
|
||||
}
|
||||
pub fn info(&self, content: String) {
|
||||
info!("{}", content);
|
||||
event!(Level::INFO, "{}", content);
|
||||
}
|
||||
pub fn warn(&self, content: String) {
|
||||
warn!("{}", content);
|
||||
event!(Level::WARN, "{}", content);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@ impl TailchatClientPy {
|
|||
#[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 get_startup_time(&self) -> SystemTime { crate::start_up_time() }
|
||||
|
||||
#[pyo3(signature = (content, converse_id, group_id = None))]
|
||||
pub fn new_message(
|
||||
&self,
|
||||
|
|
|
@ -2,6 +2,7 @@ pub mod call;
|
|||
pub mod class;
|
||||
pub mod config;
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::path::Path;
|
||||
use std::time::SystemTime;
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
@ -45,7 +46,7 @@ impl PyStatus {
|
|||
pub fn delete_file(path: &PathBuf) -> Option<PyPlugin> { Self::get_map_mut().remove(path) }
|
||||
|
||||
pub fn verify_file(path: &PathBuf) -> bool {
|
||||
Self::get_map().get(path).map_or(false, |plugin| plugin.verifiy())
|
||||
Self::get_map().get(path).is_some_and(|plugin| plugin.verifiy())
|
||||
}
|
||||
|
||||
pub fn get_map() -> &'static PyPlugins {
|
||||
|
@ -133,7 +134,7 @@ impl PyStatus {
|
|||
}
|
||||
|
||||
pub fn get_py_err_traceback(py_err: &PyErr) -> String {
|
||||
Python::with_gil(|py| match py_err.traceback_bound(py) {
|
||||
Python::with_gil(|py| match py_err.traceback(py) {
|
||||
Some(traceback) => match traceback.format() {
|
||||
Ok(trace) => trace,
|
||||
Err(e) => format!("{:?}", e),
|
||||
|
@ -398,11 +399,11 @@ pub fn get_change_time(path: &Path) -> Option<SystemTime> { path.metadata().ok()
|
|||
|
||||
pub fn py_module_from_code(content: &str, path: &Path) -> PyResult<Py<PyAny>> {
|
||||
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
|
||||
let module: PyResult<Py<PyAny>> = PyModule::from_code_bound(
|
||||
let module: PyResult<Py<PyAny>> = PyModule::from_code(
|
||||
py,
|
||||
content,
|
||||
&path.to_string_lossy(),
|
||||
&path.file_name().unwrap().to_string_lossy(),
|
||||
CString::new(content).unwrap().as_c_str(),
|
||||
CString::new(path.to_string_lossy().as_bytes()).unwrap().as_c_str(),
|
||||
CString::new(path.file_name().unwrap().to_string_lossy().as_bytes()).unwrap().as_c_str(),
|
||||
// !!!! 请注意, 一定要给他一个名字, cpython 会自动把后面的重名模块覆盖掉前面的
|
||||
)
|
||||
.map(|module| module.into());
|
||||
|
|
|
@ -6,7 +6,6 @@ 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 {
|
||||
|
@ -36,14 +35,9 @@ 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 {
|
||||
let ptr = &raw const MAIN_STATUS.config;
|
||||
|
|
Loading…
Reference in New Issue
Block a user