This commit is contained in:
1 parent
275ac9d609
commit
743d0b5d3d
10 files changed
+3028
-27
No files matched your search
@@ -0,0 +1,37 @@
|
||||
use crate::bot::define::{AttendanceBot, MessageEnum};
|
||||
use anyhow::Ok;
|
||||
use anyhow::Result;
|
||||
use matrix_sdk::async_trait;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::task::JoinHandle;
|
||||
pub struct Bot {
|
||||
pub messages_receiver: mpsc::Receiver<MessageEnum>,
|
||||
pub message_sender: mpsc::Sender<MessageEnum>,
|
||||
}
|
||||
|
||||
impl Bot {
|
||||
fn new() -> Self {
|
||||
let (tx, rx) = mpsc::channel(100);
|
||||
Self {
|
||||
messages_receiver: rx,
|
||||
message_sender: tx,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl AttendanceBot for Bot {
|
||||
async fn handle_commands(&self) -> Result<JoinHandle<()>> {
|
||||
let bot = Bot::new();
|
||||
let (_tx, mut rx) = (bot.message_sender, bot.messages_receiver);
|
||||
let handle = tokio::spawn(async move {
|
||||
while let Some(msg) = rx.blocking_recv() {
|
||||
match msg {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(handle)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
|
||||
#[async_trait]
|
||||
pub trait Sender {
|
||||
async fn send(&self, message: OutboundMessage) -> Result<String>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait Receiver {
|
||||
// Pull user inputs from upstream and return a cursor for incremental sync.
|
||||
async fn recv(&self, msg: InboundMessage) -> Result<()>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OutboundMessage {
|
||||
pub channel_id: String,
|
||||
pub text: String,
|
||||
pub reply_to_event_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InboundMessage {
|
||||
pub event_id: String,
|
||||
pub channel_id: String,
|
||||
pub user_id: String,
|
||||
pub text: String,
|
||||
pub timestamp_ms: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct InputBatch {
|
||||
pub messages: Vec<InboundMessage>,
|
||||
pub next_cursor: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait AttendanceBot {
|
||||
async fn handle_commands(&self) -> Result<JoinHandle<()>>;
|
||||
}
|
||||
|
||||
pub enum MessageEnum {
|
||||
MatrixMessage(InboundMessage),
|
||||
TelegramMessage(InboundMessage),
|
||||
StopMessage,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
struct MatrixBot {}
|
||||
|
||||
impl MatrixBot {}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod bot_handler;
|
||||
pub mod define;
|
||||
pub mod matrix;
|
||||
Reference in new issue
Block a user