Browse Source

Change to work with latest version of matrix-rust-sdk, added autoconnect timeout

pull/2/head
Stephen 10 months ago
parent
commit
e01d76e81a
5 changed files with 176 additions and 271 deletions
  1. +105
    -185
      Cargo.lock
  2. +6
    -5
      Cargo.toml
  3. +0
    -45
      src/create_relation_event.rs
  4. +22
    -36
      src/main.rs
  5. +43
    -0
      src/relation.rs

+ 105
- 185
Cargo.lock View File

@ -79,9 +79,9 @@ dependencies = [
[[package]]
name = "atomic"
version = "0.4.5"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c210c1f4db048cda477b652d170572d84c9640695835f17663595d3bd543fc28"
checksum = "64f46ca51dca4837f1520754d1c8c36636356b81553d928dc9c177025369a06e"
[[package]]
name = "autocfg"
@ -115,24 +115,18 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "bytes"
version = "0.5.5"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "118cf036fbb97d0816e3c34b2d7a1e8cfc60f68fcf63d550ddbe9bd5f59c213b"
dependencies = [
"loom",
]
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
[[package]]
name = "cat_disruptor_7000"
version = "0.4.0"
version = "0.5.0"
dependencies = [
"async-trait",
"matrix-sdk",
"matrix-sdk-common-macros",
"ruma-api",
"ruma-client-api",
"ruma-events 0.16.0",
"ruma-identifiers 0.16.2",
"ruma",
"rusqlite",
"serde",
"serde_json",
@ -146,9 +140,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.57"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fde55d2a2bfaa4c9668bbc63f531fbdeee3ffe188f4662511ce2c22b3eedebe"
checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
[[package]]
name = "cfg-if"
@ -158,9 +152,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "chrono"
version = "0.4.12"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0fee792e164f78f5fe0c296cc2eb3688a2ca2b70cdff33040922d298203f0c4"
checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6"
dependencies = [
"num-integer",
"num-traits",
@ -303,6 +297,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "form_urlencoded"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00"
dependencies = [
"matches",
"percent-encoding",
]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -438,19 +442,6 @@ dependencies = [
]
[[package]]
name = "generator"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "add72f17bb81521258fcc8a7a3245b1e184e916bfbe34f0ea89558f440df5c68"
dependencies = [
"cc",
"libc",
"log",
"rustc_version",
"winapi 0.3.9",
]
[[package]]
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -477,9 +468,9 @@ dependencies = [
[[package]]
name = "h2"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79b7246d7e4b979c03fa093da39cfb3617a96bbeee6310af63991668d7e843ff"
checksum = "993f9e0baeed60001cf565546b0d3dbe6a6ad23f2bd31644a133c641eccf6d53"
dependencies = [
"bytes",
"fnv",
@ -488,10 +479,10 @@ dependencies = [
"futures-util",
"http",
"indexmap",
"log",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]]
@ -505,9 +496,9 @@ dependencies = [
[[package]]
name = "hermit-abi"
version = "0.1.14"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909"
checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
dependencies = [
"libc",
]
@ -547,9 +538,9 @@ checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
[[package]]
name = "hyper"
version = "0.13.6"
version = "0.13.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6e7655b9594024ad0ee439f3b5a7299369dc2a3f459b47c696f9ff676f9aa1f"
checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb"
dependencies = [
"bytes",
"futures-channel",
@ -560,20 +551,20 @@ dependencies = [
"http-body",
"httparse",
"itoa",
"log",
"pin-project",
"socket2",
"time",
"tokio",
"tower-service",
"tracing",
"want",
]
[[package]]
name = "hyper-tls"
version = "0.4.1"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa"
checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed"
dependencies = [
"bytes",
"hyper",
@ -604,9 +595,9 @@ dependencies = [
[[package]]
name = "instant"
version = "0.1.5"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69da7ce1490173c2bf4d26bc8be429aaeeaf4cce6c4b970b7949651fa17655fe"
checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485"
dependencies = [
"js-sys",
"time",
@ -631,9 +622,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "js-sys"
version = "0.3.41"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4b9172132a62451e56142bff9afc91c8e4a4500aa5b847da36815b63bfda916"
checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2"
dependencies = [
"wasm-bindgen",
]
@ -665,9 +656,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.71"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
[[package]]
name = "libsqlite3-sys"
@ -688,25 +679,14 @@ checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a"
[[package]]
name = "log"
version = "0.4.8"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if",
]
[[package]]
name = "loom"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ecc775857611e1df29abba5c41355cdf540e7e9d4acfdf0f355eefee82330b7"
dependencies = [
"cfg-if",
"generator",
"scoped-tls",
]
[[package]]
name = "lru-cache"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -739,7 +719,7 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
[[package]]
name = "matrix-sdk"
version = "0.1.0"
source = "git+https://github.com/matrix-org/matrix-rust-sdk#bd56c52b3763c70ff7cb3f6333b20339cb34fb97"
source = "git+https://github.com/matrix-org/matrix-rust-sdk#d273786d83fae612a12da334a0b1e7774d911b2a"
dependencies = [
"futures-timer",
"http",
@ -757,7 +737,7 @@ dependencies = [
[[package]]
name = "matrix-sdk-base"
version = "0.1.0"
source = "git+https://github.com/matrix-org/matrix-rust-sdk#bd56c52b3763c70ff7cb3f6333b20339cb34fb97"
source = "git+https://github.com/matrix-org/matrix-rust-sdk#d273786d83fae612a12da334a0b1e7774d911b2a"
dependencies = [
"async-trait",
"matrix-sdk-common",
@ -767,21 +747,19 @@ dependencies = [
"serde_json",
"thiserror",
"tokio",
"tracing",
"zeroize",
]
[[package]]
name = "matrix-sdk-common"
version = "0.1.0"
source = "git+https://github.com/matrix-org/matrix-rust-sdk#bd56c52b3763c70ff7cb3f6333b20339cb34fb97"
source = "git+https://github.com/matrix-org/matrix-rust-sdk#d273786d83fae612a12da334a0b1e7774d911b2a"
dependencies = [
"futures-locks",
"instant",
"js_int",
"ruma-api",
"ruma-client-api",
"ruma-events 0.21.3",
"ruma-identifiers 0.16.2",
"ruma",
"tokio",
"uuid",
]
@ -789,7 +767,7 @@ dependencies = [
[[package]]
name = "matrix-sdk-common-macros"
version = "0.1.0"
source = "git+https://github.com/matrix-org/matrix-rust-sdk#bd56c52b3763c70ff7cb3f6333b20339cb34fb97"
source = "git+https://github.com/matrix-org/matrix-rust-sdk#d273786d83fae612a12da334a0b1e7774d911b2a"
dependencies = [
"quote",
"syn",
@ -798,7 +776,7 @@ dependencies = [
[[package]]
name = "matrix-sdk-crypto"
version = "0.1.0"
source = "git+https://github.com/matrix-org/matrix-rust-sdk#bd56c52b3763c70ff7cb3f6333b20339cb34fb97"
source = "git+https://github.com/matrix-org/matrix-rust-sdk#d273786d83fae612a12da334a0b1e7774d911b2a"
dependencies = [
"async-trait",
"atomic",
@ -1065,9 +1043,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.17"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
[[package]]
name = "ppv-lite86"
@ -1195,9 +1173,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.1.56"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "regex"
@ -1271,15 +1249,26 @@ dependencies = [
]
[[package]]
name = "ruma"
version = "0.1.0"
source = "git+https://github.com/ruma/ruma?rev=c19bcaab#c19bcaab313b64666fb02260dfb9e55a7d70584b"
dependencies = [
"ruma-api",
"ruma-client-api",
"ruma-common",
"ruma-events",
"ruma-identifiers",
]
[[package]]
name = "ruma-api"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82ffdb7fb9cf6af2b1d0d8254d922560ecb70081d7e70931c9b996b6b4839db5"
source = "git+https://github.com/ruma/ruma?rev=c19bcaab#c19bcaab313b64666fb02260dfb9e55a7d70584b"
dependencies = [
"http",
"percent-encoding",
"ruma-api-macros",
"ruma-identifiers 0.16.2",
"ruma-identifiers",
"ruma-serde",
"serde",
"serde_json",
@ -1289,8 +1278,7 @@ dependencies = [
[[package]]
name = "ruma-api-macros"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52b82b4567b9af9b40a86f7778821c016ea961f55e4fee255f8f24bb28ee7452"
source = "git+https://github.com/ruma/ruma?rev=c19bcaab#c19bcaab313b64666fb02260dfb9e55a7d70584b"
dependencies = [
"proc-macro2",
"quote",
@ -1300,15 +1288,14 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "082913ad135ca55ee06a55d295bea954982f2ac5e0150adc09024f5cbb8cb6cf"
source = "git+https://github.com/ruma/ruma?rev=c19bcaab#c19bcaab313b64666fb02260dfb9e55a7d70584b"
dependencies = [
"http",
"js_int",
"ruma-api",
"ruma-common",
"ruma-events 0.21.3",
"ruma-identifiers 0.16.2",
"ruma-events",
"ruma-identifiers",
"ruma-serde",
"serde",
"serde_json",
@ -1318,9 +1305,9 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cb49e83277e82c69cc258cedc7e68b3d72ba378f1cb6105cbfcc8831e422b4d"
source = "git+https://github.com/ruma/ruma?rev=c19bcaab#c19bcaab313b64666fb02260dfb9e55a7d70584b"
dependencies = [
"js_int",
"matches",
"ruma-serde",
"serde",
@ -1330,48 +1317,23 @@ dependencies = [
[[package]]
name = "ruma-events"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc37337abd986c92908aa07fe61202dc83350f5c63927eba34b28589a1b14f84"
dependencies = [
"js_int",
"ruma-events-macros 0.2.0",
"ruma-identifiers 0.14.1",
"serde",
"serde_json",
]
[[package]]
name = "ruma-events"
version = "0.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ddf82c2231e4c53443424df34e868e4b09c20de7a76780d47a133a3b3f8ad9c"
source = "git+https://github.com/ruma/ruma?rev=c19bcaab#c19bcaab313b64666fb02260dfb9e55a7d70584b"
dependencies = [
"js_int",
"ruma-common",
"ruma-events-macros 0.21.3",
"ruma-identifiers 0.16.2",
"ruma-events-macros",
"ruma-identifiers",
"ruma-serde",
"serde",
"serde_json",
]
[[package]]
name = "ruma-events-macros"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "962d93056619ed61826a9d8872c863560e4892ff6a69b70f593baa5ae8b19dc8"
dependencies = [
"proc-macro2",
"quote",
"syn",
"strum",
]
[[package]]
name = "ruma-events-macros"
version = "0.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88e5c5b242fe4ee0cc56879057353621196d0988dd359579cad8f43471e483b7"
source = "git+https://github.com/ruma/ruma?rev=c19bcaab#c19bcaab313b64666fb02260dfb9e55a7d70584b"
dependencies = [
"proc-macro2",
"quote",
@ -1380,36 +1342,23 @@ dependencies = [
[[package]]
name = "ruma-identifiers"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07e442c700a3b33fc4dd4a1c4b463ebdd252d2c2db31b83da6bb3009307039b9"
dependencies = [
"rand 0.7.3",
"serde",
"url",
]
[[package]]
name = "ruma-identifiers"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6316cb248e3e0323a5a269b8eaed571404fb4f65c81848549e9ba99fd9b8e9de"
source = "git+https://github.com/ruma/ruma?rev=c19bcaab#c19bcaab313b64666fb02260dfb9e55a7d70584b"
dependencies = [
"serde",
"strum",
]
[[package]]
name = "ruma-serde"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c71dabb8e2709ca4f59201cb72d7fe8d590e7e3f55feb348e851c18354938af"
source = "git+https://github.com/ruma/ruma?rev=c19bcaab#c19bcaab313b64666fb02260dfb9e55a7d70584b"
dependencies = [
"dtoa",
"form_urlencoded",
"itoa",
"js_int",
"serde",
"serde_json",
"url",
]
[[package]]
@ -1428,15 +1377,6 @@ dependencies = [
]
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1453,12 +1393,6 @@ dependencies = [
]
[[package]]
name = "scoped-tls"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28"
[[package]]
name = "security-framework"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1482,21 +1416,6 @@ dependencies = [
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "send_wrapper"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1572,9 +1491,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "smallvec"
version = "1.4.0"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
[[package]]
name = "socket2"
@ -1685,9 +1604,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.33"
version = "1.0.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd"
checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b"
dependencies = [
"proc-macro2",
"quote",
@ -1832,20 +1751,21 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860"
[[package]]
name = "tracing"
version = "0.1.15"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a41f40ed0e162c911ac6fcb53ecdc8134c46905fdbbae8c50add462a538b495f"
checksum = "c2e2a2de6b0d5cbb13fc21193a2296888eaab62b6044479aafb3c54c01c29fcd"
dependencies = [
"cfg-if",
"log",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.8"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99bbad0de3fd923c9c3232ead88510b783e5a4d16a6154adffa3d53308de984c"
checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b"
dependencies = [
"proc-macro2",
"quote",
@ -1854,9 +1774,9 @@ dependencies = [
[[package]]
name = "tracing-core"
version = "0.1.10"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0aa83a9a47081cd522c09c81b31aec2c9273424976f922ad61c053b58350b715"
checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f"
dependencies = [
"lazy_static",
]
@ -1914,9 +1834,9 @@ dependencies = [
[[package]]
name = "try-lock"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "unicase"
@ -2007,9 +1927,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasm-bindgen"
version = "0.2.64"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a634620115e4a229108b71bde263bb4220c483b3f07f5ba514ee8d15064c4c2"
checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d"
dependencies = [
"cfg-if",
"serde",
@ -2019,9 +1939,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.64"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e53963b583d18a5aa3aaae4b4c1cb535218246131ba22a71f05b518098571df"
checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d"
dependencies = [
"bumpalo",
"lazy_static",
@ -2034,9 +1954,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.14"
version = "0.4.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dba48d66049d2a6cc8488702e7259ab7afc9043ad0dc5448444f46f2a453b362"
checksum = "41ad6e4e8b2b7f8c90b6e09a9b590ea15cb0d1dbe28502b5a405cd95d1981671"
dependencies = [
"cfg-if",
"js-sys",
@ -2046,9 +1966,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.64"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fcfd5ef6eec85623b4c6e844293d4516470d8f19cd72d0d12246017eb9060b8"
checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -2056,9 +1976,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.64"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9adff9ee0e94b926ca81b57f57f86d5545cdcb1d259e21ec9bdd95b901754c75"
checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6"
dependencies = [
"proc-macro2",
"quote",
@ -2069,15 +1989,15 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.64"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f7b90ea6c632dd06fd765d44542e234d5e63d9bb917ecd64d79778a13bd79ae"
checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87"
[[package]]
name = "web-sys"
version = "0.3.41"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "863539788676619aac1a23e2df3655e96b32b0e05eb72ca34ba045ad573c625d"
checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2"
dependencies = [
"js-sys",
"wasm-bindgen",


+ 6
- 5
Cargo.toml View File

@ -1,6 +1,6 @@
[package]
name = "cat_disruptor_7000"
version = "0.4.0"
version = "0.5.0"
authors = ["Stephen D <@stephen:m.scd31.com>"]
edition = "2018"
@ -10,10 +10,6 @@ matrix-sdk-common-macros = { git = "https://github.com/matrix-org/matrix-rust-sd
tokio = { version = "0.2", features = ["full"] }
url = "2.1"
async-trait = "0.1.36"
ruma-identifiers = "0.16"
ruma-api = "0.16"
ruma-events = "0.16"
ruma-client-api = "0.9.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tracing = "0.1"
@ -22,6 +18,11 @@ uuid = { version = "0.8.1", features = ["v4"] }
statsd = "^0.13.1"
rusqlite = "0.22"
[dependencies.ruma]
git = "https://github.com/ruma/ruma"
features = ["client-api"]
rev = "c19bcaab"
[package.metadata.deb]
maintainer = "Stephen D <@stephen:m.scd31.com>"
copyright = "2020, Stephen D <@stephen:m.scd31.com>"


+ 0
- 45
src/create_relation_event.rs View File

@ -1,45 +0,0 @@
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use ruma_identifiers::EventId;
use ruma_api::ruma_api;
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct ContentStruct {
pub rel_type: String,
pub event_id: EventId,
pub key: String
}
ruma_api! {
metadata {
description: "Send a relation event to a room",
method: PUT,
name: "create_relation_event",
path: "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id",
rate_limited: false,
requires_authentication: true
}
request {
/// The room to send the relation to.
#[ruma_api(path)]
pub room_id: crate::RoomId,
/// The type of event to send.
#[ruma_api(path)]
pub event_type: String,
/// The transaction ID for this event
#[ruma_api(path)]
pub txn_id: String,
#[serde(flatten)]
pub content: HashMap<String, ContentStruct>
}
response {
pub event_id: String
}
error: ruma_client_api::Error
}

+ 22
- 36
src/main.rs View File

@ -1,31 +1,29 @@
use std::collections::HashMap;
use std::path::Path;
use std::fs;
use std::{
path::Path,
fs,
time::Duration
};
use url::Url;
use ruma_identifiers::user_id::UserId;
use ruma_identifiers::RoomId;
use matrix_sdk::{
self,
events::{
self,
events::{
room::{
message::{MessageEvent, MessageEventContent, TextMessageEventContent},
message::{MessageEventContent, TextMessageEventContent},
member::MemberEventContent
},
stripped::{
StrippedRoomMember,
},
StrippedStateEventStub,
MessageEventStub
},
Client, ClientConfig, EventEmitter, SyncRoom, SyncSettings, RoomState
Client, ClientConfig, EventEmitter, SyncRoom, SyncSettings, RoomState,
identifiers::UserId
};
use async_trait::async_trait;
use uuid::Uuid;
use db::DataStore;
mod create_relation_event;
mod relation;
mod config;
mod db;
@ -44,9 +42,9 @@ impl EventCallback {
#[async_trait]
impl EventEmitter for EventCallback {
//Handles room messages
async fn on_room_message(&self, room: SyncRoom, event: &MessageEvent) {
async fn on_room_message(&self, room: SyncRoom, event: &MessageEventStub<MessageEventContent>) {
if let SyncRoom::Joined(room) = room {
if let MessageEvent {
if let MessageEventStub {
content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }),
event_id,
..
@ -54,23 +52,10 @@ impl EventEmitter for EventCallback {
if msg_body.to_lowercase().contains("cat") {
// Cat in message. React with emoji
let mut content_hm: HashMap<String, create_relation_event::ContentStruct>
= HashMap::new();
content_hm.insert("m.relates_to".to_string(),
create_relation_event::ContentStruct {
rel_type: "m.annotation".to_string(),
event_id: event_id.clone(),
key: "🐈".to_string() // cat emoji
});
let request = create_relation_event::Request {
event_type: "m.reaction".to_string(),
room_id: room.read().await.room_id.clone(),
txn_id: Uuid::new_v4().to_string(),
content: content_hm
};
match self.client.send(request).await {
match relation::react(&self.client,
event_id.clone(),
room.read().await.room_id.clone(),
"🐈".to_string()).await { // Cat emoji
Ok(_) => self.statsd_client.incr("reacted.cats"),
Err(x) => {
println!("Error while reacting: {}", x);
@ -85,7 +70,7 @@ impl EventEmitter for EventCallback {
//Handles incoming invitations
async fn on_stripped_state_member(&self,
sync_room: SyncRoom,
room_member: &StrippedRoomMember,
room_member: &StrippedStateEventStub<MemberEventContent>,
_: Option<MemberEventContent>) {
if room_member.state_key == self.user_id {
match sync_room {
@ -157,7 +142,8 @@ async fn main() -> Result<(), matrix_sdk::Error> {
}
let matrix_config = ClientConfig::new()
.store_path(store_path.clone());
.store_path(store_path.clone())
.timeout(Duration::from_secs(60)); // Auto-reconnect if we lose connection
// We need to store the device ID so that restarting the bot doesn't create new sessions.
// In the future we will probably store other things in the database.


+ 43
- 0
src/relation.rs View File

@ -0,0 +1,43 @@
use std::collections::HashMap;
use matrix_sdk::{
identifiers::{ EventId, RoomId },
events::EventType,
Client
};
use serde::{Serialize, Deserialize};
use ruma::api::client::r0::message::create_message_event;
use uuid::Uuid;
#[derive(Clone, Serialize, Deserialize, Debug)]
struct ContentStruct {
pub rel_type: String,
pub event_id: EventId,
pub key: String
}
pub async fn react(client: &Client,
event_id: EventId,
room_id: RoomId,
emoji: String) -> Result<(), String> {
let mut content_hm: HashMap<String, ContentStruct>
= HashMap::new();
content_hm.insert("m.relates_to".to_string(),
ContentStruct {
rel_type: "m.annotation".to_string(),
event_id: event_id,
key: emoji
});
let request = create_message_event::Request {
event_type: EventType::Custom("m.reaction".into()),
room_id: room_id,
txn_id: Uuid::new_v4().to_string(),
data: serde_json::value::to_raw_value(&content_hm).unwrap()
};
match client.send(request).await {
Ok(_) => Ok(()),
Err(x) => Err(format!("{}", x))
}
}

Loading…
Cancel
Save