bot: receive events from webhook
This commit is contained in:
parent
e6926d5ba2
commit
d09070dae7
5 changed files with 95 additions and 15 deletions
|
|
@ -2,6 +2,7 @@ use std::{
|
|||
fs::File,
|
||||
io::{BufReader, BufWriter},
|
||||
path::PathBuf,
|
||||
sync::mpsc::Receiver,
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
|
|
@ -12,7 +13,7 @@ use matrix_sdk::{
|
|||
};
|
||||
use tracing::{debug, info};
|
||||
|
||||
use crate::config::ProloloConfig;
|
||||
use crate::{config::ProloloConfig, webhooks::Event};
|
||||
|
||||
mod handlers;
|
||||
use handlers::autojoin::autojoin_authorized_rooms;
|
||||
|
|
@ -61,11 +62,25 @@ impl Prololo {
|
|||
///
|
||||
/// [`Prololo::init`] **must** be called before this function, otherwise the [`Client`] isn't
|
||||
/// logged in.
|
||||
pub async fn run(&self) {
|
||||
pub async fn run(&self, events: Receiver<Event>) {
|
||||
debug!("running...");
|
||||
|
||||
let client = self.client.clone();
|
||||
let config = self.config.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
Self::handle_events(events, client, config);
|
||||
});
|
||||
|
||||
self.client.sync(SyncSettings::default()).await
|
||||
}
|
||||
|
||||
fn handle_events(events: Receiver<Event>, client: Client, config: ProloloConfig) {
|
||||
loop {
|
||||
let event = events.recv().unwrap();
|
||||
debug!("received event: {:?}", event);
|
||||
}
|
||||
}
|
||||
|
||||
/// This loads the session information from an existing file, and tries to login with it. If no such
|
||||
/// file is found, then login using username and password, and save the new session information on
|
||||
/// disk.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue