Added posting loop on main thread
This commit is contained in:
parent
7e61db4f3c
commit
c96ff09128
|
@ -10,6 +10,23 @@ pub struct Config {
|
||||||
top_k: String,
|
top_k: String,
|
||||||
gpt_code_path: String,
|
gpt_code_path: String,
|
||||||
fediverse_base_url: String,
|
fediverse_base_url: String,
|
||||||
|
interval_seconds: MinMax,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct MinMax {
|
||||||
|
min: u64,
|
||||||
|
max: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MinMax {
|
||||||
|
pub fn min(&self) -> u64 {
|
||||||
|
self.min
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn max(&self) -> u64 {
|
||||||
|
self.max
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
@ -19,8 +36,12 @@ impl Config {
|
||||||
model_name: String::from("117M"),
|
model_name: String::from("117M"),
|
||||||
temperature: String::from("1"),
|
temperature: String::from("1"),
|
||||||
top_k: String::from("40"),
|
top_k: String::from("40"),
|
||||||
gpt_code_path: String::from("."),
|
gpt_code_path: String::from("./gpt/"),
|
||||||
fediverse_base_url: String::from("https://lain.com"),
|
fediverse_base_url: String::from("https://lain.com"),
|
||||||
|
interval_seconds: MinMax {
|
||||||
|
min: 60 * 30,
|
||||||
|
max: 60 * 90,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,4 +93,9 @@ impl Config {
|
||||||
pub fn fediverse_base_url(&self) -> String {
|
pub fn fediverse_base_url(&self) -> String {
|
||||||
self.fediverse_base_url.clone()
|
self.fediverse_base_url.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a reference to the config's inverval seconds.
|
||||||
|
pub fn interval_seconds(&self) -> &MinMax {
|
||||||
|
&self.interval_seconds
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -1,4 +1,6 @@
|
||||||
use std::{error::Error, process};
|
use std::{error::Error, process, thread, time::Duration};
|
||||||
|
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
mod bot;
|
mod bot;
|
||||||
mod config;
|
mod config;
|
||||||
|
@ -43,8 +45,15 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let gen = generator::Generator::new(gpt_model);
|
let gen = generator::Generator::new(gpt_model);
|
||||||
let mut bot = bot::IzzilisBot::new(gen, publisher);
|
let mut bot = bot::IzzilisBot::new(gen, publisher);
|
||||||
|
|
||||||
match bot.publish() {
|
let cfg_interval = cfg.interval_seconds();
|
||||||
Some(err) => Err(err),
|
loop {
|
||||||
None => Ok(()),
|
let wait_seconds = rand::thread_rng().gen_range(cfg_interval.min()..cfg_interval.max());
|
||||||
|
let wait_time = Duration::from_secs(wait_seconds);
|
||||||
|
println!("Next post is in {} seconds", wait_seconds);
|
||||||
|
thread::sleep(wait_time);
|
||||||
|
match bot.publish() {
|
||||||
|
Some(err) => println!("Got error from publish: {}; continuing", err),
|
||||||
|
None => println!("publish() call successful"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue