Browse Source

Allow optional nick in config file

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
master
Maxime “pep” Buquet 2 months ago
parent
commit
3b36852749
No known key found for this signature in database
GPG Key ID: DEDA74AEECA9D0F2
  1. 3
      sendxmpp.toml
  2. 12
      src/main.rs

3
sendxmpp.toml

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
# jid and password exactly like this, nothing else
# jid and password exactly like this
jid = "jid@example.org"
password = "sOmePa55W0rD"
# nick = "foobar" # optional nick for Multi-User Chat

12
src/main.rs

@ -25,6 +25,7 @@ use anyhow::{anyhow, bail, Result}; @@ -25,6 +25,7 @@ use anyhow::{anyhow, bail, Result};
struct Config {
jid: String,
password: String,
nick: Option<String>,
}
fn parse_cfg<P: AsRef<Path>>(path: P) -> Result<Config> {
@ -169,11 +170,12 @@ async fn main() { @@ -169,11 +170,12 @@ async fn main() {
for recipient in recipients {
if opts.muc {
let nick = {
let opt = opts.nick.clone();
let node = BareJid::from_str(cfg.jid.as_str()).unwrap().node;
opt.or(node).die("couldn't find a nick to use")
};
let nick = opts
.nick
.clone()
.or(cfg.nick.clone())
.or_else(|| BareJid::from_str(cfg.jid.as_str()).unwrap().node)
.die("couldn't find a nick to use");
let participant = match recipient.clone() {
Jid::Full(_) => die!("Invalid room address"),
Jid::Bare(bare) => bare.with_resource(nick.clone()),

Loading…
Cancel
Save