From 9268314421b34dc23db80c7a090b232470926778 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Sat, 17 Oct 2020 13:30:07 +0000 Subject: [PATCH] Remove actix, move state to RwLock. Update dependencies. --- Cargo.lock | 649 ++++++-------------------------------- Cargo.toml | 12 +- src/actors.rs | 25 -- src/bin/dicebot.rs | 13 +- src/bot.rs | 31 +- src/error.rs | 6 - src/lib.rs | 2 +- src/{actors => }/state.rs | 33 +- 8 files changed, 131 insertions(+), 640 deletions(-) delete mode 100644 src/actors.rs rename src/{actors => }/state.rs (60%) diff --git a/Cargo.lock b/Cargo.lock index 6a28ef4..8632fd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,96 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "actix" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1be241f88f3b1e7e9a3fbe3b5a8a0f6915b5a1d7ee0d9a248d3376d01068cc60" -dependencies = [ - "actix-rt", - "actix_derive", - "bitflags", - "bytes", - "crossbeam-channel", - "derive_more", - "futures-channel", - "futures-util", - "log", - "once_cell", - "parking_lot", - "pin-project", - "smallvec", - "tokio", - "tokio-util", - "trust-dns-proto", - "trust-dns-resolver", -] - -[[package]] -name = "actix-macros" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a60f9ba7c4e6df97f3aacb14bb5c0cd7d98a49dcbaed0d7f292912ad9a6a3ed2" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "actix-rt" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143fcc2912e0d1de2bcf4e2f720d2a60c28652ab4179685a1ee159e0fb3db227" -dependencies = [ - "actix-macros", - "actix-threadpool", - "copyless", - "futures-channel", - "futures-util", - "smallvec", - "tokio", -] - -[[package]] -name = "actix-threadpool" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d209f04d002854b9afd3743032a27b066158817965bf5d036824d19ac2cc0e30" -dependencies = [ - "derive_more", - "futures-channel", - "lazy_static", - "log", - "num_cpus", - "parking_lot", - "threadpool", -] - -[[package]] -name = "actix_derive" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b95aceadaf327f18f0df5962fedc1bde2f870566a0b9f65c89508a3b1f79334c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "addr2line" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" - [[package]] name = "ahash" version = "0.3.8" @@ -102,9 +11,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +checksum = "b476ce7103678b0c6d3d395dbbae31d48ff910bd28be979ba5d48c6351131d0d" dependencies = [ "memchr", ] @@ -203,20 +112,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "backtrace" -version = "0.3.53" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707b586e0e2f247cbde68cdd2c3ce69ea7b7be43e1c5b426e37c9319c4b9838e" -dependencies = [ - "addr2line", - "cfg-if 1.0.0", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "base64" version = "0.12.3" @@ -270,31 +165,20 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "chronicle-dicebot" version = "0.7.0" dependencies = [ - "actix", - "actix-rt", "async-trait", "byteorder", "combine", "dirs", "env_logger", - "futures 0.3.6", + "futures", "indoc", "itertools", "log", "matrix-sdk", - "matrix-sdk-base 0.1.0 (git+https://github.com/matrix-org/matrix-rust-sdk?rev=0.1.0)", - "matrix-sdk-common 0.1.0 (git+https://github.com/matrix-org/matrix-rust-sdk?rev=0.1.0)", - "matrix-sdk-common-macros", "nom", "rand", "serde", @@ -374,12 +258,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" -[[package]] -name = "copyless" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" - [[package]] name = "core-foundation" version = "0.7.0" @@ -402,17 +280,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" dependencies = [ - "cfg-if 0.1.10", -] - -[[package]] -name = "crossbeam-channel" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" -dependencies = [ - "crossbeam-utils", - "maybe-uninit", + "cfg-if", ] [[package]] @@ -422,7 +290,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" dependencies = [ "autocfg", - "cfg-if 0.1.10", + "cfg-if", "crossbeam-utils", "lazy_static", "maybe-uninit", @@ -436,7 +304,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "crossbeam-utils", "maybe-uninit", ] @@ -448,7 +316,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" dependencies = [ "autocfg", - "cfg-if 0.1.10", + "cfg-if", "lazy_static", ] @@ -459,21 +327,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f260e2fc850179ef410018660006951c1b55b79e8087e87111a2c388994b9b5" dependencies = [ "ahash", - "cfg-if 0.1.10", + "cfg-if", "num_cpus", ] -[[package]] -name = "derive_more" -version = "0.99.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "dirs" version = "3.0.1" @@ -518,19 +375,7 @@ version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a51b8cf747471cb9499b6d59e59b0444f4c90eba8968c4e44874e92b5b64ace2" dependencies = [ - "cfg-if 0.1.10", -] - -[[package]] -name = "enum-as-inner" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c5f0096a91d210159eceb2ff5e1c4da18388a170e1e3ce948aac9c8fdbbf595" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", + "cfg-if", ] [[package]] @@ -603,12 +448,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "futures" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7e4c2612746b0df8fed4ce0c69156021b704c9aefa360311c04e6e9e002eed" - [[package]] name = "futures" version = "0.3.6" @@ -657,21 +496,12 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fc94b64bb39543b4e432f1790b6bf18e3ee3b74653c5449f63310e9a74b123c" -[[package]] -name = "futures-locks" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4297dd1d9d6268237e4f93aeb9c90fc1bf0d8cec7e1cef22798939e4c43a251" -dependencies = [ - "futures 0.1.30", -] - [[package]] name = "futures-locks" version = "0.6.1-pre" source = "git+https://github.com/asomers/futures-locks#908226deac658e020436e54d66680ff736e5a2b4" dependencies = [ - "futures 0.3.6", + "futures", ] [[package]] @@ -746,7 +576,7 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "libc", "wasi 0.9.0+wasi-snapshot-preview1", "wasm-bindgen", @@ -758,17 +588,11 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee8025cf36f917e6a52cce185b7c7177689b838b7ec138364e50cc2277a56cf4" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] -[[package]] -name = "gimli" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" - [[package]] name = "gloo-timers" version = "0.2.1" @@ -831,17 +655,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" -[[package]] -name = "hostname" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" -dependencies = [ - "libc", - "match_cfg", - "winapi 0.3.9", -] - [[package]] name = "http" version = "0.2.1" @@ -944,9 +757,9 @@ dependencies = [ [[package]] name = "indoc" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644defcefee68d7805653a682e99a2e2a5014a1fc3cc9be7059a215844eeea6f" +checksum = "e5a75aeaaef0ce18b58056d306c27b07436fbb34b8816c53094b76dd81803136" dependencies = [ "unindent", ] @@ -957,7 +770,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "js-sys", "time", "wasm-bindgen", @@ -973,18 +786,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ipconfig" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" -dependencies = [ - "socket2", - "widestring", - "winapi 0.3.9", - "winreg 0.6.2", -] - [[package]] name = "ipnet" version = "2.3.0" @@ -1048,7 +849,7 @@ checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616" dependencies = [ "arrayvec", "bitflags", - "cfg-if 0.1.10", + "cfg-if", "ryu", "static_assertions", ] @@ -1070,12 +871,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linked-hash-map" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" - [[package]] name = "lock_api" version = "0.4.1" @@ -1091,16 +886,7 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ - "cfg-if 0.1.10", -] - -[[package]] -name = "lru-cache" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" -dependencies = [ - "linked-hash-map", + "cfg-if", ] [[package]] @@ -1109,12 +895,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" -[[package]] -name = "match_cfg" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" - [[package]] name = "matches" version = "0.1.8" @@ -1130,8 +910,8 @@ dependencies = [ "dashmap", "futures-timer", "http", - "matrix-sdk-base 0.1.0 (git+https://github.com/matrix-org/matrix-rust-sdk?rev=master)", - "matrix-sdk-common 0.1.0 (git+https://github.com/matrix-org/matrix-rust-sdk?rev=master)", + "matrix-sdk-base", + "matrix-sdk-common", "matrix-sdk-common-macros", "reqwest", "serde_json", @@ -1141,27 +921,13 @@ dependencies = [ "url", ] -[[package]] -name = "matrix-sdk-base" -version = "0.1.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=0.1.0#fd3dc50ebe90d21520c5ff475dc6af8192d3ede3" -dependencies = [ - "async-trait", - "matrix-sdk-common 0.1.0 (git+https://github.com/matrix-org/matrix-rust-sdk?rev=0.1.0)", - "serde", - "serde_json", - "thiserror", - "tokio", - "zeroize", -] - [[package]] name = "matrix-sdk-base" version = "0.1.0" source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=master#6872cc717b8b7746ea4c4bec8d143e8653f965ed" dependencies = [ "async-trait", - "matrix-sdk-common 0.1.0 (git+https://github.com/matrix-org/matrix-rust-sdk?rev=master)", + "matrix-sdk-common", "matrix-sdk-common-macros", "matrix-sdk-crypto", "serde", @@ -1172,29 +938,13 @@ dependencies = [ "zeroize", ] -[[package]] -name = "matrix-sdk-common" -version = "0.1.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=0.1.0#fd3dc50ebe90d21520c5ff475dc6af8192d3ede3" -dependencies = [ - "futures-locks 0.5.0", - "instant", - "js_int", - "ruma-api 0.16.1", - "ruma-client-api 0.9.0", - "ruma-events 0.21.3", - "ruma-identifiers 0.16.2", - "tokio", - "uuid", -] - [[package]] name = "matrix-sdk-common" version = "0.1.0" source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=master#6872cc717b8b7746ea4c4bec8d143e8653f965ed" dependencies = [ "assign", - "futures-locks 0.6.1-pre", + "futures-locks", "instant", "js_int", "ruma", @@ -1220,7 +970,7 @@ dependencies = [ "atomic", "cjson", "dashmap", - "matrix-sdk-common 0.1.0 (git+https://github.com/matrix-org/matrix-rust-sdk?rev=master)", + "matrix-sdk-common", "matrix-sdk-common-macros", "olm-rs", "serde", @@ -1270,35 +1020,37 @@ dependencies = [ "unicase", ] -[[package]] -name = "miniz_oxide" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" -dependencies = [ - "adler", - "autocfg", -] - [[package]] name = "mio" version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "fuchsia-zircon", "fuchsia-zircon-sys", "iovec", "kernel32-sys", "libc", "log", - "miow", + "miow 0.2.1", "net2", "slab", "winapi 0.2.8", ] +[[package]] +name = "mio-named-pipes" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" +dependencies = [ + "log", + "mio", + "miow 0.3.5", + "winapi 0.3.9", +] + [[package]] name = "mio-uds" version = "0.6.8" @@ -1322,6 +1074,16 @@ dependencies = [ "ws2_32-sys", ] +[[package]] +name = "miow" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e" +dependencies = [ + "socket2", + "winapi 0.3.9", +] + [[package]] name = "native-tls" version = "0.2.4" @@ -1346,7 +1108,7 @@ version = "0.2.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "libc", "winapi 0.3.9", ] @@ -1372,12 +1134,6 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37fd5004feb2ce328a52b0b3d01dbf4ffff72583493900ed15f22d4111c51693" - [[package]] name = "olm-rs" version = "1.0.0" @@ -1412,7 +1168,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" dependencies = [ "bitflags", - "cfg-if 0.1.10", + "cfg-if", "foreign-types", "lazy_static", "libc", @@ -1455,7 +1211,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "cloudabi", "instant", "libc", @@ -1504,9 +1260,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "ppv-lite86" @@ -1619,9 +1375,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.3.9" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b" dependencies = [ "aho-corasick", "memchr", @@ -1631,9 +1387,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" +checksum = "8cab7a364d15cde1e505267766a2d3c4e22a843e1a601f0fa7564c0f82ced11c" [[package]] name = "remove_dir_all" @@ -1676,17 +1432,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg 0.7.0", -] - -[[package]] -name = "resolv-conf" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11834e137f3b14e309437a8276714eed3a80d1ef894869e510f2c0c0b98b9f4a" -dependencies = [ - "hostname", - "quick-error", + "winreg", ] [[package]] @@ -1694,28 +1440,12 @@ name = "ruma" version = "0.0.1" source = "git+https://github.com/ruma/ruma?rev=409fbcc9d745fb7290327cb7f5defc714229ab30#409fbcc9d745fb7290327cb7f5defc714229ab30" dependencies = [ - "ruma-api 0.17.0-alpha.1", - "ruma-client-api 0.10.0-alpha.1", - "ruma-common 0.2.0", - "ruma-events 0.22.0-alpha.1", - "ruma-identifiers 0.17.4", - "ruma-serde 0.2.3 (git+https://github.com/ruma/ruma?rev=409fbcc9d745fb7290327cb7f5defc714229ab30)", -] - -[[package]] -name = "ruma-api" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82ffdb7fb9cf6af2b1d0d8254d922560ecb70081d7e70931c9b996b6b4839db5" -dependencies = [ - "http", - "percent-encoding", - "ruma-api-macros 0.16.1", - "ruma-identifiers 0.16.2", - "ruma-serde 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde", - "serde_json", - "strum 0.18.0", + "ruma-api", + "ruma-client-api", + "ruma-common", + "ruma-events", + "ruma-identifiers", + "ruma-serde", ] [[package]] @@ -1725,23 +1455,12 @@ source = "git+https://github.com/ruma/ruma?rev=409fbcc9d745fb7290327cb7f5defc714 dependencies = [ "http", "percent-encoding", - "ruma-api-macros 0.17.0-alpha.1", - "ruma-identifiers 0.17.4", - "ruma-serde 0.2.3 (git+https://github.com/ruma/ruma?rev=409fbcc9d745fb7290327cb7f5defc714229ab30)", + "ruma-api-macros", + "ruma-identifiers", + "ruma-serde", "serde", "serde_json", - "strum 0.19.5", -] - -[[package]] -name = "ruma-api-macros" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52b82b4567b9af9b40a86f7778821c016ea961f55e4fee255f8f24bb28ee7452" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "strum", ] [[package]] @@ -1755,24 +1474,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ruma-client-api" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "082913ad135ca55ee06a55d295bea954982f2ac5e0150adc09024f5cbb8cb6cf" -dependencies = [ - "http", - "js_int", - "ruma-api 0.16.1", - "ruma-common 0.1.3", - "ruma-events 0.21.3", - "ruma-identifiers 0.16.2", - "ruma-serde 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde", - "serde_json", - "strum 0.18.0", -] - [[package]] name = "ruma-client-api" version = "0.10.0-alpha.1" @@ -1782,27 +1483,14 @@ dependencies = [ "http", "js_int", "percent-encoding", - "ruma-api 0.17.0-alpha.1", - "ruma-common 0.2.0", - "ruma-events 0.22.0-alpha.1", - "ruma-identifiers 0.17.4", - "ruma-serde 0.2.3 (git+https://github.com/ruma/ruma?rev=409fbcc9d745fb7290327cb7f5defc714229ab30)", + "ruma-api", + "ruma-common", + "ruma-events", + "ruma-identifiers", + "ruma-serde", "serde", "serde_json", - "strum 0.19.5", -] - -[[package]] -name = "ruma-common" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb49e83277e82c69cc258cedc7e68b3d72ba378f1cb6105cbfcc8831e422b4d" -dependencies = [ - "matches", - "ruma-serde 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde", - "serde_json", - "strum 0.18.0", + "strum", ] [[package]] @@ -1811,27 +1499,12 @@ version = "0.2.0" source = "git+https://github.com/ruma/ruma?rev=409fbcc9d745fb7290327cb7f5defc714229ab30#409fbcc9d745fb7290327cb7f5defc714229ab30" dependencies = [ "js_int", - "ruma-api 0.17.0-alpha.1", - "ruma-identifiers 0.17.4", - "ruma-serde 0.2.3 (git+https://github.com/ruma/ruma?rev=409fbcc9d745fb7290327cb7f5defc714229ab30)", - "serde", - "serde_json", - "strum 0.19.5", -] - -[[package]] -name = "ruma-events" -version = "0.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ddf82c2231e4c53443424df34e868e4b09c20de7a76780d47a133a3b3f8ad9c" -dependencies = [ - "js_int", - "ruma-common 0.1.3", - "ruma-events-macros 0.21.3", - "ruma-identifiers 0.16.2", - "ruma-serde 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "ruma-api", + "ruma-identifiers", + "ruma-serde", "serde", "serde_json", + "strum", ] [[package]] @@ -1840,24 +1513,13 @@ version = "0.22.0-alpha.1" source = "git+https://github.com/ruma/ruma?rev=409fbcc9d745fb7290327cb7f5defc714229ab30#409fbcc9d745fb7290327cb7f5defc714229ab30" dependencies = [ "js_int", - "ruma-common 0.2.0", - "ruma-events-macros 0.22.0-alpha.1", - "ruma-identifiers 0.17.4", - "ruma-serde 0.2.3 (git+https://github.com/ruma/ruma?rev=409fbcc9d745fb7290327cb7f5defc714229ab30)", + "ruma-common", + "ruma-events-macros", + "ruma-identifiers", + "ruma-serde", "serde", "serde_json", - "strum 0.19.5", -] - -[[package]] -name = "ruma-events-macros" -version = "0.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88e5c5b242fe4ee0cc56879057353621196d0988dd359579cad8f43471e483b7" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "strum", ] [[package]] @@ -1871,15 +1533,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ruma-identifiers" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6316cb248e3e0323a5a269b8eaed571404fb4f65c81848549e9ba99fd9b8e9de" -dependencies = [ - "serde", -] - [[package]] name = "ruma-identifiers" version = "0.17.4" @@ -1888,7 +1541,7 @@ dependencies = [ "ruma-identifiers-macros", "ruma-identifiers-validation", "serde", - "strum 0.19.5", + "strum", ] [[package]] @@ -1908,7 +1561,7 @@ version = "0.1.1" source = "git+https://github.com/ruma/ruma?rev=409fbcc9d745fb7290327cb7f5defc714229ab30#409fbcc9d745fb7290327cb7f5defc714229ab30" dependencies = [ "serde", - "strum 0.19.5", + "strum", ] [[package]] @@ -1923,19 +1576,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "ruma-serde" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a50045b7e93329085488c88aee95e109c32d53c89d0f4882791e2cc81eb10ce" -dependencies = [ - "form_urlencoded", - "itoa", - "js_int", - "serde", - "serde_json", -] - [[package]] name = "rust-argon2" version = "0.8.2" @@ -1948,12 +1588,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "rustc-demangle" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2610b7f643d18c87dff3b489950269617e6601a51f1f05aa5daefee36f64f0b" - [[package]] name = "ryu" version = "1.0.5" @@ -2007,18 +1641,18 @@ checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" [[package]] name = "serde" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5" +checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8" +checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e" dependencies = [ "proc-macro2", "quote", @@ -2027,9 +1661,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a230ea9107ca2220eea9d46de97eddcb04cd00e92d13dda78e478dd33fa82bd4" +checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95" dependencies = [ "itoa", "ryu", @@ -2092,7 +1726,7 @@ version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "libc", "redox_syscall", "winapi 0.3.9", @@ -2152,7 +1786,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de2ae78b783af5922d811b14665a5a3755e531c3087bb805cf24cf71f15e6780" dependencies = [ "dotenv", - "futures 0.3.6", + "futures", "heck", "lazy_static", "proc-macro2", @@ -2169,34 +1803,13 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strum" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bd81eb48f4c437cadc685403cad539345bf703d78e63707418431cecd4522b" -dependencies = [ - "strum_macros 0.18.0", -] - [[package]] name = "strum" version = "0.19.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b89a286a7e3b5720b9a477b23253bc50debac207c8d21505f8e70b36792f11b5" dependencies = [ - "strum_macros 0.19.4", -] - -[[package]] -name = "strum_macros" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", + "strum_macros", ] [[package]] @@ -2240,7 +1853,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "libc", "rand", "redox_syscall", @@ -2286,15 +1899,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "threadpool" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" -dependencies = [ - "num_cpus", -] - [[package]] name = "time" version = "0.1.44" @@ -2326,6 +1930,7 @@ dependencies = [ "libc", "memchr", "mio", + "mio-named-pipes", "mio-uds", "num_cpus", "pin-project-lite", @@ -2364,7 +1969,6 @@ checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" dependencies = [ "bytes", "futures-core", - "futures-io", "futures-sink", "log", "pin-project-lite", @@ -2392,7 +1996,7 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "log", "pin-project-lite", "tracing-attributes", @@ -2429,46 +2033,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "trust-dns-proto" -version = "0.19.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdd7061ba6f4d4d9721afedffbfd403f20f39a4301fee1b70d6fcd09cca69f28" -dependencies = [ - "async-trait", - "backtrace", - "enum-as-inner", - "futures 0.3.6", - "idna", - "lazy_static", - "log", - "rand", - "smallvec", - "thiserror", - "tokio", - "url", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.19.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f23cdfdc3d8300b3c50c9e84302d3bd6d860fb9529af84ace6cf9665f181b77" -dependencies = [ - "backtrace", - "cfg-if 0.1.10", - "futures 0.3.6", - "ipconfig", - "lazy_static", - "log", - "lru-cache", - "resolv-conf", - "smallvec", - "thiserror", - "tokio", - "trust-dns-proto", -] - [[package]] name = "try-lock" version = "0.2.3" @@ -2516,9 +2080,9 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "unindent" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af41d708427f8fd0e915dcebb2cae0f0e6acb2a939b2d399c265c39a38a18942" +checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7" [[package]] name = "url" @@ -2580,7 +2144,7 @@ version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "serde", "serde_json", "wasm-bindgen-macro", @@ -2607,7 +2171,7 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -2652,12 +2216,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "widestring" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" - [[package]] name = "winapi" version = "0.2.8" @@ -2701,15 +2259,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "winreg" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "winreg" version = "0.7.0" diff --git a/Cargo.toml b/Cargo.toml index 13465a6..926c3bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,22 +22,12 @@ async-trait = "0.1" url = "2.1" dirs = "3.0" indoc = "1.0" -actix = "0.10" -actix-rt = "1.1" combine = "4.3" sled = "0.34" zerocopy = "0.3" byteorder = "1.3" futures = "0.3" - - -# The versioning of the matrix SDK follows its Cargo.toml. The SDK and -# macros are on master, but it imports the common and base from 0.1.0. -# https://github.com/matrix-org/matrix-rust-sdk/blob/master/matrix_sdk/Cargo.toml matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "master" } -matrix-sdk-common-macros = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "master" } -matrix-sdk-common = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "0.1.0" } -matrix-sdk-base = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "0.1.0", default_features = false } [dependencies.serde] version = "1" @@ -45,7 +35,7 @@ features = ['derive'] [dependencies.tokio] version = "0.2" -features = ["rt-core", "rt-util", "macros", "time", "signal"] +features = [ "full" ] [dev-dependencies] tempfile = "3.1" diff --git a/src/actors.rs b/src/actors.rs deleted file mode 100644 index a32895c..0000000 --- a/src/actors.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::config::Config; -use crate::db::Database; -use actix::prelude::*; -use state::DiceBotState; -use std::sync::Arc; - -pub mod state; - -pub struct Actors { - global_state: Addr, -} - -impl Actors { - pub fn new(config: &Arc, _db: &Database) -> Actors { - let global_state = DiceBotState::new(&config); - - Actors { - global_state: global_state.start(), - } - } - - pub fn global_state(&self) -> Addr { - self.global_state.clone() - } -} diff --git a/src/bin/dicebot.rs b/src/bin/dicebot.rs index 22fa0ee..ad2e9e3 100644 --- a/src/bin/dicebot.rs +++ b/src/bin/dicebot.rs @@ -1,16 +1,16 @@ //Needed for nested Result handling from tokio. Probably can go away after 1.47.0. #![type_length_limit = "7605144"] -use actix::prelude::*; -use chronicle_dicebot::actors::Actors; use chronicle_dicebot::bot::DiceBot; use chronicle_dicebot::config::*; use chronicle_dicebot::db::Database; use chronicle_dicebot::error::BotError; +use chronicle_dicebot::state::DiceBotState; use env_logger::Env; use log::error; -use std::sync::Arc; +use std::sync::{Arc, RwLock}; +use tokio::prelude::*; -#[actix_rt::main] +#[tokio::main] async fn main() { env_logger::from_env(Env::default().default_filter_or("chronicle_dicebot=info,dicebot=info")) .init(); @@ -28,13 +28,12 @@ async fn run() -> Result<(), BotError> { let cfg = Arc::new(read_config(config_path)?); let db = Database::new(&sled::open(cfg.database_path())?); - let actors = Actors::new(&cfg, &db); + let state = Arc::new(RwLock::new(DiceBotState::new(&cfg))); - match DiceBot::new(&cfg, actors, &db) { + match DiceBot::new(&cfg, &state, &db) { Ok(bot) => bot.run().await?, Err(e) => println!("Error connecting: {:?}", e), }; - System::current().stop(); Ok(()) } diff --git a/src/bot.rs b/src/bot.rs index 7cc38a7..20aad35 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -1,10 +1,10 @@ -use crate::actors::state::LogSkippedOldMessages; -use crate::actors::Actors; use crate::commands::execute_command; use crate::config::*; use crate::context::Context; use crate::db::Database; use crate::error::BotError; +use crate::state::DiceBotState; +use async_trait::async_trait; use dirs; use log::{debug, error, info, trace, warn}; use matrix_sdk::{ @@ -16,11 +16,11 @@ use matrix_sdk::{ }, Client, ClientConfig, EventEmitter, JsonStore, SyncRoom, SyncSettings, }; -use matrix_sdk_common_macros::async_trait; +//use matrix_sdk_common_macros::async_trait; use std::clone::Clone; use std::ops::Sub; use std::path::PathBuf; -use std::sync::Arc; +use std::sync::{Arc, RwLock}; use std::time::{Duration, SystemTime}; use url::Url; @@ -33,8 +33,8 @@ pub struct DiceBot { /// The matrix client. client: Client, - /// Actors used by the dice bot to manage internal state. - actors: Actors, + /// State of the dicebot + state: Arc>, /// Active database layer db: Database, @@ -61,11 +61,15 @@ impl DiceBot { /// actor. This function returns a Result because it is possible /// for client creation to fail for some reason (e.g. invalid /// homeserver URL). - pub fn new(config: &Arc, actors: Actors, db: &Database) -> Result { + pub fn new( + config: &Arc, + state: &Arc>, + db: &Database, + ) -> Result { Ok(DiceBot { client: create_client(&config)?, config: config.clone(), - actors: actors, + state: state.clone(), db: db.clone(), }) } @@ -146,11 +150,12 @@ async fn should_process<'a>( ) -> Result<(String, String), BotError> { //Ignore messages that are older than configured duration. if !check_message_age(event, bot.config.oldest_message_age()) { - let res = bot.actors.global_state().send(LogSkippedOldMessages).await; - - if let Err(e) = res { - error!("Actix error: {:?}", e); - }; + let state_check = bot.state.read().unwrap(); + if !((*state_check).logged_skipped_old_messages()) { + drop(state_check); + let mut state = bot.state.write().unwrap(); + (*state).skipped_old_messages(); + } return Err(BotError::ShouldNotProcessError); } diff --git a/src/error.rs b/src/error.rs index c0dd269..7d415cd 100644 --- a/src/error.rs +++ b/src/error.rs @@ -37,9 +37,6 @@ pub enum BotError { #[error("future canceled")] FutureCanceledError, - #[error("tokio task join error")] - TokioTaskJoinError(#[from] tokio::task::JoinError), - //de = deserialization #[error("toml parsing error")] TomlParsingError(#[from] toml::de::Error), @@ -47,9 +44,6 @@ pub enum BotError { #[error("i/o error: {0}")] IoError(#[from] std::io::Error), - #[error("actor mailbox error: {0}")] - ActixMailboxError(#[from] actix::MailboxError), - #[error("parsing error")] ParserError(#[from] combine::error::StringStreamError), diff --git a/src/lib.rs b/src/lib.rs index a213379..8828a20 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -pub mod actors; pub mod bot; pub mod cofd; pub mod commands; @@ -10,4 +9,5 @@ pub mod error; mod help; mod parser; pub mod roll; +pub mod state; pub mod variables; diff --git a/src/actors/state.rs b/src/state.rs similarity index 60% rename from src/actors/state.rs rename to src/state.rs index fad5187..a223f9e 100644 --- a/src/actors/state.rs +++ b/src/state.rs @@ -1,30 +1,14 @@ use crate::config::*; -use actix::prelude::*; use log::info; use std::sync::Arc; -#[derive(Message)] -#[rtype(result = "bool")] -pub struct LogSkippedOldMessages; - /// Holds state of the dice bot, for anything requiring mutable /// transitions. This is a simple mutable trait whose values represent /// the current state of the dicebot. It provides mutable methods to /// change state. pub struct DiceBotState { logged_skipped_old_messages: bool, - config: Arc, -} - -impl Actor for DiceBotState { - type Context = Context; - - fn started(&mut self, _ctx: &mut Self::Context) { - info!( - "Oldest allowable message time is {} seconds ago", - &self.config.oldest_message_age() - ); - } + _config: Arc, } impl DiceBotState { @@ -32,10 +16,14 @@ impl DiceBotState { pub fn new(config: &Arc) -> DiceBotState { DiceBotState { logged_skipped_old_messages: false, - config: config.clone(), + _config: config.clone(), } } + pub fn logged_skipped_old_messages(&self) -> bool { + self.logged_skipped_old_messages + } + /// Log and record that we have skipped some old messages. This /// method will log once, and then no-op from that point on. pub fn skipped_old_messages(&mut self) { @@ -46,12 +34,3 @@ impl DiceBotState { self.logged_skipped_old_messages = true; } } - -impl Handler for DiceBotState { - type Result = bool; - - fn handle(&mut self, _msg: LogSkippedOldMessages, _ctx: &mut Context) -> Self::Result { - self.skipped_old_messages(); - self.logged_skipped_old_messages - } -}