use std::{fs, path::Path};
use crate::{BskyFeed, BskyPost, Result};
#[allow(unused_variables)]
pub trait AmselBot {
async fn on_post(&mut self, post: BskyPost) -> Result<()> {
Ok(())
}
async fn on_feed(&mut self, feed: BskyFeed) -> Result<()> {
Ok(())
}
fn on_post_sync(&mut self, post: &BskyPost) {}
fn on_feed_sync(&mut self, feed: &BskyFeed) {}
}
pub trait CursorStore {
fn cursor_store(&self, cursor: u64);
fn cursor_load(&self) -> Option<u64>;
}
pub trait SimpleFileCursorStore {}
impl<T> CursorStore for T
where
T: SimpleFileCursorStore,
{
fn cursor_store(&self, cursor: u64) {
let path = Path::new("cursor");
let err = fs::write(path, cursor.to_string());
if err.is_err() && path.exists() {
err.unwrap()
}
}
fn cursor_load(&self) -> Option<u64> {
let path = Path::new("cursor");
path.exists()
.then(|| fs::read_to_string(path).unwrap())
.and_then(|s| Some(s.trim().parse::<u64>().unwrap()))
}
}