Skip to main content

danmuji_sdk/
model.rs

1use crate::ffi::{FfiPluginContext, FfiPluginMetadata};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum MsgType {
5    Comment,
6    GiftSend,
7    GiftTop,
8    Welcome,
9    LiveStart,
10    LiveEnd,
11    Unknown,
12    WelcomeGuard,
13    GuardBuy,
14    SuperChat,
15    Interact,
16    Warning,
17    WatchedChange,
18    OpConnectionEnd,
19    Other(i32),
20}
21
22impl MsgType {
23    pub fn from_raw(value: i32) -> Self {
24        match value {
25            0 => Self::Comment,
26            1 => Self::GiftSend,
27            2 => Self::GiftTop,
28            3 => Self::Welcome,
29            4 => Self::LiveStart,
30            5 => Self::LiveEnd,
31            6 => Self::Unknown,
32            7 => Self::WelcomeGuard,
33            8 => Self::GuardBuy,
34            9 => Self::SuperChat,
35            10 => Self::Interact,
36            11 => Self::Warning,
37            12 => Self::WatchedChange,
38            13 => Self::OpConnectionEnd,
39            other => Self::Other(other),
40        }
41    }
42
43    pub fn as_raw(self) -> i32 {
44        match self {
45            Self::Comment => 0,
46            Self::GiftSend => 1,
47            Self::GiftTop => 2,
48            Self::Welcome => 3,
49            Self::LiveStart => 4,
50            Self::LiveEnd => 5,
51            Self::Unknown => 6,
52            Self::WelcomeGuard => 7,
53            Self::GuardBuy => 8,
54            Self::SuperChat => 9,
55            Self::Interact => 10,
56            Self::Warning => 11,
57            Self::WatchedChange => 12,
58            Self::OpConnectionEnd => 13,
59            Self::Other(value) => value,
60        }
61    }
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub enum InteractType {
66    Enter,
67    Follow,
68    Share,
69    SpecialFollow,
70    MutualFollow,
71    Like,
72    Other(i32),
73}
74
75impl InteractType {
76    pub fn from_raw(value: i32) -> Option<Self> {
77        match value {
78            0 => None,
79            1 => Some(Self::Enter),
80            2 => Some(Self::Follow),
81            3 => Some(Self::Share),
82            4 => Some(Self::SpecialFollow),
83            5 => Some(Self::MutualFollow),
84            6 => Some(Self::Like),
85            other => Some(Self::Other(other)),
86        }
87    }
88
89    pub fn as_raw(self) -> i32 {
90        match self {
91            Self::Enter => 1,
92            Self::Follow => 2,
93            Self::Share => 3,
94            Self::SpecialFollow => 4,
95            Self::MutualFollow => 5,
96            Self::Like => 6,
97            Self::Other(value) => value,
98        }
99    }
100}
101
102#[derive(Debug, Clone)]
103pub struct PluginMetadata {
104    pub name: &'static str,
105    pub author: &'static str,
106    pub contact: &'static str,
107    pub version: &'static str,
108    pub description: &'static str,
109}
110
111impl PluginMetadata {
112    pub fn into_ffi(self) -> FfiPluginMetadata {
113        FfiPluginMetadata {
114            name: self.name.into(),
115            author: self.author.into(),
116            contact: self.contact.into(),
117            version: self.version.into(),
118            description: self.description.into(),
119        }
120    }
121}
122
123#[derive(Debug, Clone, Copy, PartialEq, Eq)]
124pub struct PluginContext {
125    pub room_id: Option<i32>,
126    pub status: bool,
127    pub debug_mode: bool,
128}
129
130impl From<FfiPluginContext> for PluginContext {
131    fn from(value: FfiPluginContext) -> Self {
132        Self {
133            room_id: (value.has_room_id != 0).then_some(value.room_id),
134            status: value.status != 0,
135            debug_mode: value.debug_mode != 0,
136        }
137    }
138}
139
140#[derive(Debug, Clone)]
141pub struct DisconnectEvent {
142    pub error: Option<String>,
143}
144
145#[derive(Debug, Clone)]
146pub struct GiftRank {
147    pub user_name: Option<String>,
148    pub coin: Option<String>,
149    pub uid: i32,
150    pub uid_long: i64,
151    pub uid_str: Option<String>,
152}
153
154#[derive(Debug, Clone)]
155pub struct Danmaku {
156    pub msg_type: MsgType,
157    pub interact_type: Option<InteractType>,
158    pub comment_text: Option<String>,
159    pub comment_user: Option<String>,
160    pub user_name: Option<String>,
161    pub user_id: i32,
162    pub user_id_long: i64,
163    pub user_id_str: Option<String>,
164    pub user_guard_level: i32,
165    pub gift_user: Option<String>,
166    pub gift_name: Option<String>,
167    pub gift_num: Option<String>,
168    pub gift_count: i32,
169    pub gift_rcost: Option<String>,
170    pub gift_ranking: Vec<GiftRank>,
171    pub is_admin: bool,
172    pub is_vip: bool,
173    pub room_id: Option<String>,
174    pub raw_data: Option<String>,
175    pub json_version: i32,
176    pub price: Option<String>,
177    pub sc_keep_time: i32,
178    pub watched_count: i64,
179    pub raw_data_jtoken: Option<String>,
180}