From bd42f495dc03c39645763c895ee8fdf08ecfb58a Mon Sep 17 00:00:00 2001 From: emilis Date: Wed, 1 Sep 2021 19:30:20 +0200 Subject: [PATCH] Added support for misskey publisher, and switching between publishers via config --- Cargo.lock | 792 +++++++++++++++++++++++++++++++++++++--- Cargo.toml | 2 + src/config.rs | 27 +- src/main.rs | 79 ++-- src/publish/mastodon.rs | 7 +- src/publish/misskey.rs | 49 +++ src/publish/mod.rs | 2 + 7 files changed, 864 insertions(+), 94 deletions(-) create mode 100644 src/publish/misskey.rs diff --git a/Cargo.lock b/Cargo.lock index 8b69057..8d1dde2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,6 +34,16 @@ dependencies = [ "futures-core", ] +[[package]] +name = "async-dup" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7427a12b8dc09291528cfb1da2447059adb4a257388c2acd6497a79d55cf6f7c" +dependencies = [ + "futures-io", + "simple-mutex", +] + [[package]] name = "async-executor" version = "1.4.1" @@ -118,6 +128,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "async-rwlock" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261803dcc39ba9e72760ba6e16d0199b1eef9fc44e81bffabbebb9f5aea3906c" +dependencies = [ + "async-mutex", + "event-listener", +] + [[package]] name = "async-std" version = "1.9.0" @@ -152,6 +172,34 @@ version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" +[[package]] +name = "async-tls" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d85a97c4a0ecce878efd3f945f119c78a646d8975340bca0398f9bb05c30cc52" +dependencies = [ + "futures-core", + "futures-io", + "rustls", + "webpki", + "webpki-roots", +] + +[[package]] +name = "async-tungstenite" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39eca8dd578b18e557361e50ca767df55c5e62f690a5e53868c3c7a8123145b7" +dependencies = [ + "async-tls", + "futures-io", + "futures-util", + "log 0.4.14", + "pin-project", + "tokio 0.3.7", + "tungstenite", +] + [[package]] name = "atomic-waker" version = "1.0.0" @@ -194,12 +242,27 @@ dependencies = [ "byteorder", ] +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + [[package]] name = "blocking" version = "1.0.2" @@ -279,11 +342,13 @@ version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" dependencies = [ + "js-sys", "libc", "num-integer", "num-traits", "serde", "time", + "wasm-bindgen", "winapi 0.3.9", ] @@ -296,6 +361,19 @@ dependencies = [ "bitflags", ] +[[package]] +name = "common-multipart-rfc7578" +version = "0.2.0-rc" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7471b7b1588b2cda44e0cdf3fd3da5706c1b46224dbf486c3daceb6655ec191c" +dependencies = [ + "bytes 0.5.6", + "futures 0.3.15", + "http 0.2.4", + "mime 0.3.16", + "rand 0.5.6", +] + [[package]] name = "concurrent-queue" version = "1.2.2" @@ -349,6 +427,15 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" +[[package]] +name = "cpufeatures" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.2.1" @@ -422,8 +509,59 @@ version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e98e2ad1a782e33928b96fc3948e7c355e5af34ba4de7670fe8bac2a3b2006d" dependencies = [ - "quote", - "syn", + "quote 1.0.9", + "syn 1.0.73", +] + +[[package]] +name = "curl" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "003cb79c1c6d1c93344c7e1201bb51c2148f24ec2bd9c253709d6b2efb796515" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2 0.4.0", + "winapi 0.3.9", +] + +[[package]] +name = "curl-sys" +version = "0.4.45+curl-7.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de9e5a72b1c744eb5dd20b2be4d7eb84625070bb5c4ab9b347b70464ab1e62eb" +dependencies = [ + "cc", + "libc", + "libnghttp2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi 0.3.9", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", ] [[package]] @@ -475,9 +613,9 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", "synstructure", ] @@ -502,6 +640,17 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "flume" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bebadab126f8120d410b677ed95eee4ba6eb7c6dd8e34a5ec88a08050e26132" +dependencies = [ + "futures-core", + "futures-sink", + "spinning_top", +] + [[package]] name = "fnv" version = "1.0.7" @@ -642,9 +791,9 @@ checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" dependencies = [ "autocfg 1.0.1", "proc-macro-hack", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -686,6 +835,27 @@ dependencies = [ "slab", ] +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check 0.9.3", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.3" @@ -694,7 +864,7 @@ checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi", + "wasi 0.10.2+wasi-snapshot-preview1", ] [[package]] @@ -760,6 +930,15 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +[[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" @@ -911,7 +1090,7 @@ version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad5125567a8328ced412a29a52a3ca0a2520c617d40a8bee62d12d877eec236c" dependencies = [ - "base64", + "base64 0.10.1", "bytes 0.4.12", "cfg-if 0.1.9", "http 0.1.21", @@ -956,6 +1135,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "input_buffer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" +dependencies = [ + "bytes 0.5.6", +] + [[package]] name = "instant" version = "0.1.9" @@ -974,6 +1162,31 @@ dependencies = [ "libc", ] +[[package]] +name = "isahc" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2948a0ce43e2c2ef11d7edf6816508998d99e13badd1150be0914205df9388a" +dependencies = [ + "bytes 0.5.6", + "crossbeam-utils 0.8.5", + "curl", + "curl-sys", + "encoding_rs", + "flume", + "futures-lite", + "http 0.2.4", + "log 0.4.14", + "mime 0.3.16", + "once_cell", + "slab", + "sluice", + "tracing", + "tracing-futures", + "url 2.2.2", + "waker-fn", +] + [[package]] name = "itoa" version = "0.4.7" @@ -989,12 +1202,14 @@ dependencies = [ "futures 0.3.15", "futures-timer", "mammut", + "misskey", "rand 0.8.4", "serde", "serde_json", "telegram-bot", "thiserror", "tokio 0.2.25", + "url 2.2.2", "uuid 0.8.2", ] @@ -1040,9 +1255,31 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.97" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" +checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" + +[[package]] +name = "libnghttp2-sys" +version = "0.1.6+1.43.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0af55541a8827e138d59ec9e5877fb6095ece63fb6f4da45e7491b4fbd262855" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "libz-sys" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5435b8549c16d423ed0c03dbaafe57cf6c3344744f1242520d59c9d8ecec66" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] [[package]] name = "lock_api" @@ -1053,6 +1290,15 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "lock_api" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.3.9" @@ -1182,6 +1428,19 @@ dependencies = [ "winapi 0.2.8", ] +[[package]] +name = "mio" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" +dependencies = [ + "libc", + "log 0.4.14", + "miow 0.3.7", + "ntapi", + "winapi 0.3.9", +] + [[package]] name = "mio-named-pipes" version = "0.1.7" @@ -1189,7 +1448,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" dependencies = [ "log 0.4.14", - "mio", + "mio 0.6.23", "miow 0.3.7", "winapi 0.3.9", ] @@ -1202,7 +1461,7 @@ checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" dependencies = [ "iovec", "libc", - "mio", + "mio 0.6.23", ] [[package]] @@ -1226,6 +1485,109 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "misskey" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17e862440df20f3589eb571508176912e06eaca65d6d3edeb14a16b06b17e9f6" +dependencies = [ + "misskey-api", + "misskey-core", + "misskey-http", + "misskey-util", + "misskey-websocket", +] + +[[package]] +name = "misskey-api" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e485eaa858c5a18ae34159d53d9d637c592cd1e91a33736c2df9a93d9f5918e" +dependencies = [ + "chrono", + "mime 0.3.16", + "misskey-core", + "rand_core 0.2.2", + "serde", + "serde_json", + "strum_macros", + "thiserror", + "typed-builder", + "ulid", + "url 2.2.2", +] + +[[package]] +name = "misskey-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4c702e69d3cd5d64cd38d75e62609c89aa3780524b2a4667e45879278cb41af" +dependencies = [ + "futures-core", + "futures-sink", + "mime 0.3.16", + "serde", + "serde_json", +] + +[[package]] +name = "misskey-http" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2af7f2e155120f0bcb6fdf0432dab95e3ffdfddd5cf6bab0080e0fc0c36da3c" +dependencies = [ + "async-dup", + "common-multipart-rfc7578", + "futures 0.3.15", + "isahc", + "mime 0.3.16", + "misskey-core", + "rustc_version", + "serde", + "serde_json", + "thiserror", + "url 2.2.2", +] + +[[package]] +name = "misskey-util" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0015066edfb1aa294eb4b6a45f9cae1da77f7406b664b1f571f1a1abe9df503e" +dependencies = [ + "chrono", + "derivative", + "futures 0.3.15", + "futures-timer", + "mime 0.3.16", + "mime_guess 2.0.3", + "misskey-api", + "misskey-core", + "paste", + "ulid", + "url 2.2.2", +] + +[[package]] +name = "misskey-websocket" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06e3afe06a836a1bbc57ab7102c8d44153275c58fa230a8654cec5b2d9ca5c74" +dependencies = [ + "async-rwlock", + "async-tungstenite", + "chrono", + "futures 0.3.15", + "log 0.4.14", + "misskey-core", + "serde", + "serde_json", + "thiserror", + "tokio 0.3.7", + "url 2.2.2", + "uuid 0.8.2", +] + [[package]] name = "multipart" version = "0.16.1" @@ -1268,6 +1630,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -1312,6 +1683,12 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "openssl" version = "0.10.35" @@ -1366,7 +1743,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ - "lock_api", + "lock_api 0.3.4", "parking_lot_core", "rustc_version", ] @@ -1386,6 +1763,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "paste" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" + [[package]] name = "percent-encoding" version = "1.0.1" @@ -1452,9 +1835,9 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -1512,13 +1895,22 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + [[package]] name = "proc-macro2" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.2", ] [[package]] @@ -1531,13 +1923,35 @@ dependencies = [ "url 2.2.2", ] +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + [[package]] name = "quote" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.27", +] + +[[package]] +name = "rand" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "winapi 0.3.9", ] [[package]] @@ -1559,6 +1973,19 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", +] + [[package]] name = "rand" version = "0.8.4" @@ -1581,6 +2008,16 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + [[package]] name = "rand_chacha" version = "0.3.1" @@ -1591,6 +2028,15 @@ dependencies = [ "rand_core 0.6.3", ] +[[package]] +name = "rand_core" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "rand_core" version = "0.3.1" @@ -1606,13 +2052,22 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + [[package]] name = "rand_core" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom", + "getrandom 0.2.3", ] [[package]] @@ -1624,6 +2079,15 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + [[package]] name = "rand_hc" version = "0.3.1" @@ -1664,6 +2128,7 @@ dependencies = [ "libc", "rand_core 0.4.2", "rdrand", + "wasm-bindgen", "winapi 0.3.9", ] @@ -1725,7 +2190,7 @@ version = "0.9.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f88643aea3c1343c804950d7bf983bd2067f5ab59db6d613a08e05572f2714ab" dependencies = [ - "base64", + "base64 0.10.1", "bytes 0.4.12", "cookie", "cookie_store", @@ -1753,6 +2218,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" @@ -1768,6 +2248,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustls" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81" +dependencies = [ + "base64 0.12.3", + "log 0.4.14", + "ring", + "sct", + "webpki", +] + [[package]] name = "ryu" version = "1.0.5" @@ -1790,6 +2283,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" @@ -1853,9 +2356,9 @@ version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -1881,6 +2384,19 @@ dependencies = [ "url 1.7.2", ] +[[package]] +name = "sha-1" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +dependencies = [ + "block-buffer", + "cfg-if 1.0.0", + "cpufeatures", + "digest", + "opaque-debug", +] + [[package]] name = "signal-hook" version = "0.3.9" @@ -1900,6 +2416,15 @@ dependencies = [ "libc", ] +[[package]] +name = "simple-mutex" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38aabbeafa6f6dead8cebf246fe9fae1f9215c8d29b3a69f93bd62a9e4a3dcd6" +dependencies = [ + "event-listener", +] + [[package]] name = "siphasher" version = "0.2.3" @@ -1912,6 +2437,17 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" +[[package]] +name = "sluice" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7400c0eff44aa2fcb5e31a5f24ba9716ed90138769e4977a2ba6014ae63eb5" +dependencies = [ + "async-channel", + "futures-core", + "futures-io", +] + [[package]] name = "smallvec" version = "0.6.14" @@ -1942,6 +2478,21 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spinning_top" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75adad84ee84b521fb2cca2d4fd0f1dab1d8d026bda3c5bea4ca63b5f9f9293c" +dependencies = [ + "lock_api 0.4.5", +] + [[package]] name = "string" version = "0.2.1" @@ -1951,15 +2502,38 @@ dependencies = [ "bytes 0.4.12", ] +[[package]] +name = "strum_macros" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab9f505ab77221df59d4b5e2b918fdfb43c5f5121987c122c3ba2a3ae4997ced" +dependencies = [ + "heck", + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + [[package]] name = "syn" version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", + "proc-macro2 1.0.27", + "quote 1.0.9", + "unicode-xid 0.2.2", ] [[package]] @@ -1968,10 +2542,10 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", + "unicode-xid 0.2.2", ] [[package]] @@ -2033,9 +2607,9 @@ version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -2071,7 +2645,7 @@ checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" dependencies = [ "bytes 0.4.12", "futures 0.1.31", - "mio", + "mio 0.6.23", "num_cpus", "tokio-current-thread", "tokio-executor", @@ -2095,7 +2669,7 @@ dependencies = [ "lazy_static", "libc", "memchr", - "mio", + "mio 0.6.23", "mio-named-pipes", "mio-uds", "num_cpus", @@ -2106,6 +2680,19 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "tokio" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46409491c9375a693ce7032101970a54f8a2010efb77e13f70788f0d84489e39" +dependencies = [ + "autocfg 1.0.1", + "libc", + "mio 0.7.13", + "pin-project-lite 0.2.7", + "slab", +] + [[package]] name = "tokio-buf" version = "0.1.1" @@ -2154,9 +2741,9 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -2169,7 +2756,7 @@ dependencies = [ "futures 0.1.31", "lazy_static", "log 0.4.14", - "mio", + "mio 0.6.23", "num_cpus", "parking_lot", "slab", @@ -2197,7 +2784,7 @@ dependencies = [ "bytes 0.4.12", "futures 0.1.31", "iovec", - "mio", + "mio 0.6.23", "tokio-io", "tokio-reactor", ] @@ -2280,9 +2867,9 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -2319,6 +2906,54 @@ dependencies = [ "cfg-if 0.1.9", ] +[[package]] +name = "tungstenite" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" +dependencies = [ + "base64 0.12.3", + "byteorder", + "bytes 0.5.6", + "http 0.2.4", + "httparse", + "input_buffer", + "log 0.4.14", + "rand 0.7.3", + "sha-1", + "url 2.2.2", + "utf-8", +] + +[[package]] +name = "typed-builder" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85fc4459191c621a53ef6c6ca5642e6e0e5ccc61f3e5b8ad6b6ab5317f0200fb" +dependencies = [ + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", +] + +[[package]] +name = "typenum" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" + +[[package]] +name = "ulid" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e95a59b292ca0cf9b45be2e52294d1ca6cb24eb11b08ef4376f73f1a00c549" +dependencies = [ + "chrono", + "lazy_static", + "rand 0.6.5", + "serde", +] + [[package]] name = "unicase" version = "1.4.2" @@ -2355,12 +2990,30 @@ dependencies = [ "tinyvec", ] +[[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.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + [[package]] name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "url" version = "1.7.2" @@ -2382,8 +3035,15 @@ dependencies = [ "idna 0.2.3", "matches", "percent-encoding 2.1.0", + "serde", ] +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "uuid" version = "0.7.4" @@ -2399,7 +3059,8 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom", + "getrandom 0.2.3", + "serde", ] [[package]] @@ -2457,6 +3118,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" @@ -2482,9 +3149,9 @@ dependencies = [ "bumpalo", "lazy_static", "log 0.4.14", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", "wasm-bindgen-shared", ] @@ -2506,7 +3173,7 @@ version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" dependencies = [ - "quote", + "quote 1.0.9", "wasm-bindgen-macro-support", ] @@ -2516,9 +3183,9 @@ version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2539,6 +3206,25 @@ dependencies = [ "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.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f20dea7535251981a9670857150d571846545088359b28e4951d350bdaf179f" +dependencies = [ + "webpki", +] + [[package]] name = "wepoll-ffi" version = "0.1.2" diff --git a/Cargo.toml b/Cargo.toml index 22b2295..92f10a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,5 @@ uuid = { version = "0.8.2", features = ["v4"] } anyhow = "1.0.41" mammut = "0.13.0" thiserror = "1.0.26" +misskey = "0.2.0" +url = "2.2.2" diff --git a/src/config.rs b/src/config.rs index 47c2baa..6935bdd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,6 @@ -use std::{error::Error, path::Path}; - +use core::fmt::Debug; use serde::{Deserialize, Serialize}; +use std::{error::Error, path::Path}; use telegram_bot::ChatId; #[derive(Serialize, Deserialize, Debug, Clone)] @@ -10,12 +10,12 @@ pub struct Config { pub temperature: String, pub top_k: String, pub gpt_code_path: String, - pub fediverse_base_url: String, pub interval_seconds: MinMax, pub bot_token: String, pub chat_ref: ChatId, - pub fediverse_token: Option, + pub mastodon_token: Option, pub post_buffer: u32, + pub publisher: Publisher, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -24,6 +24,18 @@ pub struct MinMax { pub max: u64, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub enum Publisher { + Misskey(FediverseConfig), + Mastodon(FediverseConfig>), +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct FediverseConfig { + pub base_url: String, + pub token: T, +} + impl Default for Config { fn default() -> Self { Config { @@ -32,15 +44,18 @@ impl Default for Config { temperature: String::from("1"), top_k: String::from("40"), gpt_code_path: String::from("./gpt/"), - fediverse_base_url: String::from("https://lain.com"), interval_seconds: MinMax { min: 60 * 30, max: 60 * 90, }, post_buffer: 5, - fediverse_token: None, + mastodon_token: None, bot_token: "".to_owned(), chat_ref: ChatId::new(0), + publisher: Publisher::Misskey(FediverseConfig { + base_url: "".to_string(), + token: "".to_string(), + }), } } } diff --git a/src/main.rs b/src/main.rs index 9d2df03..8ae2e4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,11 +10,13 @@ use rand::Rng; use telegram_bot::{Api, ChatId, ChatRef, ToChatRef}; use crate::{ + config::{FediverseConfig, Publisher}, publish::MastodonPublisher, + publish::MisskeyPublisher, selection::{telegram::get_chat_ref, SelectorExt, TelegramSelector}, }; -use futures::{channel::mpsc::channel, sink::unfold, SinkExt, StreamExt, TryStreamExt}; +use futures::{SinkExt, StreamExt, TryStreamExt, channel::mpsc::channel, future::Either, sink::unfold}; use model::SampleModelExt; mod config; @@ -38,34 +40,7 @@ async fn main() -> Result<(), Box> { } }?; - let app = AppBuilder { - client_name: "izzilis", - redirect_uris: "urn:ietf:wg:oauth:2.0:oob", - scopes: Scopes::Write, - website: None, - }; - - let mut registration = Registration::new(cfg.fediverse_base_url.clone()); - registration.register(app)?; - - let mastodon = if let Some(data) = &cfg.fediverse_token { - Mastodon::from_data(data.clone()) - } else { - let url = registration.authorise()?; - println!("{}", url); - - let mut buffer = String::new(); - stdin().read_line(&mut buffer).await?; - - let fedi = registration.create_access_token(buffer)?; - - cfg.fediverse_token = Some(fedi.data.clone()); - cfg.save(CONFIG_PATH)?; - - fedi - }; - - let publisher = MastodonPublisher::new(mastodon); + let publisher = resolve_publisher(&mut cfg).await?; let api = Arc::new(Api::new(cfg.bot_token.clone())); @@ -145,7 +120,7 @@ async fn main() -> Result<(), Box> { }); publisher - .sink_map_err(|e| Box::new(e) as Box) + .sink_map_err(|e| e) .send_all( &mut receiver .then(|item| { @@ -165,3 +140,47 @@ async fn main() -> Result<(), Box> { return Ok(()); } + +async fn resolve_publisher( + config: &mut config::Config, +) -> Result, Box> { + let publisher = match &config.publisher { + config::Publisher::Misskey(cfg) => { + Either::Left(MisskeyPublisher::new(&cfg.base_url, cfg.token.clone())?) + } + config::Publisher::Mastodon(cfg) => { + let app = AppBuilder { + client_name: "izzilis", + redirect_uris: "urn:ietf:wg:oauth:2.0:oob", + scopes: Scopes::Write, + website: None, + }; + + let mut registration = Registration::new(cfg.base_url.clone()); + registration.register(app)?; + + let mastodon = if let Some(data) = cfg.token.clone() { + Mastodon::from_data(data.clone()) + } else { + let url = registration.authorise()?; + println!("{}", url); + + let mut buffer = String::new(); + stdin().read_line(&mut buffer).await?; + + let fedi = registration.create_access_token(buffer)?; + + config.publisher = Publisher::Mastodon(FediverseConfig { + base_url: cfg.base_url.clone(), + token: Some(fedi.data.clone()), + }); + config.save(CONFIG_PATH)?; + + fedi + }; + + Either::Right(MastodonPublisher::new(mastodon)) + } + }; + Ok(publisher) +} diff --git a/src/publish/mastodon.rs b/src/publish/mastodon.rs index 8ccd11c..78d8ba6 100644 --- a/src/publish/mastodon.rs +++ b/src/publish/mastodon.rs @@ -1,7 +1,4 @@ -use std::{ - pin::Pin, - task::{Context, Poll}, -}; +use std::{error::Error, pin::Pin, task::{Context, Poll}}; use futures::Sink; use mammut::{status_builder::Visibility, Mastodon, StatusBuilder}; @@ -17,7 +14,7 @@ impl MastodonPublisher { } impl Sink for MastodonPublisher { - type Error = mammut::Error; + type Error = Box; fn poll_ready(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) diff --git a/src/publish/misskey.rs b/src/publish/misskey.rs new file mode 100644 index 0000000..5e82519 --- /dev/null +++ b/src/publish/misskey.rs @@ -0,0 +1,49 @@ +use futures::Sink; +use misskey::{ClientExt, HttpClient}; +use std::{error::Error, task::Poll}; +use tokio::runtime::Runtime; +use url::Url; + +pub struct MisskeyPublisher { + client: HttpClient, +} + +impl MisskeyPublisher { + pub fn new(url: &String, token: String) -> Result> { + Ok(Self { + client: HttpClient::with_token(Url::parse(url)?, token)?, + }) + } +} + +impl Sink for MisskeyPublisher { + type Error = Box; + + fn poll_ready( + self: std::pin::Pin<&mut Self>, + _: &mut std::task::Context<'_>, + ) -> std::task::Poll> { + Poll::Ready(Ok(())) + } + + fn start_send(self: std::pin::Pin<&mut Self>, item: String) -> Result<(), Self::Error> { + let mut runtime = Runtime::new()?; + let fut = self.client.create_note(item); + runtime.block_on(fut)?; + Ok(()) + } + + fn poll_flush( + self: std::pin::Pin<&mut Self>, + _: &mut std::task::Context<'_>, + ) -> std::task::Poll> { + Poll::Ready(Ok(())) + } + + fn poll_close( + self: std::pin::Pin<&mut Self>, + _: &mut std::task::Context<'_>, + ) -> std::task::Poll> { + Poll::Ready(Ok(())) + } +} diff --git a/src/publish/mod.rs b/src/publish/mod.rs index 6462ab6..ab133e8 100644 --- a/src/publish/mod.rs +++ b/src/publish/mod.rs @@ -1,2 +1,4 @@ mod mastodon; +mod misskey; pub use mastodon::MastodonPublisher; +pub use crate::publish::misskey::MisskeyPublisher;