ignore messages sent from self

This commit is contained in:
Edward Shen 2022-05-06 00:28:31 -07:00
parent 8729cd0e64
commit de71131f6f
Signed by: edward
GPG key ID: 19182661E818369F

View file

@ -150,7 +150,16 @@ async fn auto_join(
Ok(())
}
async fn on_room_message(event: SyncMessageEvent<MessageEventContent>, room: Room) -> Result<()> {
async fn on_room_message(
event: SyncMessageEvent<MessageEventContent>,
room: Room,
client: Client,
) -> Result<()> {
// Ignore messages sent from self.
if client.user_id().await.as_ref() == Some(&event.sender) {
return Ok(());
}
if let Room::Joined(room) = room {
parse_message(event, room).await?;
}
@ -229,7 +238,12 @@ async fn source(room: Joined) -> Result<()> {
}
async fn uwuify(room: Joined, message: &str) -> Result<()> {
let content = MessageEventContent::text_plain(uwuifier::uwuify_str_sse(message));
let message = if message.is_empty() {
"uwu".to_owned()
} else {
uwuifier::uwuify_str_sse(message)
};
let content = MessageEventContent::text_plain(message);
room.send(content, None).await?;
Ok(())
}