/* This file is part of DarkFi (https://dark.fi)
*
* Copyright (C) 2020-2024 Dyne.org foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use darkfi::{Error::ParseFailed, Result};
use log::info;
use crate::irc::{IrcChannel, IrcContact};
/// Parse configured autojoin channels from a TOML map.
///
/// ```toml
/// autojoin = ["#dev", "#memes"]
/// ```
pub fn parse_autojoin_channels(data: &toml::Value) -> Result> {
let mut ret = vec![];
let Some(autojoin) = data.get("autojoin") else { return Ok(ret) };
let Some(autojoin) = autojoin.as_array() else {
return Err(ParseFailed("autojoin not an array"))
};
for item in autojoin {
let Some(channel) = item.as_str() else {
return Err(ParseFailed("autojoin channel not a string"))
};
if !channel.starts_with('#') {
return Err(ParseFailed("autojoin channel not a valid channel"))
}
if ret.contains(&channel.to_string()) {
return Err(ParseFailed("Duplicate autojoin channel found"))
}
ret.push(channel.to_string());
}
Ok(ret)
}
/// Parse a DM secret key from a TOML map.
///
/// ```toml
/// [crypto]
/// dm_chacha_secret = "7CkVuFgwTUpJn5Sv67Q3fyEDpa28yrSeL5Hg2GqQ4jfM"
/// ```
fn parse_dm_chacha_secret(data: &toml::Value) -> Result