Implement replies

This commit is contained in:
Jonathan Flueren 2023-07-07 12:23:23 +02:00
parent 37305a5465
commit 1fd304ddd0
2 changed files with 50 additions and 36 deletions

47
Cargo.lock generated
View file

@ -335,9 +335,9 @@ checksum = "703642b98a00b3b90513279a8ede3fcfa479c126c5fb46e78f3051522f021403"
[[package]]
name = "blake3"
version = "1.4.0"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "729b71f35bd3fa1a4c86b85d32c8b9069ea7fe14f7a53cfabb65f62d4265b888"
checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5"
dependencies = [
"arrayref",
"arrayvec",
@ -507,9 +507,9 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3"
[[package]]
name = "constant_time_eq"
version = "0.2.6"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6"
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
[[package]]
name = "core-foundation"
@ -1382,7 +1382,7 @@ dependencies = [
[[package]]
name = "matrix-sdk"
version = "0.6.2"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#fe189fda06b889c4077ff47d58ee5289b0cf630c"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#0ef819bca7173fafb883c969512f980457b99a02"
dependencies = [
"anymap2",
"async-stream",
@ -1422,7 +1422,7 @@ dependencies = [
[[package]]
name = "matrix-sdk-base"
version = "0.6.1"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#fe189fda06b889c4077ff47d58ee5289b0cf630c"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#0ef819bca7173fafb883c969512f980457b99a02"
dependencies = [
"async-trait",
"bitflags 2.3.3",
@ -1444,7 +1444,7 @@ dependencies = [
[[package]]
name = "matrix-sdk-common"
version = "0.6.0"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#fe189fda06b889c4077ff47d58ee5289b0cf630c"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#0ef819bca7173fafb883c969512f980457b99a02"
dependencies = [
"futures-core",
"futures-util",
@ -1460,7 +1460,7 @@ dependencies = [
[[package]]
name = "matrix-sdk-crypto"
version = "0.6.0"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#fe189fda06b889c4077ff47d58ee5289b0cf630c"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#0ef819bca7173fafb883c969512f980457b99a02"
dependencies = [
"aes",
"async-std",
@ -1496,7 +1496,7 @@ dependencies = [
[[package]]
name = "matrix-sdk-indexeddb"
version = "0.2.0"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#fe189fda06b889c4077ff47d58ee5289b0cf630c"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#0ef819bca7173fafb883c969512f980457b99a02"
dependencies = [
"anyhow",
"async-trait",
@ -1521,10 +1521,11 @@ dependencies = [
[[package]]
name = "matrix-sdk-sqlite"
version = "0.1.0"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#fe189fda06b889c4077ff47d58ee5289b0cf630c"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#0ef819bca7173fafb883c969512f980457b99a02"
dependencies = [
"async-trait",
"deadpool-sqlite",
"itertools 0.11.0",
"matrix-sdk-base",
"matrix-sdk-crypto",
"matrix-sdk-store-encryption",
@ -1542,7 +1543,7 @@ dependencies = [
[[package]]
name = "matrix-sdk-store-encryption"
version = "0.2.0"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#fe189fda06b889c4077ff47d58ee5289b0cf630c"
source = "git+https://github.com/matrix-org/matrix-rust-sdk.git#0ef819bca7173fafb883c969512f980457b99a02"
dependencies = [
"blake3",
"chacha20poly1305",
@ -2241,9 +2242,9 @@ dependencies = [
[[package]]
name = "schmfy"
version = "0.1.0"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9250f38131044f00dc302af28c08a2e121b47c6cf2ad614859604128f002c428"
checksum = "4c61d72da9ef0aed4dbf5ed4d312d3b15733b1e862295af1a6660c4202a2b416"
[[package]]
name = "scopeguard"
@ -2276,9 +2277,9 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.166"
version = "1.0.167"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d01b7404f9d441d3ad40e6a636a7782c377d2abdbe4fa2440e2edcc2f4f10db8"
checksum = "7daf513456463b42aa1d94cff7e0c24d682b429f020b9afa4f5ba5c40a22b237"
dependencies = [
"serde_derive",
]
@ -2294,9 +2295,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.166"
version = "1.0.167"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dd83d6dde2b6b2d466e14d9d1acce8816dedee94f735eac6395808b3483c6d6"
checksum = "b69b106b68bc8054f0e974e70d19984040f8a5cf9215ca82626ea4853f82c4b9"
dependencies = [
"proc-macro2",
"quote",
@ -2484,18 +2485,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.41"
version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c16a64ba9387ef3fdae4f9c1a7f07a0997fce91985c0336f1ddc1822b3b37802"
checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.41"
version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d14928354b01c4d6a4f0e549069adef399a284e7995c7ccca94e8a07a5346c59"
checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f"
dependencies = [
"proc-macro2",
"quote",
@ -3025,9 +3026,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "winnow"
version = "0.4.7"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448"
checksum = "a9482fe6ceabdf32f3966bfdd350ba69256a97c30253dc616fe0005af24f164e"
dependencies = [
"memchr",
]

View file

@ -8,7 +8,7 @@ use matrix_sdk::{
room::Room,
ruma::events::{room::{
member::StrippedRoomMemberEvent,
message::{MessageType, OriginalSyncRoomMessageEvent, RoomMessageEventContent},
message::{MessageType, OriginalSyncRoomMessageEvent, RoomMessageEventContent, ForwardThread},
}, relation::Annotation, reaction::ReactionEventContent},
Client,
};
@ -139,7 +139,10 @@ async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) {
// First, we need to unpack the message: We only want messages from rooms we are
// still in and that are regular text messages - ignoring everything else.
let Room::Joined(room) = room else { return };
let MessageType::Text(text_content) = event.content.msgtype else { return };
let MessageType::Text(text_content) = event.clone().content.msgtype else { return };
// full event for e.g. replies
let full_event = event.clone().into_full_event(room.room_id().to_owned());
// here comes the actual "logic": when the bot see's a `!party` in the message,
// it responds
@ -243,19 +246,29 @@ async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) {
room.send(reaction, None).await.unwrap();
}
if {let mut rng = rand::thread_rng(); rng.gen_range(0..3)} == 0 {
let msg = text_content.body
.split_whitespace()
.map(|x| schmfy(String::from(x.to_lowercase())))
.collect::<Vec<String>>()
.join(" ");
let msg = text_content.body
.split_terminator("\n")
.map(|line| {
line
.split_whitespace()
.map(|x| {
if {let mut rng = rand::thread_rng(); rng.gen_range(0..200)} <= x.len()^2 {
schmfy(String::from(x.to_lowercase()))
} else {
x.to_lowercase()
}
})
.collect::<Vec<String>>()
.join(" ")
})
.collect::<Vec<String>>()
.join("\n");
let content = RoomMessageEventContent::text_plain(msg);
let content = RoomMessageEventContent::text_plain(msg)
.make_reply_to(&full_event, ForwardThread::Yes);
//let content = event.content.make_reply_to(event.content., matrix_sdk::ruma::events::room::message::ForwardThread::Yes)
room.send(content, None).await.unwrap();
}
room.send(content, None).await.unwrap();
}
}