Skip to main content

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