mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 12:41:05 +08:00
解析 setAllRooms
This commit is contained in:
parent
c1608a2c84
commit
e5f0d1b60e
|
@ -1,6 +1,7 @@
|
||||||
use crate::data_struct::messages::{At, LastMessage};
|
use crate::data_struct::messages::{At, LastMessage};
|
||||||
use crate::data_struct::RoomId;
|
use crate::data_struct::RoomId;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
/// export default interface Room {
|
/// export default interface Room {
|
||||||
|
@ -28,9 +29,54 @@ pub struct Room {
|
||||||
pub utime: i64,
|
pub utime: i64,
|
||||||
/// 我严重怀疑是脱裤子放屁
|
/// 我严重怀疑是脱裤子放屁
|
||||||
/// 历史遗留啊,那没事了()
|
/// 历史遗留啊,那没事了()
|
||||||
pub users: JsonValue,
|
// pub users: JsonValue,
|
||||||
pub at: At,
|
pub at: At,
|
||||||
pub last_message: LastMessage,
|
pub last_message: LastMessage,
|
||||||
pub auto_donwload: String,
|
pub auto_download: Option<String>,
|
||||||
pub download_path: String,
|
pub download_path: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Room {
|
||||||
|
pub fn new_from_json(json: &JsonValue) -> Self {
|
||||||
|
let inner = serde_json::from_value::<InnerRoom>(json.clone()).unwrap();
|
||||||
|
let at = At::new_from_json(&json["at"]);
|
||||||
|
Self {
|
||||||
|
room_id: inner.room_id,
|
||||||
|
room_name: inner.room_name,
|
||||||
|
index: inner.index,
|
||||||
|
unread_count: inner.unread_count,
|
||||||
|
priority: inner.priority,
|
||||||
|
utime: inner.utime,
|
||||||
|
// users: inner.users,
|
||||||
|
at,
|
||||||
|
last_message: inner.last_message,
|
||||||
|
auto_download: inner.auto_download,
|
||||||
|
download_path: inner.download_path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
|
struct InnerRoom {
|
||||||
|
#[serde(rename = "roomId")]
|
||||||
|
pub room_id: RoomId,
|
||||||
|
#[serde(rename = "roomName")]
|
||||||
|
pub room_name: String,
|
||||||
|
#[serde(rename = "index")]
|
||||||
|
pub index: i64,
|
||||||
|
#[serde(rename = "unreadCount")]
|
||||||
|
pub unread_count: u64,
|
||||||
|
#[serde(rename = "priority")]
|
||||||
|
pub priority: u8,
|
||||||
|
#[serde(rename = "utime")]
|
||||||
|
pub utime: i64,
|
||||||
|
#[serde(rename = "users")]
|
||||||
|
pub users: JsonValue,
|
||||||
|
// 忽略 at
|
||||||
|
#[serde(rename = "lastMessage")]
|
||||||
|
pub last_message: LastMessage,
|
||||||
|
#[serde(rename = "autoDownload")]
|
||||||
|
pub auto_download: Option<String>,
|
||||||
|
#[serde(rename = "downloadPath")]
|
||||||
|
pub download_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ impl NewMessage {
|
||||||
.map(|t| NaiveDateTime::from_timestamp_micros(t).unwrap_or(current))
|
.map(|t| NaiveDateTime::from_timestamp_micros(t).unwrap_or(current))
|
||||||
.unwrap_or(current);
|
.unwrap_or(current);
|
||||||
// 身份
|
// 身份
|
||||||
let role = message["role"].as_str().unwrap();
|
let role = message["role"].as_str().unwrap_or("unknown");
|
||||||
// 文件
|
// 文件
|
||||||
let files: Vec<MessageFile> = message["files"]
|
let files: Vec<MessageFile> = message["files"]
|
||||||
.as_array()
|
.as_array()
|
||||||
|
|
|
@ -4,8 +4,10 @@ use tracing::{info, warn};
|
||||||
|
|
||||||
use crate::data_struct::messages::NewMessage;
|
use crate::data_struct::messages::NewMessage;
|
||||||
use crate::data_struct::online_data::OnlineData;
|
use crate::data_struct::online_data::OnlineData;
|
||||||
|
use crate::data_struct::all_rooms::Room;
|
||||||
use crate::py;
|
use crate::py;
|
||||||
|
|
||||||
|
/// 获取在线数据
|
||||||
pub fn get_online_data(payload: Payload, _client: RawClient) {
|
pub fn get_online_data(payload: Payload, _client: RawClient) {
|
||||||
if let Payload::Text(values) = payload {
|
if let Payload::Text(values) = payload {
|
||||||
if let Some(value) = values.first() {
|
if let Some(value) = values.first() {
|
||||||
|
@ -21,6 +23,7 @@ pub fn get_online_data(payload: Payload, _client: RawClient) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 接收消息
|
||||||
pub fn add_message(payload: Payload, _client: RawClient) {
|
pub fn add_message(payload: Payload, _client: RawClient) {
|
||||||
if let Payload::Text(values) = payload {
|
if let Payload::Text(values) = payload {
|
||||||
if let Some(value) = values.first() {
|
if let Some(value) = values.first() {
|
||||||
|
@ -42,6 +45,21 @@ pub fn delete_message(payload: Payload, _client: RawClient) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_all_room(payload: Payload, _client: RawClient) {
|
||||||
|
if let Payload::Text(values) = payload {
|
||||||
|
if let Some(value) = values.first() {
|
||||||
|
if let Some(raw_rooms) = value.as_array() {
|
||||||
|
let rooms: Vec<Room> = raw_rooms
|
||||||
|
.iter()
|
||||||
|
.map(|room| Room::new_from_json(room))
|
||||||
|
.collect();
|
||||||
|
info!("update_all_room {}", format!("{:#?}", rooms).purple());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 所有
|
||||||
pub fn any_event(event: Event, payload: Payload, _client: RawClient) {
|
pub fn any_event(event: Event, payload: Payload, _client: RawClient) {
|
||||||
let handled = vec![
|
let handled = vec![
|
||||||
// 真正处理过的
|
// 真正处理过的
|
||||||
|
@ -52,7 +70,7 @@ pub fn any_event(event: Event, payload: Payload, _client: RawClient) {
|
||||||
"onlineData",
|
"onlineData",
|
||||||
"addMessage",
|
"addMessage",
|
||||||
"deleteMessage",
|
"deleteMessage",
|
||||||
// "setAllRooms",
|
"setAllRooms",
|
||||||
// 忽略的
|
// 忽略的
|
||||||
"notify",
|
"notify",
|
||||||
"closeLoading", // 发送消息/加载新聊天 有一个 loading
|
"closeLoading", // 发送消息/加载新聊天 有一个 loading
|
||||||
|
|
|
@ -35,6 +35,7 @@ fn main() {
|
||||||
.on("authSucceed", events::connect_callback)
|
.on("authSucceed", events::connect_callback)
|
||||||
.on("authFailed", events::connect_callback)
|
.on("authFailed", events::connect_callback)
|
||||||
.on("onlineData", events::get_online_data)
|
.on("onlineData", events::get_online_data)
|
||||||
|
.on("setAllRooms", events::update_all_room)
|
||||||
.on("addMessage", events::add_message)
|
.on("addMessage", events::add_message)
|
||||||
.on("deleteMessage", events::delete_message)
|
.on("deleteMessage", events::delete_message)
|
||||||
.connect()
|
.connect()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user