1use chrono::NaiveDateTime;
2use serde::{Deserialize, Serialize};
3use solana_sdk::pubkey::Pubkey;
4
5#[cfg(feature = "redis")]
6use redis_derive::{FromRedisValue, ToRedisArgs};
7
8#[derive(Serialize, Deserialize, Debug, Clone)]
10pub struct AuthResponse {
11 pub token: String,
12}
13
14#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
16pub struct SupplyResponse {
17 pub result: String,
18}
19
20#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
22pub struct ChatSendMessageResponse {
23 pub status: String,
24 pub message: String,
25}
26
27#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
28pub struct User {
29 pub authority: String,
30 pub username: String,
31 pub profile_photo_url: Option<String>,
32 pub discord_user: Option<DiscordUser>,
33 pub updated_at: NaiveDateTime,
34 pub risk_score: i64,
35 pub is_banned: bool,
36 pub role: Option<String>,
37}
38
39#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
41#[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs))]
42pub struct ChatNotification {
43 pub authority: String,
44 pub username: String,
45 pub text: String,
46 pub id: u64,
47 pub ts: i64,
48 pub profile_photo_url: Option<String>,
49 pub role: Option<String>,
50 pub discord_user_id: Option<String>,
51 #[serde(default, skip_serializing_if = "Option::is_none")]
53 pub reply_to_id: Option<u64>,
54 #[serde(default, skip_serializing_if = "Option::is_none")]
55 pub reply_to_text: Option<String>,
56 #[serde(default, skip_serializing_if = "Option::is_none")]
57 pub reply_to_username: Option<String>,
58 #[serde(default, skip_serializing_if = "Option::is_none")]
60 pub reactions: Option<ChatReactions>,
61}
62
63#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
66#[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs))]
67pub struct ChatReactions {
68 #[serde(default, skip_serializing_if = "is_zero")]
69 pub thumbs_up: u32, #[serde(default, skip_serializing_if = "is_zero")]
71 pub heart: u32, #[serde(default, skip_serializing_if = "is_zero")]
73 pub laughing: u32, #[serde(default, skip_serializing_if = "is_zero")]
75 pub surprised: u32, #[serde(default, skip_serializing_if = "is_zero")]
77 pub sad: u32, #[serde(default, skip_serializing_if = "is_zero")]
79 pub fire: u32, }
81
82fn is_zero(n: &u32) -> bool {
83 *n == 0
84}
85
86impl ChatReactions {
87 pub fn is_empty(&self) -> bool {
89 self.thumbs_up == 0
90 && self.heart == 0
91 && self.laughing == 0
92 && self.surprised == 0
93 && self.sad == 0
94 && self.fire == 0
95 }
96
97 pub fn get(&self, emoji: &str) -> u32 {
99 match emoji {
100 "👍" => self.thumbs_up,
101 "❤️" | "❤" => self.heart,
102 "😂" => self.laughing,
103 "😮" => self.surprised,
104 "😢" => self.sad,
105 "🔥" => self.fire,
106 _ => 0,
107 }
108 }
109
110 pub fn set(&mut self, emoji: &str, count: u32) {
112 match emoji {
113 "👍" => self.thumbs_up = count,
114 "❤️" | "❤" => self.heart = count,
115 "😂" => self.laughing = count,
116 "😮" => self.surprised = count,
117 "😢" => self.sad = count,
118 "🔥" => self.fire = count,
119 _ => {}
120 }
121 }
122}
123
124pub const ALLOWED_REACTION_EMOJI: [&str; 6] = ["👍", "❤️", "😂", "😮", "😢", "🔥"];
126
127pub fn is_valid_reaction_emoji(emoji: &str) -> bool {
129 if emoji == "❤" {
131 return true;
132 }
133 ALLOWED_REACTION_EMOJI.contains(&emoji)
134}
135
136#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
137#[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs))]
138pub struct DeployNotification {
139 pub id: u64,
140 pub authority: String,
141 pub username: Option<String>,
142 pub profile_photo_url: Option<String>,
143 pub total_squares: u64,
144 pub mask: i64,
145 pub amount: u64,
146 pub round_id: u64,
147 pub ts: i64,
148}
149
150#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
151pub struct ResetNotification {
152 pub block_id: u64,
153}
154
155#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
157pub struct ReactionNotification {
158 pub message_id: u64,
159 pub emoji: String,
160 pub count: u32,
161 pub action: String, }
163
164#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
165pub enum Notification {
166 Chat(ChatNotification),
167 Reset(ResetNotification),
168 Deploy(DeployNotification),
169 Reaction(ReactionNotification),
170}
171
172impl Notification {
173 pub fn id(&self) -> String {
174 match self {
175 Notification::Chat(chat) => chat.id.to_string(),
176 Notification::Reset(reset) => reset.block_id.to_string(),
177 Notification::Deploy(deploy) => deploy.id.to_string(),
178 Notification::Reaction(reaction) => {
179 format!("{}:{}", reaction.message_id, reaction.emoji)
180 }
181 }
182 }
183}
184
185#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
187pub struct ChatReactResponse {
188 pub status: String,
189 pub action: String, pub message_id: u64,
191 pub emoji: String,
192 pub count: u32, }
194
195#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
196pub struct DailyRevenue {
197 pub day: String,
198 pub revenue: i64,
199}
200
201#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
204pub struct UsernameValidationResponse {
205 pub valid: bool,
206 pub error: Option<String>,
207}
208
209impl UsernameValidationResponse {
210 pub fn valid() -> Self {
211 Self {
212 valid: true,
213 error: None,
214 }
215 }
216
217 pub fn invalid(error: String) -> Self {
218 Self {
219 valid: false,
220 error: Some(error),
221 }
222 }
223}
224
225#[derive(Serialize, Deserialize, Debug, Clone)]
227pub struct DiscordAuthResponse {
228 pub access_token: String,
229}
230
231#[derive(Serialize, Deserialize, Debug, Clone)]
233pub struct GoogleUser {
234 pub email: String,
235 pub name: String,
236 pub picture: Option<String>,
237}
238
239#[derive(Serialize, Deserialize, Debug, Clone)]
241pub struct GoogleAuthResponse {
242 pub jwt: String,
243 pub user: GoogleUser,
244}
245
246#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
247pub struct DiscordUser {
248 pub id: String,
249 pub username: String,
250 pub discriminator: String,
251 #[serde(default, skip_serializing_if = "Option::is_none")]
252 pub global_name: Option<String>,
253 #[serde(default, skip_serializing_if = "Option::is_none")]
254 pub avatar: Option<String>,
255 #[serde(default, skip_serializing_if = "Option::is_none")]
256 pub verified: Option<bool>,
257 #[serde(default, skip_serializing_if = "Option::is_none")]
258 pub email: Option<String>,
259}
260
261#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
262pub struct OreBalance {
263 pub wallet: u64,
264 pub staked: u64,
265 pub unrefined: u64,
266 pub refined: u64,
267 pub lifetime_deployed_sol: u64,
268}
269
270#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
271pub struct LeaderboardEntry {
272 pub authority: String,
273 pub amount: u64,
274 pub username: Option<String>,
275 pub profile_picture_url: Option<String>,
276}
277
278#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
281pub struct ResetEventResponse {
282 pub disc: u8,
283 pub round_id: u64,
284 pub start_slot: u64,
285 pub end_slot: u64,
286 pub winning_square: u64,
287 pub top_miner: Pubkey,
288 pub num_winners: u64,
289 pub motherlode: u64,
290 pub total_deployed: u64,
291 pub total_vaulted: u64,
292 pub total_winnings: u64,
293 pub total_minted: u64,
294 pub ts: i64,
295 pub rng: u64,
296 pub deployed_winning_square: u64,
297 pub top_miner_username: Option<String>,
298 pub top_miner_profile_photo: Option<String>,
299}
300
301#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
303pub struct DeployHistoryEvent {
304 pub sig: String,
305 pub authority: String,
306 pub signer: String,
307 pub amount: u64,
308 pub mask: i64,
309 pub round_id: i64,
310 pub total_squares: i64,
311 pub ts: i64,
312 pub winning_square: i64,
313 pub top_miner: String,
314 pub rewards_sol: u64,
315 pub rewards_ore: u64,
316 pub total_winnings_sol: u64,
317 pub deployed_winning_square: u64,
318 pub motherlode: u64,
319}