|
|
@ -8,6 +8,8 @@ use std::path::PathBuf;
|
|
|
|
use std::process;
|
|
|
|
use std::process;
|
|
|
|
use std::time::Duration;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use toml;
|
|
|
|
|
|
|
|
|
|
|
|
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
|
|
|
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
@ -27,12 +29,11 @@ fn main() -> Result<()> {
|
|
|
|
let matches = Command::new("tbotsend")
|
|
|
|
let matches = Command::new("tbotsend")
|
|
|
|
.version("development")
|
|
|
|
.version("development")
|
|
|
|
.arg(Arg::new("config").short('f').long("config").value_name("FILE"))
|
|
|
|
.arg(Arg::new("config").short('f').long("config").value_name("FILE"))
|
|
|
|
.arg(Arg::new("chatid").short('c').long("chatid").value_name("chat_id"))
|
|
|
|
.arg(Arg::new("chatid").short('c').long("chatid").value_name("CHATID"))
|
|
|
|
.arg(Arg::new("token").short('t').long("token").value_name("token"))
|
|
|
|
.arg(Arg::new("token").short('t').long("token").value_name("TOKEN"))
|
|
|
|
.arg(Arg::new("parse").short('p').long("parse").default_value("MarkdownV2").value_name("MODE"))
|
|
|
|
.arg(Arg::new("parse").short('p').long("parse").default_value("MarkdownV2").value_name("MODE"))
|
|
|
|
.arg(Arg::new("timeout").long("timeout").value_parser(clap::value_parser!(u8)).default_value("10").value_name("SECONDS"))
|
|
|
|
.arg(Arg::new("timeout").long("timeout").value_parser(clap::value_parser!(u8)).default_value("10").value_name("SECONDS"))
|
|
|
|
.arg(Arg::new("silent").short('s').long("silent").action(ArgAction::SetTrue))
|
|
|
|
.arg(Arg::new("silent").short('s').long("silent").action(ArgAction::SetTrue))
|
|
|
|
.arg(Arg::new("version").short('v').long("version").action(ArgAction::SetTrue))
|
|
|
|
|
|
|
|
.arg(Arg::new("help").short('h').long("help").action(ArgAction::Help))
|
|
|
|
.arg(Arg::new("help").short('h').long("help").action(ArgAction::Help))
|
|
|
|
.arg(Arg::new("message").num_args(1..).required(false))
|
|
|
|
.arg(Arg::new("message").num_args(1..).required(false))
|
|
|
|
.get_matches();
|
|
|
|
.get_matches();
|
|
|
@ -61,12 +62,12 @@ fn main() -> Result<()> {
|
|
|
|
PathBuf::from(cfg)
|
|
|
|
PathBuf::from(cfg)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
dirs::home_dir()
|
|
|
|
dirs::home_dir()
|
|
|
|
.map(|p| p.join(".config/tbotsend.yaml"))
|
|
|
|
.map(|p| p.join(".config/tbotsend.toml"))
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let mut config_data = fs::read_to_string(&config_path).or_else(|_| {
|
|
|
|
let mut config_data = fs::read_to_string(&config_path).or_else(|_| {
|
|
|
|
let fallback = dirs::home_dir().unwrap().join(".tbotsend.yaml");
|
|
|
|
let fallback = dirs::home_dir().unwrap().join(".tbotsend.toml");
|
|
|
|
fs::read_to_string(&fallback)
|
|
|
|
fs::read_to_string(&fallback)
|
|
|
|
}).map_err(|e| {
|
|
|
|
}).map_err(|e| {
|
|
|
|
print_error(&format!("Failed to read configuration file: {}", e));
|
|
|
|
print_error(&format!("Failed to read configuration file: {}", e));
|
|
|
@ -74,11 +75,11 @@ fn main() -> Result<()> {
|
|
|
|
})?;
|
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
|
|
config_used = config_path.to_string_lossy().to_string();
|
|
|
|
config_used = config_path.to_string_lossy().to_string();
|
|
|
|
serde_yaml::from_str::<Config>(&mut config_data)?
|
|
|
|
toml::from_str::<Config>(&mut config_data)?
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if config.chat_id.is_empty() || config.token.is_empty() {
|
|
|
|
if config.chat_id.is_empty() || config.token.is_empty() {
|
|
|
|
print_error("Configuration is missing ChatID or Token");
|
|
|
|
print_error("Configuration is missing chat_id or token");
|
|
|
|
process::exit(2);
|
|
|
|
process::exit(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|