mutiny_rs/model/
user.rs

1use serde::{Deserialize, Serialize};
2use crate::context::Context;
3use crate::http::HttpError;
4use crate::model::file::File;
5
6#[derive(Debug, Serialize, Deserialize, Clone)]
7pub struct User {
8    #[serde(rename = "_id")]
9    pub id: String,
10    pub online: bool,
11    pub discriminator: String,
12    pub relationship: Option<RelationshipStatus>,
13    pub username: String,
14    pub avatar: Option<File>,
15    pub badges: Option<u8>,
16    pub bot: Option<Bot>,
17    pub display_name: Option<String>,
18    pub flags: Option<usize>,
19    pub privileged: Option<bool>,
20    pub status: Option<crate::model::ready::Status>,
21}
22
23#[derive(Debug, Serialize, Deserialize)]
24pub struct FetchProfile {
25    pub background: Option<Background>,
26    pub content: String,
27}
28#[derive(Debug, Serialize, Deserialize)]
29pub struct Background {
30    pub content_type: String,
31    pub filename: String,
32    pub metadata: Metadata,
33    pub size: usize,
34    pub tag: String,
35    pub _id: String,
36}
37#[derive(Debug, Serialize, Deserialize, Clone)]
38pub struct Metadata {
39    pub height: usize,
40    #[serde(rename = "type")]
41    pub _type: String,
42    pub width: usize,
43}
44
45#[derive(Debug, Serialize, Deserialize)]
46pub struct FetchUser {
47    pub _id: String,
48    pub username: String,
49    pub avatar: Option<File>,
50    pub relationship: Option<RelationshipStatus>,
51    pub badges: usize,
52    pub status: Option<Status>,
53    pub online: bool,
54    pub flags: Option<usize>,
55    pub bot: Option<Bot>
56}
57#[derive(Debug, Serialize, Deserialize, Clone)]
58pub struct Bot {
59    pub owner: String,
60}
61#[derive(Debug, Serialize, Deserialize)]
62pub struct Status {
63    pub text: Option<String>,
64    pub presence: Option<String>,
65}
66
67/// User's relationship with another user (or themselves)
68#[derive(Debug, Serialize, Deserialize, Default, PartialEq)]
69#[derive(Clone)]
70pub enum RelationshipStatus {
71    /// No relationship with other user
72    #[default]
73    None,
74    /// Other user is us
75    User,
76    /// Friends with the other user
77    Friend,
78    /// Pending friend request to user
79    Outgoing,
80    /// Incoming friend request from user
81    Incoming,
82    /// Blocked this user
83    Blocked,
84    /// Blocked by this user
85    BlockedOther,
86}
87
88impl User {
89    pub async fn fetch_self(&self, ctx: &Context) -> Result<User, HttpError> {
90         ctx.http.get::<User>("/users/@me").await
91    }
92    pub async fn fetch_user(&self, ctx: &Context, id: String) -> Result<User, HttpError> {
93        let url = format!("/users/{}", id);
94        ctx.http.get::<User>(&url).await
95    }
96    pub fn to_string(&self) -> String {
97        format!("<@{}>", self.id)
98    }
99}