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
use super::*;
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UserState {
pub tags: Tags,
pub channel: String,
}
impl UserState {
pub fn channel(&self) -> &str {
&self.channel
}
}
impl UserState {
pub fn badges(&self) -> Vec<Badge> {
badges(self.get("badges").unwrap_or_default())
}
pub fn color(&self) -> Option<TwitchColor> {
self.get("color").map(RGB::from_hex).map(Into::into)
}
pub fn display_name(&self) -> Option<&str> {
self.get("display-name")
}
pub fn emotes(&self) -> Vec<Emotes> {
emotes(self.get("emotes").unwrap_or_default())
}
pub fn moderator(&self) -> bool {
self.get_as_bool("mod")
}
}
impl Tag for UserState {
fn get(&self, key: &str) -> Option<&str> {
self.tags.get(key).map(AsRef::as_ref)
}
}