twitch_api/helix/endpoints/chat/mod.rs
1//! Helix endpoints regarding chat
2//!
3//! # Implemented endpoints
4//!
5//! <!-- generate with "cargo xtask overview" (with a nightly toolchain) -->
6//! <!-- BEGIN-OVERVIEW -->
7//! <details open><summary style="cursor: pointer">Chat 🟢 15/15</summary>
8//!
9//! | Endpoint | Helper | Module |
10//! |---|---|---|
11//! | [Get Chatters](https://dev.twitch.tv/docs/api/reference#get-chatters) | [`HelixClient::get_chatters`](crate::helix::HelixClient::get_chatters) | [`get_chatters`] |
12//! | [Get Channel Emotes](https://dev.twitch.tv/docs/api/reference#get-channel-emotes) | [`HelixClient::get_channel_emotes_from_id`](crate::helix::HelixClient::get_channel_emotes_from_id), [`HelixClient::get_channel_emotes_from_login`](crate::helix::HelixClient::get_channel_emotes_from_login) | [`get_channel_emotes`] |
13//! | [Get Global Emotes](https://dev.twitch.tv/docs/api/reference#get-global-emotes) | [`HelixClient::get_global_emotes`](crate::helix::HelixClient::get_global_emotes) | [`get_global_emotes`] |
14//! | [Get Emote Sets](https://dev.twitch.tv/docs/api/reference#get-emote-sets) | [`HelixClient::get_emote_sets`](crate::helix::HelixClient::get_emote_sets) | [`get_emote_sets`] |
15//! | [Get Channel Chat Badges](https://dev.twitch.tv/docs/api/reference#get-channel-chat-badges) | - | [`get_channel_chat_badges`] |
16//! | [Get Global Chat Badges](https://dev.twitch.tv/docs/api/reference#get-global-chat-badges) | - | [`get_global_chat_badges`] |
17//! | [Get Chat Settings](https://dev.twitch.tv/docs/api/reference#get-chat-settings) | [`HelixClient::get_chat_settings`](crate::helix::HelixClient::get_chat_settings) | [`get_chat_settings`] |
18//! | [Get Shared Chat Session](https://dev.twitch.tv/docs/api/reference#get-shared-chat-session) | [`HelixClient::get_shared_chat_session`](crate::helix::HelixClient::get_shared_chat_session) | [`get_shared_chat_session`] |
19//! | [Get User Emotes](https://dev.twitch.tv/docs/api/reference#get-user-emotes) | [`HelixClient::get_user_emotes`](crate::helix::HelixClient::get_user_emotes), [`HelixClient::get_user_emotes_in_channel`](crate::helix::HelixClient::get_user_emotes_in_channel) | [`get_user_emotes`] |
20//! | [Update Chat Settings](https://dev.twitch.tv/docs/api/reference#update-chat-settings) | - | [`update_chat_settings`] |
21//! | [Send Chat Announcement](https://dev.twitch.tv/docs/api/reference#send-chat-announcement) | [`HelixClient::send_chat_announcement`](crate::helix::HelixClient::send_chat_announcement) | [`send_chat_announcement`] |
22//! | [Send a Shoutout](https://dev.twitch.tv/docs/api/reference#send-a-shoutout) | - | [`send_a_shoutout`] |
23//! | [Send Chat Message](https://dev.twitch.tv/docs/api/reference#send-chat-message) | [`HelixClient::send_chat_message`](crate::helix::HelixClient::send_chat_message), [`HelixClient::send_chat_message_reply`](crate::helix::HelixClient::send_chat_message_reply) | [`send_chat_message`] |
24//! | [Get User Chat Color](https://dev.twitch.tv/docs/api/reference#get-user-chat-color) | [`HelixClient::get_user_chat_color`](crate::helix::HelixClient::get_user_chat_color), [`HelixClient::get_users_chat_colors`](crate::helix::HelixClient::get_users_chat_colors) | [`get_user_chat_color`] |
25//! | [Update User Chat Color](https://dev.twitch.tv/docs/api/reference#update-user-chat-color) | [`HelixClient::update_user_chat_color`](crate::helix::HelixClient::update_user_chat_color) | [`update_user_chat_color`] |
26//!
27//! </details>
28//!
29//! <!-- END-OVERVIEW -->
30
31use crate::{
32 helix::{self, Request},
33 types::{self, EmoteUrlBuilder},
34};
35use serde_derive::{Deserialize, Serialize};
36use std::borrow::Cow;
37
38pub mod get_channel_chat_badges;
39pub mod get_channel_emotes;
40pub mod get_chat_settings;
41pub mod get_chatters;
42pub mod get_emote_sets;
43pub mod get_global_chat_badges;
44pub mod get_global_emotes;
45pub mod get_shared_chat_session;
46pub mod get_user_chat_color;
47pub mod get_user_emotes;
48pub mod send_a_shoutout;
49pub mod send_chat_announcement;
50pub mod send_chat_message;
51pub mod update_chat_settings;
52pub mod update_user_chat_color;
53
54#[doc(inline)]
55pub use get_channel_chat_badges::GetChannelChatBadgesRequest;
56#[doc(inline)]
57pub use get_channel_emotes::GetChannelEmotesRequest;
58#[doc(inline)]
59pub use get_chat_settings::GetChatSettingsRequest;
60#[doc(inline)]
61pub use get_chatters::{Chatter, GetChattersRequest};
62#[doc(inline)]
63pub use get_emote_sets::GetEmoteSetsRequest;
64#[doc(inline)]
65pub use get_global_chat_badges::GetGlobalChatBadgesRequest;
66#[doc(inline)]
67pub use get_global_emotes::GetGlobalEmotesRequest;
68#[doc(inline)]
69pub use get_shared_chat_session::{
70 GetSharedChatSessionRequest, SharedChatParticipant, SharedChatSession,
71};
72#[doc(inline)]
73pub use get_user_chat_color::{GetUserChatColorRequest, UserChatColor};
74#[doc(inline)]
75pub use get_user_emotes::{GetUserEmotesRequest, UserEmote};
76#[doc(inline)]
77pub use send_a_shoutout::{SendAShoutoutRequest, SendAShoutoutResponse};
78#[doc(inline)]
79pub use send_chat_announcement::{
80 SendChatAnnouncementBody, SendChatAnnouncementRequest, SendChatAnnouncementResponse,
81};
82#[doc(inline)]
83pub use send_chat_message::{
84 ChatMessageDropCode, ChatMessageDropReason, SendChatMessageBody, SendChatMessageRequest,
85 SendChatMessageResponse,
86};
87#[doc(inline)]
88pub use update_chat_settings::{UpdateChatSettingsBody, UpdateChatSettingsRequest};
89#[doc(inline)]
90pub use update_user_chat_color::{UpdateUserChatColorRequest, UpdateUserChatColorResponse};
91
92#[doc(inline)]
93pub use crate::extra::AnnouncementColor;
94
95/// A set of badges
96#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
97#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
98#[non_exhaustive]
99pub struct BadgeSet {
100 /// ID for the chat badge set.
101 pub set_id: types::BadgeSetId,
102 /// Contains chat badge objects for the set.
103 pub versions: Vec<ChatBadge>,
104}
105
106/// A chat Badge
107#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
108#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
109#[non_exhaustive]
110pub struct ChatBadge {
111 /// ID of the chat badge version.
112 pub id: types::ChatBadgeId,
113 // FIXME: Use types::Image, see https://github.com/serde-rs/serde/issues/1504
114 /// URL to png of size 28x28
115 pub image_url_1x: String,
116 /// URL to png of size 56x56
117 pub image_url_2x: String,
118 /// URL to png of size 112x112
119 pub image_url_4x: String,
120 /// Title of the badge
121 pub title: String,
122 /// Descrition of the badge
123 pub description: String,
124}
125
126/// A chat emote
127#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
128#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
129#[non_exhaustive]
130pub struct ChannelEmote {
131 /// ID of the emote.
132 pub id: types::EmoteId,
133 /// Name of the emote a viewer types into Twitch chat for the image to appear.
134 pub name: String,
135 /// Object of image URLs for the emote.
136 pub images: types::Image,
137 /// If the emote_type is "subscriptions", this indicates the subscriber tier at which the emote is unlocked. Set to an empty string otherwise.
138 #[serde(
139 default,
140 deserialize_with = "crate::deserialize_none_from_empty_string"
141 )]
142 pub tier: Option<types::SubscriptionTier>,
143 // FIXME: Enumify?
144 /// The type of emote.
145 ///
146 /// The most common values for custom channel emotes are
147 ///
148 /// `subscriptions`: Indicates a custom subscriber emote.
149 ///
150 /// `bitstier`: Indicates a custom Bits tier emote.
151 ///
152 /// `follower`: Indicates a custom follower emote.
153 pub emote_type: String,
154 /// ID of the emote set the emote belongs to.
155 pub emote_set_id: types::EmoteSetId,
156 /// The formats that the emote is available in.
157 pub format: Vec<types::EmoteAnimationSetting>,
158 /// The sizes that the emote is available in.
159 pub scale: Vec<types::EmoteScale>,
160 /// The background themes that the emote is available in.
161 pub theme_mode: Vec<types::EmoteThemeMode>,
162}
163
164impl ChannelEmote {
165 /// Create an emote builder for this emote.
166 ///
167 /// # Examples
168 ///
169 /// ```rust, no_run
170 /// # use twitch_api::{client, helix, types};
171 /// # #[tokio::main]
172 /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
173 /// # let client: helix::HelixClient<'static, client::DummyHttpClient> = helix::HelixClient::default();
174 /// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
175 /// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
176 /// let emotes = client.get_channel_emotes_from_login("twitchdev", &token).await?.expect("user not found");
177 /// assert_eq!(emotes[0].url().size_3x().dark_mode().render(), "https://static-cdn.jtvnw.net/emoticons/v2/emotesv2_dc24652ada1e4c84a5e3ceebae4de709/default/dark/3.0");
178 /// # Ok(())
179 /// # }
180 /// ```
181 pub fn url(&self) -> types::EmoteUrlBuilder<'_> { EmoteUrlBuilder::new(&self.id) }
182}
183
184/// A chat emote
185#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
186#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
187#[non_exhaustive]
188pub struct GlobalEmote {
189 /// ID of the emote.
190 pub id: types::EmoteId,
191 /// Name of the emote a viewer types into Twitch chat for the image to appear.
192 pub name: String,
193 /// Object of image URLs for the emote.
194 pub images: types::Image,
195 /// The formats that the emote is available in.
196 pub format: Vec<types::EmoteAnimationSetting>,
197 /// The sizes that the emote is available in.
198 pub scale: Vec<types::EmoteScale>,
199 /// The background themes that the emote is available in.
200 pub theme_mode: Vec<types::EmoteThemeMode>,
201}
202
203/// Chat settings
204#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
205#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
206#[non_exhaustive]
207pub struct ChatSettings {
208 /// The ID of the broadcaster specified in the request.
209 pub broadcaster_id: types::UserId,
210 /// A Boolean value that determines whether chat messages must contain only emotes. Is true, if only messages that are 100% emotes are allowed; otherwise, false.
211 pub emote_mode: bool,
212 /// A Boolean value that determines whether the broadcaster restricts the chat room to followers only, based on how long they’ve followed.
213 ///
214 /// Is true, if the broadcaster restricts the chat room to followers only; otherwise, false.
215 /// See [`follower_mode_duration`](Self::follower_mode_duration) for how long the followers must have followed the broadcaster to participate in the chat room.
216 pub follower_mode: bool,
217 /// The length of time, in minutes, that the followers must have followed the broadcaster to participate in the chat room. See [`follower_mode`](Self::follower_mode).
218 ///
219 /// Is null if [`follower_mode`](Self::follower_mode) is false.
220 pub follower_mode_duration: Option<u64>,
221 /// The ID of the moderator specified in the request for chat settings.
222 pub moderator_id: Option<types::UserId>,
223 /// A Boolean value that determines whether the broadcaster adds a short delay before chat messages appear in the chat room. This gives chat moderators and bots a chance to remove them before viewers can see the message.
224 ///
225 /// Is true, if the broadcaster applies a delay; otherwise, false.
226 /// See [`non_moderator_chat_delay_duration`](Self::non_moderator_chat_delay_duration) for the length of the delay.
227 ///
228 /// # Notes
229 ///
230 /// This field and [`non_moderator_chat_delay_duration`](Self::non_moderator_chat_delay_duration) are not received when the request is made without a specified `moderator_id`.
231 pub non_moderator_chat_delay: Option<bool>,
232 /// The amount of time, in seconds, that messages are delayed from appearing in chat. See [`non_moderator_chat_delay`](Self::non_moderator_chat_delay).
233 ///
234 /// Is null if [`non_moderator_chat_delay`](Self::non_moderator_chat_delay) is false.
235 pub non_moderator_chat_delay_duration: Option<u64>,
236 /// A Boolean value that determines whether the broadcaster limits how often users in the chat room are allowed to send messages.
237 ///
238 /// Is true, if the broadcaster applies a delay; otherwise, false.
239 /// See [`slow_mode_wait_time`](Self::slow_mode_wait_time) for the delay.
240 pub slow_mode: bool,
241 /// The amount of time, in seconds, that users need to wait between sending messages. See slow_mode.
242 ///
243 /// Is null if slow_mode is false.
244 pub slow_mode_wait_time: Option<u64>,
245 /// A Boolean value that determines whether only users that subscribe to the broadcaster’s channel can talk in the chat room.
246 ///
247 /// Is true, if the broadcaster restricts the chat room to subscribers only; otherwise, false.
248 pub subscriber_mode: bool,
249 /// A Boolean value that determines whether the broadcaster requires users to post only unique messages in the chat room.
250 ///
251 /// Is true, if the broadcaster requires unique messages only; otherwise, false.
252 pub unique_chat_mode: bool,
253}