From 21fd9fe96859cce120828279c26d7c21a78e9e05 Mon Sep 17 00:00:00 2001 From: Emile Date: Mon, 28 Jun 2021 19:57:06 +0100 Subject: [PATCH] Added console publisher, added console selector (very poorly!) and non-implemented telegram selector --- Cargo.lock | 500 ++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 2 + src/bot.rs | 31 ++- src/main.rs | 16 +- src/publish.rs | 15 ++ src/selection.rs | 89 +++++++++ 6 files changed, 618 insertions(+), 35 deletions(-) create mode 100644 src/selection.rs diff --git a/Cargo.lock b/Cargo.lock index 8f3a5a5..3047f89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,6 +15,21 @@ 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 = "ascii" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97be891acc47ca214468e09425d02cef3af2c94d0d82081cd02061f996802f14" + [[package]] name = "autocfg" version = "0.1.7" @@ -67,6 +82,12 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + [[package]] name = "bitflags" version = "1.2.1" @@ -94,6 +115,22 @@ dependencies = [ "byte-tools", ] +[[package]] +name = "buf_redux" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" +dependencies = [ + "memchr", + "safemem", +] + +[[package]] +name = "bumpalo" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" + [[package]] name = "byte-tools" version = "0.3.1" @@ -189,6 +226,18 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "chunked_transfer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "498d20a7aaf62625b9bf26e637cf7736417cde1d0c99f1d04d1170229a85cf87" + +[[package]] +name = "chunked_transfer" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" + [[package]] name = "cloudabi" version = "0.0.3" @@ -217,7 +266,7 @@ dependencies = [ "cookie", "failure", "idna 0.1.5", - "log", + "log 0.4.14", "publicsuffix", "serde", "serde_json", @@ -342,7 +391,7 @@ dependencies = [ "doc-comment", "hyper-old-types", "isolang", - "log", + "log 0.4.14", "reqwest", "serde", "serde_derive", @@ -373,7 +422,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" dependencies = [ "backtrace", - "version_check", + "version_check 0.9.3", ] [[package]] @@ -447,6 +496,19 @@ dependencies = [ "percent-encoding 2.1.0", ] +[[package]] +name = "frankenstein" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecce8fc4d7ca2bf5c34f81342d527ee0c47de27c13c8b57df7f5431589e156" +dependencies = [ + "mime_guess 2.0.3", + "multipart", + "serde", + "serde_json", + "ureq", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -528,6 +590,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "groupable" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32619942b8be646939eaf3db0602b39f5229b74575b67efc897811ded1db4e57" + [[package]] name = "h2" version = "0.1.26" @@ -540,7 +608,7 @@ dependencies = [ "futures", "http 0.1.21", "indexmap", - "log", + "log 0.4.14", "slab", "string", "tokio-io", @@ -601,6 +669,25 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" +[[package]] +name = "hyper" +version = "0.10.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273" +dependencies = [ + "base64 0.9.3", + "httparse", + "language-tags", + "log 0.3.9", + "mime 0.2.6", + "num_cpus", + "time", + "traitobject", + "typeable", + "unicase 1.4.2", + "url 1.7.2", +] + [[package]] name = "hyper" version = "0.12.36" @@ -616,7 +703,7 @@ dependencies = [ "httparse", "iovec", "itoa", - "log", + "log 0.4.14", "net2", "rustc_version", "time", @@ -641,11 +728,11 @@ dependencies = [ "bytes 0.4.12", "httparse", "language-tags", - "log", - "mime", + "log 0.4.14", + "mime 0.3.16", "percent-encoding 1.0.1", "time", - "unicase", + "unicase 2.6.0", ] [[package]] @@ -656,7 +743,7 @@ checksum = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" dependencies = [ "bytes 0.4.12", "futures", - "hyper", + "hyper 0.12.36", "native-tls", "tokio-io", ] @@ -711,6 +798,22 @@ dependencies = [ "libc", ] +[[package]] +name = "iron" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6d308ca2d884650a8bf9ed2ff4cb13fbb2207b71f64cda11dc9b892067295e8" +dependencies = [ + "hyper 0.10.16", + "log 0.3.9", + "mime_guess 1.8.8", + "modifier", + "num_cpus", + "plugin", + "typemap", + "url 1.7.2", +] + [[package]] name = "isolang" version = "1.0.0" @@ -732,12 +835,23 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" name = "izzilis" version = "0.1.0" dependencies = [ + "chrono", "elefren", + "frankenstein", "rand 0.8.4", "serde", "serde_json", ] +[[package]] +name = "js-sys" +version = "0.3.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -775,6 +889,15 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" +dependencies = [ + "log 0.4.14", +] + [[package]] name = "log" version = "0.4.14" @@ -811,20 +934,41 @@ dependencies = [ "autocfg 1.0.1", ] +[[package]] +name = "mime" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" +dependencies = [ + "log 0.3.9", +] + [[package]] name = "mime" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "mime_guess" +version = "1.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216929a5ee4dd316b1702eedf5e74548c123d370f47841ceaac38ca154690ca3" +dependencies = [ + "mime 0.2.6", + "phf", + "phf_codegen", + "unicase 1.4.2", +] + [[package]] name = "mime_guess" version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" dependencies = [ - "mime", - "unicase", + "mime 0.3.16", + "unicase 2.6.0", ] [[package]] @@ -849,7 +993,7 @@ dependencies = [ "iovec", "kernel32-sys", "libc", - "log", + "log 0.4.14", "miow", "net2", "slab", @@ -868,6 +1012,44 @@ dependencies = [ "ws2_32-sys", ] +[[package]] +name = "modifier" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58" + +[[package]] +name = "multipart" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00dec633863867f29cb39df64a397cdf4a6354708ddd7759f70c7fb51c5f9182" +dependencies = [ + "buf_redux", + "httparse", + "hyper 0.10.16", + "iron", + "log 0.4.14", + "mime 0.3.16", + "mime_guess 2.0.3", + "nickel", + "quick-error", + "rand 0.8.4", + "safemem", + "tempfile", + "tiny_http", + "twoway", +] + +[[package]] +name = "mustache" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51956ef1c5d20a1384524d91e616fb44dfc7d8f249bf696d49c97dd3289ecab5" +dependencies = [ + "log 0.3.9", + "serde", +] + [[package]] name = "native-tls" version = "0.2.7" @@ -876,7 +1058,7 @@ checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ "lazy_static", "libc", - "log", + "log 0.4.14", "openssl", "openssl-probe", "openssl-sys", @@ -897,6 +1079,27 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "nickel" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5061a832728db2dacb61cefe0ce303b58f85764ec680e71d9138229640a46d9" +dependencies = [ + "groupable", + "hyper 0.10.16", + "lazy_static", + "log 0.3.9", + "modifier", + "mustache", + "plugin", + "regex", + "serde", + "serde_json", + "time", + "typemap", + "url 1.7.2", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -1063,6 +1266,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" dependencies = [ "siphasher", + "unicase 1.4.2", ] [[package]] @@ -1071,6 +1275,15 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +[[package]] +name = "plugin" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a6a0dc3910bc8db877ffed8e457763b317cf880df4ae19109b9f77d277cf6e0" +dependencies = [ + "typemap", +] + [[package]] name = "ppv-lite86" version = "0.2.10" @@ -1104,9 +1317,15 @@ checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" dependencies = [ "bitflags", "memchr", - "unicase", + "unicase 2.6.0", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.9" @@ -1327,6 +1546,23 @@ dependencies = [ "bitflags", ] +[[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" @@ -1350,11 +1586,11 @@ dependencies = [ "flate2", "futures", "http 0.1.21", - "hyper", + "hyper 0.12.36", "hyper-tls", - "log", - "mime", - "mime_guess", + "log 0.4.14", + "mime 0.3.16", + "mime_guess 2.0.3", "native-tls", "serde", "serde_json", @@ -1370,6 +1606,21 @@ dependencies = [ "winreg", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi 0.3.9", +] + [[package]] name = "rustc-demangle" version = "0.1.20" @@ -1385,6 +1636,19 @@ dependencies = [ "semver 0.9.0", ] +[[package]] +name = "rustls" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" +dependencies = [ + "base64 0.13.0", + "log 0.4.14", + "ring", + "sct", + "webpki", +] + [[package]] name = "ryu" version = "1.0.5" @@ -1422,6 +1686,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "security-framework" version = "2.3.1" @@ -1594,6 +1868,12 @@ dependencies = [ "maybe-uninit", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "string" version = "0.2.1" @@ -1656,6 +1936,19 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "tiny_http" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e22cb179b63e5fc2d0b5be237dc107da072e2407809ac70a8ce85b93fe8f562" +dependencies = [ + "ascii", + "chrono", + "chunked_transfer 0.3.1", + "log 0.4.14", + "url 1.7.2", +] + [[package]] name = "tinyvec" version = "1.2.0" @@ -1729,7 +2022,7 @@ checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" dependencies = [ "bytes 0.4.12", "futures", - "log", + "log 0.4.14", ] [[package]] @@ -1741,7 +2034,7 @@ dependencies = [ "crossbeam-utils", "futures", "lazy_static", - "log", + "log 0.4.14", "mio", "num_cpus", "parking_lot", @@ -1786,7 +2079,7 @@ dependencies = [ "crossbeam-utils", "futures", "lazy_static", - "log", + "log 0.4.14", "num_cpus", "slab", "tokio-executor", @@ -1813,6 +2106,12 @@ dependencies = [ "serde", ] +[[package]] +name = "traitobject" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" + [[package]] name = "try-lock" version = "0.2.3" @@ -1840,7 +2139,7 @@ dependencies = [ "http 0.2.4", "httparse", "input_buffer", - "log", + "log 0.4.14", "native-tls", "rand 0.7.3", "sha-1", @@ -1848,6 +2147,30 @@ dependencies = [ "utf-8", ] +[[package]] +name = "twoway" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" +dependencies = [ + "memchr", +] + +[[package]] +name = "typeable" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" + +[[package]] +name = "typemap" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6" +dependencies = [ + "unsafe-any", +] + [[package]] name = "typenum" version = "1.13.0" @@ -1860,13 +2183,22 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" +[[package]] +name = "unicase" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" +dependencies = [ + "version_check 0.1.5", +] + [[package]] name = "unicase" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" dependencies = [ - "version_check", + "version_check 0.9.3", ] [[package]] @@ -1893,6 +2225,37 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "unsafe-any" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f" +dependencies = [ + "traitobject", +] + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "ureq" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2475a6781e9bc546e7b64f4013d2f4032c8c6a40fcffd7c6f4ee734a890972ab" +dependencies = [ + "base64 0.13.0", + "chunked_transfer 1.4.0", + "log 0.4.14", + "once_cell", + "rustls", + "url 2.2.2", + "webpki", + "webpki-roots", +] + [[package]] name = "url" version = "1.7.2" @@ -1937,6 +2300,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version_check" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" + [[package]] name = "version_check" version = "0.9.3" @@ -1961,7 +2330,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" dependencies = [ "futures", - "log", + "log 0.4.14", "try-lock", ] @@ -1977,6 +2346,89 @@ 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.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +dependencies = [ + "bumpalo", + "lazy_static", + "log 0.4.14", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" + +[[package]] +name = "web-sys" +version = "0.3.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" +dependencies = [ + "webpki", +] + [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 6c942a5..e0b4135 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +chrono = "0.4.19" elefren = { version = "0.22.0", features = ["toml"] } +frankenstein = "0.4.0" rand = "0.8.4" serde = "1.0.126" serde_json = "1.0.64" diff --git a/src/bot.rs b/src/bot.rs index 0224779..f8b3b9d 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -1,40 +1,57 @@ use rand::Rng; use std::{error::Error, io}; -use crate::{generator, model, publish}; +use crate::{ + generator, model, publish, + selection::{self, Selector}, +}; -pub struct IzzilisBot { +pub struct IzzilisBot { generator: generator::Generator, publisher: U, // One day I'll figure out how to make this a vector with differing Publisher types + selector: V, loaded_samples: Vec, } -impl IzzilisBot +impl IzzilisBot where T: model::SampleModel, U: publish::Publisher, + V: selection::Selector, { - pub fn new(generator: generator::Generator, publisher: U) -> IzzilisBot { + pub fn new( + generator: generator::Generator, + publisher: U, + selector: V, + ) -> IzzilisBot { Self { generator, publisher, loaded_samples: Vec::new(), + selector: selector, } } - fn generate_samples(&mut self) -> Option { + pub fn generate_samples(&mut self) -> Option { let lines_result = self.generator.generate_sample_lines(); let lines = match lines_result { Ok(res) => res, Err(err) => return Some(err), }; - self.loaded_samples = lines; // wtf happens to the original self.loaded_samples??????? + for line in lines { + match self.selector.send_for_review(line) { + Some(err) => panic!("Failed selector read, yes shit error I know, help me"), // Yes, I know this is *abysmal* but idk how to deal with errors + // yet, so for the time being I have to suffer through this bad shit. Please help me, looking at this is suffering. I want it to end. + None => (), + } + } + self.loaded_samples = self.selector.collect_selected_samples(); // wtf happens to the original self.loaded_samples??????? None } pub fn publish(&mut self) -> Option> { - if self.loaded_samples.len() < 5 { + if self.loaded_samples.len() == 0 { // Refresh samples. Either none have been generated so far, // or generated ones are stale. // diff --git a/src/main.rs b/src/main.rs index e08cf12..1d1524d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,16 @@ use std::{error::Error, process, thread, time::Duration}; +use chrono::Local; use rand::Rng; +use crate::publish::ConsolePublisher; + mod bot; mod config; mod generator; mod model; mod publish; +mod selection; const CONFIG_PATH: &str = "bot_config.json"; @@ -41,18 +45,22 @@ fn main() -> Result<(), Box> { "1".to_string(), ], ); - let publisher = publish::FediversePublisher::new(cfg.fediverse_base_url())?; + // let publisher = publish::FediversePublisher::new(cfg.fediverse_base_url())?; + let publisher = ConsolePublisher::new(); let gen = generator::Generator::new(gpt_model); - let mut bot = bot::IzzilisBot::new(gen, publisher); + let console_selector = selection::ConsoleSelector::new(); + let mut bot = bot::IzzilisBot::new(gen, publisher, console_selector); + bot.generate_samples(); let cfg_interval = cfg.interval_seconds(); loop { let wait_seconds = rand::thread_rng().gen_range(cfg_interval.min()..cfg_interval.max()); let wait_time = Duration::from_secs(wait_seconds); - println!("Next post is in {} seconds", wait_seconds); + let now = Local::now(); + println!("[{}] Next post is in [{}] seconds", now, wait_seconds); thread::sleep(wait_time); match bot.publish() { - Some(err) => println!("Got error from publish: {}; continuing", err), + Some(err) => println!("Got error from publish: [{}]; continuing", err), None => println!("publish() call successful"), } } diff --git a/src/publish.rs b/src/publish.rs index 34b2b8a..9fa1f26 100644 --- a/src/publish.rs +++ b/src/publish.rs @@ -17,6 +17,21 @@ pub struct FediversePublisher { client: Mastodon, } +pub struct ConsolePublisher; + +impl Publisher for ConsolePublisher { + fn publish(&self, content: String) -> Option> { + println!("Publishing content to stdout: {}", content); + None + } +} + +impl ConsolePublisher { + pub fn new() -> ConsolePublisher { + ConsolePublisher {} + } +} + impl FediversePublisher { pub fn new(fedi_url: String) -> Result> { let fedi = if let Ok(data) = toml::from_file(FEDIVERSE_TOML_PATH.to_string()) { diff --git a/src/selection.rs b/src/selection.rs new file mode 100644 index 0000000..ab80b7c --- /dev/null +++ b/src/selection.rs @@ -0,0 +1,89 @@ +use frankenstein::{ + Api, GetUpdatesParams, KeyboardButton, ReplyKeyboardMarkup, ReplyMarkup, TelegramApi, +}; +use std::{error::Error, io, thread::JoinHandle}; + +pub trait Selector { + fn send_for_review(&mut self, message: String) -> Option>; + fn collect_selected_samples(&mut self) -> Vec; +} + +pub struct TelegramSelector { + client: frankenstein::Api, + dest_chat_id: String, + listener_handle: Option>, +} + +pub struct ConsoleSelector { + selected_samples: Vec, +} + +impl Selector for ConsoleSelector { + fn send_for_review(&mut self, message: String) -> Option> { + println!("generated sample [y+enter to accept]: {}", &message); + let mut choice = String::new(); + io::stdin().read_line(&mut choice).expect("cum"); + if choice.to_lowercase().contains("y") { + println!("accepted"); + self.selected_samples.push(message); + } + return None; + } + + fn collect_selected_samples(&mut self) -> Vec { + let cloned_samples = self.selected_samples.to_owned(); + self.selected_samples = Vec::new(); + cloned_samples + } +} + +impl ConsoleSelector { + pub fn new() -> ConsoleSelector { + Self { + selected_samples: Vec::new(), + } + } +} + +const KEEP_BUTTON: &str = "Keep"; +const TOSS_BUTTON: &str = "Toss"; + +impl Selector for TelegramSelector { + fn send_for_review(&mut self, message: String) -> Option> { + todo!(); + if !self.listener_handle.is_none() { + todo!(); + } + let mut message_def = frankenstein::SendMessageParams::new( + frankenstein::ChatId::String(self.dest_chat_id.clone()), + message, + ); + message_def.reply_markup = Some(ReplyMarkup::ReplyKeyboardMarkup( + ReplyKeyboardMarkup::new(vec![ + KeyboardButton::new(KEEP_BUTTON.to_string()), + KeyboardButton::new(TOSS_BUTTON.to_string()), + ]), + )); + let result = match self.client.send_message(&message_def) { + Ok(_) => None, + Err(_) => todo!(), + }; + + result + } + + fn collect_selected_samples(&mut self) -> Vec { + todo!() + } +} + +impl TelegramSelector { + pub fn new(token: String, dest_chat_id: String) -> TelegramSelector { + let api = Api::new(&token); + Self { + client: api, + dest_chat_id: dest_chat_id, + listener_handle: None, + } + } +}