vortaroboto

Log | Files | Refs | README

commit 8be5176203d5d7d895bb0fd2687d99f417333848
parent 095fbf41fae4d3fb80ed0b45fd07d6e593e36c16
Author: thomas.vigouroux@protonmail.com <thomas.vigouroux@protonmail.com>
Date:   Fri, 17 Dec 2021 10:52:41 +0000

Instrument appp and make it resilient
Diffstat:
MCargo.lock | 542+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
MCargo.toml | 2++
Msrc/main.rs | 237++++++++++++++++++++++++++++++++++---------------------------------------------
3 files changed, 635 insertions(+), 146 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -3,6 +3,27 @@ version = 3 [[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" + +[[package]] name = "async-mutex" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -22,6 +43,27 @@ dependencies = [ ] [[package]] +name = "async-stream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "async-trait" version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -77,6 +119,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" [[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] name = "bytes" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -154,6 +202,49 @@ dependencies = [ ] [[package]] +name = "console-api" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033fddce299c93dd44ae21d5f5a6e749baa5d103784bcdde65701c07272a9fde" +dependencies = [ + "prost", + "prost-types", + "tonic", + "tonic-build", + "tracing-core", +] + +[[package]] +name = "console-subscriber" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2380cc150266375aeda8f9aeadc5527395c1a8807ecf9fa97a46d1bb760ec5b" +dependencies = [ + "console-api", + "futures", + "hdrhistogram", + "humantime", + "serde", + "serde_json", + "thread_local", + "tokio", + "tokio-stream", + "tonic", + "tracing", + "tracing-core", + "tracing-subscriber", +] + +[[package]] +name = "crc32fast" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "738c290dfaea84fc1ca15ad9c168d083b05a714e1efddd8edaab678dc28d2836" +dependencies = [ + "cfg-if", +] + +[[package]] name = "darling" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -189,6 +280,12 @@ dependencies = [ ] [[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] name = "encoding" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -268,6 +365,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" [[package]] +name = "fixedbitset" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "398ea4fabe40b9b0d885340a2a991a44c8a645624075ad966d21f88688e2b69e" + +[[package]] +name = "flate2" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" +dependencies = [ + "cfg-if", + "crc32fast", + "libc", + "miniz_oxide", +] + +[[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -378,10 +493,21 @@ dependencies = [ ] [[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] name = "h2" -version = "0.3.6" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964" +checksum = "8f072413d126e57991455e0a922b31e4c8ba7c2ffbebf6b78b4f8521397d65cd" dependencies = [ "bytes", "fnv", @@ -403,6 +529,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] +name = "hdrhistogram" +version = "7.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6490be71f07a5f62b564bc58e36953f675833df11c7e4a0647bee7a07ca1ec5e" +dependencies = [ + "base64", + "byteorder", + "flate2", + "nom", + "num-traits", +] + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] name = "hermit-abi" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -424,9 +572,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" dependencies = [ "bytes", "http", @@ -446,10 +594,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" [[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] name = "hyper" -version = "0.14.13" +version = "0.14.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593" +checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" dependencies = [ "bytes", "futures-channel", @@ -485,6 +639,18 @@ dependencies = [ ] [[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper", + "pin-project-lite", + "tokio", + "tokio-io-timeout", +] + +[[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -561,6 +727,15 @@ dependencies = [ ] [[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + +[[package]] name = "itoa" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -624,6 +799,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + +[[package]] name = "mio" version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -646,6 +837,23 @@ dependencies = [ ] [[package]] +name = "multimap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + +[[package]] +name = "nom" +version = "7.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" +dependencies = [ + "memchr", + "minimal-lexical", + "version_check", +] + +[[package]] name = "ntapi" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -721,6 +929,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] +name = "petgraph" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a13a2fa9d0b63e5f22328828741e523766fff0ee9e779316902290dff3f824f" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] name = "pin-project" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -753,6 +971,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] +name = "ppv-lite86" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" + +[[package]] name = "proc-macro-hack" version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -774,6 +998,59 @@ dependencies = [ ] [[package]] +name = "prost" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" +dependencies = [ + "bytes", + "heck", + "itertools", + "lazy_static", + "log", + "multimap", + "petgraph", + "prost", + "prost-types", + "regex", + "tempfile", + "which", +] + +[[package]] +name = "prost-derive" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-types" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534b7a0e836e3c482d2693070f982e39e7611da9695d4d1f5a4b186b51faef0a" +dependencies = [ + "bytes", + "prost", +] + +[[package]] name = "quote" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -783,6 +1060,46 @@ dependencies = [ ] [[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core", +] + +[[package]] name = "redox_syscall" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -792,6 +1109,32 @@ dependencies = [ ] [[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] name = "reqwest" version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -921,6 +1264,15 @@ dependencies = [ ] [[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] name = "simple_logger" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -985,6 +1337,20 @@ dependencies = [ ] [[package]] +name = "tempfile" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +dependencies = [ + "cfg-if", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] name = "thiserror" version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1005,6 +1371,15 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1031,11 +1406,10 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.12.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" +checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838" dependencies = [ - "autocfg", "bytes", "libc", "memchr", @@ -1043,14 +1417,25 @@ dependencies = [ "num_cpus", "pin-project-lite", "tokio-macros", + "tracing", "winapi", ] [[package]] +name = "tokio-io-timeout" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90c49f106be240de154571dd31fbe48acb10ba6c6dd6f6517ad603abffa42de9" +dependencies = [ + "pin-project-lite", + "tokio", +] + +[[package]] name = "tokio-macros" -version = "1.4.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "154794c8f499c2619acd19e839294703e9e32e7630ef5f46ea80d4ef0fbee5eb" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ "proc-macro2", "quote", @@ -1094,6 +1479,76 @@ dependencies = [ ] [[package]] +name = "tonic" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff08f4649d10a70ffa3522ca559031285d8e421d727ac85c60825761818f5d0a" +dependencies = [ + "async-stream", + "async-trait", + "base64", + "bytes", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost", + "prost-derive", + "tokio", + "tokio-stream", + "tokio-util", + "tower", + "tower-layer", + "tower-service", + "tracing", + "tracing-futures", +] + +[[package]] +name = "tonic-build" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9403f1bafde247186684b230dc6f38b5cd514584e8bec1dd32514be4745fa757" +dependencies = [ + "proc-macro2", + "prost-build", + "quote", + "syn", +] + +[[package]] +name = "tower" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5651b5f6860a99bd1adb59dbfe1db8beb433e73709d9032b413a77e2fb7c066a" +dependencies = [ + "futures-core", + "futures-util", + "indexmap", + "pin-project", + "pin-project-lite", + "rand", + "slab", + "tokio", + "tokio-stream", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" + +[[package]] name = "tower-service" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1106,11 +1561,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" dependencies = [ "cfg-if", + "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] [[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "tracing-core" version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1120,6 +1588,27 @@ dependencies = [ ] [[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245da694cc7fc4729f3f418b304cb57789f1bed2a78c575407ab8a23f53cb4d3" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + +[[package]] name = "try-lock" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1141,6 +1630,12 @@ dependencies = [ ] [[package]] +name = "unicode-segmentation" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" + +[[package]] name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1165,12 +1660,20 @@ dependencies = [ ] [[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] name = "vortaroboto" version = "0.1.0" dependencies = [ + "async-trait", "bincode", "cached", "chrono", + "console-subscriber", "futures", "irc", "log", @@ -1193,6 +1696,12 @@ dependencies = [ ] [[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] name = "wasm-bindgen" version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1297,6 +1806,17 @@ dependencies = [ ] [[package]] +name = "which" +version = "4.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9" +dependencies = [ + "either", + "lazy_static", + "libc", +] + +[[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -18,3 +18,5 @@ bincode = "1.3.3" snap = "1.0.5" cached = "0.26.2" chrono = { version = "0.4.19", features = ["serde"] } +async-trait = "0.1.15" +console-subscriber = "0.1.0" diff --git a/src/main.rs b/src/main.rs @@ -1,8 +1,7 @@ +use chrono::{prelude::*, Duration}; use futures::prelude::*; use irc::client::prelude::*; -use serde::{de::DeserializeOwned, ser::Serialize}; use std::{collections::HashMap, str::FromStr}; -use chrono::{Duration, prelude::*}; use log::{debug, info}; use simple_logger::SimpleLogger; @@ -12,28 +11,16 @@ mod colors; use colors::{ColorKind, Formatted, FormattingKind}; mod requests; -use requests::{Difino, Traduko, Trovo, Vorto, Vortfarado, difinu, trovu}; +use requests::{difinu, trovu, Difino, Traduko, Trovo, Vortfarado, Vorto}; -const NICK: &'static str = "vortaroboto"; -const LINEO_SEP: &'static str = "\r\n"; +mod pack; +use pack::{pack_data, unpack_data}; -fn unpack_data<T>(fname: &str) -> Result<T, String> -where - T: DeserializeOwned, -{ - let r = snap::read::FrameDecoder::new(std::fs::File::open(fname).map_err(|e| e.to_string())?); - bincode::deserialize_from(r).map_err(|e| e.to_string()) -} +mod cmds; +use cmds::stats::{add_words, stats}; -fn pack_data<T>(fname: &str, data: &T) -> Result<(), String> -where - T: Serialize, -{ - let f = std::fs::File::create(fname).map_err(|e| e.to_string())?; - let w = snap::write::FrameEncoder::new(f); - bincode::serialize_into(w, data).map_err(|e| e.to_string())?; - Ok(()) -} +const NICK: &'static str = "vortaroboto"; +const LINEO_SEP: &'static str = "\r\n"; enum NumerSelektilo { Cxiuj, @@ -59,6 +46,7 @@ impl Default for NumerSelektilo { #[tokio::main] async fn main() -> irc::error::Result<()> { + console_subscriber::init(); SimpleLogger::new() .with_level(log::LevelFilter::Debug) .init() @@ -71,6 +59,7 @@ async fn main() -> irc::error::Result<()> { channels: vec!["##esperanto".to_owned()], max_messages_in_burst: Some(5), burst_window_length: Some(1), + ping_timeout: Some(600), ..Config::default() }; @@ -80,114 +69,71 @@ async fn main() -> irc::error::Result<()> { let mut stream = client.stream()?; let sender = client.sender(); - while let Some(message) = stream.next().await.transpose()? { - debug!("{}", message); - match message.command { - Command::PRIVMSG(ref target, ref msg) => { - let is_channel = target.starts_with('#'); - let target = if is_channel { - target - } else { - message.source_nickname().unwrap_or(target) - }; - - if let Some(cmd) = msg.strip_prefix('!') { - if let Some(answer) = handle_command(target, cmd).await { - let r = match (is_channel, message.source_nickname()) { - (true, Some(n)) => format!("{}:\r\n{}", n, answer), - _ => answer, + loop { + match stream.next().await.transpose() { + Ok(Some(message)) => { + debug!("{}", message); + match message.command { + Command::PRIVMSG(ref target, ref msg) => { + let is_channel = target.starts_with('#'); + let target = if is_channel { + target + } else { + message.source_nickname().unwrap_or(target) }; - sender.send_privmsg(target, r)?; - } - continue; - } - // TODO: make this local to a channel / query - tokio::task::spawn(add_words(msg.to_string())); - if let Some(nomo) = message.source_nickname() { - vidita_update(target, nomo, msg); - } + if let Some(cmd) = msg.strip_prefix('!') { + if let Some(answer) = handle_command(target, cmd).await { + let r = match (is_channel, message.source_nickname()) { + (true, Some(n)) => format!("{}:\r\n{}", n, answer), + _ => answer, + }; + sender.send_privmsg(target, r)?; + } + continue; + } - // Donu bonaj respondoj ofte - if msg.contains(client.current_nickname()) { - let msg = match msg.split_ascii_whitespace().next() { - Some("saluton" | "Saluton") => { - format!( + // TODO: make this local to a channel / query + tokio::task::spawn(add_words(msg.to_string())); + if let Some(nomo) = message.source_nickname() { + vidita_update(target, nomo, msg); + } + + // Donu bonaj respondoj ofte + if msg.contains(client.current_nickname()) { + let msg = match msg.split_ascii_whitespace().next() { + Some("saluton" | "Saluton") => { + format!( "Saluton ! Mi estas {} la roboto kiun vi povas demandi pri vortoj kaj tradukoj ! Tajpu !helpu por pli'sciiĝi !", irc_fmt!(FormattingKind::Bold => client.current_nickname()) ) + } + Some("dankon" | "Dankon") => { + format!( + "Nedankinde {} !", + message.source_nickname().unwrap_or("vi") + ) + } + _ => { + continue; + } + }; + sender.send_privmsg(target, msg)?; } - Some("dankon" | "Dankon") => { - format!("Nedankinde {} !", message.source_nickname().unwrap_or("vi")) - } - _ => { - continue; - } - }; - sender.send_privmsg(target, msg)?; - } - } - _ => (), - } - } - - Ok(()) -} - -const VORTO_PATH: &'static str = "vorto.bincode"; -async fn add_words(frazo: String) { - let mut h: HashMap<String, usize> = unpack_data(VORTO_PATH).unwrap_or_default(); - - for vorto in frazo.split_ascii_whitespace() { - if let Ok(tro) = difinu(vorto.to_owned()).await { - if let Some(vf) = tro - .vortfarado - .iter() - .filter(|vf| vf.partoj.len() > 1) - .next() - { - let mut vera_vorto = String::with_capacity(vorto.len()); - - if vf.partoj.len() > 1 { - // Konstrui la vera vorto - // sen la termnoj - for p in vf.partoj.iter().take_while(|p| p.vorto.is_some()) { - vera_vorto.push_str(p.parto.as_str()); } - vera_vorto.push('-'); - } else { - // vorto estas la vera, nura, vorto - vera_vorto = vorto.to_owned() + _ => (), } - - if let Some(v) = h.get_mut(&vera_vorto) { - *v += 1; - } else { - h.insert(vera_vorto, 1); - } - } + }, + Ok(None) | Err(irc::error::Error::PingTimeout) => {}, + Err(e) => { return Err(e) } } } - - pack_data(VORTO_PATH, &h).unwrap(); // Tre neebla, sed... -} - -fn stats() -> Result<String, String> { - let mut h: HashMap<String, usize> = unpack_data(VORTO_PATH)?; - let mut h: Vec<(String, usize)> = h.drain().collect(); - h.sort_by_cached_key(|(_, s)| *s); - h.reverse(); - - Ok(h.iter() - .take(10) - .map(|(v, o)| format!("{}: {}", v, o)) - .collect::<Vec<String>>() - .join(", ")) } const VIDITA_PATH: &'static str = "vidita.bincode"; fn vidita_update(channel: &str, nomo: &str, msg: &str) { - let mut h: HashMap<String, HashMap<String, (String, DateTime<Utc>)>> = unpack_data(VIDITA_PATH).unwrap_or_default(); + let mut h: HashMap<String, HashMap<String, (String, DateTime<Utc>)>> = + unpack_data(VIDITA_PATH).unwrap_or_default(); // Make a little dance to create the channel index if it's not here yet let inner = if let Some(inner) = h.get_mut(channel) { @@ -210,29 +156,41 @@ fn formato_dauxro(dato: Duration) -> String { (dato.num_seconds() % 60, "sekondo"), ]; - let inter: Vec<String> = inter.iter().filter_map(|(n, v)| { - if *n == 1 { - Some(format!("{} {}", n, v)) - } else if *n > 1 { - Some(format!("{} {}j", n, v)) - } else { - None - } - }).collect(); + let inter: Vec<String> = inter + .iter() + .filter_map(|(n, v)| { + if *n == 1 { + Some(format!("{} {}", n, v)) + } else if *n > 1 { + Some(format!("{} {}j", n, v)) + } else { + None + } + }) + .collect(); inter.join(" ") } fn vidita_display(channel: &str, nomo: &str) -> Option<String> { - if nomo == NICK { - return Some(format!("Eh, mi {} {}!", irc_fmt!(FormattingKind::Italics => "estas"), NICK)); + return Some(format!( + "Eh, mi {} {}!", + irc_fmt!(FormattingKind::Italics => "estas"), + NICK + )); } - let h: HashMap<String, HashMap<String, (String, DateTime<Utc>)>> = unpack_data(VIDITA_PATH).ok()?; + let h: HashMap<String, HashMap<String, (String, DateTime<Utc>)>> = + unpack_data(VIDITA_PATH).ok()?; let inner = h.get(channel)?; let (msg, time) = inner.get(nomo)?; - Some(format!("{} estis laste vidita antaŭ {}: '{}'", nomo, formato_dauxro(Utc::now() - *time), msg)) + Some(format!( + "{} estis laste vidita antaŭ {}: '{}'", + nomo, + formato_dauxro(Utc::now() - *time), + msg + )) } macro_rules! parse_or_default { @@ -289,11 +247,13 @@ async fn handle_command(source: &str, cmd: &str) -> Option<String> { } } Some("statistikoj" | "stat") => stats().ok(), - Some("vidita" | "vid") => if let Some(w) = splitted.next() { - vidita_display(source, w).or_else(|| Some(format!("Neniam vidita {}.", w))) - } else { - Some(String::from("Uzo: vidita {uzanto}")) - }, + Some("vidita" | "vid") => { + if let Some(w) = splitted.next() { + vidita_display(source, w).or_else(|| Some(format!("Neniam vidita {}.", w))) + } else { + Some(String::from("Uzo: vidita {uzanto}")) + } + } Some(u) => Some(format!("Mi ne scias kiel respondi al: {}", u)), None => None, } @@ -327,7 +287,12 @@ fn helpu() -> String { "Doni la etimologion de {vorto}", ), ("statistiko", &[], &[], "Donu la 10 vortojn plej uzatajn."), - ("vidita", &["unzanto"], &[], "Donu la lastan fojon kiam uzanto estis vidita."), + ( + "vidita", + &["unzanto"], + &[], + "Donu la lastan fojon kiam uzanto estis vidita.", + ), ]; fn format_args(am: &[&str], left: char, right: char, c: ColorKind) -> String { @@ -459,7 +424,8 @@ async fn traduki(vorto: &str, fonto: Option<&str>) -> Result<String, String> { None } }) - .collect::<Vec<String>>().join(", ") + .collect::<Vec<String>>() + .join(", ") } else { tradukoj .filter_map(|t: &Traduko| { @@ -469,7 +435,8 @@ async fn traduki(vorto: &str, fonto: Option<&str>) -> Result<String, String> { None } }) - .collect::<Vec<String>>().join(LINEO_SEP) + .collect::<Vec<String>>() + .join(LINEO_SEP) }; if tradukoj.is_empty() {