move tos-related things to config.rs
This commit is contained in:
parent
ffa2bc9bd2
commit
39f9e217b2
|
@ -1,4 +1,6 @@
|
||||||
use std::{env, error::Error, fs, io, path::PathBuf};
|
use crate::{RED, BLUE, WARN, RESET};
|
||||||
|
|
||||||
|
use std::{env, error::Error, fs, io, path::PathBuf, process::exit};
|
||||||
|
|
||||||
use home::home_dir;
|
use home::home_dir;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -48,6 +50,23 @@ impl Default for Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|
||||||
|
pub fn set_tos(&mut self, tos: bool) -> Result<(), Box<dyn Error>> {
|
||||||
|
self.tos = tos;
|
||||||
|
self.save()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check_tos(&self) -> () {
|
||||||
|
if ! self.tos {
|
||||||
|
eprintln!("{RED}You need to agree to duckduckgo AI chat TOS to continue.{RESET}");
|
||||||
|
eprintln!("{RED}Visit it on this URL: {RESET}{BLUE}https://duckduckgo.com/?q=duckduckgo+ai+chat&ia=chat{RESET}");
|
||||||
|
eprintln!("Once you read it, pass --agree-tos parameter to agree.");
|
||||||
|
eprintln!("{WARN}Note: if you want to, modify `tos` parameter in {}{RESET}", Config::get_path::<PathBuf>().join(Config::get_file_name::<String>()).display());
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_path<T: From<String>>() -> T {
|
pub fn get_path<T: From<String>>() -> T {
|
||||||
match env::var("HEY_CONFIG_PATH") {
|
match env::var("HEY_CONFIG_PATH") {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -47,18 +47,11 @@ async fn main() {
|
||||||
if ! config.tos {
|
if ! config.tos {
|
||||||
println!("{GREEN}TOS accepted{RESET}");
|
println!("{GREEN}TOS accepted{RESET}");
|
||||||
}
|
}
|
||||||
config.tos = true;
|
config.set_tos(true).expect("Error saving config");
|
||||||
config.save().expect("Error saving config");
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! config.tos {
|
config.check_tos();
|
||||||
eprintln!("{RED}You need to agree to duckduckgo AI chat TOS to continue.{RESET}");
|
|
||||||
eprintln!("{RED}Visit it on this URL: {RESET}{BLUE}https://duckduckgo.com/?q=duckduckgo+ai+chat&ia=chat{RESET}");
|
|
||||||
eprintln!("Once you read it, pass --agree-tos parameter to agree.");
|
|
||||||
eprintln!("{WARN}Note: if you want to, modify `tos` parameter in {}{RESET}", Config::get_path::<PathBuf>().join(Config::get_file_name::<String>()).display());
|
|
||||||
exit(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("{GREEN}Contacting DuckDuckGo chat AI...{RESET}");
|
println!("{GREEN}Contacting DuckDuckGo chat AI...{RESET}");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue