commit 226f30cefaf3cf608a8453aa5581a33e1d084e82
parent fd46f93434ac266dffbd5d520c811237b040d2a6
Author: tomvig38@gmail.com <tomvig38@gmail.com>
Date: Sat, 16 Oct 2021 14:17:34 +0000
Uzu simplavortao.org por trovi difinojn
Diffstat:
M | Cargo.lock | | | 474 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- |
M | Cargo.toml | | | 4 | +++- |
M | src/main.rs | | | 196 | +++++++++++++++++++++++++++++-------------------------------------------------- |
3 files changed, 429 insertions(+), 245 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -3,48 +3,34 @@
version = 3
[[package]]
-name = "ansi_term"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
-dependencies = [
- "winapi",
-]
-
-[[package]]
-name = "atty"
-version = "0.2.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
-dependencies = [
- "hermit-abi",
- "libc",
- "winapi",
-]
-
-[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
+name = "base64"
+version = "0.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
+
+[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
-name = "bytes"
-version = "1.1.0"
+name = "bumpalo"
+version = "3.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
+checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538"
[[package]]
-name = "cassowary"
-version = "0.3.0"
+name = "bytes"
+version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
+checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]]
name = "cc"
@@ -72,21 +58,6 @@ dependencies = [
]
[[package]]
-name = "clap"
-version = "2.33.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
-dependencies = [
- "ansi_term",
- "atty",
- "bitflags",
- "strsim",
- "textwrap",
- "unicode-width",
- "vec_map",
-]
-
-[[package]]
name = "core-foundation"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -167,6 +138,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
[[package]]
+name = "encoding_rs"
+version = "0.8.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "fnv"
+version = "1.0.7"
+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"
@@ -297,6 +283,31 @@ dependencies = [
]
[[package]]
+name = "h2"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964"
+dependencies = [
+ "bytes",
+ "fnv",
+ "futures-core",
+ "futures-sink",
+ "futures-util",
+ "http",
+ "indexmap",
+ "slab",
+ "tokio",
+ "tokio-util",
+ "tracing",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
+
+[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -306,6 +317,77 @@ dependencies = [
]
[[package]]
+name = "http"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b"
+dependencies = [
+ "bytes",
+ "fnv",
+ "itoa",
+]
+
+[[package]]
+name = "http-body"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5"
+dependencies = [
+ "bytes",
+ "http",
+ "pin-project-lite",
+]
+
+[[package]]
+name = "httparse"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503"
+
+[[package]]
+name = "httpdate"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440"
+
+[[package]]
+name = "hyper"
+version = "0.14.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593"
+dependencies = [
+ "bytes",
+ "futures-channel",
+ "futures-core",
+ "futures-util",
+ "h2",
+ "http",
+ "http-body",
+ "httparse",
+ "httpdate",
+ "itoa",
+ "pin-project-lite",
+ "socket2",
+ "tokio",
+ "tower-service",
+ "tracing",
+ "want",
+]
+
+[[package]]
+name = "hyper-tls"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
+dependencies = [
+ "bytes",
+ "hyper",
+ "native-tls",
+ "tokio",
+ "tokio-native-tls",
+]
+
+[[package]]
name = "idna"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -317,6 +399,16 @@ dependencies = [
]
[[package]]
+name = "indexmap"
+version = "1.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
+dependencies = [
+ "autocfg",
+ "hashbrown",
+]
+
+[[package]]
name = "instant"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -326,6 +418,12 @@ dependencies = [
]
[[package]]
+name = "ipnet"
+version = "2.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9"
+
+[[package]]
name = "irc"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -363,6 +461,21 @@ dependencies = [
]
[[package]]
+name = "itoa"
+version = "0.4.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
+
+[[package]]
+name = "js-sys"
+version = "0.3.55"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84"
+dependencies = [
+ "wasm-bindgen",
+]
+
+[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -405,6 +518,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
+name = "mime"
+version = "0.3.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
+
+[[package]]
name = "mio"
version = "0.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -483,12 +602,6 @@ dependencies = [
]
[[package]]
-name = "numtoa"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
-
-[[package]]
name = "once_cell"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -673,19 +786,6 @@ dependencies = [
]
[[package]]
-name = "redict"
-version = "0.2.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca9b15e4b237970337364ecc2db851197cd7e624e0185e417dcc4265825b049d"
-dependencies = [
- "clap",
- "termion",
- "tui",
- "unicode-segmentation",
- "url",
-]
-
-[[package]]
name = "redox_syscall"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -695,24 +795,56 @@ dependencies = [
]
[[package]]
-name = "redox_termios"
-version = "0.1.2"
+name = "remove_dir_all"
+version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
+checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
- "redox_syscall",
+ "winapi",
]
[[package]]
-name = "remove_dir_all"
-version = "0.5.3"
+name = "reqwest"
+version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
+checksum = "51c732d463dd300362ffb44b7b125f299c23d2990411a4253824630ebc7467fb"
dependencies = [
- "winapi",
+ "base64",
+ "bytes",
+ "encoding_rs",
+ "futures-core",
+ "futures-util",
+ "http",
+ "http-body",
+ "hyper",
+ "hyper-tls",
+ "ipnet",
+ "js-sys",
+ "lazy_static",
+ "log",
+ "mime",
+ "native-tls",
+ "percent-encoding",
+ "pin-project-lite",
+ "serde",
+ "serde_json",
+ "serde_urlencoded",
+ "tokio",
+ "tokio-native-tls",
+ "url",
+ "wasm-bindgen",
+ "wasm-bindgen-futures",
+ "web-sys",
+ "winreg",
]
[[package]]
+name = "ryu"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
+
+[[package]]
name = "schannel"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -772,6 +904,29 @@ dependencies = [
]
[[package]]
+name = "serde_json"
+version = "1.0.68"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8"
+dependencies = [
+ "itoa",
+ "ryu",
+ "serde",
+]
+
+[[package]]
+name = "serde_urlencoded"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9"
+dependencies = [
+ "form_urlencoded",
+ "itoa",
+ "ryu",
+ "serde",
+]
+
+[[package]]
name = "signal-hook-registry"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -793,10 +948,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
[[package]]
-name = "strsim"
-version = "0.8.0"
+name = "socket2"
+version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
+checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516"
+dependencies = [
+ "libc",
+ "winapi",
+]
[[package]]
name = "syn"
@@ -824,27 +983,6 @@ dependencies = [
]
[[package]]
-name = "termion"
-version = "1.5.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
-dependencies = [
- "libc",
- "numtoa",
- "redox_syscall",
- "redox_termios",
-]
-
-[[package]]
-name = "textwrap"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
-dependencies = [
- "unicode-width",
-]
-
-[[package]]
name = "thiserror"
version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -965,19 +1103,38 @@ dependencies = [
]
[[package]]
-name = "tui"
-version = "0.16.0"
+name = "tower-service"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
+
+[[package]]
+name = "tracing"
+version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "39c8ce4e27049eed97cfa363a5048b09d995e209994634a0efc26a14ab6c0c23"
+checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
dependencies = [
- "bitflags",
- "cassowary",
- "termion",
- "unicode-segmentation",
- "unicode-width",
+ "cfg-if",
+ "pin-project-lite",
+ "tracing-core",
+]
+
+[[package]]
+name = "tracing-core"
+version = "0.1.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4"
+dependencies = [
+ "lazy_static",
]
[[package]]
+name = "try-lock"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
+
+[[package]]
name = "unicode-bidi"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -993,18 +1150,6 @@ dependencies = [
]
[[package]]
-name = "unicode-segmentation"
-version = "1.8.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
-
-[[package]]
-name = "unicode-width"
-version = "0.1.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
-
-[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1029,28 +1174,110 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
-name = "vec_map"
-version = "0.8.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
-
-[[package]]
name = "vortaroboto"
version = "0.1.0"
dependencies = [
"futures",
"irc",
- "redict",
+ "reqwest",
+ "serde",
+ "serde_json",
"tokio",
]
[[package]]
+name = "want"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0"
+dependencies = [
+ "log",
+ "try-lock",
+]
+
+[[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"
+checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce"
+dependencies = [
+ "cfg-if",
+ "wasm-bindgen-macro",
+]
+
+[[package]]
+name = "wasm-bindgen-backend"
+version = "0.2.78"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b"
+dependencies = [
+ "bumpalo",
+ "lazy_static",
+ "log",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-futures"
+version = "0.4.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39"
+dependencies = [
+ "cfg-if",
+ "js-sys",
+ "wasm-bindgen",
+ "web-sys",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.78"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.78"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-backend",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.78"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc"
+
+[[package]]
+name = "web-sys"
+version = "0.3.55"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb"
+dependencies = [
+ "js-sys",
+ "wasm-bindgen",
+]
+
+[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1071,3 +1298,12 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
+[[package]]
+name = "winreg"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69"
+dependencies = [
+ "winapi",
+]
diff --git a/Cargo.toml b/Cargo.toml
@@ -9,4 +9,6 @@ edition = "2018"
irc = "0.15.0"
tokio = { version = "1.12.0", features = ["full"] }
futures = "0.3.17"
-redict = { version = "0.2.3", features = [] }
+reqwest = { version = "0.11", features = ["json"] }
+serde = { version = "1.0", features = ["derive"] }
+serde_json = "1.0.68"
diff --git a/src/main.rs b/src/main.rs
@@ -1,10 +1,57 @@
use futures::prelude::*;
use irc::client::prelude::*;
-
-use dictproto::connection::DICTConnection;
-use dictproto::Database;
+use serde::{Deserialize, Serialize};
const NICK: &'static str = "vortaroboto";
+const TROVI_URL: &'static str = "http://www.simplavortaro.org/api/v1/trovi";
+const VORTO_URL: &'static str = "http://www.simplavortaro.org/api/v1/vorto";
+
+#[derive(Deserialize, Debug)]
+struct Vortpartoj {
+ vorto: Option<String>,
+ parto: String,
+}
+
+#[derive(Deserialize, Debug)]
+struct Vortfarado {
+ partoj: Vec<Vortpartoj>,
+ rezulto: String,
+}
+
+#[derive(Deserialize, Debug)]
+struct Traduko {
+ kodo: String,
+ vorto: Option<String>,
+ lingvo: String,
+ traduko: String,
+}
+
+#[derive(Deserialize, Debug)]
+struct Trovo {
+ malpreciza: Vec<String>,
+ vortfarade: Vortfarado,
+ preciza: Vec<String>,
+ tradukoj: Vec<Traduko>,
+}
+
+#[derive(Deserialize, Debug)]
+struct Ekzemplo {
+ ekzemplo: String,
+ fonto: Option<String>,
+}
+
+#[derive(Deserialize, Debug)]
+struct Difino {
+ difino: String,
+ ekzemploj: Vec<Ekzemplo>,
+ tradukoj: Vec<Traduko>,
+}
+
+#[derive(Deserialize, Debug)]
+struct Vorto {
+ difinoj: Vec<Difino>,
+ vorto: String,
+}
#[tokio::main]
async fn main() -> irc::error::Result<()> {
@@ -22,8 +69,6 @@ async fn main() -> irc::error::Result<()> {
let sender = client.sender();
while let Some(message) = stream.next().await.transpose()? {
- print!("{}", message);
-
match message.command {
Command::PRIVMSG(ref target, ref msg) => {
if msg.contains(client.current_nickname()) {
@@ -33,8 +78,12 @@ async fn main() -> irc::error::Result<()> {
))?;
}
if let Some(cmd) = msg.strip_prefix('!') {
- if let Some(answer) = handle_command(cmd) {
- sender.send_privmsg(target, answer)?;
+ if let Some(answer) = handle_command(cmd).await {
+ let r = match (target.starts_with('#'), message.source_nickname()) {
+ (true, Some(n)) => format!("{}: {}", n, answer),
+ _ => answer
+ };
+ sender.send_privmsg(target, r)?;
}
}
}
@@ -45,7 +94,7 @@ async fn main() -> irc::error::Result<()> {
Ok(())
}
-fn handle_command(cmd: &str) -> Option<String> {
+async fn handle_command(cmd: &str) -> Option<String> {
let mut splitted = cmd.split_ascii_whitespace();
match splitted.next() {
Some("helpu") => Some(String::from(
@@ -56,7 +105,10 @@ fn handle_command(cmd: &str) -> Option<String> {
)),
Some("difini" | "d") => {
if let Some(w) = splitted.next() {
- define_word(w).or(Some(format!("Nenio trovata pri: {}", w)))
+ match define_word(w).await {
+ Ok(r) => Some(r),
+ Err(e) => Some(format!("Nenio trovata pri: {} ({})", w, e.to_string())),
+ }
} else {
Some(String::from("Uzo: difini [vorto]"))
}
@@ -66,123 +118,17 @@ fn handle_command(cmd: &str) -> Option<String> {
}
}
-#[derive(Debug)]
-struct Traduction(String, String);
-
-#[derive(Debug)]
-struct ParsedDefinition {
- radical: String,
- definitions: Vec<String>,
- traductions: Vec<Traduction>,
-}
-
-impl ParsedDefinition {
- // FARU: revenigi Result<Self>, por erar'traktado
- pub fn new(lines: &Vec<String>) -> Option<Self> {
-
- if lines.len() < 3 {
- return None;
- }
- let mut in_definition = false;
- let mut in_traduction = false;
-
- let radical = lines[1].to_owned();
- let mut definitions = Vec::new();
- let mut traductions = Vec::new();
-
- let mut cur_def = String::new();
- let mut cur_tra = String::new();
- let mut cur_tra_lang = String::new();
-
- fn is_digit(c: Option<char>) -> bool {
- if let Some(c) = c {
- c.is_digit(10)
- } else {
- false
- }
- }
-
- fn is_lower(c: Option<char>) -> bool {
- if let Some(c) = c {
- c.is_lowercase() && c.is_alphabetic()
- } else {
- false
- }
- }
-
- for l in lines[3..].iter() {
- println!("{:?}, {:?}, {:?}", l.trim(), in_definition, in_traduction);
- match (l.trim(), in_definition, in_traduction) {
- ("", true, _) => {
- in_definition = false;
- definitions.push(cur_def.clone());
- cur_def.clear();
- }
- ("", _, false) => {
- in_traduction = false;
- traductions.push(Traduction(cur_tra_lang, cur_tra.clone()));
- cur_tra_lang = String::new();
- cur_tra.clear();
- }
-
- ("(tr)", _, _) => {}
- (s, false, false) if is_lower(s.chars().next()) => {
- cur_tra_lang = s.to_owned();
- in_traduction = true;
- }
- (s, false, false) if is_digit(s.chars().next()) && s.ends_with('.') => {
- in_definition = true;
- }
- (s, false, false) if definitions.is_empty() => {
- in_definition = true;
- cur_def.push_str(s)
- }
-
- (_, false, false) => {}
- (s, true, false) => {
- cur_def.push_str(s);
- }
-
- (s, false, true) => {
- cur_tra.push_str(s);
- }
-
- (_, true, true) => unreachable!(),
- }
- }
-
- if in_definition {
- definitions.push(cur_def);
- } else if in_traduction {
- traductions.push(Traduction(cur_tra_lang, cur_tra));
- }
-
- Some(ParsedDefinition {
- radical,
- definitions,
- traductions,
- })
- }
-}
+async fn define_word(word: &str) -> Result<String, String> {
+ let res = reqwest::get(format!("{}/{}", VORTO_URL, word))
+ .await
+ .map_err(|e| e.to_string())?
+ .json::<Vorto>()
+ .await
+ .map_err(|e| e.to_string())?;
-fn define_word(word: &str) -> Option<String> {
- let tcp = std::net::TcpStream::connect("192.168.1.45:2628").ok()?;
- let mut conn = DICTConnection::new(tcp).ok()?;
- conn.start().ok()?;
- conn.client(String::from(NICK)).ok()?;
-
- if let Ok((defs, _)) = conn.define(
- Database {
- name: String::from("revo_eo"),
- ..Database::default()
- },
- word.to_owned(),
- ) {
- let t = defs.get(0)?;
- let d = ParsedDefinition::new(&t.text)?;
- println!("{:?}", d);
- Some(String::from(d.definitions.get(0)?))
+ if let Some(d) = res.difinoj.get(0) {
+ Ok(format!("{}: {}", word, d.difino))
} else {
- None
+ Err(format!("{} ne havas difino.", word))
}
}