mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-04-19 14:49:55 +08:00
dev 就是 dev
This commit is contained in:
parent
4d0a32ca0e
commit
1711270c9f
|
@ -1,24 +1,37 @@
|
|||
pub mod ica;
|
||||
pub mod tailchat;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use pyo3::{
|
||||
pyclass, pymethods,
|
||||
types::{PyBool, PyString},
|
||||
Bound, IntoPyObject, PyAny, PyRef,
|
||||
pyclass, pymethods, pymodule,
|
||||
types::{PyBool, PyModule, PyModuleMethods, PyString},
|
||||
Bound, IntoPyObject, PyAny, PyRef, PyResult,
|
||||
};
|
||||
use toml::Value as TomlValue;
|
||||
use tracing::{event, Level};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ConfigItem {
|
||||
String(String),
|
||||
Integer(i64),
|
||||
Float(f64),
|
||||
Boolean(bool),
|
||||
Array(Vec<ConfigItem>),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[pyclass]
|
||||
#[pyo3(name = "ConfigRequest")]
|
||||
pub struct ConfigRequestPy {
|
||||
pub path: String,
|
||||
#[pyo3(name = "ConfigItem")]
|
||||
pub struct ConfigItemPy {
|
||||
pub item: ConfigItem,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl ConfigRequestPy {
|
||||
#[new]
|
||||
pub fn py_new(path: String) -> Self { Self { path } }
|
||||
#[derive(Clone)]
|
||||
#[pyclass]
|
||||
#[pyo3(name = "ConfigStorage")]
|
||||
pub struct ConfigStoragePy {
|
||||
pub keys: HashMap<String, ConfigItemPy>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -61,3 +74,28 @@ impl ConfigDataPy {
|
|||
impl ConfigDataPy {
|
||||
pub fn new(data: TomlValue) -> Self { Self { data } }
|
||||
}
|
||||
|
||||
#[pymodule]
|
||||
#[pyo3(name = "shenbot_api")]
|
||||
fn rs_api_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
m.add_class::<ConfigDataPy>()?;
|
||||
m.add_class::<ConfigStoragePy>()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 在 python 初始化之前注册所有需要的类
|
||||
///
|
||||
/// WARNING: 这个函数需要在 Python 初始化之前调用,否则会导致报错
|
||||
///
|
||||
/// (pyo3 提供的宏会检查一遍, 不过我这里就直接用原始形式了)
|
||||
pub fn regist_class() {
|
||||
event!(Level::INFO, "向 Python 注册 Rust 侧模块/函数");
|
||||
unsafe {
|
||||
pyo3::ffi::PyImport_AppendInittab(
|
||||
rs_api_module::__PYO3_NAME.as_ptr(),
|
||||
Some(rs_api_module::__pyo3_init),
|
||||
);
|
||||
}
|
||||
|
||||
event!(Level::INFO, "注册完成");
|
||||
}
|
||||
|
|
|
@ -521,7 +521,7 @@ fn init_py_with_env_path(path: &str) {
|
|||
event!(Level::INFO, "根据配置初始化 python 完成");
|
||||
}
|
||||
pyo3::ffi::_PyStatus_TYPE::_PyStatus_TYPE_EXIT => {
|
||||
event!(Level::ERROR, "初始化 python 时发生错误: EXIT");
|
||||
event!(Level::ERROR, "不对啊, 怎么刚刚初始化 Python 就 EXIT 了");
|
||||
}
|
||||
pyo3::ffi::_PyStatus_TYPE::_PyStatus_TYPE_ERROR => {
|
||||
event!(Level::ERROR, "初始化 python 时发生错误: ERROR");
|
||||
|
@ -537,9 +537,15 @@ pub fn init_py() {
|
|||
let span = span!(Level::INFO, "py init");
|
||||
let _enter = span.enter();
|
||||
|
||||
event!(Level::INFO, "开始初始化 python");
|
||||
|
||||
// 注册东西
|
||||
class::regist_class();
|
||||
|
||||
let plugin_path = MainStatus::global_config().py().plugin_path;
|
||||
|
||||
let cli_args = std::env::args().collect::<Vec<String>>();
|
||||
|
||||
if cli_args.contains(&"-env".to_string()) {
|
||||
let env_path = cli_args.iter().find(|&arg| arg != "-env").expect("未找到 -env 参数的值");
|
||||
event!(Level::INFO, "找到 -env 参数: {} 正在初始化", env_path);
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
# icalingua bot
|
||||
|
||||
这是一个基于 icalingua docker 版的 bot
|
||||
|
||||
> 出于某个企鹅, 和保护 作者 和 原项目 ( ica ) 的原因 \
|
||||
> 功能请自行理解
|
||||
这是一个基于 icalingua-bridge 的 bot
|
||||
|
||||
[插件市场(确信)](https://github.com/shenjackyuanjie/shenbot-plugins)
|
||||
|
||||
|
@ -24,7 +21,7 @@ uv venv
|
|||
- 启动 icalingua 后端
|
||||
|
||||
```bash
|
||||
# 用你自己的方法启动你的 icalingua 后端
|
||||
# 用你自己的方法启动你的 icalingua-bridge
|
||||
# 例如
|
||||
docker start icalingua
|
||||
docker-compose up -d
|
||||
|
|
Loading…
Reference in New Issue
Block a user