1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
/*! Messages sent by the server This can be obtained by [subscribing] to an [Event] on a [Dispatcher] Or by using [Parse] on an [Message] [subscribing]: ../client/struct.Dispatcher.html#method.subscribe [Event]: ../events/index.html [Dispatcher]: ../client/struct.Dispatcher.html [Parse]: ../trait.Parse.html [Message]: ../decode/struct.Message.html */ use crate::decode::Message; use crate::Tags; use crate::{Conversion, Parse, StringMarker}; mod error; pub use error::InvalidMessage; mod expect; use expect::Expect as _; pub use parse::*; mod parse; /// A raw IRC message pub type Raw<T> = Message<T>; /// The kind of the Names event #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum NamesKind<T = String> where T: StringMarker, { /// Names begins, this'll continue until `End` is recieved Start { /// A list of user names users: Vec<T>, }, /// Names end, this'll mark the end of the event End, } /// The names event /// /// This'll will list people on a channel for your user /// /// The `kind` field lets you determine if its still 'happening' /// /// Your should keep a list of the names from the `Start` variant /// /// And once you receive an End you'll have the complete lost #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Names<T = String> where T: StringMarker, { /// Your username pub user: T, /// The channel this event is happening for pub channel: T, /// The state of the event pub kind: NamesKind<T>, } /// Identifies the channel's chat settings (e.g., slow mode duration). #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct RoomState<T = String> where T: StringMarker, { /// Tags attached to this message pub tags: Tags<T>, /// Channel this event is happening on pub channel: T, } /// Announces Twitch-specific events to the channel (e.g., a user's subscription notification). #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct UserNotice<T = String> where T: StringMarker, { /// Tags attached to this message pub tags: Tags<T>, /// Channel this event is happening on pub channel: T, /// Optional message attached to the event pub message: Option<T>, } /// Sent on successful login, if TAGs caps have been sent beforehand #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct GlobalUserState<T = String> where T: StringMarker, { /// Your user-id pub user_id: T, /// Your display name, if set pub display_name: Option<T>, /// Your color, if set. Defaults to `white` pub color: crate::color::Color, /// Your available emote sets, always contains atleast '0' pub emote_sets: Vec<T>, /// Any badges you have pub badges: Vec<crate::Badge<T>>, } /// Event kind for determine when a Host event beings or end #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum HostTargetKind<T = String> where T: StringMarker, { /// The host event started Start { /// Target channel that is being hosted target: T, }, /// The host event ended End, } /// When a channel starts to host another channel #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct HostTarget<T = String> where T: StringMarker, { /// Source channel (the one doing the hosting). pub source: T, /// How many viewers are going along pub viewers: Option<usize>, /// What kind of event this was. e.g. `Start` or `End` pub kind: HostTargetKind<T>, } /// Acknowledgement (or not) on a CAPS request #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Cap<T = String> where T: StringMarker, { /// The capability name pub capability: T, /// Whether it was acknowledged pub acknowledged: bool, } /// When a user's message(s) have been purged. /// /// Typically after a user is banned from chat or timed out #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ClearChat<T = String> where T: StringMarker, { /// Tags attached to the message pub tags: Tags<T>, /// The channel this event happened on pub channel: T, /// The user, if any, that was being purged pub user: Option<T>, } /// When a single message has been removed from a channel. /// /// This is triggered via /delete on IRC. #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ClearMsg<T = String> where T: StringMarker, { /// Tags attached to the message pub tags: Tags<T>, /// The channel this event happened on pub channel: T, /// The message that was deleted pub message: Option<T>, } /// Happens when the IRC connection has been succesfully established #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct IrcReady<T = String> where T: StringMarker, { /// The name the server will refer to you as pub nickname: T, } /// User join message /// /// The happens when a user (yourself included) joins a channel #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Join<T = String> where T: StringMarker, { /// Name of the user that joined the channel pub user: T, /// Channel which they joined pub channel: T, } /// Status of gaining or losing moderator (operator) status #[derive(Debug, Copy, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ModeStatus { /// Moderator status gained Gained, /// Moderator status lost Lost, } /// When a user gains or loses moderator (operator) status in a channel. #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Mode<T = String> where T: StringMarker, { /// The channel this event happened on pub channel: T, /// The status. gained, or lost pub status: ModeStatus, /// The user this applies too pub user: T, } /// General notices from the server. #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Notice<T = String> where T: StringMarker, { /// The tags attached to this message pub tags: Tags<T>, /// The channel this event happened on pub channel: T, /// The message from the server pub message: T, } /// User leave message /// /// The happens when a user (yourself included) leaves a channel #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Part<T = String> where T: StringMarker, { /// Name of the user that left the channel pub user: T, /// Channel which they left pub channel: T, } /// A ping request from the server /// /// This is sent periodically, and handled by the `Client` internally /// /// But you can use them however you want #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Ping<T = String> where T: StringMarker, { /// Token associated with the PING event pub token: T, } /// A pong response sent from the server /// /// This should be a response to sending a PING to the server #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Pong<T = String> where T: StringMarker, { /// Token associated with the PONG event pub token: T, } /// Message sent by a user #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Privmsg<T = String> where T: StringMarker, { /// User who sent this messages pub user: T, /// Channel this message was sent on pub channel: T, /// Data that the user provided pub data: T, /// Tags attached to the message pub tags: Tags<T>, } /// Happens when the Twitch connection has been succesfully established #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Ready<T = String> where T: StringMarker, { /// The name Twitch will refer to you as pub username: T, } /// Signals that you should reconnect and rejoin channels after a restart. /// /// Twitch IRC processes occasionally need to be restarted. When this happens, /// clients that have requested the IRC v3 twitch.tv/commands capability are /// issued a RECONNECT. After a short time, the connection is closed. In this /// case, reconnect and rejoin channels that were on the connection, as you /// would normally. #[derive(Debug, Copy, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Reconnect {} /// Identifies a user's chat settings or properties (e.g., chat color).. #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct UserState<T = String> where T: StringMarker, { /// Tags attached to this message pub tags: Tags<T>, /// Channel this event happened on pub channel: T, } #[cfg(test)] mod tests;