This project embodies an attempt to create a Discord/IRC (and possibly more extensible) bridge. Not finished.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.1 KiB

use std::sync::Arc;
use serenity::prelude::Mutex;
use crate::itercomb::DummyIter;
pub enum Message
{
Message
{
originator: String,
body: String,
},
Command
{
originator: String,
body: String,
},
Status
{
body: String,
},
}
pub enum Error
{
IOError(std::io::Error),
}
impl From<std::io::Error> for Error
{
fn from(err: std::io::Error) -> Error { Error::IOError(err) }
}
pub type BridgeResult<T = ()> = Result<T, Error>;
pub struct Bridge(Arc<Mutex<BridgeInner<Arc<dyn ReceiveCallback>>>>);
struct BridgeInner<C>
{
endpoints: Vec<Box<dyn Endpoint<C>>>,
}
impl Bridge
{
fn iter<'a, 'b>(&'a self) -> impl 'b + Iterator<Item = &'b Box<dyn Endpoint<Arc<dyn ReceiveCallback>>>> where
'a: 'b,
{
let guard = self.0.lock();
guard.endpoints.iter()
}
}
pub trait ReceiveCallback: Fn(Message) {}
pub trait Endpoint<C>
where C: AsRef<dyn ReceiveCallback>
{
fn send(&self, msg: Message) -> BridgeResult;
fn add_bridge(&mut self, br: Bridge);
fn remove_bridge(&mut self, br: Bridge);
fn add_receive_callback(&mut self, cb: C);
fn remove_receive_callback(&mut self, cb: C);
}