crieur/crieur-chatbot/src/cli.rs
koalp a16dbbc790
Some checks failed
continuous-integration/drone/pr Build is running
continuous-integration/drone/push Build is failing
feat: add basic chatbot
A basic chabot application that downloads article from one newspaper
have been added.

It can download html pages and is called with !hmtl

ArticleLocation have been refactored to own it's internal data.
2021-04-27 04:32:37 +02:00

33 lines
794 B
Rust

use std::env;
use anyhow::{bail, Result};
use dotenv::dotenv;
use crate::Chatbot;
/// Runs the chatbot
pub async fn run() -> Result<()> {
dotenv().ok();
let (user, password, homeserver, room) = match (
env::var("CRIEUR_MATRIX_USER"),
env::var("CRIEUR_MATRIX_PASSWORD"),
env::var("CRIEUR_MATRIX_HOMESERVER"),
env::var("CRIEUR_MATRIX_ROOM"),
) {
(Ok(user), Ok(password), Ok(homeserver), Ok(room)) => (user, password, homeserver, room),
_ => bail!("Configuration incomplete, please set all required environment variables"),
};
let chatbot = Chatbot::builder()
.login(&user, &password)
.homeserver(&homeserver)
.room(&room)
.connect()
.await?;
chatbot.run().await?;
Ok(())
}