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)]
166pub struct TypingUser {
167 pub authority: String,
168 pub username: String,
169}
170
171#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
173pub struct TypingNotification {
174 pub users: Vec<TypingUser>,
175}
176
177#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
178pub enum Notification {
179 Chat(ChatNotification),
180 Reset(ResetNotification),
181 Deploy(DeployNotification),
182 Reaction(ReactionNotification),
183 Typing(TypingNotification),
184}
185
186impl Notification {
187 pub fn id(&self) -> String {
188 match self {
189 Notification::Chat(chat) => chat.id.to_string(),
190 Notification::Reset(reset) => reset.block_id.to_string(),
191 Notification::Deploy(deploy) => deploy.id.to_string(),
192 Notification::Reaction(reaction) => {
193 format!("{}:{}", reaction.message_id, reaction.emoji)
194 }
195 Notification::Typing(_) => "typing".to_string(),
196 }
197 }
198}
199
200#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
202pub struct ChatReactResponse {
203 pub status: String,
204 pub action: String, pub message_id: u64,
206 pub emoji: String,
207 pub count: u32, }
209
210#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
212pub struct ChatTypingResponse {
213 pub status: String,
214}
215
216#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
217pub struct DailyRevenue {
218 pub day: String,
219 pub revenue: i64,
220}
221
222#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
225pub struct UsernameValidationResponse {
226 pub valid: bool,
227 pub error: Option<String>,
228}
229
230impl UsernameValidationResponse {
231 pub fn valid() -> Self {
232 Self {
233 valid: true,
234 error: None,
235 }
236 }
237
238 pub fn invalid(error: String) -> Self {
239 Self {
240 valid: false,
241 error: Some(error),
242 }
243 }
244}
245
246#[derive(Serialize, Deserialize, Debug, Clone)]
248pub struct DiscordAuthResponse {
249 pub access_token: String,
250}
251
252#[derive(Serialize, Deserialize, Debug, Clone)]
254pub struct GoogleUser {
255 pub email: String,
256 pub name: String,
257 pub picture: Option<String>,
258}
259
260#[derive(Serialize, Deserialize, Debug, Clone)]
262pub struct GoogleAuthResponse {
263 pub jwt: String,
264 pub user: GoogleUser,
265}
266
267#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
268pub struct DiscordUser {
269 pub id: String,
270 pub username: String,
271 pub discriminator: String,
272 #[serde(default, skip_serializing_if = "Option::is_none")]
273 pub global_name: Option<String>,
274 #[serde(default, skip_serializing_if = "Option::is_none")]
275 pub avatar: Option<String>,
276 #[serde(default, skip_serializing_if = "Option::is_none")]
277 pub verified: Option<bool>,
278 #[serde(default, skip_serializing_if = "Option::is_none")]
279 pub email: Option<String>,
280}
281
282#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
283pub struct OreBalance {
284 pub wallet: u64,
285 pub staked: u64,
286 pub unrefined: u64,
287 pub refined: u64,
288 pub lifetime_deployed_sol: u64,
289}
290
291#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
292pub struct LeaderboardEntry {
293 pub authority: String,
294 pub amount: u64,
295 pub username: Option<String>,
296 pub profile_picture_url: Option<String>,
297}
298
299#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
302pub struct ResetEventResponse {
303 pub disc: u8,
304 pub round_id: u64,
305 pub start_slot: u64,
306 pub end_slot: u64,
307 pub winning_square: u64,
308 pub top_miner: Pubkey,
309 pub num_winners: u64,
310 pub motherlode: u64,
311 pub total_deployed: u64,
312 pub total_vaulted: u64,
313 pub total_winnings: u64,
314 pub total_minted: u64,
315 pub ts: i64,
316 pub rng: u64,
317 pub deployed_winning_square: u64,
318 pub top_miner_username: Option<String>,
319 pub top_miner_profile_photo: Option<String>,
320}
321
322#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
324pub struct DeployHistoryEvent {
325 pub sig: String,
326 pub authority: String,
327 pub signer: String,
328 pub amount: u64,
329 pub mask: i64,
330 pub round_id: i64,
331 pub total_squares: i64,
332 pub ts: i64,
333 pub winning_square: i64,
334 pub top_miner: String,
335 pub rewards_sol: u64,
336 pub rewards_ore: u64,
337 pub total_winnings_sol: u64,
338 pub deployed_winning_square: u64,
339 pub motherlode: u64,
340}