From 71941137265669013ef64473748c4fde6bc48f1c Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Tue, 3 Nov 2020 21:08:46 +0100 Subject: add mumd support for muting users --- mumlib/src/command.rs | 3 +++ mumlib/src/error.rs | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index e404056..63dd5f9 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -18,6 +18,9 @@ pub enum Command { }, ServerDisconnect, Status, + DeafenSelf, + MuteSelf, + MuteOther(String), } #[derive(Debug, Deserialize, Serialize)] diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index c6d9255..e8b0323 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -9,6 +9,7 @@ pub enum Error { DisconnectedError, AlreadyConnectedError, ChannelIdentifierError(String, ChannelIdentifierError), + InvalidUserIdentifierError(String), InvalidServerAddrError(String, u16), } @@ -18,9 +19,8 @@ impl Display for Error { Error::DisconnectedError => write!(f, "Not connected to a server"), Error::AlreadyConnectedError => write!(f, "Already connected to a server"), Error::ChannelIdentifierError(id, kind) => write!(f, "{}: {}", kind, id), - Error::InvalidServerAddrError(addr, port) => { - write!(f, "Invalid server address: {}: {}", addr, port) - } + Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}: {}", addr, port), + Error::InvalidUserIdentifierError(name) => write!(f, "Invalid username: {}", name), } } } -- cgit v1.2.1 From 22579ced3d1d847a14683fe3b47fa2076df01751 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Thu, 5 Nov 2020 00:44:04 +0100 Subject: add mute feature --- mumlib/src/command.rs | 6 +++--- mumlib/src/state.rs | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 28b4d79..675fb7d 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -20,13 +20,13 @@ pub enum Command { }, ServerDisconnect, Status, - DeafenSelf, - MuteSelf, - MuteOther(String), ServerStatus { host: String, port: u16, }, + DeafenSelf(Option), + MuteSelf(Option), + MuteOther(String, Option), } #[derive(Debug, Deserialize, Serialize)] diff --git a/mumlib/src/state.rs b/mumlib/src/state.rs index b6b4039..0540f14 100644 --- a/mumlib/src/state.rs +++ b/mumlib/src/state.rs @@ -130,9 +130,19 @@ pub struct User { pub deaf: bool, // by admin } +macro_rules! true_to_str { + ($condition:expr, $res:expr) => {if $condition { $res } else { "" }}; +} + impl Display for User { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.name) + write!(f, "{} {}{}{}{}{}", + self.name, + true_to_str!(self.suppress, "s"), + true_to_str!(self.self_mute, "M"), + true_to_str!(self.self_deaf, "D"), + true_to_str!(self.mute, "m"), + true_to_str!(self.deaf, "d")) } } -- cgit v1.2.1 From 7a4e0c79be76444a8f3a8d4019175a8eb84d333e Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Thu, 5 Nov 2020 00:44:48 +0100 Subject: cargo fmt --- mumlib/src/error.rs | 4 +++- mumlib/src/state.rs | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index c9eff52..5b82fbd 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -20,7 +20,9 @@ impl Display for Error { Error::DisconnectedError => write!(f, "Not connected to a server"), Error::AlreadyConnectedError => write!(f, "Already connected to a server"), Error::ChannelIdentifierError(id, kind) => write!(f, "{}: {}", kind, id), - Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}: {}", addr, port), + Error::InvalidServerAddrError(addr, port) => { + write!(f, "Invalid server address: {}: {}", addr, port) + } Error::InvalidUserIdentifierError(name) => write!(f, "Invalid username: {}", name), Error::InvalidUsernameError(username) => write!(f, "Invalid username: {}", username), } diff --git a/mumlib/src/state.rs b/mumlib/src/state.rs index 0540f14..3b1da56 100644 --- a/mumlib/src/state.rs +++ b/mumlib/src/state.rs @@ -131,18 +131,27 @@ pub struct User { } macro_rules! true_to_str { - ($condition:expr, $res:expr) => {if $condition { $res } else { "" }}; + ($condition:expr, $res:expr) => { + if $condition { + $res + } else { + "" + } + }; } impl Display for User { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{} {}{}{}{}{}", - self.name, - true_to_str!(self.suppress, "s"), - true_to_str!(self.self_mute, "M"), - true_to_str!(self.self_deaf, "D"), - true_to_str!(self.mute, "m"), - true_to_str!(self.deaf, "d")) + write!( + f, + "{} {}{}{}{}{}", + self.name, + true_to_str!(self.suppress, "s"), + true_to_str!(self.self_mute, "M"), + true_to_str!(self.self_deaf, "D"), + true_to_str!(self.mute, "m"), + true_to_str!(self.deaf, "d") + ) } } -- cgit v1.2.1 From 0220f0372937ed179aa84fa6e2250933cd3e3896 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Thu, 5 Nov 2020 02:35:15 +0100 Subject: remove redundancy in mumlib --- mumlib/src/error.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index 5b82fbd..1e79b9c 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -9,7 +9,6 @@ pub enum Error { DisconnectedError, AlreadyConnectedError, ChannelIdentifierError(String, ChannelIdentifierError), - InvalidUserIdentifierError(String), InvalidServerAddrError(String, u16), InvalidUsernameError(String), } @@ -23,7 +22,6 @@ impl Display for Error { Error::InvalidServerAddrError(addr, port) => { write!(f, "Invalid server address: {}: {}", addr, port) } - Error::InvalidUserIdentifierError(name) => write!(f, "Invalid username: {}", name), Error::InvalidUsernameError(username) => write!(f, "Invalid username: {}", username), } } -- cgit v1.2.1