diff --git a/ica-rs/.gitignore b/ica-rs/.gitignore index a9d37c5..a8ccc9c 100644 --- a/ica-rs/.gitignore +++ b/ica-rs/.gitignore @@ -1,2 +1,3 @@ target Cargo.lock +config/ diff --git a/ica-rs/ica_typing.py b/ica-rs/ica_typing.py index 7c52b75..f0c7603 100644 --- a/ica-rs/ica_typing.py +++ b/ica-rs/ica_typing.py @@ -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() diff --git a/ica-rs/src/client.rs b/ica-rs/src/client.rs index 0356ee9..4e4dd7e 100644 --- a/ica-rs/src/client.rs +++ b/ica-rs/src/client.rs @@ -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)] diff --git a/ica-rs/src/py/class.rs b/ica-rs/src/py/class.rs index 9bcd989..ffdb614 100644 --- a/ica-rs/src/py/class.rs +++ b/ica-rs/src/py/class.rs @@ -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> { + 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 } } +}