修了,不少东西(?

This commit is contained in:
shenjack 2024-06-10 16:25:17 +08:00
parent aad9ab08f6
commit 31a490b40c
Signed by: shenjack
GPG Key ID: 7B1134A979775551
3 changed files with 27 additions and 13 deletions

View File

@ -1,7 +1,6 @@
# Python 兼容版本 3.8+
from typing import Callable, Tuple
from typing_extensions import Optional
from typing import Callable, Tuple, NewType, TYPE_CHECKING, TypeVar, Optional
"""
ica.rs
@ -10,9 +9,9 @@ pub type UserId = i64;
pub type MessageId = String;
"""
class IcaType:
RoomId = int
UserId = int
MessageId = str
RoomId = NewType('RoomId', int)
UserId = NewType('UserId', int)
MessageId = NewType('MessageId', str)
"""
tailchat.rs
@ -22,10 +21,10 @@ pub type UserId = String;
pub type MessageId = String;
"""
class TailchatType:
GroupId = str
ConverseId = str
UserId = str
MessageId = str
GroupId = NewType('GroupId', str)
ConverseId = NewType('ConverseId', str)
UserId = NewType('UserId', str)
MessageId = NewType('MessageId', str)
class IcaStatus:
"""

View File

@ -13,9 +13,6 @@ pub struct LoginData {
pub avatar: String,
}
/*
{"__v":0,"_id":"66045ddb5163504389a6f5b1","createdAt":"2024-03-27T17:56:43.528Z","members":["6602e20d7b8d10675758e36b","6604482b5163504389a6f481"],"type":"DM","updatedAt":"2024-03-27T17:56:43.528Z"}
*/
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct UpdateDMConverse {
/// 会话ID

View File

@ -5,6 +5,7 @@ use std::path::Path;
use std::time::SystemTime;
use std::{collections::HashMap, path::PathBuf};
use colored::Colorize;
use pyo3::prelude::*;
use pyo3::types::PyTuple;
use tracing::{debug, info, span, warn, Level};
@ -19,6 +20,18 @@ pub struct PyStatus {
pub type PyPluginData = HashMap<PathBuf, PyPlugin>;
pub type RawPyPlugin = (PathBuf, Option<SystemTime>, String);
pub fn get_py_err_traceback(py_err: &PyErr) -> String {
Python::with_gil(|py| match py_err.traceback_bound(py) {
Some(traceback) => match traceback.format() {
Ok(trace) => trace,
Err(e) => format!("{:?}", e),
},
None => "".to_string(),
})
.red()
.to_string()
}
#[derive(Debug, Clone)]
pub struct PyPlugin {
pub file_path: PathBuf,
@ -33,7 +46,12 @@ impl PyPlugin {
Ok(raw_file) => match Self::try_from(raw_file) {
Ok(plugin) => Some(plugin),
Err(e) => {
warn!("加载 Python 插件文件{:?}: {:?} 失败", path, e);
warn!(
"加载 Python 插件文件{:?}: {:?} 失败\n{}",
path,
e,
get_py_err_traceback(&e)
);
None
}
},