Compare commits

..

No commits in common. "feature/curator-selection" and "master" have entirely different histories.

7 changed files with 32 additions and 60 deletions

View File

@ -17,6 +17,6 @@ uuid = { version = "0.8.2", features = ["v4"] }
anyhow = "1.0.41"
mammut = "0.13.0"
thiserror = "1.0.26"
misskey = { version = "0.2.0", features = ["aid"] }
misskey = "0.2.0"
url = "2.2.2"
smol = "1.2.5"

View File

@ -1,18 +0,0 @@
use std::error::Error;
use futures::future::BoxFuture;
use super::Curator;
#[derive(Clone)]
pub struct AnyCurator;
impl Curator for AnyCurator {
type Error = Box<dyn Error>;
type Response = BoxFuture<'static, Result<bool, Self::Error>>;
fn review(&self, _: String) -> Self::Response {
Box::pin(async {Ok(true)})
}
}

View File

@ -11,20 +11,18 @@ use telegram_bot::{Api, ChatId, ChatRef, ToChatRef};
use crate::{
config::{FediverseConfig, Publisher},
curation::{telegram::get_chat_ref, CuratorExt, TelegramCurator},
publish::MastodonPublisher,
publish::MisskeyPublisher,
selection::{telegram::get_chat_ref, SelectorExt, TelegramSelector},
};
use futures::{
channel::mpsc::channel, future::Either, sink::unfold, SinkExt, StreamExt, TryStreamExt,
};
use futures::{SinkExt, StreamExt, TryStreamExt, channel::mpsc::channel, future::Either, sink::unfold};
use model::SampleModelExt;
mod config;
mod curation;
mod model;
mod publish;
mod selection;
const CONFIG_PATH: &str = "bot_config.json";
@ -68,7 +66,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let cfg_clone = cfg.clone();
let mut model = TelegramCurator::new(
let mut model = TelegramSelector::new(
api,
chat,
Box::pin(unfold((), move |_, chat_ref| {
@ -147,11 +145,9 @@ async fn resolve_publisher(
config: &mut config::Config,
) -> Result<Either<MisskeyPublisher, MastodonPublisher>, Box<dyn Error>> {
let publisher = match &config.publisher {
config::Publisher::Misskey(cfg) => Either::Left(MisskeyPublisher::new(
&cfg.base_url,
cfg.token.clone(),
cfg.visibility,
)?),
config::Publisher::Misskey(cfg) => {
Either::Left(MisskeyPublisher::new(&cfg.base_url, cfg.token.clone(), cfg.visibility)?)
}
config::Publisher::Mastodon(cfg) => {
let app = AppBuilder {
client_name: "izzilis",

View File

@ -1,5 +1,5 @@
use futures::Sink;
use misskey::{model::note::Visibility, Client, ClientExt, HttpClient};
use misskey::{Client, ClientExt, HttpClient, model::note::Visibility};
use std::{error::Error, task::Poll};
use url::Url;
@ -30,11 +30,7 @@ impl Sink<String> for MisskeyPublisher {
fn start_send(self: std::pin::Pin<&mut Self>, item: String) -> Result<(), Self::Error> {
let mut req = self.client.build_note();
let req = req.text(item).visibility(self.post_visibility).as_request();
let response = smol::block_on(self.client.request(req))?;
// If there is an ApiResult error, decode it to a regular Result error
if let Option::Some(err) = response.err() {
return Err(Box::new(err));
}
smol::block_on(self.client.request(req))?;
Ok(())
}

View File

@ -3,12 +3,12 @@ use std::error::Error;
use async_std::io::stdin;
use futures::future::BoxFuture;
use super::Curator;
use super::Selector;
#[derive(Debug, Copy, Clone)]
pub struct ConsoleCurator;
pub struct ConsoleSelector;
impl Curator for ConsoleCurator {
impl Selector for ConsoleSelector {
type Error = Box<dyn Error>;
type Response = BoxFuture<'static, Result<bool, Self::Error>>;

View File

@ -2,21 +2,19 @@ use futures::{stream::BoxStream, Future, Stream, TryStreamExt};
use std::fmt::Debug;
use thiserror::Error;
mod any;
mod console;
pub mod telegram;
pub use any::AnyCurator;
pub use console::ConsoleCurator;
pub use telegram::TelegramCurator;
pub use console::ConsoleSelector;
pub use telegram::TelegramSelector;
pub trait Curator: Sync + Send + Clone {
pub trait Selector {
type Error;
type Response: Future<Output = Result<bool, Self::Error>>;
fn review(&self, data: String) -> Self::Response;
}
pub trait CuratorExt<E: Debug, S: Stream<Item = Result<String, E>>>: Curator
pub trait SelectorExt<E: Debug, S: Stream<Item = Result<String, E>>>: Selector
where
Self::Error: Debug,
{
@ -35,9 +33,9 @@ pub enum FilterError<T: Debug, U: Debug> {
impl<
E: Debug + 'static,
T: Curator + Sync + Send + Clone + 'static,
T: Selector + Sync + Send + Clone + 'static,
S: Send + Stream<Item = Result<String, E>> + 'static,
> CuratorExt<E, S> for T
> SelectorExt<E, S> for T
where
T::Response: Send,
T::Error: Debug,

View File

@ -4,7 +4,7 @@ use futures::{
lock::Mutex,
Sink, SinkExt, StreamExt,
};
use std::{collections::HashMap, error::Error, fmt::Debug, sync::Arc};
use std::{collections::HashMap, fmt::Debug, sync::Arc};
use telegram_bot::{
self, types::requests::answer_callback_query::CanAnswerCallbackQuery, Api, ChatRef,
DeleteMessage, EditMessageReplyMarkup, InlineKeyboardButton, InlineKeyboardMarkup, Message,
@ -12,16 +12,16 @@ use telegram_bot::{
};
use uuid::Uuid;
use super::Curator;
use super::Selector;
#[derive(Clone)]
pub struct TelegramCurator {
pub struct TelegramSelector {
client: Arc<Api>,
chat_ref: Arc<Mutex<ChatRef>>,
pending: Arc<Mutex<HashMap<Uuid, Sender<bool>>>>,
}
impl TelegramCurator {
impl TelegramSelector {
pub fn new<S: Sink<ChatRef> + Send + Unpin + 'static>(
api: Arc<Api>,
chat_ref: Arc<Mutex<ChatRef>>,
@ -116,8 +116,8 @@ impl TelegramCurator {
}
}
impl Curator for TelegramCurator {
type Error = Box<dyn Error>;
impl Selector for TelegramSelector {
type Error = telegram_bot::Error;
type Response = BoxFuture<'static, Result<bool, Self::Error>>;