From 17f077d48b361a4cf8f5743750ca7408a8800797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 7 Jun 2021 01:30:40 +0200 Subject: timestamps on mumble events --- mumlib/Cargo.toml | 2 +- mumlib/src/command.rs | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'mumlib') 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), UserDisconnected(String, Option), } -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, -- cgit v1.2.1