diff options
Diffstat (limited to 'mumlib')
| -rw-r--r-- | mumlib/Cargo.toml | 2 | ||||
| -rw-r--r-- | mumlib/src/command.rs | 23 |
2 files changed, 19 insertions, 6 deletions
diff --git a/mumlib/Cargo.toml b/mumlib/Cargo.toml index 5c9d4e1..5ec9365 100644 --- a/mumlib/Cargo.toml +++ b/mumlib/Cargo.toml @@ -13,7 +13,7 @@ readme = "../README.md" [dependencies] colored = "2" -chrono = "0.4" +chrono = { version = "0.4", features = [ "serde" ] } dirs = "3" fern = "0.6" log = "0.4" diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 7551bb3..402d6b0 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -1,21 +1,34 @@ use crate::state::{Channel, Server}; +use chrono::NaiveDateTime; use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Debug, Clone, Serialize, Deserialize)] -pub enum Event { +pub struct MumbleEvent { + pub timestamp: NaiveDateTime, + pub kind: MumbleEventKind +} + +impl fmt::Display for MumbleEvent { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "[{}] {}", self.timestamp.format("%d %b %H:%M"), self.kind) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum MumbleEventKind { UserConnected(String, Option<String>), UserDisconnected(String, Option<String>), } -impl fmt::Display for Event { +impl fmt::Display for MumbleEventKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Event::UserConnected(user, channel) => { + MumbleEventKind::UserConnected(user, channel) => { write!(f, "{} connected to {}", user, channel.as_deref().unwrap_or("unknown channel")) } - Event::UserDisconnected(user, channel) => { + MumbleEventKind::UserDisconnected(user, channel) => { write!(f, "{} disconnected from {}", user, channel.as_deref().unwrap_or("unknown channel")) } } @@ -70,7 +83,7 @@ pub enum CommandResponse { is_deafened: bool, }, Event { - event: Event, + event: MumbleEvent, }, MuteStatus { is_muted: bool, |
