From 28c6c15a8f996372ea0fdb0278c3c5ea708a2235 Mon Sep 17 00:00:00 2001 From: Sokhibjon Orzikulov Date: Wed, 26 Jun 2024 01:28:12 +0500 Subject: [PATCH] mvp inline --- Cargo.lock | 496 ++++++++++++++++++++++++-- bots/xinuxmgr/Cargo.toml | 3 +- bots/xinuxmgr/src/functions/inline.rs | 157 ++++++++ bots/xinuxmgr/src/functions/mod.rs | 3 + bots/xinuxmgr/src/lib.rs | 2 + bots/xinuxmgr/src/main.rs | 4 +- bots/xinuxmgr/src/utils/inlines.rs | 82 +++++ bots/xinuxmgr/src/utils/mod.rs | 1 + 8 files changed, 711 insertions(+), 37 deletions(-) create mode 100644 bots/xinuxmgr/src/functions/inline.rs create mode 100644 bots/xinuxmgr/src/utils/inlines.rs diff --git a/Cargo.lock b/Cargo.lock index 708d0fd..6aa222b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "aquamarine" version = "0.1.12" @@ -50,6 +65,12 @@ dependencies = [ "syn 2.0.49", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.1.0" @@ -67,9 +88,9 @@ dependencies = [ "bitflags 1.3.2", "bytes", "futures-util", - "http", - "http-body", - "hyper", + "http 0.2.11", + "http-body 0.4.6", + "hyper 0.14.28", "itoa", "matchit", "memchr", @@ -81,7 +102,7 @@ dependencies = [ "serde_json", "serde_path_to_error", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 0.1.2", "tokio", "tower", "tower-layer", @@ -97,8 +118,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 0.2.11", + "http-body 0.4.6", "mime", "rustversion", "tower-layer", @@ -126,6 +147,12 @@ version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "1.3.2" @@ -167,11 +194,17 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", "num-traits", + "serde", + "wasm-bindgen", + "windows-targets 0.52.0", ] [[package]] @@ -432,6 +465,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fuzzy-matcher" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94" +dependencies = [ + "thread_local", +] + [[package]] name = "getrandom" version = "0.2.11" @@ -460,7 +502,26 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.11", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http 1.1.0", "indexmap", "slab", "tokio", @@ -497,6 +558,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -504,7 +576,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.11", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -542,9 +637,9 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.3.22", + "http 0.2.11", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -556,6 +651,43 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.5", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +dependencies = [ + "futures-util", + "http 1.1.0", + "hyper 1.3.1", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -563,12 +695,71 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper", + "hyper 0.14.28", "native-tls", "tokio", "tokio-native-tls", ] +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper 1.3.1", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.3.1", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -587,9 +778,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown", @@ -648,12 +839,37 @@ version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +[[package]] +name = "libxinux" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c1190002555c6dd2abe72f281e4f8c531d7b5d03785740f6d3b44befb75f565" +dependencies = [ + "chrono", + "fuzzy-matcher", + "reqwest 0.12.5", + "serde", + "serde_json", + "tokio", + "url", +] + [[package]] name = "linux-raw-sys" version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.20" @@ -812,9 +1028,9 @@ dependencies = [ [[package]] name = "orzklv" -version = "0.0.5" +version = "0.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e7ac91fca278079a384bc3a430672e1cc7e6cd750d60b908ac6c8995f30da7d" +checksum = "4238952fc4c59e01c1225011218f494603d73b66c757c4f3973839cc4410bd3e" dependencies = [ "async-trait", "teloxide", @@ -822,6 +1038,29 @@ dependencies = [ "url", ] +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.2", + "smallvec", + "windows-targets 0.52.0", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -972,6 +1211,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +dependencies = [ + "bitflags 2.4.1", +] + [[package]] name = "regex" version = "1.10.2" @@ -1007,16 +1255,16 @@ version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ - "base64", + "base64 0.21.5", "bytes", "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-tls", + "h2 0.3.22", + "http 0.2.11", + "http-body 0.4.6", + "hyper 0.14.28", + "hyper-tls 0.5.0", "ipnet", "js-sys", "log", @@ -1039,7 +1287,66 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", - "winreg", + "winreg 0.50.0", +] + +[[package]] +name = "reqwest" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +dependencies = [ + "base64 0.22.1", + "bytes", + "encoding_rs", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.4.5", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.3.1", + "hyper-rustls", + "hyper-tls 0.6.0", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.1", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg 0.52.0", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", ] [[package]] @@ -1070,6 +1377,46 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.23.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" +dependencies = [ + "base64 0.22.1", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" + +[[package]] +name = "rustls-webpki" +version = "0.102.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -1128,18 +1475,18 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", @@ -1148,10 +1495,11 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" dependencies = [ + "indexmap", "itoa", "ryu", "serde", @@ -1209,6 +1557,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + [[package]] name = "socket2" version = "0.5.5" @@ -1219,12 +1573,24 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "strsim" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "1.0.109" @@ -1253,6 +1619,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "system-configuration" version = "0.5.1" @@ -1334,7 +1706,7 @@ dependencies = [ "once_cell", "pin-project", "rc-box", - "reqwest", + "reqwest 0.11.23", "serde", "serde_json", "serde_with_macros", @@ -1367,7 +1739,7 @@ checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", + "redox_syscall 0.4.1", "rustix", "windows-sys 0.52.0", ] @@ -1401,6 +1773,16 @@ dependencies = [ "syn 2.0.49", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -1427,6 +1809,7 @@ dependencies = [ "libc", "mio", "num_cpus", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -1455,6 +1838,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.14" @@ -1506,8 +1900,8 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http", - "http-body", + "http 0.2.11", + "http-body 0.4.6", "http-range-header", "pin-project-lite", "tower-layer", @@ -1583,6 +1977,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.0" @@ -1751,6 +2151,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -1893,10 +2302,21 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winreg" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "xinuxmgr" version = "0.1.0" dependencies = [ + "libxinux", "log", "orzklv", "pretty_env_logger", @@ -1907,3 +2327,9 @@ dependencies = [ "url", "uuid", ] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/bots/xinuxmgr/Cargo.toml b/bots/xinuxmgr/Cargo.toml index c642da9..091e9b0 100644 --- a/bots/xinuxmgr/Cargo.toml +++ b/bots/xinuxmgr/Cargo.toml @@ -14,4 +14,5 @@ url = "2.4.1" uuid = { version = "1.5.0", features = ["v4"] } serde_json = "1.0.108" serde = { version = "1.0.192", features = ["derive"] } -orzklv = { version = "0.0.5", features = ["full"] } \ No newline at end of file +orzklv = { version = "0.0.8", features = ["full"] } +libxinux = { version = "0.2.3", features = ["pkgs-async"] } diff --git a/bots/xinuxmgr/src/functions/inline.rs b/bots/xinuxmgr/src/functions/inline.rs new file mode 100644 index 0000000..514497d --- /dev/null +++ b/bots/xinuxmgr/src/functions/inline.rs @@ -0,0 +1,157 @@ +use crate::utils::inlines::*; +use libxinux::pkgs::any::{Any as Pkgs, Data}; +use std::error::Error; +use teloxide::{prelude::*, types::*}; + +pub async fn inline( + bot: Bot, + pkgs: Pkgs, + q: InlineQuery, +) -> Result<(), Box> { + let parsed: String = q.query.clone(); + + let parsed = parsed.split_whitespace().collect::>(); + + match parsed.len() { + 0 => { + return { + bot.answer_inline_query( + q.id, + vec![InlineQueryResultArticle::new( + "101", + "Qidirishni boshlang!", + InputMessageContent::Text( + InputMessageContentText::new(NO_INPUT) + .parse_mode(ParseMode::Html) + .disable_web_page_preview(true), + ), + ) + .reply_markup(err_keyboard()) + .into()], + ) + .await?; + Ok(()) + }; + } + 1 => { + return { + bot.answer_inline_query( + q.id, + vec![InlineQueryResultArticle::new( + "102", + "Parametrlar yetarli emas!", + InputMessageContent::Text( + InputMessageContentText::new(NOT_ENOUGH) + .parse_mode(ParseMode::Html) + .disable_web_page_preview(true), + ), + ) + .reply_markup(err_keyboard()) + .into()], + ) + .await?; + Ok(()) + }; + } + 2 => {} + 3.. => { + return { + bot.answer_inline_query( + q.id, + vec![InlineQueryResultArticle::new( + "103", + "Parametrlar haddan ko'p!", + InputMessageContent::Text( + InputMessageContentText::new(TOO_MANY) + .parse_mode(ParseMode::Html) + .disable_web_page_preview(true), + ), + ) + .reply_markup(err_keyboard()) + .into()], + ) + .await?; + Ok(()) + }; + } + } + + let request = pkgs.search(parsed[1]).await; + + println!("{:?}", request); + + let request: Vec = match request { + Ok(v) => v, + Err(_) => { + return { + bot.answer_inline_query( + q.id, + vec![InlineQueryResultArticle::new( + "500", + "Xatolik yuz berdi!", + InputMessageContent::Text( + InputMessageContentText::new( + format!("API dan ma'lumot olishda xatolik yuz berdi!\nIltimos, qayta yoki keyinroq urinib ko'ring!") + ) + .parse_mode(ParseMode::Html) + .disable_web_page_preview(true), + ), + ) + .reply_markup(err_keyboard()) + .into()], + ) + .await?; + Ok(()) + }; + } + }; + + // get only 50 results + let request: Vec<&Data> = request.iter().take(49).collect(); + + if request.is_empty() { + return { + bot.answer_inline_query( + q.id, + vec![InlineQueryResultArticle::new( + "404", + "Couldn't find!", + InputMessageContent::Text( + InputMessageContentText::new( + format!("There are no results related to {}!\nPlease, Try to search with other names or parameters!", + q.query.clone()) + ) + .parse_mode(ParseMode::Html) + .disable_web_page_preview(true), + ), + ) + .reply_markup(err_keyboard()) + .into()], + ) + .await?; + Ok(()) + }; + } + + let request: Vec = request + .iter() + .map(|d: &&Data| { + InlineQueryResult::Article( + InlineQueryResultArticle::new( + uuid::Uuid::new_v4(), + d.name.clone(), + InputMessageContent::Text( + InputMessageContentText::new(view_generate(d)) + .parse_mode(ParseMode::Html) + .disable_web_page_preview(true), + ), + ) + .description(d.description.clone().unwrap()) + .reply_markup(kb_generate(d)), + ) + }) + .collect(); + + bot.answer_inline_query(q.id, request).send().await?; + Ok(()) +} diff --git a/bots/xinuxmgr/src/functions/mod.rs b/bots/xinuxmgr/src/functions/mod.rs index acd5e83..22f2257 100644 --- a/bots/xinuxmgr/src/functions/mod.rs +++ b/bots/xinuxmgr/src/functions/mod.rs @@ -1,11 +1,14 @@ pub mod about; pub mod check; pub mod help; +pub mod inline; pub mod joined; pub mod rules; pub mod start; pub mod warn; +pub use inline::inline; + use crate::utils::topics::Topics; use crate::Command; use std::error::Error; diff --git a/bots/xinuxmgr/src/lib.rs b/bots/xinuxmgr/src/lib.rs index 28abace..d982ff4 100644 --- a/bots/xinuxmgr/src/lib.rs +++ b/bots/xinuxmgr/src/lib.rs @@ -35,6 +35,8 @@ pub enum Command { pub fn handler() -> UpdateHandler> { dptree::entry() + // Inline + .branch(Update::filter_inline_query().endpoint(functions::inline)) // Callbacks .branch(Update::filter_callback_query().endpoint(functions::callback)) // Commands diff --git a/bots/xinuxmgr/src/main.rs b/bots/xinuxmgr/src/main.rs index a3578fa..6fe9ca5 100644 --- a/bots/xinuxmgr/src/main.rs +++ b/bots/xinuxmgr/src/main.rs @@ -1,3 +1,4 @@ +use libxinux::pkgs::any::Any as Pkgs; use std::error::Error; use teloxide::{prelude::*, update_listeners::webhooks}; use xinuxmgr::utils::topics::Topics; @@ -10,10 +11,11 @@ async fn main() -> Result<(), Box> { let bot = Bot::from_env(); let topics = Topics::new(); + let pkgs = Pkgs::new().unwrap(); // Dispatcher flow control let mut dispatcher = Dispatcher::builder(bot.clone(), handler()) - .dependencies(dptree::deps![topics]) + .dependencies(dptree::deps![topics, pkgs]) // If no handler succeeded to handle an update, this closure will be called .default_handler(|upd| async move { log::warn!("Unhandled update: {:?}", upd); diff --git a/bots/xinuxmgr/src/utils/inlines.rs b/bots/xinuxmgr/src/utils/inlines.rs new file mode 100644 index 0000000..f4a00eb --- /dev/null +++ b/bots/xinuxmgr/src/utils/inlines.rs @@ -0,0 +1,82 @@ +use libxinux::pkgs::any::{Data, Type}; +use orzklv::telegram::keyboard::Keyboard; +use teloxide::types::*; + +pub static NO_INPUT: &str = r#" +Salom foydalanuvchi! + +Siz hozir inlayn rejim ishga tushurdingiz. Bu xususiyat yordamida siz Arch Linux yoki NixOS paketlarini qidirishingiz va chatda ulashishingiz mumkin. Qidirishni boshlash uchun, quyida keltirilgan misol tariqasida yozing: + +@xinuxmgr <distributiv> <nomi> +"#; + +pub static NOT_ENOUGH: &str = r#" +Foydalanuvchi, siz yetarlicha parametrlar kiritmadingiz! + +Iltimos, quyidagi parametrlarni kiriting: +<distributiv> <paket nomi> +"#; + +pub static TOO_MANY: &str = r#" +Foydalanuvchi, siz keraklidan ko'p parametrlar kiritdingiz! +"#; + +pub fn view_generate(d: &Data) -> String { + let d = d.clone(); + let mut result = String::new(); + + result.push_str(&format!("Nomi: {}\n", d.name)); + + result.push_str(&format!("Versiyasi: {}\n", d.version)); + + result.push_str(&format!( + "Ma'lutot: {}\n", + d.description.unwrap_or("Ma'lumot yo'q".to_string()) + )); + + if d.repo.is_some() { + result.push_str(&format!( + "Repozitoriya: {}\n", + d.repo.clone().unwrap() + )); + } + + result.push_str("🔌 O'rnatish uchun: \n"); + + match d.repo { + Some(_) => { + result.push_str(&format!("pacman -S {}\n", d.name)); + } + None => { + result.push_str(&format!("paru -S {}\n", d.name)); + } + } + + result +} + +pub fn kb_generate(d: &Data) -> InlineKeyboardMarkup { + let d = d.clone(); + let mut keyboard = Keyboard::new(); + + keyboard + .url( + "Web sahifasi", + match d.types { + Type::Aur => format!("https://aur.archlinux.org/packages/{}", d.name), + Type::Std => format!( + "https://archlinux.org/packages/{}/{}/{}", + d.repo.unwrap(), + d.arch, + d.name + ), + } + .as_str(), + ) + .unwrap() +} + +pub fn err_keyboard() -> InlineKeyboardMarkup { + let mut keyboard = Keyboard::new(); + keyboard.switch_inline_current("Qayta urinib ko'ramizmi?", "arch linux") +} diff --git a/bots/xinuxmgr/src/utils/mod.rs b/bots/xinuxmgr/src/utils/mod.rs index e2ac1e6..ceaacd8 100644 --- a/bots/xinuxmgr/src/utils/mod.rs +++ b/bots/xinuxmgr/src/utils/mod.rs @@ -1,3 +1,4 @@ +pub mod inlines; pub mod topics; pub fn clog(title: &str, message: &str) {