diff options
Diffstat (limited to 'mumlib')
| -rw-r--r-- | mumlib/Cargo.toml | 2 | ||||
| -rw-r--r-- | mumlib/src/command.rs | 81 | ||||
| -rw-r--r-- | mumlib/src/error.rs | 2 |
3 files changed, 74 insertions, 11 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 4f4cf3a..8cb7cb9 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -1,6 +1,60 @@ use crate::state::{Channel, Server}; +use chrono::NaiveDateTime; use serde::{Deserialize, Serialize}; +use std::fmt; + +/// Something that happened in our channel at a point in time. +#[derive(Debug, Clone, Serialize, Deserialize)] +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) + } +} + +/// The different kinds of events that can happen. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum MumbleEventKind { + UserConnected(String, String), + UserDisconnected(String, String), + UserMuteStateChanged(String), // This logic is kinda weird so we only store the rendered message. + TextMessageReceived(String), + UserJoinedChannel(String, String), + UserLeftChannel(String, String), +} + +//TODO These strings are (mostly) duplicated with their respective notifications. +// The only difference is that the text message event doesn't contain the text message. +impl fmt::Display for MumbleEventKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + MumbleEventKind::UserConnected(user, channel) => { + write!(f, "{} connected to {}", user, channel) + } + MumbleEventKind::UserDisconnected(user, channel) => { + write!(f, "{} disconnected from {}", user, channel) + } + MumbleEventKind::UserMuteStateChanged(message) => { + write!(f, "{}", message) + } + MumbleEventKind::TextMessageReceived(user) => { + write!(f, "{} sent a text message", user) + } + MumbleEventKind::UserJoinedChannel(name, from) => { + write!(f, "{} moved to your channel from {}", name, from) + } + MumbleEventKind::UserLeftChannel(name, to) => { + write!(f, "{} moved to {}", name, to) + } + + } + } +} #[derive(Clone, Debug, Deserialize, Serialize)] pub enum Command { @@ -10,11 +64,21 @@ pub enum Command { ChannelList, ConfigReload, DeafenSelf(Option<bool>), + Events { + block: bool + }, InputVolumeSet(f32), MuteOther(String, Option<bool>), MuteSelf(Option<bool>), OutputVolumeSet(f32), + PastMessages { + block: bool, + }, Ping, + SendMessage { + message: String, + targets: MessageTarget, + }, ServerConnect { host: String, port: u16, @@ -29,13 +93,6 @@ pub enum Command { }, Status, UserVolumeSet(String, f32), - PastMessages { - block: bool, - }, - SendMessage { - message: String, - target: MessageTarget, - }, } #[derive(Debug, Deserialize, Serialize)] @@ -46,12 +103,19 @@ pub enum CommandResponse { DeafenStatus { is_deafened: bool, }, + Event { + event: MumbleEvent, + }, MuteStatus { is_muted: bool, }, + PastMessage { + message: (NaiveDateTime, String, String), + }, Pong, ServerConnect { welcome_message: Option<String>, + server_state: Server, }, ServerStatus { version: u32, @@ -62,9 +126,6 @@ pub enum CommandResponse { Status { server_state: Server, }, - PastMessage { - message: (String, String), - }, } /// Messages sent to channels can be sent either to a named channel or the diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index 83f97b8..2cb3927 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -11,6 +11,7 @@ pub enum Error { InvalidServerAddr(String, u16), InvalidUsername(String), InvalidServerPassword, + Unimplemented, NotConnectedToChannel, } @@ -27,6 +28,7 @@ impl fmt::Display for Error { } Error::InvalidUsername(username) => write!(f, "Invalid username: {}", username), Error::InvalidServerPassword => write!(f, "Invalid server password"), + Error::Unimplemented => write!(f, "Unimplemented"), Error::NotConnectedToChannel => write!(f, "Not connected to a channel"), } } |
