mod friend;
pub use friend::*;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
mod group;
pub use group::*;
use super::EventBase;
use crate::bot::Bot;
use strum::{Display, EnumString, IntoStaticStr};
#[derive(
Debug,
Clone,
EnumString,
Display,
IntoStaticStr,
Deserialize,
Serialize,
PartialEq,
Eq,
PartialOrd,
Ord,
)]
pub enum NotionSubEvent {
#[strum(serialize = "receiveLike")]
ReceiveLike,
#[strum(serialize = "friendAdd")]
FriendAdd,
#[strum(serialize = "friendDecrease")]
FriendDecrease,
#[strum(serialize = "privatePoke")]
PrivatePoke,
#[strum(serialize = "privateRecall")]
PrivateRecall,
#[strum(serialize = "privateFileUpload")]
PrivateFileUpload,
#[strum(serialize = "groupPoke")]
GroupPoke,
#[strum(serialize = "GroupRecall")]
GroupRecall,
#[strum(serialize = "groupFileUpload")]
GroupFileUpload,
#[strum(serialize = "groupCardChange")]
GroupCardChange,
#[strum(serialize = "groupMemberTitleChange")]
GroupMemberTitleChange,
#[strum(serialize = "groupHighlightsChange")]
GroupHighlightsChange,
#[strum(serialize = "groupMemberAdd")]
GroupMemberAdd,
#[strum(serialize = "groupMemberDecrease")]
GroupMemberDecrease,
#[strum(serialize = "groupAdminChange")]
GroupAdminChange,
#[strum(serialize = "groupSignIn")]
GroupSignIn,
#[strum(serialize = "groupMemberBan")]
GroupMemberBan,
#[strum(serialize = "groupWholeBan")]
GroupWholeBan,
#[strum(serialize = "groupMessageReaction")]
GroupMessageReaction,
#[strum(serialize = "groupLuckKing")]
GroupLuckKing,
#[strum(serialize = "groupHonorChange")]
GroupHonorChange,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "lowercase", tag = "type", content = "field0")]
pub enum NotionEvent {
ReceiveLike(ReceiveLike),
FriendAdd(FriendAdd),
PrivatePoke(PrivatePoke),
PrivateRecall(PrivateRecall),
PrivateFileUpload(PrivateFileUpload),
GroupPoke(GroupPoke),
GroupRecall(GroupRecall),
GroupFileUpload(GroupFileUpload),
GroupCardChange(GroupCardChange),
GroupMemberTitleChange(GroupMemberTitleChange),
}
pub trait NotionBase: Send + Sync + EventBase {
type Content;
fn notion(&self) -> &str;
fn content(&self) -> Self::Content;
}
pub struct NotionBuilder<Contact, Sender> {
pub bot: Arc<Bot>,
pub event_id: String,
pub time: u64,
pub self_id: String,
pub user_id: String,
pub contact: Contact,
pub sender: Sender,
}
#[cfg(feature = "event")]
#[macro_export]
macro_rules! create_notion_event {
(
$variant:ident,
$( $key:ident : $value:expr ),* $(,)?
) => {{
let mut builder = $crate::event::notion::NotionBuilder {
bot: Default::default(),
event_id: String::new(),
time: 0,
self_id: String::new(),
user_id: String::new(),
contact: Default::default(),
sender: Default::default(),
};
$(
builder.$key = create_notion_event!(@convert $key, $value);
)*
let notion = $variant::new(builder, builder.content.clone());
let event = $crate::event::Event::Notion($crate::event::notion::NotionEvent::$variant(notion));
$crate::bus::send_event($bot.clone(), event);
}};
(@convert bot, $v:expr) => { $v };
(@convert adapter, $v:expr) => { $v };
(@convert event_id, $v:expr) => { $v.to_string() };
(@convert time, $v:expr) => { $v };
(@convert self_id, $v:expr) => { $v.to_string() };
(@convert user_id, $v:expr) => { $v.to_string() };
(@convert contact, $v:expr) => { $v };
(@convert sender, $v:expr) => { $v };
(@convert content, $v:expr) => { $v };
}