From f856694aa55672e6f2fa93fbce5d47fce2d08d1e Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Wed, 19 May 2021 00:21:01 +0200 Subject: add frontend support for sending messages --- mumctl/src/main.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'mumctl/src') 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, + }, + User { + /// The message to send + message: String, + /// Which channels to send to + names: Vec, + }, } #[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() { -- cgit v1.2.1