Rust_Discord_API/utils/sticker.rs
1use reqwest::Client;
2use serde_json::Value;
3use std::error::Error;
4
5#[allow(dead_code)]
6/// Fetches a sticker by its ID.
7///
8/// # Arguments
9///
10/// * `client` - The HTTP client used to send the request.
11/// * `token` - The bot token for authentication.
12/// * `sticker_id` - The ID of the sticker to fetch.
13///
14/// # Returns
15///
16/// A result containing the sticker information as a JSON value.
17pub async fn get_sticker(client: &Client, token: &str, sticker_id: &str) -> Result<Value, Box<dyn Error>> {
18 let url = format!("https://discord.com/api/v9/stickers/{}", sticker_id);
19 let response: Value = client.get(&url)
20 .bearer_auth(token)
21 .send()
22 .await?
23 .json()
24 .await?;
25
26 Ok(response)
27}
28
29#[allow(dead_code)]
30/// Lists all standard sticker packs.
31///
32/// # Arguments
33///
34/// * `client` - The HTTP client used to send the request.
35/// * `token` - The bot token for authentication.
36///
37/// # Returns
38///
39/// A result containing the list of sticker packs as a JSON value.
40pub async fn list_sticker_packs(client: &Client, token: &str) -> Result<Value, Box<dyn Error>> {
41 let url = "https://discord.com/api/v9/sticker-packs";
42 let response: Value = client.get(url)
43 .bearer_auth(token)
44 .send()
45 .await?
46 .json()
47 .await?;
48
49 Ok(response)
50}
51
52#[allow(dead_code)]
53/// Lists all stickers for a guild.
54///
55/// # Arguments
56///
57/// * `client` - The HTTP client used to send the request.
58/// * `token` - The bot token for authentication.
59/// * `guild_id` - The ID of the guild to list stickers for.
60///
61/// # Returns
62///
63/// A result containing the list of guild stickers as a JSON value.
64pub async fn list_guild_stickers(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
65 let url = format!("https://discord.com/api/v9/guilds/{}/stickers", guild_id);
66 let response: Value = client.get(&url)
67 .bearer_auth(token)
68 .send()
69 .await?
70 .json()
71 .await?;
72
73 Ok(response)
74}
75
76#[allow(dead_code)]
77/// Fetches a guild sticker by its ID.
78///
79/// # Arguments
80///
81/// * `client` - The HTTP client used to send the request.
82/// * `token` - The bot token for authentication.
83/// * `guild_id` - The ID of the guild.
84/// * `sticker_id` - The ID of the sticker to fetch.
85///
86/// # Returns
87///
88/// A result containing the guild sticker information as a JSON value.
89pub async fn get_guild_sticker(client: &Client, token: &str, guild_id: &str, sticker_id: &str) -> Result<Value, Box<dyn Error>> {
90 let url = format!("https://discord.com/api/v9/guilds/{}/stickers/{}", guild_id, sticker_id);
91 let response: Value = client.get(&url)
92 .bearer_auth(token)
93 .send()
94 .await?
95 .json()
96 .await?;
97
98 Ok(response)
99}
100
101#[allow(dead_code)]
102/// Creates a new sticker in a guild.
103///
104/// # Arguments
105///
106/// * `client` - The HTTP client used to send the request.
107/// * `token` - The bot token for authentication.
108/// * `guild_id` - The ID of the guild.
109/// * `sticker_data` - The JSON value of the sticker data.
110///
111/// # Returns
112///
113/// A result containing the created guild sticker information as a JSON value.
114pub async fn create_guild_sticker(client: &Client, token: &str, guild_id: &str, sticker_data: Value) -> Result<Value, Box<dyn Error>> {
115 let url = format!("https://discord.com/api/v9/guilds/{}/stickers", guild_id);
116 let response: Value = client.post(&url)
117 .bearer_auth(token)
118 .json(&sticker_data)
119 .send()
120 .await?
121 .json()
122 .await?;
123
124 Ok(response)
125}
126
127#[allow(dead_code)]
128/// Modifies a guild sticker.
129///
130/// # Arguments
131///
132/// * `client` - The HTTP client used to send the request.
133/// * `token` - The bot token for authentication.
134/// * `guild_id` - The ID of the guild.
135/// * `sticker_id` - The ID of the sticker to modify.
136/// * `sticker_data` - The JSON value of the sticker data.
137///
138/// # Returns
139///
140/// A result containing the modified guild sticker information as a JSON value.
141pub async fn modify_guild_sticker(client: &Client, token: &str, guild_id: &str, sticker_id: &str, sticker_data: Value) -> Result<Value, Box<dyn Error>> {
142 let url = format!("https://discord.com/api/v9/guilds/{}/stickers/{}", guild_id, sticker_id);
143 let response: Value = client.patch(&url)
144 .bearer_auth(token)
145 .json(&sticker_data)
146 .send()
147 .await?
148 .json()
149 .await?;
150
151 Ok(response)
152}
153
154#[allow(dead_code)]
155/// Deletes a guild sticker.
156///
157/// # Arguments
158///
159/// * `client` - The HTTP client used to send the request.
160/// * `token` - The bot token for authentication.
161/// * `guild_id` - The ID of the guild.
162/// * `sticker_id` - The ID of the sticker to delete.
163///
164/// # Returns
165///
166/// A result indicating success or failure.
167pub async fn delete_guild_sticker(client: &Client, token: &str, guild_id: &str, sticker_id: &str) -> Result<(), Box<dyn Error>> {
168 let url = format!("https://discord.com/api/v9/guilds/{}/stickers/{}", guild_id, sticker_id);
169
170 client.delete(&url)
171 .bearer_auth(token)
172 .send()
173 .await?
174 .error_for_status()?;
175
176 Ok(())
177}