Ignore ancient messages

This commit is contained in:
Xiretza 2025-02-16 16:15:57 +00:00
parent 0d6fd4681d
commit cd4f9326f7

View file

@ -25,7 +25,7 @@ use matrix_sdk::{
},
},
},
OwnedRoomOrAliasId, RoomAliasId, RoomId, RoomOrAliasId,
OwnedRoomOrAliasId, RoomAliasId, RoomId, RoomOrAliasId, SecondsSinceUnixEpoch,
},
Client, RoomState,
};
@ -33,7 +33,7 @@ use never_say_never::Never;
use reqwest::Url;
use serde::Deserialize;
use time::{
convert::{Day, Hour, Minute},
convert::{Day, Hour, Minute, Second},
ext::NumericalDuration,
macros::format_description,
OffsetDateTime, UtcOffset,
@ -337,6 +337,17 @@ impl Bot {
room: &Room,
) -> Result<()> {
event!(Level::TRACE, ?ev, "handling message");
if SecondsSinceUnixEpoch::now().get() - ev.origin_server_ts.as_secs()
> Second::per(Day).into()
{
event!(
Level::INFO,
origin_server_ts = i64::from(ev.origin_server_ts.get()),
"message is too old, ignoring"
);
return Ok(());
}
if Some(&*ev.sender) == self.client.user_id() {
event!(Level::TRACE, "message from ourselves, ignoring");
return Ok(());