vortaroboto

Log | Files | Refs | README

commit e8c546019315613e2da4c50274ea6d03c45fa2ec
parent 606c0aa70c46d415b5009ac907d11a8445632cc2
Author: tomvig38@gmail.com <tomvig38@gmail.com>
Date:   Mon, 18 Oct 2021 13:24:00 +0000

Poviĝu doni la vortfarado numero
Diffstat:
MCargo.lock | 323++++++++++++++++++++++---------------------------------------------------------
MCargo.toml | 4++--
Msrc/main.rs | 41++++++++++++++++++++++++++++-------------
3 files changed, 120 insertions(+), 248 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -58,22 +58,6 @@ dependencies = [ ] [[package]] -name = "core-foundation" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" - -[[package]] name = "encoding" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -153,21 +137,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] name = "form_urlencoded" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -272,17 +241,6 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -375,16 +333,18 @@ dependencies = [ ] [[package]] -name = "hyper-tls" -version = "0.5.0" +name = "hyper-rustls" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" dependencies = [ - "bytes", + "futures-util", "hyper", - "native-tls", + "log", + "rustls", "tokio", - "tokio-native-tls", + "tokio-rustls", + "webpki", ] [[package]] @@ -434,17 +394,14 @@ dependencies = [ "futures-util", "irc-proto", "log", - "native-tls", "parking_lot", "pin-project", - "serde", - "serde_derive", "thiserror", "tokio", - "tokio-native-tls", + "tokio-rustls", "tokio-stream", "tokio-util", - "toml", + "webpki-roots 0.20.0", ] [[package]] @@ -546,24 +503,6 @@ dependencies = [ ] [[package]] -name = "native-tls" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - -[[package]] name = "ntapi" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -608,39 +547,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] -name = "openssl" -version = "0.10.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-sys", -] - -[[package]] -name = "openssl-probe" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" - -[[package]] -name = "openssl-sys" -version = "0.9.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] name = "parking_lot" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -704,18 +610,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "pkg-config" -version = "0.3.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" - -[[package]] -name = "ppv-lite86" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" - -[[package]] name = "proc-macro-hack" version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -746,46 +640,6 @@ 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" @@ -795,15 +649,6 @@ dependencies = [ ] [[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" @@ -817,70 +662,76 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-tls", + "hyper-rustls", "ipnet", "js-sys", "lazy_static", "log", "mime", - "native-tls", "percent-encoding", "pin-project-lite", + "rustls", "serde", "serde_json", "serde_urlencoded", "tokio", - "tokio-native-tls", + "tokio-rustls", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots 0.21.1", "winreg", ] [[package]] -name = "ryu" -version = "1.0.5" +name = "ring" +version = "0.16.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] [[package]] -name = "schannel" -version = "0.1.19" +name = "rustls" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ - "lazy_static", - "winapi", + "base64", + "log", + "ring", + "sct", + "webpki", ] [[package]] -name = "scopeguard" -version = "1.1.0" +name = "ryu" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] -name = "security-framework" -version = "2.4.2" +name = "scopeguard" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] -name = "security-framework-sys" -version = "2.4.2" +name = "sct" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" dependencies = [ - "core-foundation-sys", - "libc", + "ring", + "untrusted", ] [[package]] @@ -958,6 +809,12 @@ dependencies = [ ] [[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] name = "syn" version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -969,20 +826,6 @@ 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" @@ -1059,13 +902,14 @@ dependencies = [ ] [[package]] -name = "tokio-native-tls" -version = "0.3.0" +name = "tokio-rustls" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" dependencies = [ - "native-tls", + "rustls", "tokio", + "webpki", ] [[package]] @@ -1094,15 +938,6 @@ dependencies = [ ] [[package]] -name = "toml" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" -dependencies = [ - "serde", -] - -[[package]] name = "tower-service" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1156,6 +991,12 @@ 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 = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1168,12 +1009,6 @@ dependencies = [ ] [[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - -[[package]] name = "vortaroboto" version = "0.1.0" dependencies = [ @@ -1196,12 +1031,6 @@ 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" @@ -1278,6 +1107,34 @@ dependencies = [ ] [[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 = "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.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -6,9 +6,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -irc = "0.15.0" +irc = { version = "0.15.0", default-features = false, features = ["tls-rust", "ctcp"] } tokio = { version = "1.12.0", features = ["full"] } futures = "0.3.17" -reqwest = { version = "0.11", features = ["json"] } +reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.68" diff --git a/src/main.rs b/src/main.rs @@ -73,7 +73,7 @@ async fn main() -> irc::error::Result<()> { nickname: Some(NICK.to_owned()), server: Some("irc.libera.chat".to_owned()), channels: vec!["##esperanto".to_owned()], - ..Default::default() + ..Config::default() }; let mut client = Client::from_config(config).await?; @@ -112,11 +112,7 @@ async fn handle_command(cmd: &str) -> Option<String> { let mut splitted = cmd.split_ascii_whitespace(); match splitted.next() { Some("helpu") => Some(String::from( - r#" - helpu: montri ĉi tio mesaĝo - difinu [vorto] [numero]: difini [vorto], uzas la ebla [numero] - traduku [vorto] [lingvo]: traduko [vorto] al la (ebla) [lingvo] - "#, + "helpu: montri ĉi tio mesaĝo\r\ndifinu [vorto] [numero]: difini [vorto], uzas la ebla [numero]\r\ntraduku [vorto] [lingvo]: traduko [vorto] al la (ebla) [lingvo]\r\nvortfarado [vorto] [numero]: Donu la vortfarado [numero] por [vorto]", )), Some("difinu" | "d") => { if let Some(w) = splitted.next() { @@ -145,7 +141,12 @@ async fn handle_command(cmd: &str) -> Option<String> { } Some("vortfarado" | "v" | "vf") => { if let Some(w) = splitted.next() { - match vortfarado(w).await { + let index = if let Some(s) = splitted.next() { + s.parse::<usize>().ok() + } else { + None + }; + match vortfarado(w, index).await { Ok(r) => Some(r), Err(e) => Some(format!("Nenio trovata pri: {} ({})", w, e.to_string())), } @@ -153,7 +154,7 @@ async fn handle_command(cmd: &str) -> Option<String> { Some(String::from("Uzo: vortfarado [vorto]")) } } - Some(u) => Some(format!("Mi ne scias kio respondi al: {}", u)), + Some(u) => Some(format!("Mi ne scias kiel respondi al: {}", u)), None => None, } } @@ -165,7 +166,15 @@ async fn define_word(vorto: &str, difino: Option<usize>) -> Result<String, Strin return Err(format!("{} ne havas difino.", vorto)); } - let index = difino.unwrap_or(0).clamp(0, res.difinoj.len()); + if res.difinoj.len() == 1 { + if let Some(d) = res.difinoj.get(0) { + return Ok(format!("Nura difino por {}: {}", vorto, d.difino)); + } else { + unreachable!(); + } + } + + let index = difino.unwrap_or(1).clamp(1, res.difinoj.len()) - 1; if let Some(d) = res.difinoj.get(index) { Ok(format!( "Difino {} el {} por {}: {}", @@ -216,12 +225,18 @@ async fn traduki(vorto: &str, fonto: Option<&str>) -> Result<String, String> { Ok(tradukoj.join("\r\n")) } -async fn vortfarado(vorto: &str) -> Result<String, String> { +async fn vortfarado(vorto: &str, index: Option<usize>) -> Result<String, String> { let res: Trovo = difinu(vorto).await?; let vf = res.vortfarado; - if let Some(v) = vf.get(0) { + if vf.is_empty() { + return Err(format!("{} ne havas vort'faradon.", vorto)); + } + + let index = index.unwrap_or(1).clamp(1, vf.len()) - 1; + + if let Some(v) = vf.get(index) { let v = v .partoj .iter() @@ -235,8 +250,8 @@ async fn vortfarado(vorto: &str) -> Result<String, String> { .collect::<Vec<String>>() .join(" + "); - Ok(v) + Ok(format!("Vortfarado {} el {} por \"{}\":\r\n{}", index, vf.len(), vorto, v)) } else { - Err(format!("{} ne havas vort'faradon.", vorto)) + unreachable!(); } }