kovi_onebot/event/
lifecycle_event.rs1use crate::event::PostType;
2use kovi::bot::BotInformation;
3use kovi::event::{Event, InternalEvent};
4use kovi::types::ApiAndOptOneshot;
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Deserialize)]
8pub struct LifecycleEvent {
9 pub meta_event_type: String,
10 pub post_type: PostType,
11 pub self_id: i64,
12 pub time: i64,
13 pub sub_type: LifecycleAction,
14}
15
16#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
17#[serde(rename_all = "lowercase")]
18pub enum LifecycleAction {
19 Enable,
20 Disable,
21 Connect,
22}
23
24impl Event for LifecycleEvent {
25 fn de(
26 event: &InternalEvent,
27 _: &BotInformation,
28 _: &tokio::sync::mpsc::Sender<ApiAndOptOneshot>,
29 ) -> Option<Self>
30 where
31 Self: Sized,
32 {
33 let InternalEvent::DriverEvent(json_str) = event else {
34 return None;
35 };
36 let event: LifecycleEvent = serde_json::from_value(json_str.clone()).ok()?;
37 if event.meta_event_type == "lifecycle" {
38 Some(event)
39 } else {
40 None
41 }
42 }
43}