Allow optional nick in config file
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
06ecb97f4c
commit
3b36852749
@ -1,4 +1,5 @@
|
|||||||
# jid and password exactly like this, nothing else
|
# jid and password exactly like this
|
||||||
|
|
||||||
jid = "jid@example.org"
|
jid = "jid@example.org"
|
||||||
password = "sOmePa55W0rD"
|
password = "sOmePa55W0rD"
|
||||||
|
# nick = "foobar" # optional nick for Multi-User Chat
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -25,6 +25,7 @@ use anyhow::{anyhow, bail, Result};
|
|||||||
struct Config {
|
struct Config {
|
||||||
jid: String,
|
jid: String,
|
||||||
password: String,
|
password: String,
|
||||||
|
nick: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_cfg<P: AsRef<Path>>(path: P) -> Result<Config> {
|
fn parse_cfg<P: AsRef<Path>>(path: P) -> Result<Config> {
|
||||||
@ -169,11 +170,12 @@ async fn main() {
|
|||||||
|
|
||||||
for recipient in recipients {
|
for recipient in recipients {
|
||||||
if opts.muc {
|
if opts.muc {
|
||||||
let nick = {
|
let nick = opts
|
||||||
let opt = opts.nick.clone();
|
.nick
|
||||||
let node = BareJid::from_str(cfg.jid.as_str()).unwrap().node;
|
.clone()
|
||||||
opt.or(node).die("couldn't find a nick to use")
|
.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() {
|
let participant = match recipient.clone() {
|
||||||
Jid::Full(_) => die!("Invalid room address"),
|
Jid::Full(_) => die!("Invalid room address"),
|
||||||
Jid::Bare(bare) => bare.with_resource(nick.clone()),
|
Jid::Bare(bare) => bare.with_resource(nick.clone()),
|
||||||
|
Loading…
Reference in New Issue
Block a user