Allow optional nick in config file

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-09-25 00:35:25 +02:00
parent 06ecb97f4c
commit 3b36852749
No known key found for this signature in database
GPG Key ID: DEDA74AEECA9D0F2
2 changed files with 9 additions and 6 deletions

View File

@ -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

View File

@ -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() {
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()),