This commit is contained in:
1 parent
275ac9d609
commit
743d0b5d3d
10 files changed
+3028
-27
No files matched your search
Generated
+2962
-23
File diff suppressed because it is too large.
Load diff
@@ -6,8 +6,14 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.102"
|
anyhow = "1.0.102"
|
||||||
async-trait = "0.1.89"
|
async-trait = "0.1.89"
|
||||||
|
env_logger = "0.11.9"
|
||||||
reqwest = "0.13.2"
|
reqwest = "0.13.2"
|
||||||
serde = {version="1.0.228",features=["derive"]}
|
serde = {version="1.0.228",features=["derive"]}
|
||||||
sled = "0.34.7"
|
sled = "0.34.7"
|
||||||
tokio = {version="1.50.0",features=["full"]}
|
tokio = {version="1.50.0",features=["full"]}
|
||||||
toml = "1.0.7"
|
toml = "1.0.7"
|
||||||
|
|
||||||
|
[dependencies.matrix-sdk]
|
||||||
|
version="0.16.0"
|
||||||
|
default-features = false
|
||||||
|
features=["anyhow","markdown","e2e-encryption","automatic-room-key-forwarding","sqlite","rustls-tls"]
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use tokio::task::JoinHandle;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
@@ -9,7 +11,7 @@ pub trait Sender {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Receiver {
|
pub trait Receiver {
|
||||||
// Pull user inputs from upstream and return a cursor for incremental sync.
|
// Pull user inputs from upstream and return a cursor for incremental sync.
|
||||||
async fn poll_inputs(&self, cursor: Option<&str>, limit: usize) -> Result<InputBatch>;
|
async fn recv(&self, msg: InboundMessage) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -33,3 +35,15 @@ pub struct InputBatch {
|
|||||||
pub messages: Vec<InboundMessage>,
|
pub messages: Vec<InboundMessage>,
|
||||||
pub next_cursor: Option<String>,
|
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 {}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
|
pub mod bot_handler;
|
||||||
pub mod define;
|
pub mod define;
|
||||||
pub mod matrix;
|
pub mod matrix;
|
||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
use crate::config::get_config;
|
use crate::config::get_config;
|
||||||
use anyhow::{Ok, Result};
|
use anyhow::{Ok, Result};
|
||||||
pub async fn init() -> Result<()> {
|
pub async fn init() -> Result<()> {
|
||||||
let _ = get_config();//初始化日志系统
|
get_config(); //初始化配置
|
||||||
|
env_logger::init(); //初始化日志
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
+1
-1
@@ -2,4 +2,4 @@ pub mod api;
|
|||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
pub mod sender;
|
pub mod bot;
|
||||||
+1
-1
@@ -3,6 +3,6 @@ use anyhow::Ok;
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
daily_bot::init::init().await?;
|
daily_bot::init::init().await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Whitespace-only changes.
Reference in new issue
Block a user