Compare commits

..

2 commits

Author SHA1 Message Date
Antoine Martin b0483d90da matrix_sdk: bump to latest commit 2021-04-10 04:15:21 +02:00
Antoine Martin 31a7bb029b cargo: bump dependencies 2021-04-10 03:42:29 +02:00
5 changed files with 239 additions and 256 deletions

459
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -23,4 +23,4 @@ void = "1"
[dependencies.matrix-sdk]
git = "https://github.com/matrix-org/matrix-rust-sdk"
rev = "b66c666997cbcf32071d24ffe2484a215de8d0e4"
rev = "b5de20349945afcde13a78f023b906f421bb9764"

View file

@ -20,7 +20,7 @@
src = ./.;
cargoSha256 = "sha256-nWEWOY1F0TsVW5DHm2p8eOABF97Wku7Grw0Vsd79syU=";
cargoSha256 = "sha256-dNf/FYhNRu85Q4ZinvFGcJmMRayVdTJ9j28fu9BIinY=";
meta = with pkgs.lib; {
description = "A Matrix bot, bringer of bad news";

View file

@ -4,7 +4,8 @@ use matrix_sdk::{
self, async_trait,
events::{room::member::MemberEventContent, StrippedStateEvent},
identifiers::RoomId,
Client, EventEmitter, RoomState,
room::Room,
Client, EventHandler,
};
use tokio::time::sleep;
@ -20,10 +21,10 @@ impl AutoJoinHandler {
}
#[async_trait]
impl EventEmitter for AutoJoinHandler {
impl EventHandler for AutoJoinHandler {
async fn on_stripped_state_member(
&self,
room: RoomState,
room: Room,
room_member: &StrippedStateEvent<MemberEventContent>,
_: Option<MemberEventContent>,
) {
@ -31,9 +32,12 @@ impl EventEmitter for AutoJoinHandler {
return;
}
if let RoomState::Invited(room) = room {
if let Room::Invited(room) = room {
let room_id = room.room_id();
let room_name = room.display_name().await;
let room_name = room
.display_name()
.await
.expect("couldn't get joined room name!");
println!(
"Received invitation for room `{}`: `{}`",
room_id, room_name
@ -44,16 +48,14 @@ impl EventEmitter for AutoJoinHandler {
"Bot isn't authorized to join room `{}`, declining invitation",
room_id
);
// leaving a room is equivalent to rejecting the invitation, as per
// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-leave
self.client.leave_room(room_id).await.unwrap();
room.reject_invitation().await.unwrap();
return;
}
println!("Autojoining room {}", room.room_id());
let mut delay = 2;
while let Err(err) = self.client.join_room_by_id(room.room_id()).await {
while let Err(err) = room.accept_invitation().await {
// retry autojoin due to synapse sending invites, before the
// invited user can join for more information see
// https://github.com/matrix-org/synapse/issues/4345

View file

@ -4,10 +4,7 @@ use std::{
};
use matrix_sdk::{
events::{
room::message::{MessageEventContent, TextMessageEventContent},
AnyMessageEventContent,
},
events::{room::message::MessageEventContent, AnyMessageEventContent},
Client, ClientConfig, Session, SyncSettings,
};
use systemd::{journal, JournalRecord};
@ -40,7 +37,7 @@ impl BadNewsBot {
load_or_init_session(&self).await?;
self.client
.add_event_emitter(Box::new(AutoJoinHandler::new(
.set_event_handler(Box::new(AutoJoinHandler::new(
self.client.clone(),
self.config.room_id.clone(),
)))
@ -121,9 +118,8 @@ impl BadNewsBot {
unit.strip_suffix(".service").unwrap_or(unit),
message,
);
let content = AnyMessageEventContent::RoomMessage(MessageEventContent::Text(
TextMessageEventContent::plain(message),
));
let content =
AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain(message));
let room_id = self.config.room_id.clone();
let client_clone = self.client.clone();