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
use super::*;

/// When a user's message(s) have been purged.
///
/// Typically after a user is banned from chat or timed out.
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ClearChat {
    pub(super) tags: Tags,
    pub(super) channel: Channel,
    pub(super) user: Option<String>,
}

impl ClearChat {
    /// IRC tags
    pub fn tags(&self) -> &Tags {
        &self.tags
    }
    /// The owner of the message. Empty if its the entire channel
    pub fn user(&self) -> Option<&str> {
        self.user.as_ref().map(String::as_str)
    }
    /// The channel this event happened on
    pub fn channel(&self) -> &Channel {
        &self.channel
    }
}

impl ClearChat {
    /// (Optional) Duration of the timeout, in seconds. If omitted, the ban is permanent.
    pub fn ban_duration(&self) -> Option<u64> {
        self.get("ban-duration")?.parse().ok()
    }
}

impl Tag for ClearChat {
    fn get(&self, key: &str) -> Option<&str> {
        self.tags.get(key).map(AsRef::as_ref)
    }
}