mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-04-20 12:09:54 +08:00
Compare commits
No commits in common. "1e81db998f46ada9b5c7f44ca59eca100350672b" and "de12c495f01b1b030a3977d52a8c1e4909c96d38" have entirely different histories.
1e81db998f
...
de12c495f0
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -659,7 +659,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ica-rs"
|
||||
version = "0.6.8"
|
||||
version = "0.6.7"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64 0.22.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ica-rs"
|
||||
version = "0.6.8"
|
||||
version = "0.6.7"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -188,9 +188,9 @@ class TailchatReciveMessage:
|
|||
@property
|
||||
def sender_id(self) -> TailchatType.UserId:
|
||||
...
|
||||
@property
|
||||
def is_from_self(self) -> bool:
|
||||
...
|
||||
# @property
|
||||
# def is_from_self(self) -> bool:
|
||||
# ...
|
||||
@property
|
||||
def is_reply(self) -> bool:
|
||||
...
|
||||
|
|
|
@ -47,17 +47,13 @@ impl ReceiveMessage {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_from_self(&self) -> bool {
|
||||
crate::MainStatus::global_tailchat_status().user_id == self.sender_id
|
||||
}
|
||||
|
||||
/// 创建一个对这条消息的回复
|
||||
pub fn as_reply(&self) -> SendingMessage {
|
||||
SendingMessage::new(
|
||||
"".to_string(),
|
||||
self.converse_id.clone(),
|
||||
self.group_id.clone(),
|
||||
Some(ReplyMeta::from_receive_message(self)),
|
||||
Some(ReplyMeta::from_recive_message(self)),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -67,7 +63,7 @@ impl ReceiveMessage {
|
|||
content.to_string(),
|
||||
self.converse_id.clone(),
|
||||
self.group_id.clone(),
|
||||
Some(ReplyMeta::from_receive_message(self)),
|
||||
Some(ReplyMeta::from_recive_message(self)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -83,47 +79,6 @@ impl Display for ReceiveMessage {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub enum SendingFile {
|
||||
#[default]
|
||||
None,
|
||||
/// 需要生成
|
||||
/// [img height=1329 width=1918]{BACKEND}/static/files/6602e20d7b8d10675758e36b/8db505b87bdf9fb309467abcec4d8e2a.png[/img]
|
||||
Image {
|
||||
file: Vec<u8>,
|
||||
width: u32,
|
||||
height: u32,
|
||||
},
|
||||
/// [card type=file url={BACKEND}/static/files/6602e20d7b8d10675758e36b/9df28943d17b9713cb0ea9625f37d015.wav]Engine.wav[/card]
|
||||
File { file: Vec<u8>, name: String },
|
||||
}
|
||||
|
||||
impl SendingFile {
|
||||
pub fn is_some(&self) -> bool { !matches!(self, Self::None) }
|
||||
pub fn is_image(&self) -> bool { matches!(self, Self::Image { .. }) }
|
||||
pub fn is_file(&self) -> bool { matches!(self, Self::File { .. }) }
|
||||
// pub fn gen_msg(&self, file_path: &str) -> String {
|
||||
// match self {
|
||||
// Self::Image { _file, width, height } => {
|
||||
// format!(
|
||||
// "[img height={} width={}]{{BACKEND}}/static/files/{}[/img]",
|
||||
// height,
|
||||
// width,
|
||||
// file_path
|
||||
// )
|
||||
// }
|
||||
// Self::File { _file, name } => {
|
||||
// format!(
|
||||
// "[file name={}]{{BACKEND}}/static/files/{}[/file]",
|
||||
// name,
|
||||
// file_path
|
||||
// )
|
||||
// }
|
||||
// _ => "".to_string(),
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// 将要发送的消息
|
||||
///
|
||||
|
@ -141,6 +96,8 @@ pub struct SendingMessage {
|
|||
/// 消息内容
|
||||
///
|
||||
/// 其实还有个 plain, 就是不知道干啥的
|
||||
///
|
||||
/// [img height=1329 width=1918]{BACKEND}/static/files/6602e20d7b8d10675758e36b/8db505b87bdf9fb309467abcec4d8e2a.png[/img]
|
||||
pub content: String,
|
||||
/// 会话ID
|
||||
#[serde(rename = "converseId")]
|
||||
|
@ -152,7 +109,7 @@ pub struct SendingMessage {
|
|||
pub meta: Option<ReplyMeta>,
|
||||
/// 额外携带的文件
|
||||
#[serde(skip)]
|
||||
pub file: SendingFile,
|
||||
pub file: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl SendingMessage {
|
||||
|
@ -167,7 +124,7 @@ impl SendingMessage {
|
|||
converse_id,
|
||||
group_id,
|
||||
meta,
|
||||
file: SendingFile::None,
|
||||
file: None,
|
||||
}
|
||||
}
|
||||
pub fn new_without_meta(
|
||||
|
@ -180,12 +137,12 @@ impl SendingMessage {
|
|||
converse_id,
|
||||
group_id,
|
||||
meta: None,
|
||||
file: SendingFile::None,
|
||||
file: None,
|
||||
}
|
||||
}
|
||||
pub fn contain_file(&self) -> bool { self.file.is_some() }
|
||||
|
||||
pub fn add_img(&mut self, file: SendingFile) { self.file = file; }
|
||||
pub fn add_img(&mut self, file: Vec<u8>) { self.file = Some(file); }
|
||||
|
||||
pub fn as_value(&self) -> JsonValue { serde_json::to_value(self).unwrap() }
|
||||
}
|
||||
|
@ -203,7 +160,7 @@ pub struct ReplyMeta {
|
|||
}
|
||||
|
||||
impl ReplyMeta {
|
||||
pub fn from_receive_message(msg: &ReceiveMessage) -> Self {
|
||||
pub fn from_recive_message(msg: &ReceiveMessage) -> Self {
|
||||
Self {
|
||||
mentions: vec![msg.sender_id.clone()],
|
||||
reply_id: msg.msg_id.clone(),
|
||||
|
|
|
@ -15,21 +15,6 @@ pub struct LoginData {
|
|||
pub avatar: String,
|
||||
}
|
||||
|
||||
impl LoginData {
|
||||
pub fn update_to_global(&self) {
|
||||
let status = crate::status::tailchat::MainStatus {
|
||||
enable: true,
|
||||
login: true,
|
||||
user_id: self.user_id.clone(),
|
||||
nick_name: self.nickname.clone(),
|
||||
email: self.email.clone(),
|
||||
jwt_token: self.jwt.clone(),
|
||||
avatar: self.avatar.clone(),
|
||||
};
|
||||
crate::MainStatus::update_tailchat_status(status);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct UpdateDMConverse {
|
||||
/// 会话ID
|
||||
|
|
|
@ -25,7 +25,7 @@ pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientRe
|
|||
.on("message", async_callback!(events::connect_callback))
|
||||
.on("authSucceed", async_callback!(events::connect_callback))
|
||||
.on("authFailed", async_callback!(events::connect_callback))
|
||||
.on("messageSuccess", async_callback!(events::success_message))
|
||||
.on("messageSuccess", async_callback!(events::succes_message))
|
||||
.on("messageFailed", async_callback!(events::failed_message))
|
||||
.on("onlineData", async_callback!(events::get_online_data))
|
||||
.on("setAllRooms", async_callback!(events::update_all_room))
|
||||
|
|
|
@ -25,8 +25,6 @@ pub async fn get_online_data(payload: Payload, _client: Client) {
|
|||
pub async fn add_message(payload: Payload, client: Client) {
|
||||
if let Payload::Text(values) = payload {
|
||||
if let Some(value) = values.first() {
|
||||
let span = span!(Level::INFO, "ica add_message");
|
||||
let _enter = span.enter();
|
||||
let message: NewMessage = serde_json::from_value(value.clone()).unwrap();
|
||||
// 检测是否在过滤列表内
|
||||
if MainStatus::global_config().ica().filter_list.contains(&message.msg.sender_id) {
|
||||
|
@ -90,7 +88,7 @@ pub async fn update_all_room(payload: Payload, _client: Client) {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn success_message(payload: Payload, _client: Client) {
|
||||
pub async fn succes_message(payload: Payload, _client: Client) {
|
||||
if let Payload::Text(values) = payload {
|
||||
if let Some(value) = values.first() {
|
||||
info!("messageSuccess {}", value.to_string().green());
|
||||
|
|
|
@ -12,7 +12,7 @@ mod ica;
|
|||
mod tailchat;
|
||||
|
||||
use config::BotConfig;
|
||||
use tracing::{event, span, Level};
|
||||
use tracing::{event, info, span, Level};
|
||||
|
||||
pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus {
|
||||
config: None,
|
||||
|
@ -26,7 +26,7 @@ pub type StopGetter = tokio::sync::oneshot::Receiver<()>;
|
|||
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const ICA_VERSION: &str = "1.6.0";
|
||||
pub const TAILCHAT_VERSION: &str = "1.2.0";
|
||||
pub const TAILCHAT_VERSION: &str = "1.1.0";
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! async_callback_with_state {
|
||||
|
@ -104,14 +104,14 @@ async fn main() {
|
|||
|
||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||
// 等待一个输入
|
||||
event!(Level::INFO, "Press any key to exit");
|
||||
info!("Press any key to exit");
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_line(&mut input).unwrap();
|
||||
|
||||
ica_send.send(()).ok();
|
||||
tailchat_send.send(()).ok();
|
||||
|
||||
event!(Level::INFO, "Disconnected");
|
||||
info!("Disconnected");
|
||||
}
|
||||
|
||||
#[allow(dead_code, unused_variables)]
|
||||
|
|
|
@ -80,8 +80,6 @@ impl TailchatReceiveMessagePy {
|
|||
#[getter]
|
||||
pub fn get_is_reply(&self) -> bool { self.message.is_reply() }
|
||||
#[getter]
|
||||
pub fn get_is_from_self(&self) -> bool { self.message.is_from_self() }
|
||||
#[getter]
|
||||
pub fn get_msg_id(&self) -> MessageId { self.message.msg_id.clone() }
|
||||
#[getter]
|
||||
pub fn get_content(&self) -> String { self.message.content.clone() }
|
||||
|
|
|
@ -62,8 +62,6 @@ pub async fn start_tailchat(
|
|||
Err(e) => return Err(TailchatError::LoginFailed(e.to_string())),
|
||||
};
|
||||
|
||||
status.update_to_global();
|
||||
|
||||
let sharded_status = BotStatus::new(status.user_id.clone());
|
||||
let sharded_status = Arc::new(sharded_status);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ pub async fn send_message(client: &Client, message: &SendingMessage) -> bool {
|
|||
true
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("send_message failed:{}", format!("{:#?}", e).red());
|
||||
warn!("send_message faild:{}", format!("{:#?}", e).red());
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
|||
use colored::Colorize;
|
||||
use rust_socketio::asynchronous::Client;
|
||||
use rust_socketio::{Event, Payload};
|
||||
use tracing::{event, info, Level};
|
||||
use tracing::info;
|
||||
|
||||
use crate::data_struct::tailchat::messages::ReceiveMessage;
|
||||
use crate::data_struct::tailchat::status::{BotStatus, UpdateDMConverse};
|
||||
|
@ -68,12 +68,12 @@ pub async fn on_message(payload: Payload, client: Client, status: Arc<BotStatus>
|
|||
let message: ReceiveMessage = match serde_json::from_value(value.clone()) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
event!(Level::WARN, "tailchat_msg {}", value.to_string().red());
|
||||
event!(Level::WARN, "tailchat_msg {}", format!("{:?}", e).red());
|
||||
info!("tailchat_msg {}", value.to_string().red());
|
||||
info!("tailchat_msg {}", format!("{:?}", e).red());
|
||||
return;
|
||||
}
|
||||
};
|
||||
event!(Level::INFO, "tailchat_msg {}", message.to_string().yellow());
|
||||
info!("tailchat_msg {}", message.to_string().cyan());
|
||||
|
||||
if !message.is_reply() {
|
||||
if message.content == "/bot-rs" {
|
||||
|
@ -104,8 +104,8 @@ pub async fn on_converse_update(payload: Payload, client: Client) {
|
|||
let update_info: UpdateDMConverse = match serde_json::from_value(value.clone()) {
|
||||
Ok(value) => value,
|
||||
Err(e) => {
|
||||
event!(Level::WARN, "tailchat updateDMConverse {}", value.to_string().red());
|
||||
event!(Level::WARN, "tailchat updateDMConverse {}", format!("{:?}", e).red());
|
||||
info!("tailchat updateDMConverse {}", value.to_string().red());
|
||||
info!("tailchat updateDMConverse {}", format!("{:?}", e).red());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user