mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 12:41:05 +08:00
修了,不少东西(?
This commit is contained in:
parent
aad9ab08f6
commit
31a490b40c
|
@ -1,7 +1,6 @@
|
||||||
# Python 兼容版本 3.8+
|
# Python 兼容版本 3.8+
|
||||||
|
|
||||||
from typing import Callable, Tuple
|
from typing import Callable, Tuple, NewType, TYPE_CHECKING, TypeVar, Optional
|
||||||
from typing_extensions import Optional
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
ica.rs
|
ica.rs
|
||||||
|
@ -10,9 +9,9 @@ pub type UserId = i64;
|
||||||
pub type MessageId = String;
|
pub type MessageId = String;
|
||||||
"""
|
"""
|
||||||
class IcaType:
|
class IcaType:
|
||||||
RoomId = int
|
RoomId = NewType('RoomId', int)
|
||||||
UserId = int
|
UserId = NewType('UserId', int)
|
||||||
MessageId = str
|
MessageId = NewType('MessageId', str)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
tailchat.rs
|
tailchat.rs
|
||||||
|
@ -22,10 +21,10 @@ pub type UserId = String;
|
||||||
pub type MessageId = String;
|
pub type MessageId = String;
|
||||||
"""
|
"""
|
||||||
class TailchatType:
|
class TailchatType:
|
||||||
GroupId = str
|
GroupId = NewType('GroupId', str)
|
||||||
ConverseId = str
|
ConverseId = NewType('ConverseId', str)
|
||||||
UserId = str
|
UserId = NewType('UserId', str)
|
||||||
MessageId = str
|
MessageId = NewType('MessageId', str)
|
||||||
|
|
||||||
class IcaStatus:
|
class IcaStatus:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -13,9 +13,6 @@ pub struct LoginData {
|
||||||
pub avatar: String,
|
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)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct UpdateDMConverse {
|
pub struct UpdateDMConverse {
|
||||||
/// 会话ID
|
/// 会话ID
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::path::Path;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
|
use colored::Colorize;
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::PyTuple;
|
use pyo3::types::PyTuple;
|
||||||
use tracing::{debug, info, span, warn, Level};
|
use tracing::{debug, info, span, warn, Level};
|
||||||
|
@ -19,6 +20,18 @@ pub struct PyStatus {
|
||||||
pub type PyPluginData = HashMap<PathBuf, PyPlugin>;
|
pub type PyPluginData = HashMap<PathBuf, PyPlugin>;
|
||||||
pub type RawPyPlugin = (PathBuf, Option<SystemTime>, String);
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PyPlugin {
|
pub struct PyPlugin {
|
||||||
pub file_path: PathBuf,
|
pub file_path: PathBuf,
|
||||||
|
@ -33,7 +46,12 @@ impl PyPlugin {
|
||||||
Ok(raw_file) => match Self::try_from(raw_file) {
|
Ok(raw_file) => match Self::try_from(raw_file) {
|
||||||
Ok(plugin) => Some(plugin),
|
Ok(plugin) => Some(plugin),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("加载 Python 插件文件{:?}: {:?} 失败", path, e);
|
warn!(
|
||||||
|
"加载 Python 插件文件{:?}: {:?} 失败\n{}",
|
||||||
|
path,
|
||||||
|
e,
|
||||||
|
get_py_err_traceback(&e)
|
||||||
|
);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user