aboutsummaryrefslogtreecommitdiffstats
path: root/mumctl/src/main.rs
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2021-05-19 00:21:01 +0200
committerEskil Queseth <eskilq@kth.se>2021-05-19 00:21:01 +0200
commitf856694aa55672e6f2fa93fbce5d47fce2d08d1e (patch)
tree7caaed3dac5f3b1949bd459af2cb47ad5c1c04d5 /mumctl/src/main.rs
parent7ac57f3803bcf0f357ee307a6f0daf0783efbf92 (diff)
downloadmum-f856694aa55672e6f2fa93fbce5d47fce2d08d1e.tar.gz
add frontend support for sending messages
Diffstat (limited to 'mumctl/src/main.rs')
-rw-r--r--mumctl/src/main.rs48
1 files changed, 47 insertions, 1 deletions
diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs
index 5f1d8f7..5d3f332 100644
--- a/mumctl/src/main.rs
+++ b/mumctl/src/main.rs
@@ -1,6 +1,6 @@
use colored::Colorize;
use log::*;
-use mumlib::command::{Command as MumCommand, CommandResponse};
+use mumlib::command::{Command as MumCommand, CommandResponse, MessageTarget};
use mumlib::config::{self, Config, ServerConfig};
use mumlib::state::Channel as MumChannel;
use std::fmt;
@@ -90,6 +90,27 @@ enum Command {
Undeafen,
/// Get messages
Messages,
+ /// Send a message to a channel or a user
+ Message(Target),
+}
+
+#[derive(Debug, StructOpt)]
+enum Target {
+ Channel {
+ /// The message to send
+ message: String,
+ /// If the message should be sent recursivley to sub-channels
+ #[structopt(short = "r", long = "recursive")]
+ recursive: bool,
+ /// Which channels to send to
+ names: Vec<String>,
+ },
+ User {
+ /// The message to send
+ message: String,
+ /// Which channels to send to
+ names: Vec<String>,
+ },
}
#[derive(Debug, StructOpt)]
@@ -361,6 +382,31 @@ fn match_opt() -> Result<(), Error> {
_ => unreachable!("Response should only be a PastMessages"),
}
}
+ Command::Message(target) => {
+ match target {
+ Target::Channel {
+ message,
+ recursive,
+ names,
+ } => {
+ let msg = MumCommand::SendMessage {
+ message,
+ targets: names.into_iter().map(|name| MessageTarget::Channel { name, recursive }).collect(),
+ };
+ send_command(msg)??;
+ },
+ Target::User {
+ message,
+ names
+ } => {
+ let msg = MumCommand::SendMessage {
+ message,
+ targets: names.into_iter().map(|name| MessageTarget::User { name }).collect(),
+ };
+ send_command(msg)??;
+ },
+ }
+ }
}
if !config::cfg_exists() {