Skip to content

Commit 0aa9153

Browse files
committed
Add send-matrix-message command
1 parent ad9d787 commit 0aa9153

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/command/matrix.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use crate::{
2+
rpc::{self},
3+
Result,
4+
};
5+
use clap::Args;
6+
use serde_json::json;
7+
8+
#[derive(Args)]
9+
pub struct SendMatrixMessageArgs {
10+
pub room_id: String,
11+
pub message: String,
12+
}
13+
14+
pub fn send_matrix_message(args: &SendMatrixMessageArgs) -> Result<()> {
15+
let params = json!({
16+
"room_id": args.room_id,
17+
"message": args.message,
18+
});
19+
rpc::call("send_matrix_message", params)?.print()
20+
}

src/command/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod common;
55
pub mod element;
66
pub mod event;
77
pub mod import;
8+
pub mod matrix;
89
pub mod report;
910
pub mod setup;
1011
pub mod user;

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,16 @@ enum Commands {
118118
RevokeSubmittedPlace(command::import::RevokeSubmittedPlaceArgs),
119119

120120
SetApiKey(command::admin::SetApiKeyArgs),
121+
122+
SendMatrixMessage(command::matrix::SendMatrixMessageArgs),
121123
}
122124

123125
type Result<T> = std::result::Result<T, Box<dyn Error>>;
124126

125127
fn main() -> Result<()> {
126128
let cli = Cli::parse();
127129

128-
std::env::set_var("VERBOSITY", cli.verbose.to_string());
130+
unsafe { std::env::set_var("VERBOSITY", cli.verbose.to_string()) };
129131

130132
if let Some(Commands::SetServer(args)) = &cli.command {
131133
return command::setup::set_server(args);
@@ -222,6 +224,8 @@ fn main() -> Result<()> {
222224
Commands::RevokeSubmittedPlace(args) => command::import::revoke_submitted_place(args),
223225

224226
Commands::SetApiKey(args) => command::admin::set_api_key(args),
227+
228+
Commands::SendMatrixMessage(args) => command::matrix::send_matrix_message(args),
225229
}
226230
}
227231

0 commit comments

Comments
 (0)