Split web and xmpp parts into different tasks
Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
parent
fc0b13079f
commit
d16ead8bc9
2 changed files with 40 additions and 28 deletions
18
src/bot.rs
18
src/bot.rs
|
|
@ -20,6 +20,7 @@ use xmpp::jid::{BareJid, Jid};
|
|||
use xmpp::parsers::message::MessageType;
|
||||
use xmpp::tokio_xmpp::connect::StartTlsServerConnector;
|
||||
use xmpp::{Agent, ClientBuilder, ClientFeature, ClientType, Event};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
pub struct XmppClient {
|
||||
is_online: bool,
|
||||
|
|
@ -75,8 +76,22 @@ impl XmppClient {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn receive(&mut self, mut rx: mpsc::UnboundedReceiver<Hook>) {
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = self.next() => (),
|
||||
wh = rx.recv() => {
|
||||
if let Some(hook) = wh {
|
||||
debug!("XMPP Bot Received Hook");
|
||||
self.hook(hook).await
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn hook(&mut self, wh: Hook) {
|
||||
debug!("Received Hook");
|
||||
debug!("XMPP Bot Processing Hook");
|
||||
if let Some(display) = format_hook(&wh) {
|
||||
debug!("Hook: {}", display);
|
||||
for room in &self.rooms {
|
||||
|
|
@ -89,6 +104,7 @@ impl XmppClient {
|
|||
)
|
||||
.await
|
||||
}
|
||||
debug!("XMPP Bot Processed Hook");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue