aboutsummaryrefslogtreecommitdiffstats
path: root/mumlib/src/command.rs
diff options
context:
space:
mode:
Diffstat (limited to 'mumlib/src/command.rs')
-rw-r--r--mumlib/src/command.rs81
1 files changed, 71 insertions, 10 deletions
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