Compare commits

..

No commits in common. "8afd74995b1daf543912ade779609add926cbb2a" and "a64096fa87d646788c9838bedd8cfaa7c42f0d38" have entirely different histories.

6 changed files with 22 additions and 33 deletions

View File

@ -1,6 +1,6 @@
--- ---
name: "🗣 Discussion" name: "🗣 Design discussion"
about: "For discussion about the software, when you want to discuss about several conception possibilities" about: "For discussion about the design of features in the application, when there are several possibilities for implementation"
title: "" title: ""
labels: labels:
- "type::discussion" - "type::discussion"
@ -8,8 +8,12 @@ labels:
--- ---
*describe the problem * *describe shortly the problem*
## Requirements
*list requirements that the feature have*
## Propositions ## Propositions
*(optionnal) explain the different implementation that you would propose* *explain the different implementation that you would propose for the feature*

View File

@ -20,7 +20,7 @@ pub(crate) struct Builder {
password: String, password: String,
homeserver: String, homeserver: String,
//TODO: rooms //TODO: rooms
rooms: Vec<String>, room: String,
} }
impl Builder { impl Builder {
@ -34,9 +34,9 @@ impl Builder {
.login(self.user.as_str(), self.password.as_str(), None, None) .login(self.user.as_str(), self.password.as_str(), None, None)
.await?; .await?;
assert!(client.logged_in().await); assert!(client.logged_in().await);
for room in &self.rooms { client
client.join_room_by_id(&room.as_str().try_into()?).await?; .join_room_by_id(&self.room.as_str().try_into()?)
} .await?;
Ok(Chatbot { client }) Ok(Chatbot { client })
} }
@ -56,15 +56,8 @@ impl Builder {
self self
} }
pub(crate) fn room(&mut self, room: impl AsRef<str>) -> &mut Self { pub(crate) fn room(&mut self, room: &impl AsRef<str>) -> &mut Self {
self.rooms.push(room.as_ref().into()); self.room = room.as_ref().into();
self
}
pub(crate) fn rooms(&mut self, rooms: Vec<String>) -> &mut Self {
for room in rooms {
self.room(room);
}
self self
} }
} }

View File

@ -9,28 +9,20 @@ use crate::Chatbot;
pub async fn run() -> Result<()> { pub async fn run() -> Result<()> {
dotenv().ok(); dotenv().ok();
let (user, password, homeserver, rooms) = match ( let (user, password, homeserver, room) = match (
env::var("CRIEUR_MATRIX_USER"), env::var("CRIEUR_MATRIX_USER"),
env::var("CRIEUR_MATRIX_PASSWORD"), env::var("CRIEUR_MATRIX_PASSWORD"),
env::var("CRIEUR_MATRIX_HOMESERVER"), env::var("CRIEUR_MATRIX_HOMESERVER"),
env::var("CRIEUR_MATRIX_ROOMS"), env::var("CRIEUR_MATRIX_ROOM"),
) { ) {
(Ok(user), Ok(password), Ok(homeserver), Ok(rooms)) => ( (Ok(user), Ok(password), Ok(homeserver), Ok(room)) => (user, password, homeserver, room),
user,
password,
homeserver,
rooms
.split(",")
.map(|s| s.to_string())
.collect::<Vec<String>>(),
),
_ => bail!("Configuration incomplete, please set all required environment variables"), _ => bail!("Configuration incomplete, please set all required environment variables"),
}; };
let chatbot = Chatbot::builder() let chatbot = Chatbot::builder()
.login(&user, &password) .login(&user, &password)
.homeserver(&homeserver) .homeserver(&homeserver)
.rooms(rooms) .room(&room)
.connect() .connect()
.await?; .await?;

View File

@ -87,7 +87,7 @@ where
}; };
room.send_attachment( room.send_attachment(
"article.html", "test.html",
&mime::TEXT_HTML_UTF_8, &mime::TEXT_HTML_UTF_8,
&mut article_html.as_bytes(), &mut article_html.as_bytes(),
None, None,

View File

@ -8,7 +8,7 @@ title: Build and run the chatbot
CRIEUR_MATRIX_USER=user CRIEUR_MATRIX_USER=user
CRIEUR_MATRIX_PASSWORD=password CRIEUR_MATRIX_PASSWORD=password
CRIEUR_MATRIX_HOMESERVER=https://homeserv.er CRIEUR_MATRIX_HOMESERVER=https://homeserv.er
CRIEUR_MATRIX_ROOMS=roomid1,roomid2, CRIEUR_MATRIX_ROOM=roomid
``` ```
You can put it in a `.env` file. You can put it in a `.env` file.

View File

@ -13,5 +13,5 @@ CRIEUR_MATRIX_PASSWORD
CRIEUR_MATRIX_HOMESERVER CRIEUR_MATRIX_HOMESERVER
: homeserver of the matrix bot account : homeserver of the matrix bot account
CRIEUR_MATRIX_ROOMS CRIEUR_MATRIX_ROOM
: rooms in which to listen to events : the room in which to listen to events