Skip to content

Commit

Permalink
feat: group reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
pk5ls20 committed Feb 11, 2025
1 parent 590f436 commit 4d42e06
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
| Linux | 🟢 | EasyLogin | 🟡 | File | 🟡[^1] | Leave Group | 🔴 | BotOffline | 🟢 |
| | | ~~UnusualDevice<br/>Password~~ | 🔴 | Forward | 🟢 | Set Special Title | 🔴 | Message | 🟢 |
| | | ~~UnusualDevice<br/>Easy~~ | 🔴 | ~~GreyTip~~ | 🔴 | Kick Member | 🔴 | Poke | 🟢 |
| | | ~~NewDeviceVerify~~ | 🔴 | GroupReaction | 🔴 | Mute Member | 🔴 | MessageRecall | 🔴 |
| | | ~~NewDeviceVerify~~ | 🔴 | GroupReaction | 🟡[^1] | Mute Member | 🔴 | MessageRecall | 🔴 |
| | | | | Image | 🟢 | Set Admin | 🔴 | GroupMemberDecrease | 🔴 |
| | | | | Json | 🟢 | Friend Request | 🔴 | GroupMemberIncrease | 🔴 |
| | | | | KeyBoard | 🔴 | Group Request | 🔴 | GroupPromoteAdmin | 🔴 |
Expand Down
29 changes: 28 additions & 1 deletion mania/src/core/business/messaging_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use crate::core::business::LogicRegistry;
use crate::core::business::{BusinessHandle, LogicFlow};
use crate::core::event::message::push_msg::PushMessageEvent;
use crate::core::event::notify::group_sys_poke::GroupSysPokeEvent;
use crate::core::event::notify::group_sys_reaction::GroupSysReactionEvent;
use crate::core::event::notify::group_sys_request_join::GroupSysRequestJoinEvent;
use crate::core::event::prelude::*;
use crate::event::friend::{FriendEvent, friend_message};
use crate::event::group::group_poke::GroupPokeEvent;
use crate::event::group::group_reaction::GroupReactionEvent;
use crate::event::group::{GroupEvent, group_join_request, group_message};
use crate::event::system::{SystemEvent, temp_message};
use crate::message::chain::{MessageChain, MessageType};
Expand All @@ -14,7 +16,12 @@ use crate::message::entity::file::FileUnique;
use mania_macros::handle_event;
use std::sync::Arc;

#[handle_event(PushMessageEvent, GroupSysRequestJoinEvent, GroupSysPokeEvent)]
#[handle_event(
PushMessageEvent,
GroupSysRequestJoinEvent,
GroupSysPokeEvent,
GroupSysReactionEvent
)]
async fn messaging_logic(
event: &mut dyn ServerEvent,
handle: Arc<BusinessHandle>,
Expand Down Expand Up @@ -143,6 +150,26 @@ async fn messaging_logic_incoming(
}
return event;
}
if let Some(reaction) = event.as_any_mut().downcast_mut::<GroupSysReactionEvent>() {
if let Err(e) = handle
.event_dispatcher
.group
.send(Some(GroupEvent::GroupReaction(GroupReactionEvent {
target_group_uin: reaction.target_group_uin,
target_sequence: reaction.target_sequence,
operator_uin: handle
.uid2uin(&reaction.operator_uid, Some(reaction.target_group_uin))
.await
.unwrap_or_default(),
is_add: reaction.is_add,
code: reaction.code.to_owned(),
count: reaction.count,
})))
{
tracing::error!("Failed to send group reaction event: {:?}", e);
}
return event;
}
}
event
}
Expand Down
50 changes: 50 additions & 0 deletions mania/src/core/event/message/push_msg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::core::event::notify::group_sys_poke::GroupSysPokeEvent;
use crate::core::event::notify::group_sys_reaction::GroupSysReactionEvent;
use crate::core::event::notify::group_sys_request_join::GroupSysRequestJoinEvent;
use crate::core::event::prelude::*;
use crate::core::protos::message::{GroupJoin, NotifyMessageBody, PushMsg};
Expand Down Expand Up @@ -139,6 +140,7 @@ impl ClientEvent for PushMessageEvent {
}
}

#[allow(clippy::single_match)] // FIXME:
fn process_event_0x2dc<'a>(
packet: &'a PushMsg,
extra: &'a mut Option<Vec<Box<dyn ServerEvent>>>,
Expand Down Expand Up @@ -171,6 +173,54 @@ fn process_event_0x2dc<'a>(
}
};
match sub_type {
Event0x2DCSubType::SubType16 => {
let msg_content = match packet
.message
.as_ref()
.and_then(|m| m.body.as_ref())
.and_then(|b| b.msg_content.as_ref())
{
Some(content) => content,
None => return Ok(extra),
};
let mut packet_reader = PacketReader::new(Bytes::from(msg_content.to_owned()));
let group_uin = packet_reader.u32();
packet_reader.u8();
let proto = packet_reader
.read_with_length::<_, { PREFIX_U16 | PREFIX_LENGTH_ONLY }>(|p| p.bytes());
let msg_body = NotifyMessageBody::decode(proto)?;
match Event0x2DCSubType16Field13::try_from(msg_body.field13.unwrap_or_default()) {
Ok(ev) => match ev {
Event0x2DCSubType16Field13::GroupReactionNotice => {
let data_2 = msg_body
.reaction
.as_ref()
.and_then(|d| d.data.to_owned())
.and_then(|d| d.data)
.ok_or(EventError::OtherError(
"Missing reaction data_2 in 0x2dc sub type 16 field 13".into(),
))?;
let data_3 = data_2.data.as_ref().ok_or(EventError::OtherError(
"Missing reaction data_3 in 0x2dc sub type 16 field 13".into(),
))?;
extra.as_mut().unwrap().push(Box::new(GroupSysReactionEvent {
target_group_uin: group_uin,
target_sequence: data_2.target.ok_or_else(
|| EventError::OtherError("Missing target_sequence in reaction in 0x2dc sub type 16 field 13".into())
)?.sequence,
operator_uid: data_3.operator_uid.to_owned(),
is_add: data_3.r#type == 1,
code: data_3.code.to_owned(),
count: data_3.count,
}));
}
_ => {}
},
Err(e) => {
tracing::warn!("Failed to parse 0x2dc sub type 16 field 13: {}", e);
}
}
}
Event0x2DCSubType::GroupGreyTipNotice => {
let msg_content = match packet
.message
Expand Down
11 changes: 11 additions & 0 deletions mania/src/core/event/notify/group_sys_reaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::core::event::prelude::*;

#[derive(Debug, DummyEvent, Default)]
pub struct GroupSysReactionEvent {
pub target_group_uin: u32,
pub target_sequence: u32,
pub operator_uid: String,
pub is_add: bool,
pub code: String,
pub count: u32,
}
1 change: 1 addition & 0 deletions mania/src/core/event/notify/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod group_sys_poke;
pub mod group_sys_reaction;
pub mod group_sys_request_join;
3 changes: 2 additions & 1 deletion mania/src/core/protos/message/notify.proto
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ message NotifyMessageBody {
uint32 GroupUin = 4;
bytes EventParam = 5;
GroupRecall Recall = 11;
uint32 Field13 = 13;
optional uint32 Field13 = 13;
string OperatorUid = 21;
GeneralGrayTipInfo GrayTipInfo = 26;
EssenceMessage EssenceMessage = 33;
uint32 MsgSequence = 37;
uint32 Field39 = 39;
GroupReactionData0 Reaction = 44;
}

message EssenceMessage {
Expand Down

0 comments on commit 4d42e06

Please sign in to comment.