Mongo storage of event messages
This commit is contained in:
parent
3c4f45189a
commit
d8fe8edf04
6 changed files with 948 additions and 107 deletions
617
Cargo.lock
generated
617
Cargo.lock
generated
|
@ -17,6 +17,17 @@ version = "1.0.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.0.2"
|
||||
|
@ -49,7 +60,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -122,6 +133,18 @@ version = "1.3.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitvec"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
|
||||
dependencies = [
|
||||
"funty",
|
||||
"radium",
|
||||
"tap",
|
||||
"wyz",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
|
@ -131,6 +154,27 @@ dependencies = [
|
|||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bson"
|
||||
version = "2.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9aeb8bae494e49dbc330dd23cf78f6f7accee22f640ce3ab17841badaa4ce232"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"base64 0.13.1",
|
||||
"bitvec",
|
||||
"hex",
|
||||
"indexmap 1.9.3",
|
||||
"js-sys",
|
||||
"lazy_static",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"serde_json",
|
||||
"time",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.13.0"
|
||||
|
@ -174,6 +218,12 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "convert_case"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.3"
|
||||
|
@ -218,14 +268,38 @@ dependencies = [
|
|||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.13.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
|
||||
dependencies = [
|
||||
"darling_core 0.13.4",
|
||||
"darling_macro 0.13.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
"darling_core 0.14.4",
|
||||
"darling_macro 0.14.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.13.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -242,13 +316,24 @@ dependencies = [
|
|||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.13.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
|
||||
dependencies = [
|
||||
"darling_core 0.13.4",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_core 0.14.4",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
@ -260,13 +345,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"hashbrown",
|
||||
"hashbrown 0.12.3",
|
||||
"lock_api",
|
||||
"once_cell",
|
||||
"parking_lot_core",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "data-encoding"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
|
||||
|
||||
[[package]]
|
||||
name = "derivative"
|
||||
version = "2.2.0"
|
||||
|
@ -278,6 +369,19 @@ dependencies = [
|
|||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more"
|
||||
version = "0.99.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
|
||||
dependencies = [
|
||||
"convert_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustc_version 0.4.0",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
|
@ -286,6 +390,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
|||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -297,6 +402,24 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enum-as-inner"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.1"
|
||||
|
@ -367,6 +490,12 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "funty"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
|
||||
|
||||
[[package]]
|
||||
name = "futf"
|
||||
version = "0.1.5"
|
||||
|
@ -407,6 +536,17 @@ version = "0.3.28"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.28"
|
||||
|
@ -421,7 +561,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -493,7 +633,7 @@ dependencies = [
|
|||
"futures-sink",
|
||||
"futures-util",
|
||||
"http",
|
||||
"indexmap",
|
||||
"indexmap 1.9.3",
|
||||
"slab",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
|
@ -506,6 +646,18 @@ version = "0.12.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.2.6"
|
||||
|
@ -521,6 +673,32 @@ version = "0.3.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "hmac"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
|
||||
dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hostname"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"match_cfg",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "html5ever"
|
||||
version = "0.26.0"
|
||||
|
@ -586,7 +764,7 @@ dependencies = [
|
|||
"httpdate",
|
||||
"itoa",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"socket2 0.4.9",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
|
@ -648,6 +826,17 @@ version = "1.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8"
|
||||
dependencies = [
|
||||
"matches",
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.4.0"
|
||||
|
@ -665,7 +854,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
"hashbrown 0.12.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.14.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -688,6 +887,18 @@ dependencies = [
|
|||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipconfig"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f"
|
||||
dependencies = [
|
||||
"socket2 0.5.3",
|
||||
"widestring",
|
||||
"windows-sys 0.48.0",
|
||||
"winreg 0.50.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.8.0"
|
||||
|
@ -727,6 +938,12 @@ version = "0.2.147"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.3.8"
|
||||
|
@ -749,6 +966,15 @@ version = "0.4.19"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
|
||||
|
||||
[[package]]
|
||||
name = "lru-cache"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c"
|
||||
dependencies = [
|
||||
"linked-hash-map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mac"
|
||||
version = "0.1.1"
|
||||
|
@ -781,6 +1007,27 @@ dependencies = [
|
|||
"xml5ever",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "match_cfg"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4"
|
||||
|
||||
[[package]]
|
||||
name = "matches"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
|
||||
|
||||
[[package]]
|
||||
name = "md-5"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca"
|
||||
dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
|
@ -832,6 +1079,53 @@ dependencies = [
|
|||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mongodb"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebcd85ec209a5b84fd9f54b9e381f6fa17462bc74160d018fc94fd8b9f61faa8"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.13.1",
|
||||
"bitflags",
|
||||
"bson",
|
||||
"chrono",
|
||||
"derivative",
|
||||
"derive_more",
|
||||
"futures-core",
|
||||
"futures-executor",
|
||||
"futures-io",
|
||||
"futures-util",
|
||||
"hex",
|
||||
"hmac",
|
||||
"lazy_static",
|
||||
"md-5",
|
||||
"pbkdf2",
|
||||
"percent-encoding",
|
||||
"rand",
|
||||
"rustc_version_runtime",
|
||||
"rustls 0.20.8",
|
||||
"rustls-pemfile",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"serde_with",
|
||||
"sha-1",
|
||||
"sha2",
|
||||
"socket2 0.4.9",
|
||||
"stringprep",
|
||||
"strsim",
|
||||
"take_mut",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-rustls 0.23.4",
|
||||
"tokio-util",
|
||||
"trust-dns-proto",
|
||||
"trust-dns-resolver",
|
||||
"typed-builder",
|
||||
"uuid",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "native-tls"
|
||||
version = "0.2.11"
|
||||
|
@ -886,10 +1180,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "obsessed-yanqing"
|
||||
version = "1.1.3"
|
||||
version = "1.2.0"
|
||||
dependencies = [
|
||||
"levenshtein",
|
||||
"mongodb",
|
||||
"poise",
|
||||
"rand",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"select",
|
||||
|
@ -930,7 +1226,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -983,6 +1279,15 @@ dependencies = [
|
|||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pbkdf2"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917"
|
||||
dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.0"
|
||||
|
@ -1070,7 +1375,7 @@ version = "0.5.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40270099e1527efae99fdc0609d397e76310b529d4980ad38ab14d81803ca0fa"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"darling 0.14.4",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
|
@ -1097,6 +1402,12 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.28"
|
||||
|
@ -1106,6 +1417,12 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "radium"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
|
@ -1216,7 +1533,17 @@ dependencies = [
|
|||
"wasm-streams",
|
||||
"web-sys",
|
||||
"webpki-roots",
|
||||
"winreg",
|
||||
"winreg 0.10.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "resolv-conf"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00"
|
||||
dependencies = [
|
||||
"hostname",
|
||||
"quick-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1240,6 +1567,34 @@ version = "0.1.23"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
dependencies = [
|
||||
"semver 0.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
|
||||
dependencies = [
|
||||
"semver 1.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version_runtime"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d31b7153270ebf48bf91c65ae5b0c00e749c4cfad505f66530ac74950249582f"
|
||||
dependencies = [
|
||||
"rustc_version 0.2.3",
|
||||
"semver 0.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.37.20"
|
||||
|
@ -1369,10 +1724,31 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.164"
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d"
|
||||
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
dependencies = [
|
||||
"semver-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.174"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b88756493a5bd5e5395d53baa70b194b05764ab85b59e43e4b8f4e1192fa9b1"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
@ -1388,14 +1764,23 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.164"
|
||||
name = "serde_bytes"
|
||||
version = "0.11.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68"
|
||||
checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.174"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e5c3a298c7f978e53536f95a63bdc4c4a64550582f31a0359a9afda6aede62e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1404,6 +1789,7 @@ version = "1.0.99"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3"
|
||||
dependencies = [
|
||||
"indexmap 2.0.0",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
|
@ -1430,6 +1816,28 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_with"
|
||||
version = "1.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_with_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_with_macros"
|
||||
version = "1.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082"
|
||||
dependencies = [
|
||||
"darling 0.13.4",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serenity"
|
||||
version = "0.11.5"
|
||||
|
@ -1473,6 +1881,26 @@ dependencies = [
|
|||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.10"
|
||||
|
@ -1504,6 +1932,16 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.5.2"
|
||||
|
@ -1536,12 +1974,28 @@ dependencies = [
|
|||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stringprep"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db3737bde7edce97102e0e2b15365bf7a20bfdb5f60f4f9e8d7004258a51a8da"
|
||||
dependencies = [
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
|
@ -1555,15 +2009,27 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.22"
|
||||
version = "2.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616"
|
||||
checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "take_mut"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60"
|
||||
|
||||
[[package]]
|
||||
name = "tap"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.6.0"
|
||||
|
@ -1606,7 +2072,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1664,7 +2130,8 @@ dependencies = [
|
|||
"mio",
|
||||
"num_cpus",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"signal-hook-registry",
|
||||
"socket2 0.4.9",
|
||||
"tokio-macros",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
@ -1677,7 +2144,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1719,6 +2186,7 @@ checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d"
|
|||
dependencies = [
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
|
@ -1752,7 +2220,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1764,6 +2232,51 @@ dependencies = [
|
|||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "trust-dns-proto"
|
||||
version = "0.21.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c31f240f59877c3d4bb3b3ea0ec5a6a0cff07323580ff8c7a605cd7d08b255d"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"cfg-if",
|
||||
"data-encoding",
|
||||
"enum-as-inner",
|
||||
"futures-channel",
|
||||
"futures-io",
|
||||
"futures-util",
|
||||
"idna 0.2.3",
|
||||
"ipnet",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"rand",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"tinyvec",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "trust-dns-resolver"
|
||||
version = "0.21.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4ba72c2ea84515690c9fcef4c6c660bb9df3036ed1051686de84605b74fd558"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
"ipconfig",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"lru-cache",
|
||||
"parking_lot",
|
||||
"resolv-conf",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"trust-dns-proto",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "try-lock"
|
||||
version = "0.2.4"
|
||||
|
@ -1791,6 +2304,17 @@ dependencies = [
|
|||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typed-builder"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89851716b67b937e393b3daa8423e67ddfc4bbbf1654bcf05488e95e0828db0c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typemap_rev"
|
||||
version = "0.1.5"
|
||||
|
@ -1846,7 +2370,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"idna 0.4.0",
|
||||
"percent-encoding",
|
||||
"serde",
|
||||
]
|
||||
|
@ -1857,6 +2381,16 @@ version = "0.7.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
|
@ -1905,7 +2439,7 @@ dependencies = [
|
|||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.27",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
|
@ -1939,7 +2473,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.27",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
@ -1992,6 +2526,12 @@ dependencies = [
|
|||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "widestring"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
|
@ -2155,6 +2695,25 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
version = "0.50.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wyz"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
|
||||
dependencies = [
|
||||
"tap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xml5ever"
|
||||
version = "0.17.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "obsessed-yanqing"
|
||||
version = "1.2.0"
|
||||
version = "1.3.0"
|
||||
edition = "2021"
|
||||
authors = ["Evann Regnault"]
|
||||
license = "MIT"
|
||||
|
@ -17,3 +17,5 @@ serde = "1.0.160"
|
|||
serde_path_to_error = "0.1.11"
|
||||
select = "0.6.0"
|
||||
regex = "1.9.1"
|
||||
rand = "0.8.5"
|
||||
mongodb = "2.6.0"
|
||||
|
|
|
@ -1,16 +1,24 @@
|
|||
use std::cmp::Ordering;
|
||||
use std::i32;
|
||||
use std::str::Split;
|
||||
use regex::{Regex};
|
||||
use select::document::Document;
|
||||
use select::node::Node;
|
||||
use select::predicate::{Class, Name, Predicate};
|
||||
use serenity::builder::CreateEmbed;
|
||||
use serenity::http::CacheHttp;
|
||||
use serenity::model::channel::Channel;
|
||||
use serenity::model::id::{ChannelId, MessageId};
|
||||
use serenity::utils::{Color, Colour};
|
||||
use crate::data::{Context, Error};
|
||||
use crate::mongo::core::{add_discord_status_message, get_discord_status_message, StatusMessage};
|
||||
|
||||
|
||||
pub async fn get_main_prydwen() -> String {
|
||||
reqwest::get("https://www.prydwen.gg/star-rail/").await.expect("Cannot get Prydwen").text().await.expect("Cannot get data")
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
enum EventType {
|
||||
CharacterBanner,
|
||||
ConeBanner,
|
||||
|
@ -18,104 +26,159 @@ enum EventType {
|
|||
Other,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct BannerData {
|
||||
five_stars: String,
|
||||
four_stars: Vec<String>
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Event {
|
||||
name: String,
|
||||
description: Option<(String, String)>,
|
||||
time: Option<String>,
|
||||
image: Option<String>,
|
||||
banner_data: Option<BannerData>,
|
||||
color: Option<Color>,
|
||||
event_type: EventType
|
||||
}
|
||||
|
||||
async fn get_events_from_document(doc: String) -> Vec<Event> {
|
||||
let document = Document::from(doc.as_str());
|
||||
let event_nodes = document.find(Class("event-tracker")).take(1).next();
|
||||
struct Code {
|
||||
code: String,
|
||||
new: bool
|
||||
}
|
||||
|
||||
fn get_current_events_from_document(doc: &str) -> Vec<Event> {
|
||||
let document = Document::from(doc);
|
||||
let nodes = document.find(Class("event-tracker")).collect::<Vec<Node>>();
|
||||
let event_nodes = nodes.get(0);
|
||||
|
||||
let mut events : Vec<Event> = vec![];
|
||||
|
||||
if let Some(x) = event_nodes {
|
||||
for event in x.find(Class("accordion-item")) {
|
||||
let mut attributes = event.attr("class").expect("").split(' ');
|
||||
if attributes.clone().count() != 2 {continue;}
|
||||
parse_events(&doc, event_nodes, &mut events);
|
||||
|
||||
let id = attributes.find(|p| !p.to_owned().eq("accordion-item")).expect("Error while getting other id");
|
||||
|
||||
let name = event.find(Class("event-name")).next().expect("Cannot find name").text();
|
||||
|
||||
let image_regex = Regex::new(r".accordion-item\.idofevent button\{background-color:#[0-9a-f]{6};background-image:url\((/static/.*?\.jpg)\)}".replace("idofevent", id).as_str()).expect("Cannot created REGEX");
|
||||
let image = image_regex.captures(doc.as_str()).expect("Cannot scan document").get(1).map(|x| format!("https://www.prydwen.gg{}", x.as_str()));
|
||||
|
||||
let description = event.find(Class("description")).next().map(|x| {
|
||||
let text = x.text();
|
||||
let desc = text.split(": ").collect::<Vec<&str>>();
|
||||
(desc.first().expect("").to_string(), desc.get(1).expect("").to_string())
|
||||
});
|
||||
|
||||
let time = event.find(Class("time")).next().map(|x| x.text());
|
||||
|
||||
let event_type = match &description {
|
||||
None => {
|
||||
match event.find(Class("featured-characters")).next() {
|
||||
None => EventType::ConeBanner,
|
||||
Some(_) => EventType::CharacterBanner
|
||||
}
|
||||
}
|
||||
Some(desc) => {
|
||||
match desc.0.as_str() {
|
||||
"Memory Turbulence" => EventType::Memory,
|
||||
_ => EventType::Other
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let five_stars = event.find(Class("rarity-5").descendant(Name("picture")).descendant(Name("img"))).next().map(|x| x.attr("alt").expect("No alt on five star image").to_string());
|
||||
let four_stars = event.find(Class("rarity-4")).take(3).map(|four_stars_node| {
|
||||
four_stars_node.find(Name("picture").descendant(Name("img"))).next().map(|x| x.attr("alt").expect("No alt on four star image").to_string()).expect("")
|
||||
}).collect::<Vec<String>>();
|
||||
|
||||
let banner_data = match five_stars {
|
||||
None => None,
|
||||
Some(x) => match four_stars.len() {
|
||||
3 => Some(BannerData { five_stars: x, four_stars}),
|
||||
_ => None
|
||||
}
|
||||
};
|
||||
|
||||
events.push(Event {name, description, time, image, banner_data, event_type })
|
||||
}
|
||||
};
|
||||
events
|
||||
}
|
||||
|
||||
pub async fn create_events_embeds() -> Vec<CreateEmbed> {
|
||||
let doc = get_main_prydwen().await;
|
||||
let mut events = get_events_from_document(doc).await;
|
||||
fn parse_events(doc: &&str, event_nodes: Option<&Node>, events: &mut Vec<Event>) {
|
||||
if let Some(x) = event_nodes {
|
||||
for event in x.find(Class("accordion-item")) {
|
||||
let mut attributes = event.attr("class").expect("").split(' ');
|
||||
if attributes.clone().count() != 2 { continue; }
|
||||
|
||||
events.sort_by(|a, b| {
|
||||
match (&a.event_type,&b.event_type) {
|
||||
(EventType::CharacterBanner, EventType::ConeBanner) => Ordering::Less,
|
||||
(EventType::CharacterBanner, EventType::Other) => Ordering::Less,
|
||||
(EventType::CharacterBanner, EventType::Memory) => Ordering::Less,
|
||||
(EventType::ConeBanner, EventType::Other) => Ordering::Less,
|
||||
(EventType::ConeBanner, EventType::Memory) => Ordering::Less,
|
||||
(EventType::Other, EventType::Memory) => Ordering::Less,
|
||||
|
||||
(EventType::Memory, EventType::Other) => Ordering::Greater,
|
||||
(EventType::Memory, EventType::ConeBanner) => Ordering::Greater,
|
||||
(EventType::Memory, EventType::CharacterBanner) => Ordering::Greater,
|
||||
(EventType::Other, EventType::CharacterBanner) => Ordering::Greater,
|
||||
(EventType::Other, EventType::ConeBanner) => Ordering::Greater,
|
||||
(EventType::ConeBanner, EventType::CharacterBanner) => Ordering::Greater,
|
||||
let name = event.find(Class("event-name")).next().expect("Cannot find name").text();
|
||||
|
||||
(_, _) => {Ordering::Equal}
|
||||
let (image, color) = get_image_color(&doc, &mut attributes);
|
||||
|
||||
let description = get_description(event);
|
||||
|
||||
let time = event.find(Class("time")).next().map(|x| x.text());
|
||||
|
||||
let event_type = get_event_type(event, &description);
|
||||
|
||||
let banner_data = get_banner_data(event);
|
||||
|
||||
events.push(Event { name, description, time, image, banner_data, color, event_type })
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn get_upcoming_events_from_document(doc: &str) -> Vec<Event> {
|
||||
let document = Document::from(doc);
|
||||
let nodes = document.find(Class("event-tracker")).collect::<Vec<Node>>();
|
||||
let event_nodes = nodes.get(1);
|
||||
let mut events : Vec<Event> = vec![];
|
||||
|
||||
parse_events(&doc, event_nodes, &mut events);
|
||||
events
|
||||
}
|
||||
|
||||
fn get_codes_from_document(doc: &str) -> Option<Vec<Code>> {
|
||||
let document = Document::from(doc);
|
||||
document.find(Class("codes")).next().map( |codes | {
|
||||
let mut x = codes.find(Class("code")).map(|code| {
|
||||
match code.find(Class("new")).next() {
|
||||
None => Code {
|
||||
code: code.text(),
|
||||
new: false
|
||||
},
|
||||
Some(_) => Code {
|
||||
code: code.text().split(' ').collect::<Vec<&str>>().first().expect("Cannot get code").to_string(),
|
||||
new: true
|
||||
},
|
||||
}
|
||||
}).collect::<Vec<Code>>();
|
||||
|
||||
x.sort_by(|a,b| match (a.new,b.new) {
|
||||
(true, false) => Ordering::Less,
|
||||
(false, true) => Ordering::Less,
|
||||
_ => Ordering::Equal
|
||||
});
|
||||
|
||||
x
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
fn get_description(event: Node) -> Option<(String, String)> {
|
||||
let description = event.find(Class("description")).next().map(|x| {
|
||||
let text = x.text();
|
||||
let desc = text.split(": ").collect::<Vec<&str>>();
|
||||
(desc.first().expect("").to_string(), desc.get(1).expect("").to_string())
|
||||
});
|
||||
description
|
||||
}
|
||||
|
||||
fn get_image_color(doc: &str, attributes: &mut Split<char>) -> (Option<String>, Option<Colour>) {
|
||||
let id = attributes.find(|p| !p.to_owned().eq("accordion-item")).expect("Error while getting other id");
|
||||
let image_regex = Regex::new(r".accordion-item\.idofevent button\{background-color:#([0-9a-f]{6});background-image:url\((/static/.*?\.jpg)\)}".replace("idofevent", id).as_str()).expect("Cannot created REGEX");
|
||||
let captures = image_regex.captures(doc).expect("Cannot scan document");
|
||||
let color = captures.get(1).map(|c| {
|
||||
let num = i32::from_str_radix(c.as_str(), 16).expect("Cannot convert color to int");
|
||||
Color::from_rgb(((num >> 16) & 0xff) as u8, ((num >> 8) & 0xff) as u8, (num & 0xff) as u8)
|
||||
});
|
||||
let image = captures.get(2).map(|x| format!("https://www.prydwen.gg{}", x.as_str()));
|
||||
(image, color)
|
||||
}
|
||||
|
||||
fn get_event_type(event: Node, description: &Option<(String, String)>) -> EventType {
|
||||
let event_type = match &description {
|
||||
None => {
|
||||
match event.find(Class("featured-characters")).next() {
|
||||
None => EventType::ConeBanner,
|
||||
Some(_) => EventType::CharacterBanner
|
||||
}
|
||||
}
|
||||
Some(desc) => {
|
||||
match desc.0.as_str() {
|
||||
"Memory Turbulence" => EventType::Memory,
|
||||
_ => EventType::Other
|
||||
}
|
||||
}
|
||||
};
|
||||
event_type
|
||||
}
|
||||
|
||||
fn get_banner_data(event: Node) -> Option<BannerData> {
|
||||
let five_stars = event.find(Class("rarity-5").descendant(Name("picture")).descendant(Name("img"))).next().map(|x| x.attr("alt").expect("No alt on five star image").to_string());
|
||||
let four_stars = event.find(Class("rarity-4")).take(3).map(|four_stars_node| {
|
||||
four_stars_node.find(Name("picture").descendant(Name("img"))).next().map(|x| x.attr("alt").expect("No alt on four star image").to_string()).expect("")
|
||||
}).collect::<Vec<String>>();
|
||||
|
||||
match five_stars {
|
||||
None => None,
|
||||
Some(x) => match four_stars.len() {
|
||||
3 => Some(BannerData { five_stars: x, four_stars }),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_current_events_embeds(doc : &str) -> Vec<CreateEmbed> {
|
||||
let mut events = get_current_events_from_document(doc);
|
||||
|
||||
events.sort_by(sort_events());
|
||||
|
||||
events.into_iter().map(|event| {
|
||||
let mut default = CreateEmbed::default();
|
||||
|
@ -126,6 +189,10 @@ pub async fn create_events_embeds() -> Vec<CreateEmbed> {
|
|||
embed = embed.image(image);
|
||||
}
|
||||
|
||||
if let Some(color) = event.color {
|
||||
embed = embed.color(color);
|
||||
}
|
||||
|
||||
if let Some(time) = event.time {
|
||||
embed = embed.description(format!("Time remaining : {}", time));
|
||||
}
|
||||
|
@ -140,10 +207,85 @@ pub async fn create_events_embeds() -> Vec<CreateEmbed> {
|
|||
.field("4 Stars", format!("- {}", banner_infos.four_stars.join("\n- ")), false);
|
||||
}
|
||||
|
||||
embed.to_owned()
|
||||
|
||||
embed.footer(|f| f.text("Data from https://www.prydwen.gg")).to_owned()
|
||||
}).collect::<Vec<CreateEmbed>>()
|
||||
}
|
||||
|
||||
fn create_upcoming_embed(doc : &str) -> Option<CreateEmbed> {
|
||||
let mut events = get_upcoming_events_from_document(doc);
|
||||
events.sort_by(sort_events());
|
||||
if events.is_empty() {return None;}
|
||||
|
||||
let banner_events : Vec<Event> = events.to_vec().into_iter().filter(|p| matches!(p.event_type, EventType::ConeBanner | EventType::CharacterBanner)).collect();
|
||||
|
||||
let other_events: Vec<Event> = events.iter().cloned().filter(|p| !matches!(p.event_type, EventType::ConeBanner | EventType::CharacterBanner)).collect();
|
||||
|
||||
Some(CreateEmbed::default()
|
||||
.title("Upcoming Events")
|
||||
.field("Banners", banner_events.iter().map(|banner| {
|
||||
format!("{} - **{}** : Starts in {}", banner.name, banner.banner_data.as_ref().expect("").five_stars, banner.time.as_ref().expect(""))
|
||||
}).collect::<Vec<String>>().join("\n"),false)
|
||||
.field("Events", other_events.iter().map(|event| {
|
||||
format!("{} : Starts in {}", event.name, event.time.as_ref().expect(""))
|
||||
}).collect::<Vec<String>>().join("\n"),false)
|
||||
.color(Color::from_rgb(rand::random(), rand::random(), rand::random()))
|
||||
.footer(|f| f.text("Data from https://www.prydwen.gg"))
|
||||
.to_owned()
|
||||
)
|
||||
}
|
||||
|
||||
fn create_codes_embed(doc : &str) -> Option<CreateEmbed> {
|
||||
let codes = get_codes_from_document(doc);
|
||||
codes.map(|codes| CreateEmbed::default()
|
||||
.title("Codes")
|
||||
.description(codes.iter().map(|code| {
|
||||
match code.new {
|
||||
true => format!("- {} :sparkles:", code.code),
|
||||
false => format!("- {}", code.code)
|
||||
}
|
||||
}).collect::<Vec<String>>().join("\n"))
|
||||
.color(Color::from_rgb(rand::random(), rand::random(), rand::random()))
|
||||
.footer(|f| f.text("Data from https://www.prydwen.gg"))
|
||||
.to_owned())
|
||||
}
|
||||
|
||||
|
||||
pub async fn create_event_embeds() -> Vec<CreateEmbed> {
|
||||
let doc = get_main_prydwen().await;
|
||||
let mut embeds: Vec<CreateEmbed> = vec![];
|
||||
embeds.append(create_current_events_embeds(&doc).as_mut());
|
||||
if let Some(embed) = create_upcoming_embed(&doc) {
|
||||
embeds.push(embed);
|
||||
};
|
||||
if let Some(embed) = create_codes_embed(&doc) {
|
||||
embeds.push(embed);
|
||||
};
|
||||
embeds
|
||||
}
|
||||
|
||||
fn sort_events() -> fn(&Event, &Event) -> Ordering {
|
||||
|a, b| {
|
||||
match (&a.event_type, &b.event_type) {
|
||||
(EventType::CharacterBanner, EventType::ConeBanner) => Ordering::Less,
|
||||
(EventType::CharacterBanner, EventType::Other) => Ordering::Less,
|
||||
(EventType::CharacterBanner, EventType::Memory) => Ordering::Less,
|
||||
(EventType::ConeBanner, EventType::Other) => Ordering::Less,
|
||||
(EventType::ConeBanner, EventType::Memory) => Ordering::Less,
|
||||
(EventType::Other, EventType::Memory) => Ordering::Less,
|
||||
|
||||
(EventType::Memory, EventType::Other) => Ordering::Greater,
|
||||
(EventType::Memory, EventType::ConeBanner) => Ordering::Greater,
|
||||
(EventType::Memory, EventType::CharacterBanner) => Ordering::Greater,
|
||||
(EventType::Other, EventType::CharacterBanner) => Ordering::Greater,
|
||||
(EventType::Other, EventType::ConeBanner) => Ordering::Greater,
|
||||
(EventType::ConeBanner, EventType::CharacterBanner) => Ordering::Greater,
|
||||
|
||||
(_, _) => { Ordering::Equal }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Create a message that gets updated automatically
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
|
@ -151,16 +293,42 @@ pub async fn create_event_message(
|
|||
ctx: Context<'_>,
|
||||
#[description = "Create Event Tab"] channel: Channel
|
||||
) -> Result<(), Error> {
|
||||
let embeds = create_events_embeds().await;
|
||||
channel.id().send_message(ctx, |f| {
|
||||
f.set_embeds(embeds)
|
||||
|
||||
let message = get_discord_status_message(ctx.guild().expect("").id.0).await;
|
||||
if let Some(e) = message {
|
||||
let rm = ChannelId::from(e.channel_id as u64)
|
||||
.message(&ctx.http(), MessageId::from(e.message_id as u64))
|
||||
.await;
|
||||
match rm {
|
||||
msg if rm.is_ok() => {
|
||||
msg.unwrap().delete(&ctx.http()).await.unwrap();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
let embeds = create_event_embeds().await;
|
||||
|
||||
let msg = channel.id().send_message(ctx, |f| {
|
||||
f.add_embeds(embeds)
|
||||
}).await.unwrap();
|
||||
|
||||
let sm = StatusMessage {
|
||||
message_id: *msg.id.as_u64() as i64,
|
||||
channel_id: msg.channel_id.0 as i64,
|
||||
guild_id: ctx.guild_id().unwrap().0 as i64
|
||||
};
|
||||
|
||||
add_discord_status_message(sm).await;
|
||||
|
||||
let channel_name = channel.id().name(ctx).await.unwrap();
|
||||
|
||||
ctx.send(|f| {
|
||||
f.embed(|e|{
|
||||
e.title("Success !")
|
||||
.description(format!("The event message has been created in #{}", channel_name))
|
||||
}).ephemeral(true)
|
||||
}).await.expect("TODO: panic message");
|
||||
|
||||
Ok(())
|
||||
}
|
43
src/main.rs
43
src/main.rs
|
@ -1,9 +1,48 @@
|
|||
mod commands;
|
||||
mod data;
|
||||
mod utils;
|
||||
mod mongo;
|
||||
|
||||
use std::time::Duration;
|
||||
use poise::serenity_prelude::GatewayIntents;
|
||||
use serenity::client::Context;
|
||||
use serenity::model::id::ChannelId;
|
||||
use serenity::model::prelude::Activity;
|
||||
use crate::data::Data;
|
||||
use crate::commands::events::create_event_embeds;
|
||||
use crate::data::{Data};
|
||||
use crate::mongo::core::get_all_status_messages;
|
||||
|
||||
fn update_daily(ctx: Context) {
|
||||
tokio::task::spawn(async move {
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(60*60));
|
||||
loop {
|
||||
let status_messages = get_all_status_messages().await;
|
||||
let embeds = create_event_embeds().await;
|
||||
|
||||
for sm in status_messages {
|
||||
let ctx = ctx.clone();
|
||||
let embeds = embeds.clone();
|
||||
tokio::spawn(async move {
|
||||
if sm.channel_id == 0 {return}
|
||||
let msg = ChannelId::from(sm.channel_id as u64).message(ctx.clone().http, sm.message_id as u64).await;
|
||||
match msg {
|
||||
Ok (mut m) => {
|
||||
match m.edit(&ctx.http, |f| {
|
||||
f.set_embeds(embeds)
|
||||
}).await {
|
||||
Ok(..) => {},
|
||||
Err(e) => println!("Error while editing message {}", e)
|
||||
}
|
||||
},
|
||||
Err(_) => {println!("Cannot update guild : {}", sm.channel_id);}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
interval.tick().await;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
@ -22,10 +61,12 @@ async fn main() {
|
|||
Box::pin(async move {
|
||||
ctx.set_activity(Activity::listening("/character")).await;
|
||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
update_daily(ctx.clone());
|
||||
println!("Bot Started");
|
||||
Ok(Data {})
|
||||
})
|
||||
});
|
||||
|
||||
framework.run().await.unwrap();
|
||||
|
||||
}
|
70
src/mongo/core.rs
Normal file
70
src/mongo/core.rs
Normal file
|
@ -0,0 +1,70 @@
|
|||
use std::env;
|
||||
use mongodb::bson::{Bson, doc, Document, from_bson, to_bson};
|
||||
use mongodb::{Client, Collection, options::ClientOptions};
|
||||
use poise::futures_util::TryStreamExt;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct StatusMessage {
|
||||
pub(crate) guild_id: i64,
|
||||
pub(crate) message_id: i64,
|
||||
pub(crate) channel_id: i64
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn add_discord_status_message(status_message: StatusMessage) -> bool {
|
||||
let client = get_mongo_client().await;
|
||||
|
||||
let serialized = to_bson(&status_message).expect("Can't serialize status_message");
|
||||
let document = serialized.as_document().unwrap();
|
||||
|
||||
let collection: Collection<Document> = client.database("obsessed_yanqing").collection("StatusMessages");
|
||||
let updated = collection.update_one(doc! {"guild_id": status_message.guild_id}, doc! {"$set" : document}, None).await;
|
||||
let is_ok = &updated.is_ok();
|
||||
match updated.unwrap() {
|
||||
e if e.matched_count == 0 => {
|
||||
let inserted = collection.insert_one(document, None).await;
|
||||
inserted.is_ok()
|
||||
}
|
||||
_ => *is_ok
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn get_discord_status_message(gid: u64) -> Option<StatusMessage> {
|
||||
let client = get_mongo_client().await;
|
||||
|
||||
let status_messages: Collection<Document> = client.database("obsessed_yanqing").collection("StatusMessages");
|
||||
|
||||
let infos = status_messages.find_one(doc! {"guild_id" : gid as i64}, None).await.expect("Can't find one");
|
||||
|
||||
|
||||
match infos {
|
||||
Some(i) => {
|
||||
let m_infos: StatusMessage = from_bson(Bson::Document(i)).expect("Can't get");
|
||||
Some(m_infos)
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn get_all_status_messages() -> Vec<StatusMessage> {
|
||||
let client = get_mongo_client().await;
|
||||
|
||||
let collection: Collection<StatusMessage> = client.database("obsessed_yanqing").collection::<StatusMessage>("StatusMessages");
|
||||
let documents = collection.find(None, None).await.expect("Can't get everything");
|
||||
let all_docs: Vec<StatusMessage> = documents.try_collect().await.unwrap_or_else(|_| vec![]);
|
||||
all_docs
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_mongo_client() -> Client {
|
||||
let host = env::var("MONGO_HOST").expect("MONGO_HOST not in ENV");
|
||||
let port = env::var("MONGO_PORT").expect("MONGO_PORT not in ENV");
|
||||
let mut client_options = ClientOptions::parse(format!("mongodb://{}:{}/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false", host, port)).await.expect("Can't connect to db");
|
||||
client_options.app_name = Some("Obsessed Yanqing".to_string());
|
||||
client_options.default_database = Some("obsessed_yanqing".to_string());
|
||||
|
||||
Client::with_options(client_options).expect("Can't add options")
|
||||
}
|
1
src/mongo/mod.rs
Normal file
1
src/mongo/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod core;
|
Loading…
Reference in a new issue