Compare commits

..

No commits in common. "main" and "2.2.6" have entirely different histories.
main ... 2.2.6

9 changed files with 631 additions and 1198 deletions

View file

@ -137,7 +137,7 @@ jobs:
run: rm release_blobs/build.env run: rm release_blobs/build.env
- -
name: Release New Version name: Release New Version
uses: actions/forgejo-release@v2 uses: actions/forgejo-release@v1
with: with:
direction: upload direction: upload
url: https://forgejo.neshweb.net url: https://forgejo.neshweb.net

563
Cargo.lock generated
View file

@ -41,18 +41,9 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "anyhow"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
dependencies = [
"backtrace",
]
[[package]] [[package]]
name = "aob-lemmy-bot" name = "aob-lemmy-bot"
version = "3.2.0" version = "2.2.6"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",
@ -60,35 +51,23 @@ dependencies = [
"lemmy_api_common", "lemmy_api_common",
"lemmy_db_schema", "lemmy_db_schema",
"log", "log",
"notify",
"once_cell", "once_cell",
"reqwest", "reqwest",
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"strum_macros", "strum_macros 0.26.2",
"systemd-journal-logger", "systemd-journal-logger",
"tokio", "tokio",
"toml", "toml",
"url", "url",
] ]
[[package]]
name = "async-lock"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18"
dependencies = [
"event-listener",
"event-listener-strategy",
"pin-project-lite",
]
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.81" version = "0.1.77"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -116,6 +95,12 @@ dependencies = [
"rustc-demangle", "rustc-demangle",
] ]
[[package]]
name = "base64"
version = "0.21.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9"
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.22.1" version = "0.22.1"
@ -163,9 +148,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.38" version = "0.4.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
dependencies = [ dependencies = [
"android-tzdata", "android-tzdata",
"iana-time-zone", "iana-time-zone",
@ -173,16 +158,7 @@ dependencies = [
"num-traits", "num-traits",
"serde", "serde",
"wasm-bindgen", "wasm-bindgen",
"windows-targets 0.52.0", "windows-targets 0.48.5",
]
[[package]]
name = "concurrent-queue"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973"
dependencies = [
"crossbeam-utils",
] ]
[[package]] [[package]]
@ -197,12 +173,6 @@ dependencies = [
"toml", "toml",
] ]
[[package]]
name = "convert_case"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.4" version = "0.9.4"
@ -219,30 +189,6 @@ version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "crossbeam-channel"
version = "0.5.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
[[package]] [[package]]
name = "darling" name = "darling"
version = "0.20.3" version = "0.20.3"
@ -288,17 +234,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "derive-new"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "directories" name = "directories"
version = "5.0.1" version = "5.0.1"
@ -365,45 +300,12 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "event-listener"
version = "5.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba"
dependencies = [
"concurrent-queue",
"parking",
"pin-project-lite",
]
[[package]]
name = "event-listener-strategy"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1"
dependencies = [
"event-listener",
"pin-project-lite",
]
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "2.0.1" version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
[[package]]
name = "filetime"
version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.4.1",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -434,15 +336,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "fsevent-sys"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "futures-channel" name = "futures-channel"
version = "0.3.29" version = "0.3.29"
@ -455,21 +348,21 @@ dependencies = [
[[package]] [[package]]
name = "futures-core" name = "futures-core"
version = "0.3.30" version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
[[package]] [[package]]
name = "futures-io" name = "futures-io"
version = "0.3.30" version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa"
[[package]] [[package]]
name = "futures-macro" name = "futures-macro"
version = "0.3.30" version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -478,21 +371,21 @@ dependencies = [
[[package]] [[package]]
name = "futures-sink" name = "futures-sink"
version = "0.3.30" version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817"
[[package]] [[package]]
name = "futures-task" name = "futures-task"
version = "0.3.30" version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2"
[[package]] [[package]]
name = "futures-util" name = "futures-util"
version = "0.3.30" version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-io", "futures-io",
@ -507,9 +400,9 @@ dependencies = [
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.15" version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
@ -557,9 +450,9 @@ checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.5.0" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
@ -730,26 +623,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "inotify"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff"
dependencies = [
"bitflags 1.3.2",
"inotify-sys",
"libc",
]
[[package]]
name = "inotify-sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "ipnet" name = "ipnet"
version = "2.9.0" version = "2.9.0"
@ -771,26 +644,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "kqueue"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c"
dependencies = [
"kqueue-sys",
"libc",
]
[[package]]
name = "kqueue-sys"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b"
dependencies = [
"bitflags 1.3.2",
"libc",
]
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -799,11 +652,10 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "lemmy_api_common" name = "lemmy_api_common"
version = "0.19.5" version = "0.19.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0350aefa5e5b7bc90fe5a6f992dbac5a1960c776ff16f4bee18660f11b3b95fc" checksum = "17366fcde90b07f4e5a8fefa62378fe348424ba79c8e9fb3ddc63ef76d687493"
dependencies = [ dependencies = [
"anyhow",
"chrono", "chrono",
"enum-map", "enum-map",
"getrandom", "getrandom",
@ -811,31 +663,25 @@ dependencies = [
"lemmy_db_views", "lemmy_db_views",
"lemmy_db_views_actor", "lemmy_db_views_actor",
"lemmy_db_views_moderator", "lemmy_db_views_moderator",
"lemmy_utils",
"moka",
"regex", "regex",
"serde", "serde",
"serde_with", "serde_with",
"url", "url",
"urlencoding",
] ]
[[package]] [[package]]
name = "lemmy_db_schema" name = "lemmy_db_schema"
version = "0.19.5" version = "0.19.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4280976725dce988e4750e124a5600ead8d7fca0a07a7cf9e42da3ece946396c" checksum = "5e2d9a0c6f8f3df4664f9479ceca138ee6217b89653bafb753a498cabc5f3ab5"
dependencies = [ dependencies = [
"anyhow",
"async-trait", "async-trait",
"chrono", "chrono",
"derive-new",
"futures-util", "futures-util",
"moka",
"serde", "serde",
"serde_with", "serde_with",
"strum", "strum",
"strum_macros", "strum_macros 0.25.3",
"tracing", "tracing",
"typed-builder", "typed-builder",
"url", "url",
@ -844,11 +690,10 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_views" name = "lemmy_db_views"
version = "0.19.5" version = "0.19.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7107a8725ed7fd12eb0cb451dff52d969ca5ac445d1aabb77881cfe75715a45" checksum = "02659eb474ab54da6296d4edb5a974c0affa5cfcf8a2fa31bb52793dedef9d5a"
dependencies = [ dependencies = [
"chrono",
"lemmy_db_schema", "lemmy_db_schema",
"serde", "serde",
"serde_with", "serde_with",
@ -856,47 +701,34 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_views_actor" name = "lemmy_db_views_actor"
version = "0.19.5" version = "0.19.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb7eeb5e65373c37aff03793cf90f8096557af7eb5f41426be9d3bc64b782152" checksum = "5187730858dc808b5cf06aadbb1d1f8ca360d4ed3c375e5606e63be4c9e24e06"
dependencies = [ dependencies = [
"chrono", "chrono",
"lemmy_db_schema", "lemmy_db_schema",
"serde", "serde",
"serde_with", "serde_with",
"strum", "strum",
"strum_macros", "strum_macros 0.25.3",
] ]
[[package]] [[package]]
name = "lemmy_db_views_moderator" name = "lemmy_db_views_moderator"
version = "0.19.5" version = "0.19.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52b9425bb6059979ebe5b4f2124ff5af898ac6e5fcf43053bd2485c504afe39e" checksum = "18f6fab36e1dcadc043b81c5916044ee65219d837f5d221a908296f9c55f3872"
dependencies = [ dependencies = [
"lemmy_db_schema", "lemmy_db_schema",
"serde", "serde",
"serde_with", "serde_with",
] ]
[[package]]
name = "lemmy_utils"
version = "0.19.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5afa108b6db73c057eb9aadaecd84269c138500519789c76106c671df684fb5a"
dependencies = [
"cfg-if",
"rosetta-build",
"serde",
"strum",
"strum_macros",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.155" version = "0.2.151"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
[[package]] [[package]]
name = "libredox" name = "libredox"
@ -906,7 +738,7 @@ checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8"
dependencies = [ dependencies = [
"bitflags 2.4.1", "bitflags 2.4.1",
"libc", "libc",
"redox_syscall 0.4.1", "redox_syscall",
] ]
[[package]] [[package]]
@ -915,16 +747,6 @@ version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456"
[[package]]
name = "lock_api"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.20" version = "0.4.20"
@ -962,35 +784,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09"
dependencies = [ dependencies = [
"libc", "libc",
"log",
"wasi", "wasi",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
[[package]]
name = "moka"
version = "0.12.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32cf62eb4dd975d2dde76432fb1075c49e3ee2331cf36f1f8fd4b66550d32b6f"
dependencies = [
"async-lock",
"async-trait",
"crossbeam-channel",
"crossbeam-epoch",
"crossbeam-utils",
"event-listener",
"futures-util",
"once_cell",
"parking_lot",
"quanta",
"rustc_version",
"smallvec",
"tagptr",
"thiserror",
"triomphe",
"uuid",
]
[[package]] [[package]]
name = "native-tls" name = "native-tls"
version = "0.2.11" version = "0.2.11"
@ -1009,31 +806,6 @@ dependencies = [
"tempfile", "tempfile",
] ]
[[package]]
name = "notify"
version = "6.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d"
dependencies = [
"bitflags 2.4.1",
"crossbeam-channel",
"filetime",
"fsevent-sys",
"inotify",
"kqueue",
"libc",
"log",
"mio",
"walkdir",
"windows-sys 0.48.0",
]
[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.17" version = "0.2.17"
@ -1118,35 +890,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "parking"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae"
[[package]]
name = "parking_lot"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.5.3",
"smallvec",
"windows-targets 0.52.0",
]
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.3.1" version = "2.3.1"
@ -1206,21 +949,6 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "quanta"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5167a477619228a0b284fac2674e3c388cba90631d7b7de620e6f1fcd08da5"
dependencies = [
"crossbeam-utils",
"libc",
"once_cell",
"raw-cpuid",
"wasi",
"web-sys",
"winapi",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.35" version = "1.0.35"
@ -1230,15 +958,6 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "raw-cpuid"
version = "11.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e29830cbb1290e404f24c73af91c5d8d631ce7e128691e9477556b540cd01ecd"
dependencies = [
"bitflags 2.4.1",
]
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.4.1" version = "0.4.1"
@ -1248,15 +967,6 @@ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
] ]
[[package]]
name = "redox_syscall"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4"
dependencies = [
"bitflags 2.4.1",
]
[[package]] [[package]]
name = "redox_users" name = "redox_users"
version = "0.4.4" version = "0.4.4"
@ -1270,9 +980,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.10.5" version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -1282,9 +992,9 @@ dependencies = [
[[package]] [[package]]
name = "regex-automata" name = "regex-automata"
version = "0.4.7" version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -1303,7 +1013,7 @@ version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10"
dependencies = [ dependencies = [
"base64", "base64 0.22.1",
"bytes", "bytes",
"encoding_rs", "encoding_rs",
"futures-channel", "futures-channel",
@ -1340,35 +1050,12 @@ dependencies = [
"winreg", "winreg",
] ]
[[package]]
name = "rosetta-build"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24191a1fed7ae7a5d89f816366f5c03ebce70a7a4d7158534afdf8dd719749fe"
dependencies = [
"convert_case",
"lazy_static",
"proc-macro2",
"quote",
"regex",
"tinyjson",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.23" version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "rustc_version"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
]
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.28" version = "0.38.28"
@ -1388,7 +1075,7 @@ version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d"
dependencies = [ dependencies = [
"base64", "base64 0.22.1",
"rustls-pki-types", "rustls-pki-types",
] ]
@ -1410,15 +1097,6 @@ version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.22" version = "0.1.22"
@ -1428,12 +1106,6 @@ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
name = "security-framework" name = "security-framework"
version = "2.9.2" version = "2.9.2"
@ -1457,26 +1129,20 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "semver"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.204" version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.204" version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1517,17 +1183,16 @@ dependencies = [
[[package]] [[package]]
name = "serde_with" name = "serde_with"
version = "3.9.0" version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23"
dependencies = [ dependencies = [
"base64", "base64 0.21.5",
"chrono", "chrono",
"hex", "hex",
"indexmap 1.9.3", "indexmap 1.9.3",
"indexmap 2.1.0", "indexmap 2.1.0",
"serde", "serde",
"serde_derive",
"serde_json", "serde_json",
"serde_with_macros", "serde_with_macros",
"time", "time",
@ -1535,9 +1200,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_with_macros" name = "serde_with_macros"
version = "3.9.0" version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350" checksum = "93634eb5f75a2323b16de4748022ac4297f9e76b6dced2be287a099f41b5e788"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
@ -1578,15 +1243,28 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "strum" name = "strum"
version = "0.26.3" version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125"
[[package]] [[package]]
name = "strum_macros" name = "strum_macros"
version = "0.26.4" version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0"
dependencies = [
"heck",
"proc-macro2",
"quote",
"rustversion",
"syn",
]
[[package]]
name = "strum_macros"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@ -1643,12 +1321,6 @@ dependencies = [
"rustix", "rustix",
] ]
[[package]]
name = "tagptr"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.8.1" version = "3.8.1"
@ -1657,7 +1329,7 @@ checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"fastrand", "fastrand",
"redox_syscall 0.4.1", "redox_syscall",
"rustix", "rustix",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@ -1684,13 +1356,12 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.36" version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
dependencies = [ dependencies = [
"deranged", "deranged",
"itoa", "itoa",
"num-conv",
"powerfmt", "powerfmt",
"serde", "serde",
"time-core", "time-core",
@ -1705,20 +1376,13 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
[[package]] [[package]]
name = "time-macros" name = "time-macros"
version = "0.2.18" version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20"
dependencies = [ dependencies = [
"num-conv",
"time-core", "time-core",
] ]
[[package]]
name = "tinyjson"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ab95735ea2c8fd51154d01e39cf13912a78071c2d89abc49a7ef102a7dd725a"
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.6.0" version = "1.6.0"
@ -1880,12 +1544,6 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "triomphe"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3"
[[package]] [[package]]
name = "try-lock" name = "try-lock"
version = "0.2.5" version = "0.2.5"
@ -1894,18 +1552,18 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]] [[package]]
name = "typed-builder" name = "typed-builder"
version = "0.18.2" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77739c880e00693faef3d65ea3aad725f196da38b22fdc7ea6ded6e1ce4d3add" checksum = "e47c0496149861b7c95198088cbf36645016b1a0734cf350c50e2a38e070f38a"
dependencies = [ dependencies = [
"typed-builder-macro", "typed-builder-macro",
] ]
[[package]] [[package]]
name = "typed-builder-macro" name = "typed-builder-macro"
version = "0.18.2" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f718dfaf347dcb5b983bfc87608144b0bad87970aebcbea5ce44d2a30c08e63" checksum = "982ee4197351b5c9782847ef5ec1fdcaf50503fb19d68f9771adae314e72b492"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1945,17 +1603,11 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "urlencoding"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.10.0" version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560"
dependencies = [ dependencies = [
"getrandom", "getrandom",
"serde", "serde",
@ -1973,16 +1625,6 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "walkdir"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",
]
[[package]] [[package]]
name = "want" name = "want"
version = "0.3.1" version = "0.3.1"
@ -2074,37 +1716,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-core" name = "windows-core"
version = "0.51.1" version = "0.51.1"

View file

@ -1,7 +1,7 @@
[package] [package]
authors = ["Neshura"] authors = ["Neshura"]
name = "aob-lemmy-bot" name = "aob-lemmy-bot"
version = "3.2.0" version = "2.2.6"
edition = "2021" edition = "2021"
description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club" description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"
@ -17,8 +17,8 @@ systemd-units = { enable = false }
[dependencies] [dependencies]
chrono = "^0.4" chrono = "^0.4"
lemmy_api_common = "0.19.5" lemmy_api_common = "0.19.3"
lemmy_db_schema = "0.19.5" lemmy_db_schema = "0.19.3"
once_cell = "^1.19" once_cell = "^1.19"
reqwest = { version = "^0.12", features = ["blocking", "json"] } reqwest = { version = "^0.12", features = ["blocking", "json"] }
serde = "^1.0" serde = "^1.0"
@ -32,4 +32,3 @@ toml = "^0.8"
systemd-journal-logger = "^2.1.1" systemd-journal-logger = "^2.1.1"
log = "^0.4" log = "^0.4"
async-trait = "^0.1" async-trait = "^0.1"
notify = "6.1.1"

View file

@ -1,21 +1,16 @@
use crate::{config::{Config}, HTTP_CLIENT}; use crate::{config::{Config, PostBody, SeriesConfig}, fetchers::{jnovel}, lemmy};
use crate::lemmy::{Lemmy}; use crate::fetchers::jnovel::JPostInfo;
use crate::post_history::{SeriesHistory}; use crate::lemmy::{Lemmy, PostInfo};
use chrono::{DateTime, Duration, Utc}; use crate::post_history::SeriesHistory;
use std::sync::{Arc, RwLock}; use chrono::{DateTime, Duration, Timelike, Utc};
use notify::{Event, EventKind, event::{AccessKind, AccessMode}, RecursiveMode, Watcher}; use lemmy_api_common::post::CreatePost;
use lemmy_db_schema::newtypes::{CommunityId, LanguageId};
use lemmy_db_schema::PostFeatureType;
use std::collections::HashMap;
use tokio::time::sleep; use tokio::time::sleep;
use crate::fetchers::Fetcher;
use systemd_journal_logger::connected_to_journal; use systemd_journal_logger::connected_to_journal;
macro_rules! debug {
($msg:tt) => {
match connected_to_journal() {
true => log::debug!("[DEBUG] {}", $msg),
false => println!("[DEBUG] {}", $msg),
}
};
}
macro_rules! info { macro_rules! info {
($msg:tt) => { ($msg:tt) => {
match connected_to_journal() { match connected_to_journal() {
@ -25,6 +20,15 @@ macro_rules! info {
}; };
} }
macro_rules! warn {
($msg:tt) => {
match connected_to_journal() {
true => log::warn!("[WARN] {}", $msg),
false => println!("[WARN] {}", $msg),
}
};
}
macro_rules! error { macro_rules! error {
($msg:tt) => { ($msg:tt) => {
match connected_to_journal() { match connected_to_journal() {
@ -34,103 +38,232 @@ macro_rules! error {
}; };
} }
pub(crate) struct Bot { pub(crate) async fn run() {
shared_config: Arc<RwLock<Config>>, let mut last_reload: DateTime<Utc>;
history: SeriesHistory, let mut lemmy: Lemmy;
run_start_time: DateTime<Utc> let mut login_error: bool;
} let mut communities: HashMap<String, CommunityId>;
let mut post_history: SeriesHistory;
let mut start: DateTime<Utc>;
let mut config: Config = Config::load();
last_reload = Utc::now();
enum Wait { lemmy = match lemmy::login(&config).await {
Absolute, Ok(data) => data,
Buffer Err(_) => panic!(),
} };
login_error = false;
impl Bot { communities = match lemmy.get_communities().await {
pub(crate) fn new() -> Self { Ok(data) => data,
let config = Config::load(); Err(_) => panic!(),
let shared_config: Arc<RwLock<Config>> = Arc::new(RwLock::new(config)); };
let shared_config_copy = shared_config.clone(); start = Utc::now();
let mut watcher = notify::recommended_watcher(move |res: Result<Event, notify::Error>| {
match res {
Ok(event) => {
if event.kind == EventKind::Access(AccessKind::Close(AccessMode::Write)) {
let mut write = shared_config_copy.write().expect("Write Lock Failed");
let new_config = Config::load();
write.series = new_config.series;
write.instance = new_config.instance;
write.protected_communities = new_config.protected_communities;
write.status_post_url = new_config.status_post_url;
info!("Reloaded Configuration");
}
},
Err(e) => {
let msg = format!("Error watching files: {e}");
error!(msg);
}
}
}).expect("Watcher Error");
watcher.watch(&Config::get_path(), RecursiveMode::NonRecursive).expect("Error in watcher"); let info_msg = "Bot init successful, starting normal operations".to_owned();
info!(info_msg);
let history: SeriesHistory = SeriesHistory::load_history(); loop {
idle(&start, &config).await;
start = Utc::now();
Bot { shared_config, history, run_start_time: Utc::now() } // replace with watcher
} if start - last_reload >= Duration::seconds(config.config_reload_seconds as i64) {
pub(crate) async fn run(&mut self) { config = Config::load();
loop { let message = "Config reloaded".to_owned();
let mut lemmy = match Lemmy::new(&self.shared_config).await { info!(message);
}
if login_error {
let info_msg = "Login invalid, refreshing session";
info!(info_msg);
lemmy = match lemmy::login(&config).await {
Ok(data) => data, Ok(data) => data,
Err(_) => continue, Err(_) => continue,
}; };
login_error = false;
}
lemmy.get_communities().await; if start - last_reload >= Duration::seconds(config.config_reload_seconds as i64) {
communities = match lemmy.get_communities().await {
self.history = SeriesHistory::load_history(); Ok(data) => data,
Err(_) => {
let start: DateTime<Utc> = Utc::now(); login_error = true;
while Utc::now() - start <= Duration::minutes(60) { continue;
self.run_start_time = Utc::now();
self.ping_status().await;
let read_copy = self.shared_config.read().expect("Read Lock Failed").clone();
for series in read_copy.series {
series.update(&mut self.history, &lemmy, &self.shared_config).await;
debug!("Done Updating Series");
self.wait(1, Wait::Absolute).await;
} }
debug!("Awaiting Timeout"); };
self.wait(30, Wait::Buffer).await; let message = "Communities reloaded".to_owned();
debug!("Pinging Server"); info!(message);
self.ping_status().await; last_reload = Utc::now();
debug!("Awaiting Timeout 2");
self.wait(30, Wait::Absolute).await;
}
lemmy.logout().await;
} }
}
async fn ping_status(&self) { post_history = SeriesHistory::load_history();
let read_config = &self.shared_config.read().expect("Read Lock Failed").clone();
if let Some(status_url) = &read_config.status_post_url {
match HTTP_CLIENT.get(status_url).send().await {
Ok(_) => {},
Err(e) => {
let err_msg = format!("While pinging status URL: {e}");
error!(err_msg);
}
}
}
}
async fn wait(&self, seconds: i64, start_time: Wait) { let series = config.series.clone();
let duration: Duration = Duration::seconds(seconds); for series in series {
let start_time: DateTime<Utc> = match start_time { sleep(Duration::seconds(1).to_std().unwrap()).await;
Wait::Absolute => Utc::now(), let info_msg = format!("Handling Series {}", series.slug);
Wait::Buffer => self.run_start_time, info!(info_msg);
}; if handle_series(&series, &communities, &lemmy, &config, &mut post_history)
while Utc::now() - start_time < duration { .await
sleep(Duration::milliseconds(100).to_std().unwrap()).await .is_err()
{
login_error = true;
continue;
};
} }
idle(&start, &config).await;
} }
} }
async fn idle(start: &DateTime<Utc>, config: &Config) {
let mut sleep_duration = Duration::seconds(30);
if Utc::now() - start > sleep_duration {
sleep_duration = Duration::seconds(60);
}
let info_msg = format!("Idling for {} seconds", sleep_duration);
info!(info_msg);
if let Some(status_url) = config.status_post_url.clone() {
match reqwest::get(status_url).await {
Ok(_) => {}
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
}
}
};
while Utc::now() - start < sleep_duration {
sleep(Duration::milliseconds(100).to_std().unwrap()).await;
}
}
async fn handle_series(series: &SeriesConfig, communities: &HashMap<String, CommunityId>, lemmy: &Lemmy, config: &Config, post_history: &mut SeriesHistory ) -> Result<(), ()> {
let jnc = jnovel::JFetcherOptions::new(series.slug.clone(), series.parted);
let post_list = match jnc.check_feed().await {
Ok(data) => data,
Err(_) => return Err(()),
};
if post_list.is_empty() && Utc::now().minute() % 10 == 0 {
let info_msg = "No Updates found";
info!(info_msg);
}
for post_info in post_list.clone().iter() {
let post_part_info = post_info.get_part_info();
let post_lemmy_info = post_info.get_info();
if post_history.check_for_post(
series.slug.as_str(),
post_part_info.as_string().as_str(),
post_lemmy_info.title.as_str(),
) {
continue;
}
let post_series_config = match post_info {
JPostInfo::Chapter { .. } => &series.prepub_community,
JPostInfo::Volume { .. } => &series.volume_community,
};
let community_id = *communities
.get(post_series_config.name.as_str())
.expect("Given community is invalid");
let post_body = match &post_series_config.post_body {
PostBody::None => None,
PostBody::Description => post_info.get_description(),
PostBody::Custom(text) => Some(text.clone()),
};
let post_data = CreatePost {
name: post_lemmy_info.title.clone(),
community_id,
url: Some(post_lemmy_info.url),
body: post_body,
honeypot: None,
nsfw: None,
language_id: Some(LanguageId(37)), // TODO get this id once every few hours per API request, the ordering of IDs suggests that the EN Id might change in the future
};
let info = format!(
"Posting '{}' to {}",
post_lemmy_info.title.as_str(),
post_series_config.name.as_str()
);
info!(info);
let post_id = lemmy.post(post_data).await?;
if post_series_config.pin_settings.pin_new_post_community
&& config
.protected_communities
.contains(&post_series_config.name)
{
let info = format!(
"Pinning '{}' to {}",
post_lemmy_info.title,
post_series_config.name.as_str()
);
info!(info);
let pinned_posts = lemmy.get_community_pinned(community_id).await?;
if !pinned_posts.is_empty() {
let community_pinned_post = &pinned_posts[0];
lemmy
.unpin(community_pinned_post.post.id, PostFeatureType::Community)
.await?;
}
lemmy.pin(post_id, PostFeatureType::Community).await?;
} else if config
.protected_communities
.contains(&post_series_config.name)
{
let message = format!(
"Community '{}' for Series '{}' is protected. Is this intended?",
&post_series_config.name, series.slug
);
warn!(message);
}
if post_series_config.pin_settings.pin_new_post_local {
let info = format!("Pinning '{}' to Instance", post_lemmy_info.title);
info!(info);
let pinned_posts = lemmy.get_local_pinned().await?;
if !pinned_posts.is_empty() {
for pinned_post in pinned_posts {
if config
.protected_communities
.contains(&pinned_post.community.name)
{
continue;
} else {
let community_pinned_post = &pinned_post;
lemmy
.unpin(community_pinned_post.post.id, PostFeatureType::Local)
.await?;
break;
}
}
}
lemmy.pin(post_id, PostFeatureType::Local).await?;
}
let mut series_history = post_history.get_series(series.slug.as_str());
let mut part_history = series_history.get_part(post_part_info.as_string().as_str());
match post_info {
JPostInfo::Chapter { .. } => part_history.chapter = post_info.get_info().title,
JPostInfo::Volume { .. } => part_history.volume = post_info.get_info().title,
}
series_history.set_part(post_part_info.as_string().as_str(), part_history);
post_history
.set_series(series.slug.as_str(), series_history);
post_history.save_history();
}
Ok(())
}

View file

@ -1,57 +1,12 @@
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
use chrono::{Timelike, Utc};
use crate::config::PostBody::Description; use crate::config::PostBody::Description;
use lemmy_db_schema::PostFeatureType; use lemmy_api_common::sensitive::Sensitive;
use lemmy_db_schema::sensitive::SensitiveString;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use crate::lemmy::{Lemmy, PartInfo, PostType};
use crate::post_history::{SeriesHistory};
use systemd_journal_logger::connected_to_journal;
use crate::fetchers::{FetcherTrait, Fetcher};
use crate::fetchers::jnovel::{JNovelFetcher};
macro_rules! debug {
($msg:tt) => {
match connected_to_journal() {
true => log::debug!("[DEBUG] {}", $msg),
false => println!("[DEBUG] {}", $msg),
}
};
}
macro_rules! info {
($msg:tt) => {
match connected_to_journal() {
true => log::info!("[INFO] {}", $msg),
false => println!("[INFO] {}", $msg),
}
};
}
macro_rules! warn {
($msg:tt) => {
match connected_to_journal() {
true => log::warn!("[WARN] {}", $msg),
false => println!("[WARN] {}", $msg),
}
};
}
macro_rules! error {
($msg:tt) => {
match connected_to_journal() {
true => log::error!("[ERROR] {}", $msg),
false => eprintln!("[ERROR] {}", $msg),
}
};
}
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct Config { pub(crate) struct Config {
pub(crate) instance: String, pub(crate) instance: String,
username: SensitiveString, username: String,
password: SensitiveString, password: String,
pub(crate) status_post_url: Option<String>, pub(crate) status_post_url: Option<String>,
pub(crate) config_reload_seconds: u32, pub(crate) config_reload_seconds: u32,
pub(crate) protected_communities: Vec<String>, pub(crate) protected_communities: Vec<String>,
@ -85,16 +40,12 @@ impl Config {
cfg cfg
} }
pub(crate) fn get_path() -> PathBuf { pub(crate) fn get_username(&self) -> Sensitive<String> {
confy::get_configuration_file_path(env!("CARGO_PKG_NAME"), "config").expect("Application will not without confy") Sensitive::new(self.username.clone())
} }
pub(crate) fn get_username(&self) -> SensitiveString { pub(crate) fn get_password(&self) -> Sensitive<String> {
self.username.clone() Sensitive::new(self.password.clone())
}
pub(crate) fn get_password(&self) -> SensitiveString {
self.password.clone()
} }
} }
@ -102,8 +53,8 @@ impl Default for Config {
fn default() -> Self { fn default() -> Self {
Config { Config {
instance: "".to_owned(), instance: "".to_owned(),
username: SensitiveString::from("".to_owned()), username: "".to_owned(),
password: SensitiveString::from("".to_owned()), password: "".to_owned(),
status_post_url: None, status_post_url: None,
config_reload_seconds: 21600, config_reload_seconds: 21600,
protected_communities: vec![], protected_communities: vec![],
@ -118,162 +69,6 @@ pub(crate) struct SeriesConfig {
pub(crate) parted: bool, pub(crate) parted: bool,
pub(crate) prepub_community: PostConfig, pub(crate) prepub_community: PostConfig,
pub(crate) volume_community: PostConfig, pub(crate) volume_community: PostConfig,
pub(crate) fetcher: Fetcher
}
impl SeriesConfig {
pub(crate) async fn update(&self, history: &mut SeriesHistory, lemmy: &Lemmy, config: &Arc<RwLock<Config>>) {
let info_msg = format!("Checking {} for Updates", self.slug);
info!(info_msg);
let mut fetcher: Fetcher = match &self.fetcher {
Fetcher::Jnc(_) => {
Fetcher::Jnc(JNovelFetcher::new())
},
/*default => {
let err_msg = format!("Fetcher {default} not implemented");
error!(err_msg);
return;
}*/
};
match fetcher {
Fetcher::Jnc(ref mut jnc) => {
jnc.set_series(self.slug.clone());
jnc.set_part_option(self.parted);
}
}
let post_list = match fetcher.check_feed().await {
Ok(data) => data,
Err(_) => {
let err_msg = format!("While checking feed for {}", self.slug);
error!(err_msg);
return;
}
};
if post_list.is_empty() && Utc::now().minute() % 10 == 0 {
let info_msg = "No Updates found";
info!(info_msg);
}
for post_info in post_list.iter() {
if history.check_for_post(
self.slug.as_str(),
post_info.get_part_info().unwrap_or(PartInfo::NoParts).as_string().as_str(),
post_info.get_info().title.as_str()
) {
continue
}
let post_data = post_info.get_post_data(self, lemmy);
let info = format!(
"Posting '{}' to {}",
post_info.get_info().title.as_str(),
post_info.get_post_config(self).name.as_str()
);
info!(info);
let post_id = match lemmy.post(post_data).await {
Some(data) => data,
None=> {
error!("Error posting chapter");
return;
}
};
let read_config = config.read().expect("Read Lock Failed").clone();
if post_info.get_post_config(self).pin_settings.pin_new_post_community
&& !read_config
.protected_communities
.contains(&post_info.get_post_config(self).name)
{
let info = format!(
"Pinning '{}' to {}",
post_info.get_info().title,
post_info.get_post_config(self).name.as_str()
);
info!(info);
let pinned_posts = lemmy.get_community_pinned(lemmy.get_community_id(&post_info.get_post_config(self).name)).await.unwrap_or_else(|| {
error!("Pinning of Post to community failed");
vec![]
});
if !pinned_posts.is_empty() {
let community_pinned_post = &pinned_posts[0];
if lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Community).await.is_none() {
error!("Error un-pinning post");
}
}
if lemmy.pin(post_id, PostFeatureType::Community).await.is_none() {
error!("Error pinning post");
}
} else if read_config
.protected_communities
.contains(&post_info.get_post_config(self).name)
{
let message = format!(
"Community '{}' for Series '{}' is protected. Is this intended?",
&post_info.get_post_config(self).name, self.slug
);
warn!(message);
}
if post_info.get_post_config(self).pin_settings.pin_new_post_local {
let info = format!("Pinning '{}' to Instance", post_info.get_info().title);
info!(info);
let pinned_posts = match lemmy.get_local_pinned().await {
Some(data) => {data}
None => {
error!("Error fetching pinned posts");
vec![]
}
};
if !pinned_posts.is_empty() {
for pinned_post in pinned_posts {
if read_config
.protected_communities
.contains(&pinned_post.community.name)
{
continue;
} else {
let community_pinned_post = &pinned_post;
if lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Local).await.is_none() {
error!("Error pinning post");
continue;
}
break;
}
}
}
if lemmy.pin(post_id, PostFeatureType::Local).await.is_none() {
error!("Error pinning post");
};
}
let mut series_history = history.get_series(self.slug.as_str());
let mut part_history = series_history.get_part(post_info.get_part_info().unwrap_or(PartInfo::NoParts).as_string().as_str());
match post_info.post_type {
Some(post_type) => {
match post_type {
PostType::Chapter => part_history.chapter = post_info.get_info().title,
PostType::Volume => part_history.volume = post_info.get_info().title,
}
}
None => part_history.chapter = post_info.get_info().title,
}
series_history.set_part(post_info.get_part_info().unwrap_or(PartInfo::NoParts).as_string().as_str(), part_history);
history
.set_series(self.slug.as_str(), series_history);
debug!("Saving History");
history.save_history();
}
}
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]

View file

@ -1,13 +1,16 @@
use crate::{HTTP_CLIENT}; use crate::{HTTP_CLIENT, lemmy};
use chrono::{DateTime, Duration, Utc}; use chrono::{DateTime, Duration, Utc};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::collections::HashMap; use std::collections::HashMap;
use std::ops::Sub; use std::ops::Sub;
use async_trait::async_trait; use async_trait::async_trait;
use crate::fetchers::{FetcherTrait}; use url::Url;
use crate::lemmy::{PartInfo, PostInfo, PostInfoInner, PostType}; use crate::fetchers::Fetcher;
use crate::fetchers::jnovel::JPostInfo::{Chapter, Volume};
use crate::fetchers::jnovel::PartInfo::{NoParts, Part};
use crate::lemmy::{PostInfo, PostInfoInner};
use systemd_journal_logger::connected_to_journal; use systemd_journal_logger::connected_to_journal;
use crate::lemmy::PartInfo::{NoParts, Part};
macro_rules! error { macro_rules! error {
($msg:tt) => { ($msg:tt) => {
@ -31,7 +34,7 @@ static PAST_DAYS_ELIGIBLE: u8 = 4;
macro_rules! api_url { macro_rules! api_url {
() => { () => {
"https://labs.j-novel.club/app/v2".to_owned() "https://labs.j-novel.club/app/v1".to_owned()
}; };
} }
@ -88,41 +91,191 @@ pub(crate) struct ChapterDetail {
pub(crate) cover: Option<Cover>, pub(crate) cover: Option<Cover>,
} }
#[derive(Deserialize, Serialize, Debug, Clone)] #[derive(Debug, Copy, Clone)]
pub(crate) struct JNovelFetcher { pub(crate) enum PartInfo {
NoParts,
Part(u8),
}
impl PartInfo {
pub(crate) fn as_u8(&self) -> u8 {
match self {
Part(number) => *number,
NoParts => 0,
}
}
pub(crate) fn as_string(&self) -> String {
self.as_u8().to_string()
}
}
impl PartialEq for PartInfo {
fn eq(&self, other: &Self) -> bool {
let self_numeric = self.as_u8();
let other_numeric = other.as_u8();
self_numeric == other_numeric
}
}
impl PartialOrd for PartInfo {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.gt(other) {
Some(Ordering::Greater)
} else if self.eq(other) {
Some(Ordering::Equal)
} else {
Some(Ordering::Less)
}
}
fn lt(&self, other: &Self) -> bool {
let self_numeric = self.as_u8();
let other_numeric = other.as_u8();
self_numeric < other_numeric
}
fn le(&self, other: &Self) -> bool {
!self.gt(other)
}
fn gt(&self, other: &Self) -> bool {
let self_numeric = self.as_u8();
let other_numeric = other.as_u8();
self_numeric > other_numeric
}
fn ge(&self, other: &Self) -> bool {
!self.lt(other)
}
}
#[derive(Debug, Clone)]
pub(crate) enum JPostInfo {
Chapter {
part: PartInfo,
lemmy_info: PostInfoInner,
},
Volume {
part: PartInfo,
description: String,
lemmy_info: PostInfoInner,
},
}
impl JPostInfo {
pub(crate) fn get_part_info(&self) -> PartInfo {
match self {
Chapter {
part: part_info, ..
} => *part_info,
Volume {
part: part_info, ..
} => *part_info,
}
}
}
impl PostInfo for JPostInfo {
fn get_info(&self) -> PostInfoInner {
match self {
Chapter { lemmy_info, .. } => lemmy_info.clone(),
Volume { lemmy_info, .. } => lemmy_info.clone(),
}
}
fn get_description(&self) -> Option<String> {
match self {
Chapter { .. } => None,
Volume { description, .. } => Some(description.clone()),
}
}
}
impl PartialEq for JPostInfo {
fn eq(&self, other: &Self) -> bool {
let self_part = match self {
Chapter { part, .. } => part,
Volume { part, .. } => part,
};
let other_part = match other {
Chapter { part, .. } => part,
Volume { part, .. } => part,
};
self_part.eq(other_part)
}
}
impl PartialOrd for JPostInfo {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.gt(other) {
Some(Ordering::Greater)
} else if self.eq(other) {
Some(Ordering::Equal)
} else {
Some(Ordering::Less)
}
}
fn lt(&self, other: &Self) -> bool {
let self_part = match self {
Chapter { part, .. } => part,
Volume { part, .. } => part,
};
let other_part = match other {
Chapter { part, .. } => part,
Volume { part, .. } => part,
};
self_part < other_part
}
fn le(&self, other: &Self) -> bool {
!self.gt(other)
}
fn gt(&self, other: &Self) -> bool {
let self_part = match self {
Chapter { part, .. } => part,
Volume { part, .. } => part,
};
let other_part = match other {
Chapter { part, .. } => part,
Volume { part, .. } => part,
};
self_part > other_part
}
fn ge(&self, other: &Self) -> bool {
!self.lt(other)
}
}
pub(crate) struct JFetcherOptions {
series_slug: String, series_slug: String,
series_has_parts: bool series_has_parts: bool
} }
impl Default for JNovelFetcher { impl JFetcherOptions {
fn default() -> Self { pub(crate) fn new(series_slug: String, series_has_parts: bool) -> Self {
Self { JFetcherOptions {
series_slug: "".to_owned(), series_slug,
series_has_parts: false, series_has_parts
} }
} }
} }
impl JNovelFetcher {
pub(crate) fn set_series(&mut self, series: String) {
self.series_slug = series;
}
pub(crate) fn set_part_option(&mut self, has_parts: bool) {
self.series_has_parts = has_parts;
}
}
#[async_trait] #[async_trait]
impl FetcherTrait for JNovelFetcher { impl Fetcher for JFetcherOptions {
fn new() -> Self { type Return = JPostInfo;
JNovelFetcher { async fn check_feed(&self) -> Result<Vec<Self::Return>, ()> {
series_slug: "".to_owned(),
series_has_parts: false
}
}
async fn check_feed(&self) -> Result<Vec<PostInfo>, ()> {
let response = match HTTP_CLIENT let response = match HTTP_CLIENT
.get(api_url!() + "/series/" + self.series_slug.as_str() + "/volumes?format=json") .get(api_url!() + "/series/" + self.series_slug.as_str() + "/volumes?format=json")
.send() .send()
@ -131,7 +284,7 @@ impl FetcherTrait for JNovelFetcher {
Ok(data) => match data.text().await { Ok(data) => match data.text().await {
Ok(data) => data, Ok(data) => data,
Err(e) => { Err(e) => {
let err_msg = format!("While checking feed: {e}"); let err_msg = format!("{e}");
error!(err_msg); error!(err_msg);
return Err(()); return Err(());
} }
@ -154,8 +307,8 @@ impl FetcherTrait for JNovelFetcher {
volume_brief_data.volumes.reverse(); // Makes breaking out of the volume loop easier volume_brief_data.volumes.reverse(); // Makes breaking out of the volume loop easier
// If no parts just use 0 as Part indicator as no Series with Parts has a Part 0 // If no parts just use 0 as Part indicator as no Series with Parts has a Part 0
let mut volume_map: HashMap<u8, PostInfo> = HashMap::new(); let mut volume_map: HashMap<u8, JPostInfo> = HashMap::new();
let mut prepub_map: HashMap<u8, PostInfo> = HashMap::new(); let mut prepub_map: HashMap<u8, JPostInfo> = HashMap::new();
for volume in volume_brief_data.volumes.iter() { for volume in volume_brief_data.volumes.iter() {
let publishing_date = DateTime::parse_from_rfc3339(&volume.publishing).unwrap(); let publishing_date = DateTime::parse_from_rfc3339(&volume.publishing).unwrap();
@ -198,16 +351,14 @@ impl FetcherTrait for JNovelFetcher {
self.series_slug.as_str(), self.series_slug.as_str(),
volume.number volume.number
); );
let post_details = PostInfoInner { let post_details = lemmy::PostInfoInner {
title: volume.title.clone(), title: volume.title.clone(),
url: post_url.clone(), url: Url::parse(&post_url).unwrap(),
thumbnail: Some(volume.cover.thumbnail.clone())
}; };
let new_post_info = PostInfo { let new_post_info = Volume {
post_type: Some(PostType::Volume), part: new_part_info,
part: Some(new_part_info), description: volume.short_description.clone(),
description: Some(volume.short_description.clone()),
lemmy_info: post_details, lemmy_info: post_details,
}; };
@ -224,12 +375,10 @@ impl FetcherTrait for JNovelFetcher {
.or_insert(new_post_info); .or_insert(new_post_info);
} }
if let Some(prepub_info) = get_latest_prepub(&volume.slug).await { if let Some(prepub_info) = get_latest_prepub(&volume.slug).await? {
let prepub_post_info = PostInfo { let prepub_post_info = Chapter {
post_type: Some(PostType::Chapter), part: new_part_info,
part: Some(new_part_info),
lemmy_info: prepub_info, lemmy_info: prepub_info,
description: None,
}; };
prepub_map prepub_map
@ -243,8 +392,8 @@ impl FetcherTrait for JNovelFetcher {
} }
} }
let mut result_vec: Vec<PostInfo> = volume_map.values().cloned().collect(); let mut result_vec: Vec<JPostInfo> = volume_map.values().cloned().collect();
let mut prepub_vec: Vec<PostInfo> = prepub_map.values().cloned().collect(); let mut prepub_vec: Vec<JPostInfo> = prepub_map.values().cloned().collect();
result_vec.append(&mut prepub_vec); result_vec.append(&mut prepub_vec);
Ok(result_vec) Ok(result_vec)
@ -252,7 +401,7 @@ impl FetcherTrait for JNovelFetcher {
} }
async fn get_latest_prepub(volume_slug: &str) -> Option<PostInfoInner> { async fn get_latest_prepub(volume_slug: &str) -> Result<Option<lemmy::PostInfoInner>, ()> {
let response = match HTTP_CLIENT let response = match HTTP_CLIENT
.get(api_url!() + "/volumes/" + volume_slug + "/parts?format=json") .get(api_url!() + "/volumes/" + volume_slug + "/parts?format=json")
.send() .send()
@ -261,15 +410,15 @@ async fn get_latest_prepub(volume_slug: &str) -> Option<PostInfoInner> {
Ok(data) => match data.text().await { Ok(data) => match data.text().await {
Ok(data) => data, Ok(data) => data,
Err(e) => { Err(e) => {
let err_msg = format!("While getting latest PrePub: {e}"); let err_msg = format!("{e}");
error!(err_msg); error!(err_msg);
return None; return Err(());
} }
}, },
Err(e) => { Err(e) => {
let err_msg = format!("{e}"); let err_msg = format!("{e}");
error!(err_msg); error!(err_msg);
return None; return Err(());
} }
}; };
@ -278,12 +427,12 @@ async fn get_latest_prepub(volume_slug: &str) -> Option<PostInfoInner> {
Err(e) => { Err(e) => {
let err_msg = format!("{e}"); let err_msg = format!("{e}");
error!(err_msg); error!(err_msg);
return None; return Err(());
} }
}; };
volume_prepub_parts_data.parts.reverse(); // Makes breaking out of the parts loop easier volume_prepub_parts_data.parts.reverse(); // Makes breaking out of the parts loop easier
let mut post_details: Option<PostInfoInner> = None; let mut post_details: Option<lemmy::PostInfoInner> = None;
for prepub_part in volume_prepub_parts_data.parts.iter() { for prepub_part in volume_prepub_parts_data.parts.iter() {
let publishing_date = DateTime::parse_from_rfc3339(&prepub_part.launch).unwrap(); let publishing_date = DateTime::parse_from_rfc3339(&prepub_part.launch).unwrap();
@ -293,15 +442,12 @@ async fn get_latest_prepub(volume_slug: &str) -> Option<PostInfoInner> {
continue; continue;
} }
let thumbnail = prepub_part.cover.as_ref().map(|cover| cover.thumbnail.clone());
let post_url = format!("{}/read/{}", jnc_base_url!(), prepub_part.slug); let post_url = format!("{}/read/{}", jnc_base_url!(), prepub_part.slug);
post_details = Some(PostInfoInner { post_details = Some(lemmy::PostInfoInner {
title: prepub_part.title.clone(), title: prepub_part.title.clone(),
url: post_url.clone(), url: Url::parse(&post_url).unwrap(),
thumbnail
}); });
} }
post_details Ok(post_details)
} }

View file

@ -1,33 +1,9 @@
use async_trait::async_trait; use async_trait::async_trait;
use serde_derive::{Deserialize, Serialize};
use strum_macros::Display;
use crate::fetchers::Fetcher::Jnc;
use crate::fetchers::jnovel::JNovelFetcher;
use crate::lemmy::{PostInfo};
pub mod jnovel; pub mod jnovel;
#[async_trait] #[async_trait]
pub(crate) trait FetcherTrait { pub(crate) trait Fetcher {
fn new() -> Self where Self: Sized; type Return;
async fn check_feed(&self) -> Result<Vec<PostInfo>, ()>; async fn check_feed(&self) -> Result<Vec<Self::Return>, ()>;
}
impl Fetcher {
pub(crate) async fn check_feed(&self) -> Result<Vec<PostInfo>, ()> {
match self {
Jnc(fetcher) => fetcher.check_feed().await,
/*default => {
let err_msg = format!("Fetcher {default} is not implemented");
error!(err_msg);
Err(())
}*/
}
}
}
#[derive(Deserialize, Serialize, Debug, Clone, Display)]
pub(crate) enum Fetcher {
#[serde(rename = "jnc")]
Jnc(#[serde(skip)] JNovelFetcher)
} }

View file

@ -1,28 +1,18 @@
use std::cmp::Ordering; use crate::config::Config;
use crate::config::{Config, PostBody, PostConfig, SeriesConfig};
use crate::{HTTP_CLIENT}; use crate::{HTTP_CLIENT};
use lemmy_api_common::community::{ListCommunities, ListCommunitiesResponse}; use lemmy_api_common::community::{ListCommunities, ListCommunitiesResponse};
use lemmy_api_common::lemmy_db_views::structs::PostView; use lemmy_api_common::lemmy_db_views::structs::PostView;
use lemmy_api_common::person::{Login, LoginResponse}; use lemmy_api_common::person::{Login, LoginResponse};
use lemmy_api_common::post::{CreatePost, FeaturePost, GetPosts, GetPostsResponse}; use lemmy_api_common::post::{CreatePost, FeaturePost, GetPosts, GetPostsResponse};
use lemmy_db_schema::newtypes::{CommunityId, LanguageId, PostId}; use lemmy_api_common::sensitive::Sensitive;
use lemmy_db_schema::newtypes::{CommunityId, PostId};
use lemmy_db_schema::{ListingType, PostFeatureType}; use lemmy_db_schema::{ListingType, PostFeatureType};
use reqwest::StatusCode; use reqwest::StatusCode;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{RwLock};
use lemmy_db_schema::sensitive::SensitiveString;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url;
use systemd_journal_logger::connected_to_journal; use systemd_journal_logger::connected_to_journal;
macro_rules! debug {
($msg:tt) => {
match connected_to_journal() {
true => log::debug!("[DEBUG] {}", $msg),
false => println!("[DEBUG] {}", $msg),
}
};
}
macro_rules! error { macro_rules! error {
($msg:tt) => { ($msg:tt) => {
match connected_to_journal() { match connected_to_journal() {
@ -33,263 +23,86 @@ macro_rules! error {
} }
pub(crate) struct Lemmy { pub(crate) struct Lemmy {
jwt_token: SensitiveString, jwt_token: Sensitive<String>,
instance: String, instance: String,
communities: HashMap<String, CommunityId>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PostInfoInner { pub(crate) struct PostInfoInner {
pub(crate) title: String, pub(crate) title: String,
pub(crate) url: String, pub(crate) url: Url,
pub(crate) thumbnail: Option<String>
} }
#[derive(Debug, Copy, Clone)] pub(crate) trait PostInfo {
pub(crate) enum PartInfo { fn get_info(&self) -> PostInfoInner;
NoParts,
Part(u8), fn get_description(&self) -> Option<String>;
} }
impl PartInfo { pub(crate) async fn login(config: &Config) -> Result<Lemmy, ()> {
pub(crate) fn as_u8(&self) -> u8 { let login_params = Login {
match self { username_or_email: config.get_username(),
PartInfo::Part(number) => *number, password: config.get_password(),
PartInfo::NoParts => 0, totp_2fa_token: None,
};
let response = match HTTP_CLIENT
.post(config.instance.to_owned() + "/api/v3/user/login")
.json(&login_params)
.send()
.await
{
Ok(data) => data,
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
return Err(());
} }
} };
pub(crate) fn as_string(&self) -> String { match response.status() {
self.as_u8().to_string() StatusCode::OK => {
} let data: LoginResponse = response
} .json()
.await
impl PartialEq for PartInfo { .expect("Successful Login Request should return JSON");
fn eq(&self, other: &Self) -> bool { match data.jwt {
let self_numeric = self.as_u8(); Some(token) => Ok(Lemmy {
let other_numeric = other.as_u8(); jwt_token: token.clone(),
self_numeric == other_numeric instance: config.instance.to_owned(),
} }),
} None => {
let err_msg = "Login did not return JWT token. Are the credentials valid?".to_owned();
impl PartialOrd for PartInfo { error!(err_msg);
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Err(())
if self.gt(other) {
Some(Ordering::Greater)
} else if self.eq(other) {
Some(Ordering::Equal)
} else {
Some(Ordering::Less)
}
}
fn lt(&self, other: &Self) -> bool {
let self_numeric = self.as_u8();
let other_numeric = other.as_u8();
self_numeric < other_numeric
}
fn le(&self, other: &Self) -> bool {
!self.gt(other)
}
fn gt(&self, other: &Self) -> bool {
let self_numeric = self.as_u8();
let other_numeric = other.as_u8();
self_numeric > other_numeric
}
fn ge(&self, other: &Self) -> bool {
!self.lt(other)
}
}
#[derive(Debug, Clone, Copy)]
pub(crate) enum PostType {
Chapter,
Volume
}
#[derive(Debug, Clone)]
pub(crate) struct PostInfo {
pub(crate) part: Option<PartInfo>,
pub(crate) lemmy_info: PostInfoInner,
pub(crate) description: Option<String>,
pub(crate) post_type: Option<PostType>
}
impl PostInfo {
pub(crate)fn get_info(&self) -> PostInfoInner {
self.lemmy_info.clone()
}
pub(crate)fn get_description(&self) -> Option<String> {
self.description.clone()
}
pub(crate) fn get_part_info(&self) -> Option<PartInfo> {
self.part
}
pub(crate) fn get_post_config(&self, series: &SeriesConfig) -> PostConfig {
match self.post_type {
Some(post_type) => {
match post_type {
PostType::Chapter => series.prepub_community.clone(),
PostType::Volume => series.volume_community.clone(),
} }
} }
None => series.prepub_community.clone(),
} }
} status => {
let err_msg = format!("Unexpected HTTP Status '{}' during Login", status);
pub(crate) fn get_post_data(&self, series: &SeriesConfig, lemmy: &Lemmy) -> CreatePost { error!(err_msg);
let post_config = self.get_post_config(series); Err(())
let post_body = match &post_config.post_body {
PostBody::None => None,
PostBody::Description => self.get_description(),
PostBody::Custom(text) => Some(text.clone()),
};
let community_id: CommunityId = lemmy.get_community_id(&post_config.name);
CreatePost {
name: self.get_info().title.clone(),
community_id,
url: Some(self.get_info().url),
custom_thumbnail: self.get_info().thumbnail,
body: post_body,
alt_text: None,
honeypot: None,
nsfw: None,
language_id: Some(LanguageId(37)), // TODO get this id once every few hours per API request, the ordering of IDs suggests that the EN Id might change in the future
} }
} }
} }
impl PartialEq for PostInfo {
fn eq(&self, other: &Self) -> bool {
self.part.eq(&other.part)
}
}
impl PartialOrd for PostInfo {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.gt(other) {
Some(Ordering::Greater)
} else if self.eq(other) {
Some(Ordering::Equal)
} else {
Some(Ordering::Less)
}
}
fn lt(&self, other: &Self) -> bool {
self.part < other.part
}
fn le(&self, other: &Self) -> bool {
!self.gt(other)
}
fn gt(&self, other: &Self) -> bool {
self.part > other.part
}
fn ge(&self, other: &Self) -> bool {
!self.lt(other)
}
}
impl Lemmy { impl Lemmy {
pub(crate) fn get_community_id(&self, name: &str) -> CommunityId { pub(crate) async fn post(&self, post: CreatePost) -> Result<PostId, ()> {
*self.communities.get(name).expect("Given community is invalid") let response: String = self.post_data_json("/api/v3/post", &post).await?;
} let json_data: PostView = self.parse_json_map(&response).await?;
pub(crate) async fn new(config: &RwLock<Config>) -> Result<Self, ()> {
let read_config = config.read().expect("Read Lock Failed").clone();
let login_params = Login {
username_or_email: read_config.get_username(),
password: read_config.get_password(),
totp_2fa_token: None,
};
let response = match HTTP_CLIENT Ok(json_data.post.id)
.post(read_config.instance.to_owned() + "/api/v3/user/login")
.json(&login_params)
.send()
.await
{
Ok(data) => data,
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
return Err(());
}
};
match response.status() {
StatusCode::OK => {
let data: LoginResponse = response
.json()
.await
.expect("Successful Login Request should return JSON");
match data.jwt {
Some(token) => Ok(Lemmy {
jwt_token: token.clone(),
instance: read_config.instance.to_owned(),
communities: HashMap::new(),
}),
None => {
let err_msg = "Login did not return JWT token. Are the credentials valid?".to_owned();
error!(err_msg);
Err(())
}
}
}
status => {
let err_msg = format!("Unexpected HTTP Status '{}' during Login", status);
error!(err_msg);
Err(())
}
}
} }
pub(crate) async fn logout(&self) { async fn feature(&self, params: FeaturePost) -> Result<PostView, ()> {
let _ = self.post_data_json("/api/v3/user/logout", &"").await; let response: String = self.post_data_json("/api/v3/post/feature", &params).await?;
let json_data: PostView = self.parse_json_map(&response).await?;
Ok(json_data)
} }
pub(crate) async fn unpin(&self, post_id: PostId, location: PostFeatureType) -> Result<PostView, ()> {
pub(crate) async fn post(&self, post: CreatePost) -> Option<PostId> {
let response: String = match self.post_data_json("/api/v3/post", &post).await {
Some(data) => data,
None => return None,
};
let json_data: PostView = match self.parse_json_map(&response).await {
Some(data) => data,
None => return None,
};
Some(json_data.post.id)
}
async fn feature(&self, params: FeaturePost) -> Option<PostView> {
let response: String = match self.post_data_json("/api/v3/post/feature", &params).await {
Some(data) => data,
None => return None,
};
let json_data: PostView = match self.parse_json_map(&response).await {
Some(data) => data,
None => return None,
};
Some(json_data)
}
pub(crate) async fn unpin(&self, post_id: PostId, location: PostFeatureType) -> Option<PostView> {
let pin_params = FeaturePost { let pin_params = FeaturePost {
post_id, post_id,
featured: false, featured: false,
@ -298,7 +111,7 @@ impl Lemmy {
self.feature(pin_params).await self.feature(pin_params).await
} }
pub(crate) async fn pin(&self, post_id: PostId, location: PostFeatureType) -> Option<PostView> { pub(crate) async fn pin(&self, post_id: PostId, location: PostFeatureType) -> Result<PostView, ()> {
let pin_params = FeaturePost { let pin_params = FeaturePost {
post_id, post_id,
featured: true, featured: true,
@ -307,23 +120,17 @@ impl Lemmy {
self.feature(pin_params).await self.feature(pin_params).await
} }
pub(crate) async fn get_community_pinned(&self, community: CommunityId) -> Option<Vec<PostView>> { pub(crate) async fn get_community_pinned(&self, community: CommunityId) -> Result<Vec<PostView>, ()> {
let list_params = GetPosts { let list_params = GetPosts {
community_id: Some(community), community_id: Some(community),
type_: Some(ListingType::Local), type_: Some(ListingType::Local),
..Default::default() ..Default::default()
}; };
let response: String = match self.get_data_query("/api/v3/post/list", &list_params).await { let response: String = self.get_data_query("/api/v3/post/list", &list_params).await?;
Some(data) => data, let json_data: GetPostsResponse = self.parse_json(&response).await?;
None => return None,
};
let json_data: GetPostsResponse = match self.parse_json(&response).await {
Some(data) => data,
None => return None,
};
Some(json_data Ok(json_data
.posts .posts
.iter() .iter()
.filter(|post| post.post.featured_community) .filter(|post| post.post.featured_community)
@ -331,22 +138,16 @@ impl Lemmy {
.collect()) .collect())
} }
pub(crate) async fn get_local_pinned(&self) -> Option<Vec<PostView>> { pub(crate) async fn get_local_pinned(&self) -> Result<Vec<PostView>, ()> {
let list_params = GetPosts { let list_params = GetPosts {
type_: Some(ListingType::Local), type_: Some(ListingType::Local),
..Default::default() ..Default::default()
}; };
let response: String = match self.get_data_query("/api/v3/post/list", &list_params).await { let response: String = self.get_data_query("/api/v3/post/list", &list_params).await?;
Some(data) => data, let json_data: GetPostsResponse = self.parse_json(&response).await?;
None => return None,
};
let json_data: GetPostsResponse = match self.parse_json(&response).await {
Some(data) => data,
None => return None,
};
Some(json_data Ok(json_data
.posts .posts
.iter() .iter()
.filter(|post| post.post.featured_local) .filter(|post| post.post.featured_local)
@ -354,20 +155,14 @@ impl Lemmy {
.collect()) .collect())
} }
pub(crate) async fn get_communities(&mut self) { pub(crate) async fn get_communities(&self) -> Result<HashMap<String, CommunityId>, ()> {
let list_params = ListCommunities { let list_params = ListCommunities {
type_: Some(ListingType::Local), type_: Some(ListingType::Local),
..Default::default() ..Default::default()
}; };
let response: String = match self.get_data_query("/api/v3/community/list", &list_params).await { let response: String = self.get_data_query("/api/v3/community/list", &list_params).await?;
Some(data) => data, let json_data: ListCommunitiesResponse = self.parse_json(&response).await?;
None => return,
};
let json_data: ListCommunitiesResponse = match self.parse_json::<ListCommunitiesResponse>(&response).await {
Some(data) => data,
None => return,
};
let mut communities: HashMap<String, CommunityId> = HashMap::new(); let mut communities: HashMap<String, CommunityId> = HashMap::new();
for community_view in json_data.communities { for community_view in json_data.communities {
@ -375,10 +170,10 @@ impl Lemmy {
communities.insert(community.name, community.id); communities.insert(community.name, community.id);
} }
self.communities = communities; Ok(communities)
} }
async fn post_data_json<T: Serialize>(&self, route: &str, json: &T ) -> Option<String> { async fn post_data_json<T: Serialize>(&self, route: &str, json: &T ) -> Result<String,()> {
let res = HTTP_CLIENT let res = HTTP_CLIENT
.post(format!("{}{route}", &self.instance)) .post(format!("{}{route}", &self.instance))
.bearer_auth(&self.jwt_token.to_string()) .bearer_auth(&self.jwt_token.to_string())
@ -388,7 +183,7 @@ impl Lemmy {
self.extract_data(res).await self.extract_data(res).await
} }
async fn get_data_query<T: Serialize>(&self, route: &str, param: &T ) -> Option<String> { async fn get_data_query<T: Serialize>(&self, route: &str, param: &T ) -> Result<String,()> {
let res = HTTP_CLIENT let res = HTTP_CLIENT
.get(format!("{}{route}", &self.instance)) .get(format!("{}{route}", &self.instance))
.bearer_auth(&self.jwt_token.to_string()) .bearer_auth(&self.jwt_token.to_string())
@ -398,52 +193,42 @@ impl Lemmy {
self.extract_data(res).await self.extract_data(res).await
} }
async fn extract_data(&self, response: Result<reqwest::Response, reqwest::Error>) -> Option<String> { async fn extract_data(&self, response: Result<reqwest::Response, reqwest::Error>) -> Result<String,()> {
match response { match response {
Ok(data) => { Ok(data) => match data.text().await {
if data.status().is_success() { Ok(data) => Ok(data),
match data.text().await { Err(e) => {
Ok(data) => Some(data), let err_msg = format!("{e}");
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
None
}
}
}
else {
let err_msg = format!("HTTP Request failed: {}", data.text().await.unwrap());
error!(err_msg); error!(err_msg);
None Err(())
} }
}, },
Err(e) => { Err(e) => {
let err_msg = format!("{e}"); let err_msg = format!("{e}");
error!(err_msg); error!(err_msg);
None Err(())
} }
} }
} }
async fn parse_json<'a, T: Deserialize<'a>>(&self, response: &'a str) -> Option<T> { async fn parse_json<'a, T: Deserialize<'a>>(&self, response: &'a str) -> Result<T,()> {
match serde_json::from_str::<T>(response) { match serde_json::from_str::<T>(response) {
Ok(data) => Some(data), Ok(data) => Ok(data),
Err(e) => { Err(e) => {
let err_msg = format!("while parsing JSON: {e} "); let err_msg = format!("{e} while parsing JSON");
error!(err_msg); error!(err_msg);
None Err(())
} }
} }
} }
async fn parse_json_map<'a, T: Deserialize<'a>>(&self, response: &'a str) -> Option<T> { async fn parse_json_map<'a, T: Deserialize<'a>>(&self, response: &'a str) -> Result<T,()> {
debug!(response);
match serde_json::from_str::<HashMap<&str, T>>(response) { match serde_json::from_str::<HashMap<&str, T>>(response) {
Ok(mut data) => Some(data.remove("post_view").expect("Element should be present")), Ok(mut data) => Ok(data.remove("post_view").expect("Element should be present")),
Err(e) => { Err(e) => {
let err_msg = format!("while parsing JSON HashMap: {e}"); let err_msg = format!("{e} while parsing JSON HashMap");
error!(err_msg); error!(err_msg);
None Err(())
} }
} }
} }

View file

@ -3,7 +3,6 @@ use log::{LevelFilter};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use reqwest::Client; use reqwest::Client;
use systemd_journal_logger::{JournalLog}; use systemd_journal_logger::{JournalLog};
use crate::bot::Bot;
mod bot; mod bot;
mod config; mod config;
@ -25,17 +24,6 @@ async fn main() {
.expect("Systemd-Logger crate error") .expect("Systemd-Logger crate error")
.install() .install()
.expect("Systemd-Logger crate error"); .expect("Systemd-Logger crate error");
match std::env::var("LOG_LEVEL") { log::set_max_level(LevelFilter::Info);
Ok(level) => { bot::run().await;
match level.as_str() {
"debug" => log::set_max_level(LevelFilter::Debug),
"info" => log::set_max_level(LevelFilter::Info),
_ => log::set_max_level(LevelFilter::Info),
}
}
_ => log::set_max_level(LevelFilter::Info),
}
let mut bot = Bot::new();
bot.run().await;
} }