From 8e4eb574d2497322586ffa47a8330c631d4f6e62 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Mon, 15 Mar 2021 20:10:42 +0000 Subject: [PATCH] Update to latest matrix SDK and other dependencies. --- Cargo.lock | 367 ++++++++++++++++--------------------- src/bot.rs | 23 +-- src/bot/event_handlers.rs | 99 +++++----- src/commands/management.rs | 2 +- src/commands/variables.rs | 8 +- src/context.rs | 10 +- src/dice.rs | 2 +- src/matrix.rs | 24 ++- 8 files changed, 248 insertions(+), 287 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d1b197..6bb2286 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -95,9 +95,9 @@ checksum = "5f093eed78becd229346bf859eec0aa4dd7ddde0757287b2b4107a1f09c80002" [[package]] name = "async-trait" -version = "0.1.42" +version = "0.1.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d" +checksum = "36ea56748e10732c49404c153638a15ec3d6211ec5ff35d9bb20e13b93576adf" dependencies = [ "proc-macro2", "quote", @@ -139,7 +139,7 @@ dependencies = [ "futures-core", "getrandom 0.2.2", "instant", - "pin-project 1.0.5", + "pin-project", "rand 0.8.3", "tokio", ] @@ -194,15 +194,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.6.0" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099e596ef14349721d9016f6b80dd3419ea1bf289ab9b44df8e4dfd3a005d5d9" +checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" [[package]] name = "byteorder" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" @@ -212,15 +212,9 @@ checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cc" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" [[package]] name = "cfg-if" @@ -354,17 +348,16 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] name = "crossbeam-epoch" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d" +checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12" dependencies = [ - "cfg-if 1.0.0", - "const_fn", + "cfg-if", "crossbeam-utils", "lazy_static", "memoffset", @@ -373,12 +366,12 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" +checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" dependencies = [ "autocfg", - "cfg-if 1.0.0", + "cfg-if", "lazy_static", ] @@ -407,7 +400,7 @@ version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "num_cpus", ] @@ -458,14 +451,14 @@ version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] name = "env_logger" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26ecb66b4bdca6c1409b40fb255eefc2bd4f6d135dab3c3124f80ffa2a9661e" +checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" dependencies = [ "atty", "humantime", @@ -497,9 +490,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" dependencies = [ "matches", "percent-encoding", @@ -527,9 +520,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9052a1a50244d8d5aa9bf55cbc2fb6f357c86cc52e46c62ed390a7180cf150" +checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1" dependencies = [ "futures-channel", "futures-core", @@ -542,9 +535,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2d31b7ec7efab6eefc7c57233bb10b847986139d88cc2f5a02a1ae6871a1846" +checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" dependencies = [ "futures-core", "futures-sink", @@ -552,15 +545,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e5145dde8da7d1b3892dad07a9c98fc04bc39892b1ecc9692cf53e2b780a65" +checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" [[package]] name = "futures-executor" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e59fdc009a4b3096bf94f740a0f2424c082521f20a9b08c5c07c48d90fd9b9" +checksum = "891a4b7b96d84d5940084b2a37632dd65deeae662c114ceaa2c879629c9c0ad1" dependencies = [ "futures-core", "futures-task", @@ -569,9 +562,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28be053525281ad8259d47e4de5de657b25e7bac113458555bb4b70bc6870500" +checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" [[package]] name = "futures-locks" @@ -584,9 +577,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c287d25add322d9f9abdcdc5927ca398917996600182178774032e9f8258fedd" +checksum = "ea405816a5139fb39af82c2beb921d52143f556038378d6db21183a5c37fbfb7" dependencies = [ "proc-macro-hack", "proc-macro2", @@ -596,18 +589,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf5c69029bda2e743fddd0582d1083951d65cc9539aebf8812f36c3491342d6" +checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3" [[package]] name = "futures-task" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13de07eb8ea81ae445aca7b69f5f7bf15d7bf4912d8ca37d6645c77ae8a58d86" -dependencies = [ - "once_cell", -] +checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" [[package]] name = "futures-timer" @@ -621,9 +611,9 @@ dependencies = [ [[package]] name = "futures-util" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632a8cd0f2a4b3fdea1657f08bde063848c3bd00f9bbf6e256b8be78802e624b" +checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" dependencies = [ "futures-channel", "futures-core", @@ -664,7 +654,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] @@ -675,7 +665,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "libc", "wasi 0.10.2+wasi-snapshot-preview1", @@ -707,9 +697,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b67e66362108efccd8ac053abafc8b7a8d86a37e6e48fc4f6f7485eb5e9e6a5" +checksum = "d832b01df74254fe364568d6ddc294443f61cbec82816b60904303af87efae78" dependencies = [ "bytes", "fnv", @@ -722,7 +712,6 @@ dependencies = [ "tokio", "tokio-util", "tracing", - "tracing-futures", ] [[package]] @@ -830,7 +819,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project 1.0.5", + "pin-project", "socket2", "tokio", "tower-service", @@ -853,9 +842,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de910d521f7cc3135c4de8db1cb910e0b5ed1dc6f57c381cd07e8e661ce10094" +checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" dependencies = [ "matches", "unicode-bidi", @@ -864,9 +853,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.1" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", "hashbrown", @@ -887,7 +876,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "time 0.2.25", "wasm-bindgen", @@ -917,9 +906,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.47" +version = "0.3.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65" +checksum = "dc9f84f9b115ce7843d60706df1422a916680bfdfcbdb0447c5614ff9d7e4d78" dependencies = [ "wasm-bindgen", ] @@ -941,22 +930,22 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lexical-core" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616" +checksum = "21f866863575d0e1d654fbeeabdc927292fdf862873dc3c96c6f753357e13374" dependencies = [ "arrayvec", "bitflags", - "cfg-if 0.1.10", + "cfg-if", "ryu", "static_assertions", ] [[package]] name = "libc" -version = "0.2.86" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" [[package]] name = "lock_api" @@ -973,7 +962,7 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1026,7 +1015,7 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "matrix-sdk" version = "0.2.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#e437aea01213338d7f11787411a025b6133efcff" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#31dd031269ad7d91ca9f097e345a7125585efcf6" dependencies = [ "backoff", "dashmap", @@ -1049,7 +1038,7 @@ dependencies = [ [[package]] name = "matrix-sdk-base" version = "0.2.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#e437aea01213338d7f11787411a025b6133efcff" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#31dd031269ad7d91ca9f097e345a7125585efcf6" dependencies = [ "chacha20poly1305", "dashmap", @@ -1072,7 +1061,7 @@ dependencies = [ [[package]] name = "matrix-sdk-common" version = "0.2.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#e437aea01213338d7f11787411a025b6133efcff" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#31dd031269ad7d91ca9f097e345a7125585efcf6" dependencies = [ "async-trait", "futures-locks", @@ -1086,7 +1075,7 @@ dependencies = [ [[package]] name = "matrix-sdk-crypto" version = "0.2.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#e437aea01213338d7f11787411a025b6133efcff" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#31dd031269ad7d91ca9f097e345a7125585efcf6" dependencies = [ "aes-ctr", "aes-gcm", @@ -1137,9 +1126,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "mio" -version = "0.7.7" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" +checksum = "a5dede4e2065b3842b8b0af444119f3aa331cc7cc2dd20388bfb0f5d5a38823a" dependencies = [ "libc", "log", @@ -1227,18 +1216,18 @@ dependencies = [ [[package]] name = "olm-sys" -version = "1.0.2" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0823939cee8b6f39ed0e39d8abf98919099f999ebef3eae2c67d9cd2e93ea008" +checksum = "9d29b3debd2916908e725d936ef5722d014a338a57c74e59dbf4c8c43855254d" dependencies = [ "cmake", ] [[package]] name = "once_cell" -version = "1.5.2" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] name = "opaque-debug" @@ -1248,15 +1237,15 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.32" +version = "0.10.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70" +checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577" dependencies = [ "bitflags", - "cfg-if 1.0.0", + "cfg-if", "foreign-types", - "lazy_static", "libc", + "once_cell", "openssl-sys", ] @@ -1268,9 +1257,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-sys" -version = "0.9.60" +version = "0.9.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" +checksum = "313752393519e876837e09e1fa183ddef0be7735868dced3196f4472d536277f" dependencies = [ "autocfg", "cc", @@ -1292,23 +1281,23 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "instant", "libc", - "redox_syscall 0.1.57", + "redox_syscall 0.2.5", "smallvec", "winapi", ] [[package]] name = "paste" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5d65c4d95931acda4498f675e332fcbdc9a06705cd07086c510e9b6009cd1c1" +checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" [[package]] name = "pbkdf2" @@ -1379,33 +1368,13 @@ dependencies = [ "siphasher", ] -[[package]] -name = "pin-project" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" -dependencies = [ - "pin-project-internal 0.4.27", -] - [[package]] name = "pin-project" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" dependencies = [ - "pin-project-internal 1.0.5", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "pin-project-internal", ] [[package]] @@ -1421,9 +1390,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -1502,9 +1471,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2", ] @@ -1531,7 +1500,7 @@ checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" dependencies = [ "libc", "rand_chacha 0.3.0", - "rand_core 0.6.1", + "rand_core 0.6.2", "rand_hc 0.3.0", ] @@ -1552,7 +1521,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ "ppv-lite86", - "rand_core 0.6.1", + "rand_core 0.6.2", ] [[package]] @@ -1566,9 +1535,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c026d7df8b298d90ccbbc5190bd04d85e159eaf5576caeacf8741da93ccbd2e5" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ "getrandom 0.2.2", ] @@ -1588,7 +1557,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" dependencies = [ - "rand_core 0.6.1", + "rand_core 0.6.2", ] [[package]] @@ -1608,9 +1577,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_syscall" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" dependencies = [ "bitflags", ] @@ -1628,21 +1597,20 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.3" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" +checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] name = "regex-syntax" -version = "0.6.22" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" +checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "remove_dir_all" @@ -1655,9 +1623,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd281b1030aa675fb90aa994d07187645bb3c8fc756ca766e7c3070b439de9de" +checksum = "bf12057f289428dbf5c591c74bf10392e4a8003f993405a902f20117019022d4" dependencies = [ "base64", "bytes", @@ -1690,7 +1658,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.0.2" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "assign", "js_int", @@ -1706,7 +1674,7 @@ dependencies = [ [[package]] name = "ruma-api" version = "0.17.0-alpha.2" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "http", "percent-encoding", @@ -1721,7 +1689,7 @@ dependencies = [ [[package]] name = "ruma-api-macros" version = "0.17.0-alpha.2" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1732,7 +1700,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.10.0-alpha.2" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "assign", "http", @@ -1751,7 +1719,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.3.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "js_int", "maplit", @@ -1764,7 +1732,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.22.0-alpha.2" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "js_int", "ruma-common", @@ -1778,7 +1746,7 @@ dependencies = [ [[package]] name = "ruma-events-macros" version = "0.22.0-alpha.2" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1789,7 +1757,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.1.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "js_int", "ruma-api", @@ -1804,7 +1772,7 @@ dependencies = [ [[package]] name = "ruma-identifiers" version = "0.18.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "paste", "ruma-identifiers-macros", @@ -1817,7 +1785,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-macros" version = "0.18.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "proc-macro2", "quote", @@ -1828,12 +1796,12 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.2.0" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" [[package]] name = "ruma-serde" version = "0.3.0" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "form_urlencoded", "itoa", @@ -1846,7 +1814,7 @@ dependencies = [ [[package]] name = "ruma-serde-macros" version = "0.3.0" -source = "git+https://github.com/ruma/ruma?rev=d6aa37c848b7f682a98c25b346899e284ffc6df7#d6aa37c848b7f682a98c25b346899e284ffc6df7" +source = "git+https://github.com/ruma/ruma?rev=c27e66741a8cb0cf5dba45ae3a977f4d6bba715d#c27e66741a8cb0cf5dba45ae3a977f4d6bba715d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1899,9 +1867,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.0.0" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69" +checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d" dependencies = [ "bitflags", "core-foundation", @@ -1912,9 +1880,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b" +checksum = "dee48cdde5ed250b0d3252818f646e174ab414036edb884dde62d80a3ac6082d" dependencies = [ "core-foundation-sys", "libc", @@ -1943,18 +1911,18 @@ checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" [[package]] name = "serde" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" +checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" dependencies = [ "proc-macro2", "quote", @@ -1963,9 +1931,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.62" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "itoa", "ryu", @@ -1997,7 +1965,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de" dependencies = [ "block-buffer", - "cfg-if 1.0.0", + "cfg-if", "cpuid-bool 0.1.2", "digest", "opaque-debug", @@ -2052,7 +2020,7 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "winapi", ] @@ -2154,9 +2122,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.60" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f" dependencies = [ "proc-macro2", "quote", @@ -2181,10 +2149,10 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "rand 0.8.3", - "redox_syscall 0.2.4", + "redox_syscall 0.2.5", "remove_dir_all", "winapi", ] @@ -2211,33 +2179,24 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76cc616c6abf8c8928e2fdcc0dbfab37175edd8fb49a4641066ad1364fdab146" +checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be73a2caec27583d0046ef3796c3794f868a5bc813db689eed00c7631275cd1" +checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "thread_local" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" -dependencies = [ - "once_cell", -] - [[package]] name = "time" version = "0.1.43" @@ -2303,9 +2262,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" +checksum = "8d56477f6ed99e10225f38f9f75f872f29b8b8bd8c0b946f63345bb144e9eeda" dependencies = [ "autocfg", "bytes", @@ -2344,9 +2303,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebb7cb2f00c5ae8df755b252306272cd1790d39728363936e01827e11f0b017b" +checksum = "ec31e5cc6b46e653cf57762f36f71d5e6386391d88a72fd6db4508f8f676fb29" dependencies = [ "bytes", "futures-core", @@ -2373,11 +2332,11 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.23" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d40a22fd029e33300d8d89a5cc8ffce18bb7c587662f54629e94c9de5487f3" +checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -2385,9 +2344,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.12" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f080ea7e4107844ef4766459426fa2d5c1ada2e47edba05dc7fa99d9629f47" +checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" dependencies = [ "proc-macro2", "quote", @@ -2405,11 +2364,11 @@ dependencies = [ [[package]] name = "tracing-futures" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" dependencies = [ - "pin-project 0.4.27", + "pin-project", "tracing", ] @@ -2421,9 +2380,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "typenum" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" [[package]] name = "unicode-bidi" @@ -2473,9 +2432,9 @@ dependencies = [ [[package]] name = "url" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ "form_urlencoded", "idna", @@ -2535,11 +2494,11 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" +checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "serde", "serde_json", "wasm-bindgen-macro", @@ -2547,9 +2506,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" +checksum = "5b7d8b6942b8bb3a9b0e73fc79b98095a27de6fa247615e59d096754a3bc2aa8" dependencies = [ "bumpalo", "lazy_static", @@ -2562,11 +2521,11 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" +checksum = "8e67a5806118af01f0d9045915676b22aaebecf4178ae7021bc171dab0b897ab" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -2574,9 +2533,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c" +checksum = "e5ac38da8ef716661f0f36c0d8320b89028efe10c7c0afde65baffb496ce0d3b" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2584,9 +2543,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385" +checksum = "cc053ec74d454df287b9374ee8abb36ffd5acb95ba87da3ba5b7d3fe20eb401e" dependencies = [ "proc-macro2", "quote", @@ -2597,15 +2556,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64" +checksum = "7d6f8ec44822dd71f5f221a5847fb34acd9060535c1211b70a05844c0f6383b1" [[package]] name = "web-sys" -version = "0.3.47" +version = "0.3.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3" +checksum = "ec600b26223b2948cedfde2a0aa6756dcf1fef616f43d7b3097aaf53a6c4d92b" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/src/bot.rs b/src/bot.rs index d656052..1ab4800 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -8,11 +8,7 @@ use crate::state::DiceBotState; use dirs; use futures::stream::{self, StreamExt}; use log::info; -use matrix_sdk::{ - self, - identifiers::{EventId, RoomId}, - Client, ClientConfig, JoinedRoom, SyncSettings, -}; +use matrix_sdk::{self, identifiers::EventId, room::Joined, Client, ClientConfig, SyncSettings}; use std::clone::Clone; use std::path::PathBuf; use std::sync::{Arc, RwLock}; @@ -62,11 +58,11 @@ async fn handle_single_result( client: &Client, cmd_result: &ExecutionResult, respond_to: &str, - room_id: &RoomId, + room: &Joined, event_id: EventId, ) { let html = cmd_result.message_html(respond_to); - matrix::send_message(client, room_id, &html, Some(event_id)).await; + matrix::send_message(client, room.room_id(), &html, Some(event_id)).await; } /// Handle responding to multiple commands being executed. Will print @@ -75,7 +71,7 @@ async fn handle_multiple_results( client: &Client, results: &[(&str, ExecutionResult)], respond_to: &str, - room_id: &RoomId, + room: &Joined, ) { let errors: Vec<(&str, &ExecutionError)> = results .into_iter() @@ -103,7 +99,7 @@ async fn handle_multiple_results( .replace("\n", "
") }; - matrix::send_message(client, room_id, &message, None).await; + matrix::send_message(client, room.room_id(), &message, None).await; } impl DiceBot { @@ -165,7 +161,7 @@ impl DiceBot { info!("Performing intial sync (no commands will be responded to)"); self.client.sync_once(SyncSettings::default()).await?; - client.add_event_emitter(Box::new(self)).await; + client.set_event_handler(Box::new(self)).await; info!("Listening for commands"); let token = client @@ -183,13 +179,12 @@ impl DiceBot { async fn execute_commands( &self, - room: &JoinedRoom, + room: &Joined, sender_username: &str, msg_body: &str, event_id: EventId, ) { let room_name: &str = &room.display_name().await.ok().unwrap_or_default(); - let room_id = room.room_id().clone(); let commands: Vec<&str> = msg_body .lines() @@ -223,12 +218,12 @@ impl DiceBot { &self.client, &results[0].1, sender_username, - &room_id, + &room, event_id, ) .await; } else if results.len() > 1 { - handle_multiple_results(&self.client, &results, sender_username, &room_id).await; + handle_multiple_results(&self.client, &results, sender_username, &room).await; } info!("[{}] {} executed: {}", room_name, sender_username, msg_body); diff --git a/src/bot/event_handlers.rs b/src/bot/event_handlers.rs index f934afc..c18dcfe 100644 --- a/src/bot/event_handlers.rs +++ b/src/bot/event_handlers.rs @@ -8,11 +8,12 @@ use matrix_sdk::{ self, events::{ room::member::{MemberEventContent, MembershipChange}, - room::message::{MessageEventContent, TextMessageEventContent}, + room::message::{MessageEventContent, MessageType, TextMessageEventContent}, StrippedStateEvent, SyncMessageEvent, SyncStateEvent, }, identifiers::RoomId, - EventEmitter, RoomState, + room::{Common, Invited, Joined}, + EventHandler, Room, }; use std::clone::Clone; use std::ops::Sub; @@ -65,7 +66,11 @@ async fn should_process_message<'a>( } let (msg_body, sender_username) = if let SyncMessageEvent { - content: MessageEventContent::Text(TextMessageEventContent { body, .. }), + content: + MessageEventContent { + msgtype: MessageType::Text(TextMessageEventContent { body, .. }), + .. + }, sender, .. } = event @@ -93,30 +98,14 @@ fn should_process_event(db: &Database, room_id: &str, event_id: &str) -> bool { }) } -/// Convert room state object to the room ID and display name, if -/// possible. We only care about the room if it is a joined or left -/// room. -async fn convert_room_state(state: &RoomState) -> Option<(&RoomId, String)> { - match state { - RoomState::Joined(room) => Some(( - room.room_id(), - room.display_name().await.ok().unwrap_or_default(), - )), - RoomState::Left(room) => Some(( - room.room_id(), - room.display_name().await.ok().unwrap_or_default(), - )), - _ => None, - } -} - /// This event emitter listens for messages with dice rolling commands. /// Originally adapted from the matrix-rust-sdk examples. #[async_trait] -impl EventEmitter for DiceBot { - async fn on_room_member(&self, state: RoomState, event: &SyncStateEvent) { - let (room_id, room_display_name) = match convert_room_state(&state).await { - Some((room_id, room_display_name)) => (room_id, room_display_name), +impl EventHandler for DiceBot { + async fn on_room_member(&self, room: Room, event: &SyncStateEvent) { + let room = Common::new(self.client.clone(), room); + let (room_id, room_display_name) = match room.display_name().await { + Ok(display_name) => (room.room_id(), display_name), _ => return, }; @@ -173,46 +162,54 @@ impl EventEmitter for DiceBot { async fn on_stripped_state_member( &self, - state: RoomState, + room: Room, event: &StrippedStateEvent, _: Option, ) { - if let RoomState::Invited(room) = state { - if let Some(user_id) = self.client.user_id().await { - if event.state_key != user_id { - return; - } - } + let room = match Invited::new(self.client.clone(), room) { + Some(invited_room) => invited_room, + _ => return, + }; - info!("Autojoining room {}", room.display_name().await); + if room.own_user_id().as_str() != event.state_key { + return; + } - if let Err(e) = self.client.join_room_by_id(&room.room_id()).await { - warn!("Could not join room: {}", e.to_string()) - } + // if let Some(user_id) = self.client.user_id().await { + // if event.state_key != user_id { + // return; + // } + // } + + info!( + "Autojoining room {}", + room.display_name().await.ok().unwrap_or_default() + ); + + if let Err(e) = self.client.join_room_by_id(&room.room_id()).await { + warn!("Could not join room: {}", e.to_string()) } } - async fn on_room_message( - &self, - state: RoomState, - event: &SyncMessageEvent, - ) { - if let RoomState::Joined(room) = state { - let room_id = room.room_id().as_str(); - if !should_process_event(&self.db, room_id, event.event_id.as_str()) { - return; - } + async fn on_room_message(&self, room: Room, event: &SyncMessageEvent) { + let room = match Joined::new(self.client.clone(), room) { + Some(joined_room) => joined_room, + _ => return, + }; - let (msg_body, sender_username) = if let Ok((msg_body, sender_username)) = - should_process_message(self, &event).await - { + let room_id = room.room_id().as_str(); + if !should_process_event(&self.db, room_id, event.event_id.as_str()) { + return; + } + + let (msg_body, sender_username) = + if let Ok((msg_body, sender_username)) = should_process_message(self, &event).await { (msg_body, sender_username) } else { return; }; - self.execute_commands(&room, &sender_username, &msg_body, event.event_id.clone()) - .await; - } + self.execute_commands(&room, &sender_username, &msg_body, event.event_id.clone()) + .await; } } diff --git a/src/commands/management.rs b/src/commands/management.rs index 803c366..eb3b13a 100644 --- a/src/commands/management.rs +++ b/src/commands/management.rs @@ -19,7 +19,7 @@ impl Command for ResyncCommand { record_room_information( ctx.matrix_client, &ctx.db, - ctx.room.id, + ctx.room_id(), &ctx.room.display_name, our_username, ) diff --git a/src/commands/variables.rs b/src/commands/variables.rs index a00111b..326041d 100644 --- a/src/commands/variables.rs +++ b/src/commands/variables.rs @@ -13,7 +13,7 @@ impl Command for GetAllVariablesCommand { } async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { - let key = UserAndRoom(&ctx.username, &ctx.room.id.as_str()); + let key = UserAndRoom(&ctx.username, &ctx.room_id().as_str()); let variables = ctx.db.variables.get_user_variables(&key)?; let mut variable_list: Vec = variables @@ -43,7 +43,7 @@ impl Command for GetVariableCommand { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { let name = &self.0; - let key = UserAndRoom(&ctx.username, &ctx.room.id.as_str()); + let key = UserAndRoom(&ctx.username, &ctx.room_id().as_str()); let result = ctx.db.variables.get_user_variable(&key, name); let value = match result { @@ -68,7 +68,7 @@ impl Command for SetVariableCommand { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { let name = &self.0; let value = self.1; - let key = UserAndRoom(&ctx.username, ctx.room.id.as_str()); + let key = UserAndRoom(&ctx.username, ctx.room_id().as_str()); ctx.db.variables.set_user_variable(&key, name, value)?; @@ -88,7 +88,7 @@ impl Command for DeleteVariableCommand { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { let name = &self.0; - let key = UserAndRoom(&ctx.username, ctx.room.id.as_str()); + let key = UserAndRoom(&ctx.username, ctx.room_id().as_str()); let result = ctx.db.variables.delete_user_variable(&key, name); let value = match result { diff --git a/src/context.rs b/src/context.rs index 0e32264..e971b39 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,7 +1,7 @@ use crate::db::Database; use matrix_sdk::identifiers::RoomId; +use matrix_sdk::room::Joined; use matrix_sdk::Client; -use matrix_sdk::JoinedRoom; /// A context carried through the system providing access to things /// like the database. @@ -14,6 +14,12 @@ pub struct Context<'a> { pub message_body: &'a str, } +impl Context<'_> { + pub fn room_id(&self) -> &RoomId { + self.room.id + } +} + #[derive(Clone)] pub struct RoomContext<'a> { pub id: &'a RoomId, @@ -21,7 +27,7 @@ pub struct RoomContext<'a> { } impl RoomContext<'_> { - pub fn new_with_name<'a>(room: &'a JoinedRoom, display_name: &'a str) -> RoomContext<'a> { + pub fn new_with_name<'a>(room: &'a Joined, display_name: &'a str) -> RoomContext<'a> { RoomContext { id: room.room_id(), display_name, diff --git a/src/dice.rs b/src/dice.rs index ad1eae6..75ae13f 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -11,7 +11,7 @@ use futures::stream::{self, StreamExt, TryStreamExt}; /// it cannot find a variable defined, or if the database errors. pub async fn calculate_dice_amount(amounts: &[Amount], ctx: &Context<'_>) -> Result { let stream = stream::iter(amounts); - let key = UserAndRoom(&ctx.username, ctx.room.id.as_str()); + let key = UserAndRoom(&ctx.username, ctx.room_id().as_str()); let variables = &ctx.db.variables.get_user_variables(&key)?; use DiceRollingError::VariableNotFound; diff --git a/src/matrix.rs b/src/matrix.rs index af2be49..b60f034 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -1,16 +1,12 @@ use log::error; +use matrix_sdk::{events::room::message::NoticeMessageEventContent, RoomMember}; use matrix_sdk::{ events::room::message::{InReplyTo, Relation}, + events::room::message::{MessageEventContent, MessageType}, + events::AnyMessageEventContent, identifiers::EventId, Error as MatrixError, }; -use matrix_sdk::{ - events::{ - room::message::{MessageEventContent::Notice, NoticeMessageEventContent}, - AnyMessageEventContent::RoomMessage, - }, - RoomMember, -}; use matrix_sdk::{identifiers::RoomId, Client}; /// Extracts more detailed error messages out of a matrix SDK error. @@ -43,16 +39,24 @@ pub async fn send_message( message: &str, reply_to: Option, ) { + let room = match client.get_joined_room(room_id) { + Some(room) => room, + _ => return, + }; + let plain = html2text::from_read(message.as_bytes(), message.len()); - let mut content = NoticeMessageEventContent::html(plain.trim(), message); + let mut content = MessageEventContent::new(MessageType::Notice( + NoticeMessageEventContent::html(plain.trim(), message), + )); content.relates_to = reply_to.map(|event_id| Relation::Reply { in_reply_to: InReplyTo { event_id }, }); - let response = RoomMessage(Notice(content)); + let content = AnyMessageEventContent::RoomMessage(content); + + let result = room.send(content, None).await; - let result = client.room_send(&room_id, response, None).await; if let Err(e) = result { let message = extract_error_message(e); error!("Error sending message: {}", message);