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
use super::*;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UserState<'t> {
pub tags: Tags<'t>,
pub channel: Cow<'t, str>,
}
impl<'t> UserState<'t> {
pub fn badge_info(&'t self) -> Vec<crate::BadgeInfo<'t>> {
self.tags
.get_ref("badge-info")
.map(|s| crate::parse_badges(s))
.unwrap_or_default()
}
pub fn badges(&'t self) -> Vec<crate::Badge<'t>> {
self.tags
.get_ref("badges")
.map(|s| crate::parse_badges(s))
.unwrap_or_default()
}
pub fn color(&self) -> Option<crate::color::Color> {
self.tags.get_parsed("color")
}
pub fn display_name(&'t self) -> Option<Cow<'t, str>> {
self.tags.get("display-name")
}
pub fn emotes(&self) -> Vec<crate::Emotes> {
self.tags
.get("emotes")
.map(|s| crate::parse_emotes(&s))
.unwrap_or_default()
}
pub fn is_moderator(&self) -> bool {
self.tags.get_as_bool("mod")
}
}
impl<'a: 't, 't> Parse<&'a Message<'t>> for UserState<'t> {
fn parse(msg: &'a Message<'t>) -> Result<Self, InvalidMessage> {
msg.expect_command("USERSTATE")?;
msg.expect_arg(0).map(|channel| Self {
channel,
tags: msg.tags.clone(),
})
}
}
impl<'t> AsOwned for UserState<'t> {
type Owned = UserState<'static>;
fn as_owned(&self) -> Self::Owned {
UserState {
tags: self.tags.as_owned(),
channel: self.channel.as_owned(),
}
}
}