mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 20:45:06 +08:00
写点pyo3的东西(
This commit is contained in:
parent
77a899c765
commit
9c22f6c7b3
5
ica-rs/Cargo.lock
generated
5
ica-rs/Cargo.lock
generated
|
@ -569,6 +569,7 @@ dependencies = [
|
||||||
"ed25519",
|
"ed25519",
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
"hex",
|
"hex",
|
||||||
|
"pkg-config",
|
||||||
"pyo3",
|
"pyo3",
|
||||||
"rust_socketio",
|
"rust_socketio",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -871,9 +872,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.27"
|
version = "0.3.29"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
|
checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "platforms"
|
name = "platforms"
|
||||||
|
|
|
@ -30,4 +30,4 @@ version = "0.20.2"
|
||||||
rust_socketio = { git = "https://github.com/shenjackyuanjie/rust-socketio.git", branch = "mult_payload" }
|
rust_socketio = { git = "https://github.com/shenjackyuanjie/rust-socketio.git", branch = "mult_payload" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
pkg-config = "0.3.29"
|
||||||
|
|
|
@ -11,11 +11,29 @@ fn pyo3_config() {
|
||||||
// wsl
|
// wsl
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
env::set_var("PYO3_PRINT_CONFIG", "1");
|
// env::set_var("PYO3_PRINT_CONFIG", "1");
|
||||||
env::set_var("PYO3_PYTHON", "/usr/bin/python3.11");
|
// env::set_var("PYO3_PYTHON", "/usr/bin/python3.10");
|
||||||
|
|
||||||
|
// cargo:rustc-link-lib=static=
|
||||||
|
// println!("cargo:rustc-link-lib=python3.10");
|
||||||
|
// println!("cargo:rustc-link-arg-bins=-Wl,-Bstatic");
|
||||||
|
// println!("cargo:rustc-link-arg-bins=-Wl,--whole-archive");
|
||||||
|
// println!("cargo:rustc-link-arg-bins=-lpython3.10");
|
||||||
|
// println!("cargo:rustc-link-arg-bins=-Wl,-Bdynamic");
|
||||||
|
// println!("cargo:rustc-link-arg-bins=-Wl,--no-whole-archive");
|
||||||
|
// println!("cargo:rustc-link-arg-bins=-lz");
|
||||||
|
// println!("cargo:rustc-link-arg-bins=-lexpat");
|
||||||
|
// println!("cargo:rustc-link-arg-bins=-lutil");
|
||||||
|
// println!("cargo:rustc-link-arg-bins=-lm");
|
||||||
|
// println!("cargo:rustc-link-arg-bins=-Wl,--export-dynamic");
|
||||||
|
|
||||||
|
// pkg_config::Config::new()
|
||||||
|
// .atleast_version("3.8")
|
||||||
|
// .probe("python3-embed")
|
||||||
|
// .unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// pyo3_config();
|
pyo3_config();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ fn any_event(event: Event, payload: Payload, _client: RawClient) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ws_main() {
|
fn ws_main() {
|
||||||
|
py::init_py();
|
||||||
// define a callback which is called when a payload is received
|
// define a callback which is called when a payload is received
|
||||||
// this callback gets the payload as well as an instance of the
|
// this callback gets the payload as well as an instance of the
|
||||||
// socket to communicate with the server
|
// socket to communicate with the server
|
||||||
|
@ -34,7 +35,10 @@ fn ws_main() {
|
||||||
// println!("{}", "已经登录到 icalingua!".green());
|
// println!("{}", "已经登录到 icalingua!".green());
|
||||||
// }
|
// }
|
||||||
match value.as_str() {
|
match value.as_str() {
|
||||||
Some("authSucceed") => println!("{}", "已经登录到 icalingua!".green()),
|
Some("authSucceed") => {
|
||||||
|
py::run();
|
||||||
|
println!("{}", "已经登录到 icalingua!".green())
|
||||||
|
}
|
||||||
Some("authFailed") => {
|
Some("authFailed") => {
|
||||||
println!("{}", "登录到 icalingua 失败!".red());
|
println!("{}", "登录到 icalingua 失败!".red());
|
||||||
panic!("登录失败")
|
panic!("登录失败")
|
||||||
|
@ -67,7 +71,6 @@ fn ws_main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
.with_max_level(tracing::Level::DEBUG)
|
.with_max_level(tracing::Level::DEBUG)
|
||||||
.init();
|
.init();
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
// use inline_python::{python, Context};
|
// use inline_python::{python, Context};
|
||||||
|
|
||||||
// use pyo3::prelude::*;
|
use pyo3::{prelude::*, types::IntoPyDict};
|
||||||
|
|
||||||
// #[pyclass]
|
#[pyclass]
|
||||||
// #[pyo3(name = "BotStatus")]
|
#[pyo3(name = "BotStatus")]
|
||||||
// pub struct BotStatusPy {}
|
pub struct BotStatusPy {}
|
||||||
|
|
||||||
// pub fn run() {
|
pub fn run() {
|
||||||
//
|
Python::with_gil(|py| {
|
||||||
// }
|
let bot_status = BotStatusPy {};
|
||||||
|
let _bot_status = PyCell::new(py, bot_status).unwrap();
|
||||||
|
let locals = [("state", _bot_status)].into_py_dict(py);
|
||||||
|
py.run("print(state)", None, Some(locals)).unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_py() {
|
||||||
|
pyo3::prepare_freethreaded_python();
|
||||||
|
}
|
||||||
|
|
||||||
// pub fn run() {
|
// pub fn run() {
|
||||||
// let con: Context = python! {
|
// let con: Context = python! {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user