diff options
Diffstat (limited to 'mumlib')
| -rw-r--r-- | mumlib/src/command.rs | 79 | ||||
| -rw-r--r-- | mumlib/src/error.rs | 2 |
2 files changed, 71 insertions, 10 deletions
diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 27ca60c..48174fc 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -2,6 +2,59 @@ 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 { @@ -11,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: Vec<MessageTarget>, + }, ServerConnect { host: String, port: u16, @@ -30,13 +93,6 @@ pub enum Command { }, Status, UserVolumeSet(String, f32), - PastMessages { - block: bool, - }, - SendMessage { - message: String, - targets: Vec<MessageTarget>, - }, } #[derive(Debug, Deserialize, Serialize)] @@ -47,9 +103,15 @@ 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>, @@ -63,9 +125,6 @@ pub enum CommandResponse { Status { server_state: Server, }, - PastMessage { - message: (NaiveDateTime, String, String), - }, } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index e88bd97..c492a5f 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, } impl std::error::Error for Error {} @@ -26,6 +27,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"), } } } |
