app refactor 2

This commit is contained in:
Junko 2024-02-16 12:08:09 +01:00
parent 0f7cf9fd4d
commit f43c0b6b5d
7 changed files with 409 additions and 453 deletions

340
Cargo.lock generated
View File

@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "ahash"
version = "0.8.7"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01"
checksum = "42cd52102d3df161c77a887b608d7a4897d7cc112886a9537b738a887a03aaff"
dependencies = [
"cfg-if",
"once_cell",
@ -37,9 +37,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
[[package]]
name = "anstream"
version = "0.6.7"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cd2405b3ac1faab2990b74d728624cd9fd115651fcecc7c2d8daf01376275ba"
checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
dependencies = [
"anstyle",
"anstyle-parse",
@ -51,9 +51,9 @@ dependencies = [
[[package]]
name = "anstyle"
version = "1.0.4"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
[[package]]
name = "anstyle-parse"
@ -106,9 +106,9 @@ dependencies = [
[[package]]
name = "base64"
version = "0.21.5"
version = "0.21.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9"
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
[[package]]
name = "bitflags"
@ -118,15 +118,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.4.1"
version = "2.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
[[package]]
name = "bumpalo"
version = "3.14.0"
version = "3.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
checksum = "d32a994c2b3ca201d9b263612a374263f05e7adde37c4707f693dcd375076d1f"
[[package]]
name = "bytes"
@ -166,9 +166,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.4.17"
version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80932e03c33999b9235edb8655bc9df3204adc9887c2f95b50cb1deb9fd54253"
checksum = "80c21025abd42669a92efc996ef13cfb2c5c627858421ea58d5c3b331a6c134f"
dependencies = [
"clap_builder",
"clap_derive",
@ -176,9 +176,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.4.17"
version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6c0db58c659eef1c73e444d298c27322a1b52f6927d2ad470c0c0f96fa7b8fa"
checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99"
dependencies = [
"anstream",
"anstyle",
@ -188,21 +188,21 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "4.4.7"
version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.39",
"syn 2.0.49",
]
[[package]]
name = "clap_lex"
version = "0.6.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
[[package]]
name = "color-eyre"
@ -252,9 +252,9 @@ dependencies = [
[[package]]
name = "core-foundation"
version = "0.9.3"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
dependencies = [
"core-foundation-sys",
"libc",
@ -262,9 +262,9 @@ dependencies = [
[[package]]
name = "core-foundation-sys"
version = "0.8.4"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "crossterm"
@ -272,7 +272,7 @@ version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df"
dependencies = [
"bitflags 2.4.1",
"bitflags 2.4.2",
"crossterm_winapi",
"libc",
"mio",
@ -335,12 +335,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.7"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8"
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
dependencies = [
"libc",
"windows-sys 0.48.0",
"windows-sys 0.52.0",
]
[[package]]
@ -382,45 +382,45 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "form_urlencoded"
version = "1.2.0"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
dependencies = [
"percent-encoding",
]
[[package]]
name = "futures-channel"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb"
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
dependencies = [
"futures-core",
]
[[package]]
name = "futures-core"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
[[package]]
name = "futures-sink"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817"
checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5"
[[package]]
name = "futures-task"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2"
checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004"
[[package]]
name = "futures-util"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
dependencies = [
"futures-core",
"futures-task",
@ -430,9 +430,9 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.2.11"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5"
dependencies = [
"cfg-if",
"libc",
@ -441,15 +441,15 @@ dependencies = [
[[package]]
name = "gimli"
version = "0.28.0"
version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "h2"
version = "0.3.22"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178"
checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9"
dependencies = [
"bytes",
"fnv",
@ -466,9 +466,9 @@ dependencies = [
[[package]]
name = "hashbrown"
version = "0.14.2"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
dependencies = [
"ahash",
"allocator-api2",
@ -482,9 +482,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.3.3"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd"
[[package]]
name = "http"
@ -499,9 +499,9 @@ dependencies = [
[[package]]
name = "http-body"
version = "0.4.5"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"
dependencies = [
"bytes",
"http",
@ -522,9 +522,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "hyper"
version = "0.14.27"
version = "0.14.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468"
checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80"
dependencies = [
"bytes",
"futures-channel",
@ -537,7 +537,7 @@ dependencies = [
"httpdate",
"itoa",
"pin-project-lite",
"socket2 0.4.10",
"socket2",
"tokio",
"tower-service",
"tracing",
@ -559,9 +559,9 @@ dependencies = [
[[package]]
name = "idna"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c"
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
dependencies = [
"unicode-bidi",
"unicode-normalization",
@ -575,9 +575,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]]
name = "indexmap"
version = "2.1.0"
version = "2.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177"
dependencies = [
"equivalent",
"hashbrown",
@ -606,15 +606,15 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.9"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]]
name = "js-sys"
version = "0.3.65"
version = "0.3.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8"
checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee"
dependencies = [
"wasm-bindgen",
]
@ -627,9 +627,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.150"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libredox"
@ -637,16 +637,16 @@ version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8"
dependencies = [
"bitflags 2.4.1",
"bitflags 2.4.2",
"libc",
"redox_syscall",
]
[[package]]
name = "linux-raw-sys"
version = "0.4.11"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829"
checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
[[package]]
name = "lock_api"
@ -675,9 +675,9 @@ dependencies = [
[[package]]
name = "memchr"
version = "2.6.4"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "mime"
@ -697,18 +697,18 @@ dependencies = [
[[package]]
name = "miniz_oxide"
version = "0.7.1"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
dependencies = [
"adler",
]
[[package]]
name = "mio"
version = "0.8.9"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0"
checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09"
dependencies = [
"libc",
"log",
@ -746,26 +746,26 @@ dependencies = [
[[package]]
name = "object"
version = "0.32.1"
version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.18.0"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "openssl"
version = "0.10.59"
version = "0.10.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a257ad03cd8fb16ad4172fedf8094451e1af1c4b70097636ef2eac9a5f0cc33"
checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8"
dependencies = [
"bitflags 2.4.1",
"bitflags 2.4.2",
"cfg-if",
"foreign-types",
"libc",
@ -782,7 +782,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
"syn 2.0.49",
]
[[package]]
@ -793,9 +793,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.95"
version = "0.9.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40a4130519a360279579c2053038317e40eff64d13fd3f004f9e1b72b8a6aaf9"
checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae"
dependencies = [
"cc",
"libc",
@ -846,9 +846,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "percent-encoding"
version = "2.3.0"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pin-project-lite"
@ -864,9 +864,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.27"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
[[package]]
name = "pluralsync"
@ -885,29 +885,29 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.69"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.33"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "ratatui"
version = "0.26.0"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "154b85ef15a5d1719bcaa193c3c81fe645cd120c156874cd660fe49fd21d1373"
checksum = "bcb12f8fbf6c62614b0d56eb352af54f6a22410c3b079eb53ee93c7b97dd31d8"
dependencies = [
"bitflags 2.4.1",
"bitflags 2.4.2",
"cassowary",
"compact_str",
"crossterm",
@ -943,9 +943,9 @@ dependencies = [
[[package]]
name = "reqwest"
version = "0.11.22"
version = "0.11.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b"
checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251"
dependencies = [
"base64",
"bytes",
@ -966,9 +966,11 @@ dependencies = [
"once_cell",
"percent-encoding",
"pin-project-lite",
"rustls-pemfile",
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper",
"system-configuration",
"tokio",
"tokio-native-tls",
@ -988,15 +990,24 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "rustix"
version = "0.38.24"
version = "0.38.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ad981d6c340a49cdc40a1028d9c6084ec7e9fa33fcb839cab656a267071e234"
checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949"
dependencies = [
"bitflags 2.4.1",
"bitflags 2.4.2",
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.48.0",
"windows-sys 0.52.0",
]
[[package]]
name = "rustls-pemfile"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c"
dependencies = [
"base64",
]
[[package]]
@ -1007,17 +1018,17 @@ checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]]
name = "ryu"
version = "1.0.15"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[package]]
name = "schannel"
version = "0.1.22"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88"
checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534"
dependencies = [
"windows-sys 0.48.0",
"windows-sys 0.52.0",
]
[[package]]
@ -1051,29 +1062,29 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.192"
version = "1.0.196"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001"
checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.192"
version = "1.0.196"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1"
checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
"syn 2.0.49",
]
[[package]]
name = "serde_json"
version = "1.0.108"
version = "1.0.113"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79"
dependencies = [
"itoa",
"ryu",
@ -1142,19 +1153,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.11.2"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
[[package]]
name = "socket2"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d"
dependencies = [
"libc",
"winapi",
]
checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
[[package]]
name = "socket2"
@ -1184,9 +1185,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strsim"
version = "0.10.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
[[package]]
name = "strum"
@ -1207,7 +1208,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.39",
"syn 2.0.49",
]
[[package]]
@ -1223,15 +1224,21 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.39"
version = "2.0.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
checksum = "915aea9e586f80826ee59f8453c1101f9d1c4b3964cd2460185ee8e299ada496"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "sync_wrapper"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
[[package]]
name = "system-configuration"
version = "0.5.1"
@ -1255,35 +1262,34 @@ dependencies = [
[[package]]
name = "tempfile"
version = "3.8.1"
version = "3.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67"
dependencies = [
"cfg-if",
"fastrand",
"redox_syscall",
"rustix",
"windows-sys 0.48.0",
"windows-sys 0.52.0",
]
[[package]]
name = "thiserror"
version = "1.0.50"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.50"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
"syn 2.0.49",
]
[[package]]
@ -1313,9 +1319,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.34.0"
version = "1.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9"
checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931"
dependencies = [
"backtrace",
"bytes",
@ -1325,7 +1331,7 @@ dependencies = [
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2 0.5.5",
"socket2",
"tokio-macros",
"windows-sys 0.48.0",
]
@ -1338,7 +1344,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
"syn 2.0.49",
]
[[package]]
@ -1414,9 +1420,9 @@ dependencies = [
[[package]]
name = "try-lock"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "unicase"
@ -1429,9 +1435,9 @@ dependencies = [
[[package]]
name = "unicode-bidi"
version = "0.3.13"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
[[package]]
name = "unicode-ident"
@ -1462,9 +1468,9 @@ checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]]
name = "url"
version = "2.4.1"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5"
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
dependencies = [
"form_urlencoded",
"idna",
@ -1512,9 +1518,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.88"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce"
checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
@ -1522,24 +1528,24 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.88"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217"
checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.39",
"syn 2.0.49",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.38"
version = "0.4.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02"
checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97"
dependencies = [
"cfg-if",
"js-sys",
@ -1549,9 +1555,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.88"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2"
checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -1559,28 +1565,28 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.88"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907"
checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
"syn 2.0.49",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.88"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b"
checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838"
[[package]]
name = "web-sys"
version = "0.3.65"
version = "0.3.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85"
checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446"
dependencies = [
"js-sys",
"wasm-bindgen",
@ -1767,5 +1773,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
"syn 2.0.49",
]

View File

@ -26,21 +26,23 @@ pub mod pk {
let response = http_get(url,key)?;
Ok(serde_json::from_str(&response)?)
let values: Vec<Value> = serde_json::from_str(&response)?;
Ok(values)
}
pub fn get_fronters(key: &str, sys: &System) -> Result<Vec<Member>> {
let url = format!("{}/systems/{}/fronters", PK_URL, sys.pk_userid);
let result = http_get(url,key)?;
let json: Value = serde_json::from_str(&result)?;
let json: Value = serde_json::from_str(&result).unwrap();
let json_members = &json["members"].as_array();
let mut members: Vec<Member> = Vec::new();
for member in json_members {
for m in member.into_iter() {
for dbmem in &sys.members {
if m["name"].to_string() == dbmem.name {
if m["name"].as_str().unwrap().to_string() == dbmem.name {
members.push(dbmem.clone());
}
}
@ -105,7 +107,7 @@ pub mod sp {
let json: Value = serde_json::from_str(&response)?;
Ok(json["id"].to_string())
Ok(json["id"].as_str().unwrap().to_string())
}
pub fn get_member_ids(key: &str, system_id: &str) -> Result<HashMap<String, String>> {
@ -117,8 +119,8 @@ pub mod sp {
let mut sp_member_data: HashMap<String, String> = HashMap::new();
for member in json {
sp_member_data.insert(
member["content"]["name"].to_string(),
member["id"].to_string());
member["content"]["name"].as_str().unwrap().to_string(),
member["id"].as_str().unwrap().to_string());
}
Ok(sp_member_data)
@ -143,7 +145,7 @@ pub mod sp {
let mut members = Vec::new();
for data in json {
let sp_id = &data["content"]["member"].to_string();
let sp_id = &data["content"]["member"].as_str().unwrap().to_string();
for member in &sys.members {
if &member.sp_id == sp_id {
members.push(member.clone());

View File

@ -2,7 +2,7 @@ use crate::configdata::*;
use crate::systemdata::*;
use crate::clap_ps::ForceFrom;
use color_eyre::eyre::Result;
use color_eyre::eyre::{eyre, Result};
pub enum CurrentScreen {
Dash,
@ -76,19 +76,111 @@ impl App {
}
pub fn get_fronters(&mut self, ff: ForceFrom) -> Result<()> {
fn get(&mut self, ff: ForceFrom) -> Result<()> {
self.fronters = Some(Fronters::get(self, ff)?);
Ok(())
}
pub fn set_fronters(&mut self, to_front: Vec<Member>) -> Result<()> {
fn set(&mut self, to_front: Vec<Member>) -> Result<()> {
self.get_fronters(ForceFrom::None)?;
self.get(ForceFrom::None)?;
self.fronters = Some(Fronters::set(self, to_front)?);
Ok(())
}
fn add(&mut self, to_front: Vec<Member>) -> Result<()> {
let aux_fronters: Fronters = Fronters::get(self, ForceFrom::None)?;
let mut addfronters: Vec<Member> = Vec::new();
addfronters.append(&mut aux_fronters.pk.clone());
addfronters.append(&mut to_front.clone());
self.fronters = Some(Fronters::set(self, addfronters)?);
Ok(())
}
pub fn memberlist(&self) -> Result<()> {
if let Some(sys) = &self.sys {
for member in &sys.members {
println!("{} / {}", member.name, member.aliases.join(" | "));
}
}
Ok(())
}
pub fn set_member(&mut self, tf_members: Vec<String>, append: bool) -> Result<()> {
if let Some(sys) = &self.sys {
let mut to_front: Vec<Member> = Vec::new();
for member in &tf_members {
for mem in &sys.members {
let lowcase_aliases: Vec<String> = mem.aliases.iter().map(|x| x.to_lowercase()).collect();
if mem.name.to_lowercase() == member.to_lowercase() || lowcase_aliases.iter().any(|e| member.contains(e)) {
println!("Member {member} found.");
to_front.push(mem.clone());
break;
}
}
}
if to_front.len() == tf_members.len() {
if !append {
self.set(to_front)?;
} else {
self.add(to_front)?;
}
} else {
println!("One or more members were not found. Known members:\n--------------------------");
self.memberlist()?;
println!("--------------------------\nIf a member is missing from the system try running \"pluralsync update\" to refresh the local database");
return Err(eyre!("Missing member"));
}
#[cfg(feature = "jlog")] {
let mut names = Vec::new();
for m in &to_front {
names.push(String::from(&m.name));
}
let log_fronters = names.join(" || ");
#[cfg(target_os = "windows")]
std::process::Command::new("jlog").args(["info", format!("Switch registered: {}", log_fronters)]).output().expect("Logging error");
#[cfg(not(target_os = "windows"))]
std::process::Command::new("jlog").arg("info").arg(format!("Switch registered: {}", log_fronters)).output().expect("Logging error");
}
return Ok(());
}
Err(eyre!("No system found"))
}
pub fn get_front(&mut self, ff: ForceFrom) -> Result<Vec<String>> {
self.get(ff)?;
if let Some(fronters) = &self.fronters {
let mut names: Vec<String> = Vec::new();
for member in &fronters.pk {
names.push(String::from(&member.name));
}
let fronters = names.join(" || ");
println!("Currently fronting: {}", fronters);
std::fs::write(format!("{}/.front", &self.cfg_dir), &fronters)?;
return Ok(names);
}
Err(eyre!("No fronters found"))
}
}

View File

@ -20,7 +20,7 @@ pub struct Args {
#[derive(Subcommand)]
pub enum Commands {
/// Fetches the system member information from PluralKit and SimplyPlural
Sync,
Update,
/// TUI configuration tool
TUI,
/// Sets one or more members to the front

View File

@ -5,27 +5,13 @@ mod api;
mod utils;
mod clap_ps;
use std::fs;
#[cfg(feature = "avatar")]
use std::fs::remove_file;
use std::path::Path;
use std::collections::HashMap;
#[cfg(feature = "avatar")]
use std::process::Command;
use serde::Serialize;
use serde_json::Value;
use dirs;
use app::*;
use configdata::*;
use systemdata::*;
use utils::update_avatars;
use clap_ps::*;
use clap::{builder::TypedValueParser, Parser};
use clap::Parser;
use color_eyre::eyre::{eyre, Result};
@ -41,11 +27,11 @@ fn main() -> Result<()> {
};
let mut app: App = App::new(config_path.clone());
app.load_config();
app.load_system(false);
app.load_config()?;
app.load_system(false)?;
match cli.cmd {
Commands::Sync => {
Commands::Update => {
app.load_system(true)?;
},
@ -54,29 +40,17 @@ fn main() -> Result<()> {
},
Commands::Set { members, #[cfg(feature = "discord")] discord, #[cfg(feature = "fedi")] fedi } => {
let res = set_member(&app, members);
app.set_member(members, false)?;
#[cfg(feature = "avatar")] {
match res {
Ok(_) => {
let _ = update_avatars(config_path.clone(), #[cfg(feature = "discord")] discord, #[cfg(feature = "fedi")] fedi);
},
Err(_) => (),
}
}
#[cfg(feature = "avatar")]
update_avatars(&mut app, #[cfg(feature = "discord")] discord, #[cfg(feature = "fedi")] fedi)?;
},
Commands::Add { members, #[cfg(feature = "discord")] discord, #[cfg(feature = "fedi")] fedi } => {
let res = add_member(config_path.clone(), members);
app.set_member(members, true)?;
#[cfg(feature = "avatar")] {
match res {
Ok(_) => {
let _ = update_avatars(config_path.clone(), #[cfg(feature = "discord")] discord, #[cfg(feature = "fedi")] fedi);
},
Err(_) => (),
}
}
#[cfg(feature = "avatar")]
update_avatars(&mut app, #[cfg(feature = "discord")] discord, #[cfg(feature = "fedi")] fedi)?;
},
Commands::Get { force_from, #[cfg(feature = "discord")] discord, #[cfg(feature = "fedi")] fedi } => {
@ -85,245 +59,16 @@ fn main() -> Result<()> {
None => ForceFrom::None,
};
let _ = get(config_path.clone(), ff);
app.get_front(ff)?;
#[cfg(feature = "avatar")]
let _ = update_avatars(config_path.clone(), #[cfg(feature = "discord")] discord, #[cfg(feature = "fedi")] fedi);
update_avatars(&mut app, #[cfg(feature = "discord")] discord, #[cfg(feature = "fedi")] fedi)?;
},
Commands::Members => {
let _res = memberlist(config_path);
app.memberlist()?;
},
}
Ok(())
}
fn set_member(app: &App, tf_members: Vec<String>) -> Result<()> {
let system = &app.sys.ok_or(eyre!("No system data found"))?;
let mut to_front: Vec<Member> = Vec::new();
for member in &tf_members {
for mem in &system.members {
let lowcase_aliases: Vec<String> = mem.aliases.iter().map(|x| x.to_lowercase()).collect();
if mem.name.to_lowercase() == member.to_lowercase() || lowcase_aliases.iter().any(|e| member.contains(e)) {
println!("Member {member} found.");
to_front.push(mem.clone());
break;
}
}
}
if to_front.len() == tf_members.len() {
app.set_fronters(to_front)?;
} BOOKMARK else {
println!("One or more members were not found. Known members:\n--------------------------");
let _ = memberlist(app);
println!("--------------------------\nIf a member is missing from the system try running \"pluralsync sync\" to refresh the local database");
return Err(eyre!("Missing member"));
}
#[cfg(feature = "jlog")] {
let mut names = Vec::new();
for m in &to_front {
names.push(String::from(&m.name));
}
let log_fronters = names.join(" || ");
#[cfg(target_os = "windows")]
std::process::Command::new("jlog").args(["info", format!("Switch registered: {}", log_fronters)]).output().expect("Logging error");
#[cfg(not(target_os = "windows"))]
std::process::Command::new("jlog").arg("info").arg(format!("Switch registered: {}", log_fronters)).output().expect("Logging error");
}
Ok(())
}
fn add_member(config_path: String, tf_members: Vec<String>) -> Result<(), &'static str> {
let config: Config = match get_config(&config_path) {
Ok(c) => c,
Err(e) => return Err(e)
};
let system: System = get_system(&config_path);
let mut to_front: Vec<Member> = Vec::new();
for member in &tf_members {
for mem in &system.members {
if mem.name.to_lowercase() == member.to_lowercase() || mem.alias.to_lowercase() == member.to_lowercase() {
to_front.push(mem.clone());
break;
}
}
}
if to_front.len() == tf_members.len() {
let fronters = get_fronters(&config.pk_key, &config.sp_key, &system, ForceFrom::None);
let mut aux: Vec<Member> = Vec::new();
aux.append(&mut fronters.pk.clone());
aux.append(&mut to_front);
to_front = aux;
pk_set_fronters(&config.pk_key, &system, &to_front, &fronters);
sp_set_fronters(&config.sp_key, &to_front, &fronters);
let _ = get(config_path, ForceFrom::None);
} else {
println!("One or more members were not found. Known members:\n--------------------------");
let _ = memberlist(config_path);
println!("--------------------------\nIf a member is missing from the system try running \"pluralsync sync\" to refresh the local database");
return Err("Missing member");
}
#[cfg(feature = "jlog")] {
let mut names = Vec::new();
for m in &to_front {
names.push(String::from(&m.name));
}
let log_fronters = names.join(" || ");
#[cfg(target_os = "windows")]
std::process::Command::new("jlog").args(["info", format!("Switch registered: {}", log_fronters)]).output().expect("Logging error");
#[cfg(not(target_os = "windows"))]
std::process::Command::new("jlog").arg("info").arg(format!("Switch registered: {}", log_fronters)).output().expect("Logging error");
}
Ok(())
}
fn memberlist(config_path: String) -> Result<(), &'static str> {
let sys = get_system(&config_path);
for mem in sys.members {
if mem.name != mem.alias {
println!("{} / {}", mem.name, mem.alias);
} else {
println!("{}", mem.name);
}
}
Ok(())
}
fn get(config_path: String, ff: ForceFrom) -> Result<Vec<String>, &'static str> {
let config: Config = match get_config(&config_path) {
Ok(c) => c,
Err(e) => return Err(e)
};
let sys = get_system(&config_path);
let f = get_fronters(&config.pk_key, &config.sp_key, &sys, ff);
let mut names = Vec::new();
for m in &f.pk {
names.push(String::from(&m.name));
}
let fronters = names.join(" || ");
println!("Currently fronting: {}", fronters);
let _ = fs::write(format!("{}/.front", config_path), fronters);
Ok(names)
}
#[cfg(feature = "avatar")]
#[allow(unused_variables)]
fn update_avatars(config_path: String, #[cfg(feature = "discord")] discord: bool, #[cfg(feature = "fedi")] fedi: bool) -> Result<(), &'static str>{
#[allow(unused_mut)]
let mut config: Config = match get_config(&config_path) {
Ok(c) => c,
Err(e) => return Err(e)
};
let names = get(config_path, ForceFrom::None).unwrap();
#[cfg(feature = "avatar")]
match avatar_module(&config, &names) {
Ok(_) => {
#[cfg(feature = "discord")] {
config.disc_module.enabled |= discord;
discord_module(&config);
}
#[cfg(feature = "fedi")] {
config.fedi_module.enabled |= fedi;
fedi_module(&config);
}
},
Err(e) => println!("{}", e),
}
Ok(())
}
#[cfg(feature = "avatar")]
fn avatar_module(config: &Config, names: &Vec<String>) -> Result<(), &'static str>{
if config.avatar_module.enabled {
let mut whitelisted_names: Vec<String> = names.iter().map(|i| i.to_lowercase()).collect();
let blacklist: Vec<String> = config.avatar_module.blacklist.iter().map(|i| i.to_lowercase()).collect();
for name in names {
if blacklist.contains(&name.to_lowercase()) {
let index = whitelisted_names.iter().position(|x| *x == name.to_lowercase()).unwrap();
whitelisted_names.remove(index);
println!("{} blacklisted from avatar module", name);
}
}
let avatarnames = whitelisted_names.join("").to_lowercase() + ".png";
if Path::new(&config.avatar_module.avatar_output_path).exists() {
let _ = remove_file(&config.avatar_module.avatar_output_path);
}
if cfg!(target_os = "windows") {
let cmdaug = format!("copy {}\\{} {}", &config.avatar_module.avatar_folder, avatarnames, &config.avatar_module.avatar_output_path);
Command::new("cmd").args(["/C", &cmdaug]).output().expect("Avatar module error");
} else {
Command::new("sh").arg("-c").arg(format!("cp {}/{} {}", &config.avatar_module.avatar_folder, avatarnames, &config.avatar_module.avatar_output_path)).output().expect("Avatar module error");
}
if Path::new(&config.avatar_module.avatar_output_path).exists() {
println!("Avatar module finished");
return Ok(())
} else {
return Err("Avatar module failed")
}
} else {
Err("Avatar mode disabled")
}
}
#[cfg(feature = "discord")]
fn discord_module(config: &Config) {
if config.disc_module.enabled {
if cfg!(target_os = "windows") {
let mut c = Command::new("cmd").args(["/C", format!("{} {}", &config.disc_module.python_path, &config.disc_module.script_path).as_str()]).spawn().expect("Discord module error");
let _ = c.wait().expect("Error");
} else {
let mut c = Command::new("sh").arg("-c").arg(format!("{} {}", &config.disc_module.python_path, &config.disc_module.script_path)).spawn().expect("Discord module error");
let _ = c.wait().expect("Error");
}
}
}
#[cfg(feature = "fedi")]
fn fedi_module(config: &Config) {
if config.fedi_module.enabled {
let client = reqwest::Client::new();
let form = Form::new().part("avatar", Part::bytes(fs::read(config.avatar_module.avatar_output_path.clone()).unwrap()).file_name("face.png").mime_str("image/png").unwrap());
let rb = client
.patch(config.fedi_module.instance.clone() + "/api/v1/accounts/update_credentials")
.multipart(form)
.header(USER_AGENT, "Pluralsync")
.header(AUTHORIZATION, format!("Bearer {}", &config.fedi_module.token).as_str());
println!("Fedi module finished");
match http_request(rb) {
Ok(_) => (),
Err(e) => println!("{}", e.to_string()),
}
}
}

View File

@ -53,7 +53,7 @@ impl System {
// PluralKit
let pk_sys = pk::get_system(&conf.pk_key)?;
let pk_id = pk_sys["id"].to_string();
let pk_id = pk_sys["id"].as_str().unwrap();
let pk_members = pk::get_members(&conf.pk_key, &pk_id)?;
// Simplyplural
@ -64,14 +64,14 @@ impl System {
let mut members: Vec<Member> = Vec::new();
for pk_mem in pk_members {
let mut m = Member {
pk_id: pk_mem["id"].to_string(),
pk_id: pk_mem["id"].as_str().unwrap().to_string(),
sp_id: String::new(),
name: pk_mem["name"].to_string(),
name: pk_mem["name"].as_str().unwrap().to_string(),
aliases: Vec::new(),
};
if pk_mem["display_name"].as_str() != None {
m.aliases.push(pk_mem["display_name"].to_string());
m.aliases.push(pk_mem["display_name"].as_str().unwrap().to_string());
}
m.sp_id = sp::get_member_id(&m, &sp_member_ids)?;
@ -142,8 +142,10 @@ impl Fronters {
return Ok(Fronters::new(to_front.clone(), to_front.clone()));
}
return Err(eyre!("Missing Fronters"));
}
return Err(eyre!("Missing System"));
}
Err(eyre!("Missing app information"))
Err(eyre!("Missing Config"))
}
}

View File

@ -2,6 +2,21 @@ use std::fs;
use serde_json::Value;
use color_eyre::eyre::Result;
#[cfg(feature = "avatar")]
use {
std::{
process::Command,
fs::remove_file,
path::Path,
},
crate::{
configdata::Config,
app::App,
clap_ps::ForceFrom,
},
color_eyre::eyre::eyre,
};
pub fn load_json(file_path: &str) -> Result<Value> {
let file_data = fs::read_to_string(&file_path)?;
@ -9,3 +24,97 @@ pub fn load_json(file_path: &str) -> Result<Value> {
Ok(json_value)
}
#[cfg(feature = "avatar")]
pub fn update_avatars(app: &mut App, #[cfg(feature = "discord")] discord: bool, #[cfg(feature = "fedi")] fedi: bool) -> Result<()>{
if let Some(cfg) = app.cfg.clone() {
let names = &app.get_front(ForceFrom::None)?; // TODO CHANGE INTO USING LOCAL FRONT
match avatar_module(&cfg, &names) {
Ok(_) => {
#[cfg(feature = "discord")] {
config.disc_module.enabled |= discord;
discord_module(&config);
}
#[cfg(feature = "fedi")] {
config.fedi_module.enabled |= fedi;
fedi_module(&config);
}
},
Err(e) => println!("{}", e),
}
return Ok(());
}
Err(eyre!("No config found"))
}
#[cfg(feature = "avatar")]
fn avatar_module(config: &Config, names: &Vec<String>) -> Result<(), &'static str>{
if config.avatar_module.enabled {
let mut whitelisted_names: Vec<String> = names.iter().map(|i| i.to_lowercase()).collect();
let blacklist: Vec<String> = config.avatar_module.blacklist.iter().map(|i| i.to_lowercase()).collect();
for name in names {
if blacklist.contains(&name.to_lowercase()) {
let index = whitelisted_names.iter().position(|x| *x == name.to_lowercase()).unwrap();
whitelisted_names.remove(index);
println!("{} blacklisted from avatar module", name);
}
}
let avatarnames = whitelisted_names.join("").to_lowercase() + ".png";
if Path::new(&config.avatar_module.avatar_output_path).exists() {
let _ = remove_file(&config.avatar_module.avatar_output_path);
}
if cfg!(target_os = "windows") {
let cmdaug = format!("copy {}\\{} {}", &config.avatar_module.avatar_folder, avatarnames, &config.avatar_module.avatar_output_path);
Command::new("cmd").args(["/C", &cmdaug]).output().expect("Avatar module error");
} else {
Command::new("sh").arg("-c").arg(format!("cp {}/{} {}", &config.avatar_module.avatar_folder, avatarnames, &config.avatar_module.avatar_output_path)).output().expect("Avatar module error");
}
if Path::new(&config.avatar_module.avatar_output_path).exists() {
println!("Avatar module finished");
Ok(())
} else {
Err("Avatar module failed")
}
} else {
Err("Avatar mode disabled")
}
}
#[cfg(feature = "discord")]
fn discord_module(config: &Config) {
if config.disc_module.enabled {
if cfg!(target_os = "windows") {
let mut c = Command::new("cmd").args(["/C", format!("{} {}", &config.disc_module.python_path, &config.disc_module.script_path).as_str()]).spawn().expect("Discord module error");
let _ = c.wait().expect("Error");
} else {
let mut c = Command::new("sh").arg("-c").arg(format!("{} {}", &config.disc_module.python_path, &config.disc_module.script_path)).spawn().expect("Discord module error");
let _ = c.wait().expect("Error");
}
}
}
#[cfg(feature = "fedi")]
fn fedi_module(config: &Config) {
if config.fedi_module.enabled {
let client = reqwest::Client::new();
let form = Form::new().part("avatar", Part::bytes(fs::read(config.avatar_module.avatar_output_path.clone()).unwrap()).file_name("face.png").mime_str("image/png").unwrap());
let rb = client
.patch(config.fedi_module.instance.clone() + "/api/v1/accounts/update_credentials")
.multipart(form)
.header(USER_AGENT, "Pluralsync")
.header(AUTHORIZATION, format!("Bearer {}", &config.fedi_module.token).as_str());
println!("Fedi module finished");
match http_request(rb) {
Ok(_) => (),
Err(e) => println!("{}", e.to_string()),
}
}
}