先push一波似乎能跑的(

This commit is contained in:
shenjack 2024-02-25 17:27:02 +08:00
parent d246913b4c
commit 7b8db8136b
Signed by: shenjack
GPG Key ID: 7B1134A979775551
4 changed files with 88 additions and 0 deletions

1
ica-rs/.gitignore vendored
View File

@ -1,2 +1,3 @@
target
Cargo.lock
config/

View File

@ -120,6 +120,18 @@ class IcaClient:
"""向日志中输出警告信息"""
class ConfigRequest:
def __init__(self, path: str, ) -> None:
...
class ConfigData:
def __getitem__(self, key: str):
...
def have_key(self, key: str) -> bool:
...
on_load = Callable[[IcaClient], None]
# def on_load(client: IcaClient) -> None:
# ...
@ -131,3 +143,7 @@ on_message = Callable[[NewMessage, IcaClient], None]
on_delete_message = Callable[[MessageId, IcaClient], None]
# def on_delete_message(msg_id: MessageId, client: IcaClient) -> None:
# ...
config = Callable[[None], ConfigRequest]
CONFIG_DATA: ConfigData = ConfigData()

View File

@ -44,6 +44,7 @@ pub async fn delete_message(client: &Client, message: &DeleteMessage) -> bool {
/// ```typescript
/// async fetchHistory(messageId: string, roomId: number, currentLoadedMessagesCount: number)
/// ```
#[allow(dead_code)]
pub async fn fetch_history(client: &Client, roomd_id: RoomId) -> bool { false }
#[derive(Debug, Clone)]

View File

@ -2,6 +2,7 @@ use pyo3::prelude::*;
use rust_socketio::asynchronous::Client;
use tokio::runtime::Runtime;
use tracing::{debug, info, warn};
use toml::Value as TomlValue;
use crate::client::{delete_message, send_message, IcalinguaStatus};
use crate::data_struct::messages::{
@ -205,3 +206,72 @@ impl IcaClientPy {
}
}
}
#[derive(Clone)]
#[pyclass]
#[pyo3(name = "ConfigRequest")]
pub struct ConfigRequestPy {
pub path: String,
}
#[pymethods]
impl ConfigRequestPy {
#[new]
pub fn py_new(path: String) -> Self { Self { path } }
}
#[derive(Clone)]
#[pyclass]
#[pyo3(name = "ConfigData")]
pub struct ConfigDataPy {
pub data: TomlValue,
}
#[pymethods]
impl ConfigDataPy {
pub fn __getitem__(self_: PyRef<'_, Self>, key: String) -> Option<Py<PyAny>> {
match self_.data.get(&key) {
Some(value) => {
match value {
TomlValue::String(s) => {
let py_value = s.into_py(self_.py());
Some(py_value)
},
TomlValue::Integer(i) => {
let py_value = i.into_py(self_.py());
Some(py_value)
},
TomlValue::Float(f) => {
let py_value = f.into_py(self_.py());
Some(py_value)
},
TomlValue::Boolean(b) => {
let py_value = b.into_py(self_.py());
Some(py_value)
},
TomlValue::Array(a) => {
let new_self = Self::new(TomlValue::Array(a.clone()));
let py_value = new_self.into_py(self_.py());
Some(py_value)
},
TomlValue::Table(t) => {
let new_self = Self::new(TomlValue::Table(t.clone()));
let py_value = new_self.into_py(self_.py());
Some(py_value)
},
_ => None,
}
}
None => None,
}
}
pub fn have_key(&self, key: String) -> bool {
self.data.get(&key).is_some()
}
}
impl ConfigDataPy {
pub fn new(data: TomlValue) -> Self { Self { data } }
}