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
use super::*;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RoomState<'t> {
pub tags: Tags<'t>,
pub channel: Cow<'t, str>,
}
impl<'t> RoomState<'t> {
pub fn is_emote_only(&self) -> bool {
self.tags.get_as_bool("emote-only")
}
pub fn is_followers_only(&self) -> Option<FollowersOnly> {
self.tags
.get_parsed::<_, isize>("followers-only")
.map(|s| match s {
-1 => FollowersOnly::Disabled,
0 => FollowersOnly::All,
d => FollowersOnly::Limit(d),
})
}
pub fn is_r9k(&self) -> bool {
self.tags.get_as_bool("r9k")
}
pub fn room_id(&self) -> Option<u64> {
self.tags.get_parsed("room-id")
}
pub fn is_slow_mode(&self) -> Option<u64> {
self.tags.get_parsed("slow").filter(|&s| s > 0)
}
pub fn is_subs_only(&self) -> bool {
self.tags.get_as_bool("subs-only")
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum FollowersOnly {
Disabled,
All,
Limit(isize),
}
impl<'a: 't, 't> Parse<&'a Message<'t>> for RoomState<'t> {
fn parse(msg: &'a Message<'t>) -> Result<Self, InvalidMessage> {
msg.expect_command("ROOMSTATE")?;
Ok(Self {
channel: msg.expect_arg(0)?,
tags: msg.tags.clone(),
})
}
}
impl<'t> AsOwned for RoomState<'t> {
type Owned = RoomState<'static>;
fn as_owned(&self) -> Self::Owned {
RoomState {
tags: self.tags.as_owned(),
channel: self.channel.as_owned(),
}
}
}