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
use super::*;
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PrivMsg {
pub tags: Tags,
pub user: String,
pub channel: String,
pub message: String,
pub action: bool,
}
impl PrivMsg {
pub fn user(&self) -> &str {
&self.user
}
pub fn channel(&self) -> &str {
&self.channel
}
pub fn message(&self) -> &str {
self.message.as_str()
}
pub fn is_action(&self) -> bool {
self.action
}
}
impl PrivMsg {
pub fn badges(&self) -> Vec<Badge> {
badges(self.get("badges").unwrap_or_default())
}
pub fn bits(&self) -> u64 {
self.get_parsed("bits").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 id(&self) -> Option<&str> {
self.get("id")
}
pub fn moderator(&self) -> bool {
self.get_as_bool("mod")
}
pub fn room_id(&self) -> Option<u64> {
self.get_parsed("room-id")
}
pub fn tmi_sent_ts(&self) -> Option<u64> {
self.get_parsed("tmi-sent-ts")
}
pub fn user_id(&self) -> Option<u64> {
self.get_parsed("user-id")
}
}
impl Tag for PrivMsg {
fn get(&self, key: &str) -> Option<&str> {
self.tags.get(key).map(AsRef::as_ref)
}
}