From 2b63fa8ac1b7e7d995955758f8cd9ab2ec7d4e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 7 Jun 2021 00:50:15 +0200 Subject: events command --- mumlib/src/command.rs | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 351d7f6..7551bb3 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -1,6 +1,26 @@ use crate::state::{Channel, Server}; use serde::{Deserialize, Serialize}; +use std::fmt; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum Event { + UserConnected(String, Option), + UserDisconnected(String, Option), +} + +impl fmt::Display for Event { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Event::UserConnected(user, channel) => { + write!(f, "{} connected to {}", user, channel.as_deref().unwrap_or("unknown channel")) + } + Event::UserDisconnected(user, channel) => { + write!(f, "{} disconnected from {}", user, channel.as_deref().unwrap_or("unknown channel")) + } + } + } +} #[derive(Clone, Debug, Deserialize, Serialize)] pub enum Command { @@ -10,11 +30,21 @@ pub enum Command { ChannelList, ConfigReload, DeafenSelf(Option), + Events { + block: bool + }, InputVolumeSet(f32), MuteOther(String, Option), MuteSelf(Option), OutputVolumeSet(f32), + PastMessages { + block: bool, + }, Ping, + SendMessage { + message: String, + targets: Vec, + }, ServerConnect { host: String, port: u16, @@ -29,13 +59,6 @@ pub enum Command { }, Status, UserVolumeSet(String, f32), - PastMessages { - block: bool, - }, - SendMessage { - message: String, - targets: Vec, - }, } #[derive(Debug, Deserialize, Serialize)] @@ -46,9 +69,15 @@ pub enum CommandResponse { DeafenStatus { is_deafened: bool, }, + Event { + event: Event, + }, MuteStatus { is_muted: bool, }, + PastMessage { + message: (String, String), + }, Pong, ServerConnect { welcome_message: Option, @@ -62,9 +91,6 @@ pub enum CommandResponse { Status { server_state: Server, }, - PastMessage { - message: (String, String), - }, } #[derive(Clone, Debug, Deserialize, Serialize)] -- cgit v1.2.1 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/src/command.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'mumlib/src') 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 From f22d3847a23484122fad83b22d7ca48316c9d7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 7 Jun 2021 17:17:41 +0200 Subject: additional events --- mumlib/src/command.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 402d6b0..818fd70 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -20,8 +20,15 @@ impl fmt::Display for MumbleEvent { pub enum MumbleEventKind { UserConnected(String, Option), UserDisconnected(String, Option), + /// This logic is kinda weird so we only store the rendered message. + UserMuteStateChanged(String), + 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 { @@ -31,6 +38,19 @@ impl fmt::Display for MumbleEventKind { MumbleEventKind::UserDisconnected(user, channel) => { write!(f, "{} disconnected from {}", user, channel.as_deref().unwrap_or("unknown 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) + } + } } } -- cgit v1.2.1 From 2aafe6967e38851d56f747cb3e615da7e9fa9bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 8 Jun 2021 09:46:59 +0200 Subject: doc --- mumlib/src/command.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 818fd70..fff921a 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -4,6 +4,7 @@ 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, @@ -16,12 +17,12 @@ impl fmt::Display for MumbleEvent { } } +/// The different kinds of events that can happen. #[derive(Debug, Clone, Serialize, Deserialize)] pub enum MumbleEventKind { UserConnected(String, Option), UserDisconnected(String, Option), - /// This logic is kinda weird so we only store the rendered message. - UserMuteStateChanged(String), + UserMuteStateChanged(String), // This logic is kinda weird so we only store the rendered message. TextMessageReceived(String), UserJoinedChannel(String, String), UserLeftChannel(String, String), -- cgit v1.2.1 From d3eb004bcca01c87cb12ba297e568eaf9d25cd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 8 Jun 2021 09:47:10 +0200 Subject: mumlib error unimplemented --- mumlib/src/error.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'mumlib/src') 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"), } } } -- cgit v1.2.1 From 52a4740f252391c944bf910c1a81a07bd7aea610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 8 Jun 2021 10:00:33 +0200 Subject: always send user joined/left channels and events --- mumlib/src/command.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index fff921a..f1b52b8 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -20,8 +20,8 @@ impl fmt::Display for MumbleEvent { /// The different kinds of events that can happen. #[derive(Debug, Clone, Serialize, Deserialize)] pub enum MumbleEventKind { - UserConnected(String, Option), - UserDisconnected(String, Option), + 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), @@ -34,10 +34,10 @@ 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.as_deref().unwrap_or("unknown channel")) + write!(f, "{} connected to {}", user, channel) } MumbleEventKind::UserDisconnected(user, channel) => { - write!(f, "{} disconnected from {}", user, channel.as_deref().unwrap_or("unknown channel")) + write!(f, "{} disconnected from {}", user, channel) } MumbleEventKind::UserMuteStateChanged(message) => { write!(f, "{}", message) -- cgit v1.2.1