mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 20:45:06 +08:00
p3
This commit is contained in:
parent
de12c495f0
commit
b1511a972f
|
@ -53,7 +53,7 @@ impl ReceiveMessage {
|
||||||
"".to_string(),
|
"".to_string(),
|
||||||
self.converse_id.clone(),
|
self.converse_id.clone(),
|
||||||
self.group_id.clone(),
|
self.group_id.clone(),
|
||||||
Some(ReplyMeta::from_recive_message(self)),
|
Some(ReplyMeta::from_receive_message(self)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ impl ReceiveMessage {
|
||||||
content.to_string(),
|
content.to_string(),
|
||||||
self.converse_id.clone(),
|
self.converse_id.clone(),
|
||||||
self.group_id.clone(),
|
self.group_id.clone(),
|
||||||
Some(ReplyMeta::from_recive_message(self)),
|
Some(ReplyMeta::from_receive_message(self)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,47 @@ 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)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
/// 将要发送的消息
|
/// 将要发送的消息
|
||||||
///
|
///
|
||||||
|
@ -96,8 +137,6 @@ pub struct SendingMessage {
|
||||||
/// 消息内容
|
/// 消息内容
|
||||||
///
|
///
|
||||||
/// 其实还有个 plain, 就是不知道干啥的
|
/// 其实还有个 plain, 就是不知道干啥的
|
||||||
///
|
|
||||||
/// [img height=1329 width=1918]{BACKEND}/static/files/6602e20d7b8d10675758e36b/8db505b87bdf9fb309467abcec4d8e2a.png[/img]
|
|
||||||
pub content: String,
|
pub content: String,
|
||||||
/// 会话ID
|
/// 会话ID
|
||||||
#[serde(rename = "converseId")]
|
#[serde(rename = "converseId")]
|
||||||
|
@ -109,7 +148,7 @@ pub struct SendingMessage {
|
||||||
pub meta: Option<ReplyMeta>,
|
pub meta: Option<ReplyMeta>,
|
||||||
/// 额外携带的文件
|
/// 额外携带的文件
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub file: Option<Vec<u8>>,
|
pub file: SendingFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendingMessage {
|
impl SendingMessage {
|
||||||
|
@ -124,7 +163,7 @@ impl SendingMessage {
|
||||||
converse_id,
|
converse_id,
|
||||||
group_id,
|
group_id,
|
||||||
meta,
|
meta,
|
||||||
file: None,
|
file: SendingFile::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn new_without_meta(
|
pub fn new_without_meta(
|
||||||
|
@ -137,12 +176,12 @@ impl SendingMessage {
|
||||||
converse_id,
|
converse_id,
|
||||||
group_id,
|
group_id,
|
||||||
meta: None,
|
meta: None,
|
||||||
file: None,
|
file: SendingFile::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn contain_file(&self) -> bool { self.file.is_some() }
|
pub fn contain_file(&self) -> bool { self.file.is_some() }
|
||||||
|
|
||||||
pub fn add_img(&mut self, file: Vec<u8>) { self.file = Some(file); }
|
pub fn add_img(&mut self, file: SendingFile) { self.file = file; }
|
||||||
|
|
||||||
pub fn as_value(&self) -> JsonValue { serde_json::to_value(self).unwrap() }
|
pub fn as_value(&self) -> JsonValue { serde_json::to_value(self).unwrap() }
|
||||||
}
|
}
|
||||||
|
@ -160,7 +199,7 @@ pub struct ReplyMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReplyMeta {
|
impl ReplyMeta {
|
||||||
pub fn from_recive_message(msg: &ReceiveMessage) -> Self {
|
pub fn from_receive_message(msg: &ReceiveMessage) -> Self {
|
||||||
Self {
|
Self {
|
||||||
mentions: vec![msg.sender_id.clone()],
|
mentions: vec![msg.sender_id.clone()],
|
||||||
reply_id: msg.msg_id.clone(),
|
reply_id: msg.msg_id.clone(),
|
||||||
|
|
|
@ -15,6 +15,21 @@ pub struct LoginData {
|
||||||
pub avatar: String,
|
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)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct UpdateDMConverse {
|
pub struct UpdateDMConverse {
|
||||||
/// 会话ID
|
/// 会话ID
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientRe
|
||||||
.on("message", async_callback!(events::connect_callback))
|
.on("message", async_callback!(events::connect_callback))
|
||||||
.on("authSucceed", async_callback!(events::connect_callback))
|
.on("authSucceed", async_callback!(events::connect_callback))
|
||||||
.on("authFailed", async_callback!(events::connect_callback))
|
.on("authFailed", async_callback!(events::connect_callback))
|
||||||
.on("messageSuccess", async_callback!(events::succes_message))
|
.on("messageSuccess", async_callback!(events::success_message))
|
||||||
.on("messageFailed", async_callback!(events::failed_message))
|
.on("messageFailed", async_callback!(events::failed_message))
|
||||||
.on("onlineData", async_callback!(events::get_online_data))
|
.on("onlineData", async_callback!(events::get_online_data))
|
||||||
.on("setAllRooms", async_callback!(events::update_all_room))
|
.on("setAllRooms", async_callback!(events::update_all_room))
|
||||||
|
|
|
@ -25,6 +25,8 @@ pub async fn get_online_data(payload: Payload, _client: Client) {
|
||||||
pub async fn add_message(payload: Payload, client: Client) {
|
pub async fn add_message(payload: Payload, client: Client) {
|
||||||
if let Payload::Text(values) = payload {
|
if let Payload::Text(values) = payload {
|
||||||
if let Some(value) = values.first() {
|
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();
|
let message: NewMessage = serde_json::from_value(value.clone()).unwrap();
|
||||||
// 检测是否在过滤列表内
|
// 检测是否在过滤列表内
|
||||||
if MainStatus::global_config().ica().filter_list.contains(&message.msg.sender_id) {
|
if MainStatus::global_config().ica().filter_list.contains(&message.msg.sender_id) {
|
||||||
|
@ -88,7 +90,7 @@ pub async fn update_all_room(payload: Payload, _client: Client) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn succes_message(payload: Payload, _client: Client) {
|
pub async fn success_message(payload: Payload, _client: Client) {
|
||||||
if let Payload::Text(values) = payload {
|
if let Payload::Text(values) = payload {
|
||||||
if let Some(value) = values.first() {
|
if let Some(value) = values.first() {
|
||||||
info!("messageSuccess {}", value.to_string().green());
|
info!("messageSuccess {}", value.to_string().green());
|
||||||
|
|
|
@ -12,7 +12,7 @@ mod ica;
|
||||||
mod tailchat;
|
mod tailchat;
|
||||||
|
|
||||||
use config::BotConfig;
|
use config::BotConfig;
|
||||||
use tracing::{event, info, span, Level};
|
use tracing::{event, span, Level};
|
||||||
|
|
||||||
pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus {
|
pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus {
|
||||||
config: None,
|
config: None,
|
||||||
|
@ -104,14 +104,14 @@ async fn main() {
|
||||||
|
|
||||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||||
// 等待一个输入
|
// 等待一个输入
|
||||||
info!("Press any key to exit");
|
event!(Level::INFO, "Press any key to exit");
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
|
|
||||||
ica_send.send(()).ok();
|
ica_send.send(()).ok();
|
||||||
tailchat_send.send(()).ok();
|
tailchat_send.send(()).ok();
|
||||||
|
|
||||||
info!("Disconnected");
|
event!(Level::INFO, "Disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code, unused_variables)]
|
#[allow(dead_code, unused_variables)]
|
||||||
|
|
|
@ -62,6 +62,8 @@ pub async fn start_tailchat(
|
||||||
Err(e) => return Err(TailchatError::LoginFailed(e.to_string())),
|
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 = BotStatus::new(status.user_id.clone());
|
||||||
let sharded_status = Arc::new(sharded_status);
|
let sharded_status = Arc::new(sharded_status);
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub async fn send_message(client: &Client, message: &SendingMessage) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("send_message faild:{}", format!("{:#?}", e).red());
|
warn!("send_message failed:{}", format!("{:#?}", e).red());
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user