Compare commits

...

191 commits
1.3.1 ... main

Author SHA1 Message Date
041590a559
Release 3.2.0
All checks were successful
Run Tests on Code / run-tests (push) Successful in 35s
Build and Release Binary File / test (push) Successful in 35s
Build and Release Binary File / build (push) Successful in 39s
Build and Release Binary File / upload-generic-package (push) Successful in 1s
Build and Release Binary File / upload-debian-package (push) Successful in 1s
Build and Release Binary File / upload-release (push) Successful in 6s
2024-10-22 16:15:19 +02:00
d6f883f890
Bump API version
All checks were successful
Run Tests on Code / run-tests (push) Successful in 35s
2024-10-22 16:14:46 +02:00
b07420e0bd Merge pull request 'Bump forgejo-release to v2' (#26) from actions-update into main
All checks were successful
Run Tests on Code / run-tests (push) Successful in 19s
Reviewed-on: https://forgejo.neshweb.net///Neshura/aob-lemmy-bot/pulls/26
2024-08-06 12:23:26 +00:00
0fc71f0a7d Bump forgejo-release to v2
All checks were successful
Run Tests on Code / run-tests (push) Successful in 1m7s
Build binary file and bundle packages / test (pull_request) Successful in 1m6s
Build binary file and bundle packages / build (pull_request) Successful in 1m10s
2024-08-06 12:19:37 +00:00
2ae6468ad8
Release 3.1.0
All checks were successful
Run Tests on Code / run-tests (push) Successful in 47s
Build and Release Binary File / test (push) Successful in 16s
Build and Release Binary File / build (push) Successful in 48s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 37s
2024-07-15 22:15:49 +02:00
2ecfe88cb9
Update to 0.19.5 and include optional thumbnail 2024-07-15 22:15:31 +02:00
7dcc7bfee2
Release 3.0.3
All checks were successful
Run Tests on Code / run-tests (push) Successful in 33s
Build and Release Binary File / test (push) Successful in 33s
Build and Release Binary File / build (push) Successful in 36s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 7s
2024-05-08 16:34:48 +02:00
94d8a4e673
Add Timeout to Status Ping HTTP Request
All checks were successful
Run Tests on Code / run-tests (push) Successful in 14s
2024-05-08 16:34:32 +02:00
1b585eab7e
Release 3.0.2
All checks were successful
Run Tests on Code / run-tests (push) Successful in 37s
Build and Release Binary File / test (push) Successful in 37s
Build and Release Binary File / build (push) Successful in 37s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 7s
2024-05-07 23:50:14 +02:00
b6f5c38e4a
Overhaul Error handling (Option instead of Result<T, ()> + Logging changes
All checks were successful
Run Tests on Code / run-tests (push) Successful in 15s
2024-05-07 23:49:55 +02:00
5d708bdb82
Release 3.0.1
All checks were successful
Run Tests on Code / run-tests (push) Successful in 34s
Build and Release Binary File / test (push) Successful in 34s
Build and Release Binary File / build (push) Successful in 38s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 8s
2024-05-07 22:50:22 +02:00
6a8c1662f0
Fix enum problems in config
All checks were successful
Run Tests on Code / run-tests (push) Successful in 16s
2024-05-07 22:50:12 +02:00
e02cd900ed
Release 3.0.0
All checks were successful
Run Tests on Code / run-tests (push) Successful in 41s
Build and Release Binary File / test (push) Successful in 35s
Build and Release Binary File / build (push) Successful in 37s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 8s
2024-05-07 22:35:15 +02:00
32ea83a7bb
Release Candidate 3.0.0-rc.2
All checks were successful
Run Tests on Code / run-tests (push) Successful in 34s
Build and Release Binary File / test (push) Successful in 32s
Build and Release Binary File / build (push) Successful in 37s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 8s
2024-05-07 22:30:02 +02:00
4297860b9e
Legacy fixes for async traits
All checks were successful
Run Tests on Code / run-tests (push) Successful in 32s
2024-05-07 22:29:48 +02:00
affe62b973
Release Candidate 3.0.0-rc.1
Some checks failed
Build and Release Binary File / test (push) Failing after 27s
Run Tests on Code / run-tests (push) Failing after 39s
Build and Release Binary File / build (push) Has been skipped
Build and Release Binary File / upload-generic-package (push) Has been skipped
Build and Release Binary File / upload-debian-package (push) Has been skipped
Build and Release Binary File / upload-release (push) Has been skipped
2024-05-07 22:11:16 +02:00
6520cc65a3
Rewrite Version 3
Some checks failed
Run Tests on Code / run-tests (push) Failing after 36s
2024-05-07 22:10:21 +02:00
aefceda628
Release 2.2.8
All checks were successful
Run Tests on Code / run-tests (push) Successful in 33s
Build and Release Binary File / test (push) Successful in 33s
Build and Release Binary File / build (push) Successful in 36s
Build and Release Binary File / upload-generic-package (push) Successful in 1s
Build and Release Binary File / upload-debian-package (push) Successful in 1s
Build and Release Binary File / upload-release (push) Successful in 7s
2024-05-06 22:57:55 +02:00
ee5a159431
Yet another another logging fix
All checks were successful
Run Tests on Code / run-tests (push) Successful in 11s
2024-05-06 22:57:41 +02:00
85f8b97607
Yet another logging fix
All checks were successful
Run Tests on Code / run-tests (push) Successful in 11s
2024-05-06 22:57:05 +02:00
966dd8f359
Release 2.2.7
All checks were successful
Run Tests on Code / run-tests (push) Successful in 34s
Build and Release Binary File / test (push) Successful in 31s
Build and Release Binary File / build (push) Successful in 35s
Build and Release Binary File / upload-generic-package (push) Successful in 1s
Build and Release Binary File / upload-debian-package (push) Successful in 1s
Build and Release Binary File / upload-release (push) Successful in 7s
2024-05-06 22:54:15 +02:00
17e161bc27
Small fixes to logging 2024-05-06 22:54:01 +02:00
3928367692
Release 2.2.6
All checks were successful
Run Tests on Code / run-tests (push) Successful in 32s
Build and Release Binary File / test (push) Successful in 33s
Build and Release Binary File / build (push) Successful in 35s
Build and Release Binary File / upload-generic-package (push) Successful in 1s
Build and Release Binary File / upload-debian-package (push) Successful in 1s
Build and Release Binary File / upload-release (push) Successful in 8s
2024-05-06 22:36:33 +02:00
070eae961a
Yet more logging and delay between series handling requests (should avoid potential rate limit)
Some checks failed
Run Tests on Code / run-tests (push) Has been cancelled
2024-05-06 22:36:21 +02:00
92103e28ba
Release 2.2.5
All checks were successful
Run Tests on Code / run-tests (push) Successful in 35s
Build and Release Binary File / test (push) Successful in 33s
Build and Release Binary File / build (push) Successful in 35s
Build and Release Binary File / upload-generic-package (push) Successful in 1s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 8s
2024-05-06 22:21:14 +02:00
cd78d3c1c7
Reduced connection timeouts and added some logging
Some checks failed
Run Tests on Code / run-tests (push) Has been cancelled
2024-05-06 22:21:04 +02:00
22bbaaa002
Release 2.2.4
All checks were successful
Run Tests on Code / run-tests (push) Successful in 36s
Build and Release Binary File / test (push) Successful in 35s
Build and Release Binary File / build (push) Successful in 36s
Build and Release Binary File / upload-generic-package (push) Successful in 1s
Build and Release Binary File / upload-debian-package (push) Successful in 1s
Build and Release Binary File / upload-release (push) Successful in 11s
2024-05-06 21:53:14 +02:00
9ee9db5792
Dependency bumps
Some checks failed
Run Tests on Code / run-tests (push) Has been cancelled
2024-05-06 21:53:02 +02:00
23ac0de189
Release 2.2.3
All checks were successful
Run Tests on Code / run-tests (push) Successful in 34s
Build and Release Binary File / test (push) Successful in 32s
Build and Release Binary File / build (push) Successful in 37s
Build and Release Binary File / upload-generic-package (push) Successful in 1s
Build and Release Binary File / upload-debian-package (push) Successful in 1s
Build and Release Binary File / upload-release (push) Successful in 11s
2024-05-06 21:28:00 +02:00
2dc695577e
Further Bugfixing 2024-05-06 21:27:47 +02:00
534a8022a9
Release 2.2.2
All checks were successful
Run Tests on Code / run-tests (push) Successful in 33s
Build and Release Binary File / test (push) Successful in 32s
Build and Release Binary File / build (push) Successful in 38s
Build and Release Binary File / upload-generic-package (push) Successful in 1s
Build and Release Binary File / upload-debian-package (push) Successful in 1s
Build and Release Binary File / upload-release (push) Successful in 8s
2024-05-06 21:17:08 +02:00
45bfca8cc5
Bugfix due to bad deduplication
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
2024-05-06 21:16:53 +02:00
34b3bb45c5
Release 2.2.1
All checks were successful
Run Tests on Code / run-tests (push) Successful in 33s
Build and Release Binary File / test (push) Successful in 33s
Build and Release Binary File / build (push) Successful in 37s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 1s
Build and Release Binary File / upload-release (push) Successful in 13s
2024-05-06 21:06:17 +02:00
3e78ce5bf6
Merge pull request 'Various Fixes and Changes' (#21) from hotfix-1 into main
All checks were successful
Run Tests on Code / run-tests (push) Successful in 16s
2024-05-06 21:05:07 +02:00
fc4ce74567
Clippy changes
All checks were successful
Build binary file and bundle packages / test (pull_request) Successful in 36s
Run Tests on Code / run-tests (push) Successful in 38s
Build binary file and bundle packages / build (pull_request) Successful in 36s
2024-05-06 21:00:55 +02:00
85f3044224
Lemmy API Crate bump 2024-05-06 20:57:35 +02:00
d50bf01db6
Fix erroneous print statement to use logger 2024-05-06 20:57:32 +02:00
c8d7053b87
De-duplicate Code 2024-05-06 20:57:29 +02:00
962d90fe1d
Remove unnecessary thread structure 2024-05-06 20:57:26 +02:00
36b59240d9
Use macros over functions for error logging 2024-05-06 20:57:20 +02:00
1cd30b1145
Add async-trait crate
Some checks failed
Run Tests on Code / run-tests (push) Failing after 31s
2024-01-08 21:07:49 +01:00
167fcdb7ad
Import fetchers instead of jnovel module in main 2024-01-08 21:07:36 +01:00
b9a26a7b1c
Partially adapt bot module to changes due to fetchers modularization 2024-01-08 21:07:17 +01:00
e5862ba0ec
Move relevant structs to lemmy module 2024-01-08 21:06:52 +01:00
6bd7369ecc
Move jnovel module into fetchers module 2024-01-08 21:06:25 +01:00
ba3110da0e
Add fetchers trait module 2024-01-08 21:06:18 +01:00
0e88326293
Release 2.2.0
All checks were successful
Run Tests on Code / run-tests (push) Successful in 32s
Build and Release Binary File / test (push) Successful in 33s
Build and Release Binary File / build (push) Successful in 42s
Build and Release Binary File / upload-generic-package (push) Successful in 5s
Build and Release Binary File / upload-debian-package (push) Successful in 4s
Build and Release Binary File / upload-release (push) Successful in 7s
2024-01-08 11:07:09 +01:00
a0ff81d582
Remove excessive "Skipping since already posted" logging
All checks were successful
Run Tests on Code / run-tests (push) Successful in 11s
2024-01-08 11:06:00 +01:00
2d65a12781 Delete deprecated deploy script
All checks were successful
Run Tests on Code / run-tests (push) Successful in 29s
2024-01-08 09:54:40 +00:00
bed8881d70 Delete deprecated systemd service file
Some checks failed
Run Tests on Code / run-tests (push) Has been cancelled
2024-01-08 09:54:20 +00:00
bb98a6bfce Merge pull request 'Systemd Unit File' (#16) from systemd into main
All checks were successful
Run Tests on Code / run-tests (push) Successful in 14s
Reviewed-on: #16
2023-12-30 00:43:11 +00:00
7a6ebd6381
Release Candidate 2.2.0-rc.3 (Fix Debian binary location in systemd file)
All checks were successful
Build and Release Binary File / test (push) Successful in 44s
Build and Release Binary File / build (push) Successful in 40s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 1s
Build and Release Binary File / upload-release (push) Successful in 8s
Run Tests on Code / run-tests (push) Successful in 9s
Build binary file and bundle packages / test (pull_request) Successful in 14s
Build binary file and bundle packages / build (pull_request) Successful in 37s
2023-12-30 01:37:16 +01:00
d0375b1d8d
Release Candidate 2.2.0-rc.2
All checks were successful
Run Tests on Code / run-tests (push) Successful in 34s
Build and Release Binary File / test (push) Successful in 29s
Build binary file and bundle packages / test (pull_request) Successful in 20s
Build and Release Binary File / build (push) Successful in 40s
Build and Release Binary File / upload-generic-package (push) Successful in 1s
Build and Release Binary File / upload-debian-package (push) Successful in 1s
Build and Release Binary File / upload-release (push) Successful in 22s
Build binary file and bundle packages / build (pull_request) Successful in 38s
2023-12-30 01:31:18 +01:00
75d479b4e2
Add systemd service file
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
2023-12-30 01:30:53 +01:00
5e565df7c0 Merge pull request 'Removes the TUI in favor of event based logging' (#15) from remove_tui into main
All checks were successful
Run Tests on Code / run-tests (push) Successful in 12s
Reviewed-on: #15
2023-12-30 00:28:46 +00:00
8c1da63e0c
rustfmt
All checks were successful
Run Tests on Code / run-tests (push) Successful in 14s
Build binary file and bundle packages / test (pull_request) Successful in 13s
Build binary file and bundle packages / build (pull_request) Successful in 34s
2023-12-30 01:27:11 +01:00
8be74585a0
Extend logging for new posts
All checks were successful
Run Tests on Code / run-tests (push) Successful in 14s
2023-12-30 01:22:13 +01:00
c3ff578c57
Clean up code 2023-12-30 01:22:04 +01:00
cbb50e5d53
Utilize confy for reading and saving history 2023-12-30 01:02:20 +01:00
f08e60a89d
Release Candidate 2.2.0-rc.1
All checks were successful
Build and Release Binary File / test (push) Successful in 33s
Run Tests on Code / run-tests (push) Successful in 35s
Build and Release Binary File / build (push) Successful in 36s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 9s
2023-12-30 00:53:15 +01:00
0f1de67db6
Bugfix for moved history.toml 2023-12-30 00:53:00 +01:00
9c15ea791f
Release Candidate 2.1.7-rc.1
All checks were successful
Run Tests on Code / run-tests (push) Successful in 28s
Build and Release Binary File / test (push) Successful in 14s
Build and Release Binary File / build (push) Successful in 36s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 9s
2023-12-30 00:42:50 +01:00
4a4dff8c22
Add logging dependencies
All checks were successful
Run Tests on Code / run-tests (push) Successful in 33s
2023-12-30 00:41:45 +01:00
c355bc141f
Adapt module changes to main.rs 2023-12-30 00:41:29 +01:00
1db4cb19bd
Delete TUI module 2023-12-30 00:41:17 +01:00
e4e1767083
Move bot module out of subdir, port logging from tui to println/journald 2023-12-30 00:40:12 +01:00
f2730a8eaf
Move post_history module out of subdir, port logging from tui to println/journald 2023-12-30 00:28:10 +01:00
89b2d19c80
Move jnovel module out of subdir, port logging from tui to println/journald 2023-12-30 00:24:53 +01:00
c0bff03120
Move lemmy module out of subdir, port logging from tui to println/journald
Some checks failed
Run Tests on Code / run-tests (push) Failing after 18s
2023-12-30 00:23:01 +01:00
ecc05a2812
Make config username + password fields private 2023-12-30 00:22:21 +01:00
9cca302018
Move config module out of subdirectory 2023-12-29 22:40:07 +01:00
a66180d817
Remove Result from Config loading 2023-12-29 22:35:16 +01:00
b8a5ca2b95
Add .directory file to gitignore
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
2023-12-29 14:59:31 +01:00
295a7b95a1
Remove erroneous note regarding passwords in README 2023-12-29 14:59:11 +01:00
81c51e52cd
Release 2.1.6 + Full Debian Dependencies
All checks were successful
Run Tests on Code / run-tests (push) Successful in 29s
Build and Release Binary File / test (push) Successful in 12s
Build and Release Binary File / build (push) Successful in 36s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 10s
2023-12-29 14:56:16 +01:00
7a4f075b58
Last fix to rc naming
All checks were successful
Run Tests on Code / run-tests (push) Successful in 14s
Build and Release Binary File / test (push) Successful in 13s
Build and Release Binary File / build (push) Successful in 33s
Build and Release Binary File / upload-generic-package (push) Successful in 2s
Build and Release Binary File / upload-debian-package (push) Successful in 2s
Build and Release Binary File / upload-release (push) Successful in 10s
2023-12-29 14:53:19 +01:00
855988e947
Change rc naming from x.y.zrc to x.y.z-rc
All checks were successful
Run Tests on Code / run-tests (push) Successful in 17s
2023-12-29 14:51:26 +01:00
c5f28890a8 Merge pull request 'Add debian packaging (Closes #16)' (#14) from debian into main
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
Reviewed-on: #14
2023-12-29 13:48:40 +00:00
1ebedb3eb2
Release Candidate 2.1.6-rc.1
All checks were successful
Run Tests on Code / run-tests (push) Successful in 30s
Build binary file and bundle packages / test (pull_request) Successful in 12s
Build binary file and bundle packages / build (pull_request) Successful in 1m29s
2023-12-29 14:45:24 +01:00
80aa007857
Add cargo deb config files 2023-12-29 14:45:05 +01:00
e1a85fbc31
Add author, description and license field to Cargo.toml 2023-12-29 14:44:32 +01:00
94b8ec6d2c
remove dotenv dependency 2023-12-29 14:44:06 +01:00
4a4980e38b
Renaming the project from ascendance-of-a-bookworm-bot to a shorter aob-lemmy-bot 2023-12-29 14:43:55 +01:00
f7c4aa395c
remove in directory config files from .gitignore, add license + add placeholder systemd unit file 2023-12-29 14:42:58 +01:00
8d75aaa4f7
Move username and password to config file 2023-12-29 14:35:07 +01:00
654bc5c7f8
Switch from .to_string() to .to_owned() 2023-12-29 14:34:33 +01:00
3ecd434580
Update release actions, add pull-request check
All checks were successful
Run Tests on Code / run-tests (push) Successful in 29s
2023-12-29 14:29:57 +01:00
e1fe276fa7
Remove unused dependency 2023-12-20 20:56:27 +01:00
9771b75b94
Release 2.1.5
All checks were successful
Run Tests on Code / run-tests (push) Successful in 38s
Build and Release Binary File / test (push) Successful in 37s
Build and Release Binary File / build (push) Successful in 34s
Build and Release Binary File / upload-release (push) Successful in 11s
2023-12-20 20:47:20 +01:00
c85f761e85
Fix Bug where series existing in history but not in config crashed the bot
All checks were successful
Run Tests on Code / run-tests (push) Successful in 32s
2023-12-20 20:46:21 +01:00
2531af3739
Remove lifetime from TUI module 2023-12-20 20:45:48 +01:00
f22e2d6278
Use lemmy crates again 2023-12-20 20:45:13 +01:00
b94aecefe2
Use custom rust-node docker image
All checks were successful
Run Tests on Code / run-tests (push) Successful in 36s
2023-12-19 23:49:16 +01:00
f32e7d6ee5
Move cache action after repo clone
All checks were successful
Run Tests on Code / run-tests (push) Successful in 30s
2023-12-19 22:49:03 +01:00
db88d475dd
Revert "Use setup-node action"
All checks were successful
Run Tests on Code / run-tests (push) Successful in 41s
This reverts commit 1503628491.

node is required for actions to work, not available on the rust image
2023-12-19 22:46:20 +01:00
8ee5da5d53
Cache cargo dependencies using cache action
Some checks failed
Run Tests on Code / run-tests (push) Failing after 24s
2023-12-19 22:44:57 +01:00
1503628491
Use setup-node action 2023-12-19 22:44:50 +01:00
c6297b9157
Install clippy during Actions
All checks were successful
Run Tests on Code / run-tests (push) Successful in 33s
2023-12-19 22:21:52 +01:00
1f10a39db1
Add missing Node install step to Actions + Formatting
Some checks failed
Run Tests on Code / run-tests (push) Failing after 11s
2023-12-19 22:19:21 +01:00
5c59437595
Add Clippy checks to regular push and release Actions
Some checks failed
Run Tests on Code / run-tests (push) Failing after 1s
2023-12-19 22:12:28 +01:00
1f0c42bfdb
Updated Cargo.toml for previous commit + Release 2.1.4
All checks were successful
Run Tests on Code / run-tests (push) Successful in 1s
Build and Release Binary File / test (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m4s
Build and Release Binary File / upload-release (push) Successful in 2m14s
2023-12-19 22:08:59 +01:00
5084da92fb
Replaced custom structs in favor of github tag version, removed unused dependencies 2023-12-19 22:08:23 +01:00
9fa940f385
Release 2.1.3
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / test (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m3s
Build and Release Binary File / upload-release (push) Successful in 9s
2023-12-18 23:33:32 +01:00
f0e1bca08e
Fix write lock while read lock still present 2023-12-18 23:33:14 +01:00
b14d37e01c
Release 2.1.2
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / test (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m7s
Build and Release Binary File / upload-release (push) Successful in 11s
2023-12-18 22:28:26 +01:00
51d3cef75f
Display times in local timezone instead of UTC 2023-12-18 22:26:52 +01:00
57c9891d9b
Update README
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-18 14:22:42 +01:00
6e5d8d27fd
Remove API Examples from Repo 2023-12-18 14:22:33 +01:00
1e6e431a56
Release 2.1.1
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / test (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m2s
Build and Release Binary File / upload-release (push) Successful in 7s
2023-12-18 14:04:34 +01:00
67e02e79fd
Sorted Series Printing
Some checks failed
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / test (push) Failing after 2s
Build and Release Binary File / build (push) Has been skipped
Build and Release Binary File / upload-release (push) Has been skipped
2023-12-18 11:52:19 +01:00
173a93280e
Release 2.1.0
All checks were successful
Build and Release Binary File / test (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m1s
Build and Release Binary File / upload-release (push) Successful in 7s
2023-12-18 11:51:33 +01:00
5ba963305c
Deduplicate Config reload logging 2023-12-18 11:24:02 +01:00
080b0bf4d8
New protected communitites feature 2023-12-18 11:23:47 +01:00
2069345e9e Update .forgejo/workflows/build+release.yml
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-18 08:06:58 +00:00
469d5b5a2b
Release 2.0.7
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / run-tests (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m2s
Build and Release Binary File / upload-release (push) Successful in 8s
2023-12-17 23:39:17 +01:00
4cb22e630e
Remove excessive Info level Logging
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-17 23:39:02 +01:00
4f61905ba7
Remove json files from gitignore 2023-12-17 23:37:07 +01:00
0d8ecb2a55
Release 2.0.6 - TUI formatting fix
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / run-tests (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m2s
Build and Release Binary File / upload-release (push) Successful in 8s
2023-12-17 23:03:34 +01:00
b218773148
Release 2.0.5
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / run-tests (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m3s
Build and Release Binary File / upload-release (push) Successful in 7s
2023-12-17 23:01:03 +01:00
608a3bbdeb
Info Logging Bugfix
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-17 23:00:37 +01:00
3badff94ec
Release 2.0.4
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / run-tests (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m2s
Build and Release Binary File / upload-release (push) Successful in 11s
2023-12-17 22:49:11 +01:00
2f428470e1
Add reload info
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-17 22:48:53 +01:00
c9998cad57
Revert jnovel past_days_eligible to 4
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-17 22:33:57 +01:00
0c6ae1fcb0
Release 2.0.3
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / run-tests (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m2s
Build and Release Binary File / upload-release (push) Successful in 8s
2023-12-17 22:29:47 +01:00
47e6cc59c0
Working Error Logging
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-17 22:29:18 +01:00
bba7fae8b9
Bugfix Release 2.0.2
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / run-tests (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m3s
Build and Release Binary File / upload-release (push) Successful in 8s
2023-12-17 20:57:03 +01:00
b10455a30f
Actions Path Fix + 2.0.1 Release
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / run-tests (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m3s
Build and Release Binary File / upload-release (push) Successful in 9s
2023-12-17 20:37:28 +01:00
40e142ccc7
Linter changes
Some checks failed
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / build (push) Has been cancelled
Build and Release Binary File / upload-release (push) Has been cancelled
Build and Release Binary File / run-tests (push) Has been cancelled
2023-12-17 20:35:37 +01:00
079e9f5e11
Release 2.0.0
Some checks failed
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / run-tests (push) Failing after 3s
Build and Release Binary File / build (push) Successful in 1m9s
Build and Release Binary File / upload-release (push) Successful in 9s
2023-12-17 20:19:37 +01:00
f0da95ffae
Cleanup of unused imports 2023-12-17 20:19:24 +01:00
7cd56e530d
Usage of new Modules 2023-12-17 20:18:03 +01:00
6cfdf3e085
New bot module 2023-12-17 20:17:14 +01:00
d3d61f6602
Small QOL changes 2023-12-17 20:17:00 +01:00
9a26d2821f
TUI moved to separate module 2023-12-17 20:16:40 +01:00
a7354f1939
Separate Module for Lemmy HTTP requests 2023-12-17 18:03:11 +01:00
69aedda7a1
Added missing Debug derive for config module 2023-12-17 18:02:51 +01:00
966847f788
Module for reading and writing the post history to history.toml
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-17 14:43:48 +01:00
3675495d5f
Added some Sanity checking for config values 2023-12-17 14:43:21 +01:00
5ddb6b3b75
Switch of several config attributes to pub(crate) 2023-12-17 14:43:00 +01:00
dd11620ffa
Added description field to jnovel PostInfo struct 2023-12-17 14:42:22 +01:00
da9505cd61
Utility functions for jnovel module 2023-12-17 14:42:00 +01:00
d32e1001a1
Update .gitignore
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-17 03:26:59 +01:00
8683282182
Add Cargo.toml Version validation to Forgejo Actions
All checks were successful
Run Tests on Code / run-tests (push) Successful in 1s
2023-12-17 01:56:32 +01:00
955592ac41
Add dotenv crate to project
All checks were successful
Run Tests on Code / run-tests (push) Successful in 1s
2023-12-17 01:51:21 +01:00
de435e00cf
Add .env to gitignore 2023-12-17 01:51:05 +01:00
7b712727bd
Removed feeds module since no longer needed
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-17 01:43:25 +01:00
e7bbe9cf03
Config Module rewrite 2023-12-17 01:42:41 +01:00
dd2cde35e4
Clearer language separation of Series Parts and Prepub Parts
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-16 13:44:37 +01:00
6187fa1230
Add Util function to PartInfo Enum for easier number extraction
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-16 13:28:38 +01:00
30e5fcbf72
New J-Novel API Module, should be finished
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-16 03:09:18 +01:00
b128f243fc
Added more API examples 2023-12-16 03:08:58 +01:00
7ea596760e Delete .gitlab-ci.yml
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
2023-12-12 07:17:14 +00:00
de542aa9b2 Artifact Path Update
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / run-tests (push) Successful in 0s
Build and Release Binary File / build (push) Successful in 1m6s
Build and Release Binary File / upload-release (push) Successful in 10s
2023-11-27 08:09:17 +00:00
09cf07a25a Remove Debugging from Actions Workflow
All checks were successful
Run Tests on Code / run-tests (push) Successful in 10s
2023-11-17 11:05:16 +00:00
3dff75922d Fix Syntax Error in Actions File
All checks were successful
Run Tests on Code / run-tests (push) Successful in 10s
Build and Release Binary File / run-tests (push) Successful in 9s
Build and Release Binary File / build (push) Successful in 1m10s
Build and Release Binary File / upload-release (push) Successful in 19s
2023-11-17 11:01:43 +00:00
8d1e9c3d03 Update Release Binary Paths, Changed Debugging
Some checks failed
Run Tests on Code / run-tests (push) Successful in 6s
Build and Release Binary File / run-tests (push) Successful in 10s
Build and Release Binary File / build (push) Successful in 1m19s
Build and Release Binary File / upload-release (push) Failing after 1s
2023-11-17 10:58:41 +00:00
9ff6661a59 Update Release Directory
All checks were successful
Run Tests on Code / run-tests (push) Successful in 9s
2023-11-17 10:55:37 +00:00
4e7331f0b7 More Debugging for Actions
All checks were successful
Run Tests on Code / run-tests (push) Successful in 2s
Build and Release Binary File / run-tests (push) Successful in 13s
Build and Release Binary File / build (push) Successful in 1m15s
Build and Release Binary File / upload-release (push) Successful in 30s
2023-11-17 10:39:19 +00:00
7a5198bf56 Fix Artifact Upload File Path
Some checks failed
Run Tests on Code / run-tests (push) Successful in 3s
Build and Release Binary File / run-tests (push) Successful in 14s
Build and Release Binary File / build (push) Successful in 1m7s
Build and Release Binary File / upload-release (push) Failing after 22s
2023-11-17 10:36:36 +00:00
9599a2070d Fix Artifact Debugging
Some checks failed
Run Tests on Code / run-tests (push) Successful in 8s
Build and Release Binary File / run-tests (push) Successful in 17s
Build and Release Binary File / build (push) Successful in 1m9s
Build and Release Binary File / upload-release (push) Failing after 4s
2023-11-17 10:33:35 +00:00
ff2b443005 Fixed artifact download parameters
Some checks failed
Run Tests on Code / run-tests (push) Successful in 4s
Build and Release Binary File / run-tests (push) Successful in 23s
Build and Release Binary File / build (push) Successful in 1m9s
Build and Release Binary File / upload-release (push) Failing after 21s
2023-11-17 10:30:39 +00:00
2e8dfe9327 Redirect Artifacts Download to "artifacts" Folder
Some checks failed
Run Tests on Code / run-tests (push) Successful in 16s
Build and Release Binary File / run-tests (push) Successful in 10s
Build and Release Binary File / build (push) Successful in 1m13s
Build and Release Binary File / upload-release (push) Failing after 9s
2023-11-17 10:27:18 +00:00
97c3ab5fc6 Remove Name from Download-Artifact Action to reduce Nesting
Some checks failed
Run Tests on Code / run-tests (push) Successful in 6s
Build and Release Binary File / run-tests (push) Successful in 26s
Build and Release Binary File / build (push) Successful in 1m21s
Build and Release Binary File / upload-release (push) Failing after 10s
2023-11-17 10:22:26 +00:00
02c1ba7b83 Rename and Move Linux Binary after Compilation
Some checks failed
Run Tests on Code / run-tests (push) Successful in 14s
Build and Release Binary File / run-tests (push) Successful in 9s
Build and Release Binary File / build (push) Successful in 1m2s
Build and Release Binary File / upload-release (push) Failing after 10s
2023-11-17 10:19:46 +00:00
2a24ac1ec1 Potential Fix Artifact Uploads
Some checks failed
Run Tests on Code / run-tests (push) Successful in 6s
Build and Release Binary File / run-tests (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m21s
Build and Release Binary File / upload-release (push) Failing after 10s
2023-11-17 10:03:06 +00:00
ec565523b3 Update Release Workflow
Some checks failed
Run Tests on Code / run-tests (push) Successful in 9s
Build and Release Binary File / run-tests (push) Successful in 11s
Build and Release Binary File / build (push) Successful in 1m24s
Build and Release Binary File / upload-release (push) Failing after 14s
2023-11-17 09:56:31 +00:00
0d99cffb34 Update/Fix Release Workflow
All checks were successful
Run Tests on Code / run-tests (push) Successful in 15s
Build and Release Binary File / run-tests (push) Successful in 10s
Build and Release Binary File / build (push) Successful in 1m1s
Build and Release Binary File / upload-release (push) Successful in 18s
2023-11-17 09:46:29 +00:00
1b922e4d37 Debug Release Workflow
All checks were successful
Run Tests on Code / run-tests (push) Successful in 3s
Build and Release Binary File / run-tests (push) Successful in 14s
Build and Release Binary File / build (push) Successful in 1m22s
Build and Release Binary File / upload-release (push) Successful in 3s
2023-11-17 09:36:02 +00:00
461066fdff Debug Release Workflow
All checks were successful
Run Tests on Code / run-tests (push) Successful in 11s
Build and Release Binary File / run-tests (push) Successful in 8s
Build and Release Binary File / build (push) Successful in 1m16s
Build and Release Binary File / upload-release (push) Successful in 12s
2023-11-17 09:31:48 +00:00
222b59c9d2 Debug Release Workflow
All checks were successful
Run Tests on Code / run-tests (push) Successful in 10s
Build and Release Binary File / run-tests (push) Successful in 2s
Build and Release Binary File / build (push) Successful in 1m12s
Build and Release Binary File / upload-release (push) Successful in 21s
2023-11-17 09:24:50 +00:00
ba78bca3ab Debug Release Workflow
All checks were successful
Run Tests on Code / run-tests (push) Successful in 14s
Build and Release Binary File / run-tests (push) Successful in 5s
Build and Release Binary File / build (push) Successful in 1m11s
Build and Release Binary File / upload-release (push) Successful in 11s
2023-11-17 09:20:06 +00:00
d0dccfe946 Debug Release Workflow
All checks were successful
Run Tests on Code / run-tests (push) Successful in 6s
2023-11-17 09:11:09 +00:00
5ea18fa900 Debug Release Workflow
Some checks failed
Run Tests on Code / run-tests (push) Successful in 13s
Build and Release Binary File / run-tests (push) Successful in 7s
Build and Release Binary File / build (push) Successful in 1m17s
Build and Release Binary File / upload-release (push) Failing after 22s
2023-11-17 09:05:34 +00:00
82efecded4 Debug Release Workflow
Some checks failed
Run Tests on Code / run-tests (push) Successful in 11s
Build and Release Binary File / run-tests (push) Successful in 24s
Build and Release Binary File / build (push) Successful in 1m13s
Build and Release Binary File / upload-release (push) Failing after 33s
2023-11-17 08:59:41 +00:00
d28be84001 Debug Release Workflow
Some checks failed
Run Tests on Code / run-tests (push) Successful in 5s
Build and Release Binary File / run-tests (push) Successful in 22s
Build and Release Binary File / build (push) Successful in 1m3s
Build and Release Binary File / upload-release (push) Failing after 8s
2023-11-17 08:50:36 +00:00
2b90bf3438 Debug Release Workflow
Some checks failed
Run Tests on Code / run-tests (push) Successful in 7s
Build and Release Binary File / run-tests (push) Successful in 4s
Build and Release Binary File / build (push) Successful in 1m13s
Build and Release Binary File / upload-release (push) Failing after 32s
2023-11-17 08:47:07 +00:00
195f88e297 Debug Release Workflow
Some checks failed
Run Tests on Code / run-tests (push) Successful in 11s
Build and Release Binary File / run-tests (push) Successful in 12s
Build and Release Binary File / build (push) Successful in 1m19s
Build and Release Binary File / upload-release (push) Failing after 33s
2023-11-17 08:37:11 +00:00
8d703347df Fix Release Workflow Artifact Path
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
Build and Release Binary File / run-tests (push) Successful in 9s
Build and Release Binary File / build (push) Successful in 1m16s
Build and Release Binary File / upload-release (push) Successful in 19s
2023-11-17 08:25:43 +00:00
92a26a798b Fix Test Workflow
All checks were successful
Run Tests on Code / run-tests (push) Successful in 14s
2023-11-17 08:25:01 +00:00
732b210b58 Debugging for Release Workflow
Some checks failed
Build and Release Binary File / run-tests (push) Successful in 9s
Build and Release Binary File / build (push) Failing after 1m10s
Build and Release Binary File / upload-release (push) Has been skipped
2023-11-17 08:23:14 +00:00
9f20630511 Only run tests on regular pushes, not on tags 2023-11-17 08:21:00 +00:00
3097c7cf90 Adjust Path of Build Artifact
Some checks failed
Build and Release Binary File / run-tests (push) Successful in 4s
Run Tests on Code / run-tests (push) Successful in 24s
Build and Release Binary File / build (push) Failing after 1m51s
Build and Release Binary File / upload-release (push) Has been skipped
2023-11-17 08:19:46 +00:00
a3a4efb2d9 Update Release Workflow
Some checks failed
Build and Release Binary File / run-tests (push) Successful in 5s
Run Tests on Code / run-tests (push) Successful in 8s
Build and Release Binary File / build (push) Failing after 1m38s
Build and Release Binary File / upload-release (push) Has been skipped
2023-11-17 08:17:05 +00:00
621975df0f Add Tests Workflow to be run every push
Some checks failed
Build and Release Binary File / run-tests (push) Successful in 3s
Run Tests on Code / run-tests (push) Successful in 2s
Build and Release Binary File / build (push) Failing after 4s
Build and Release Binary File / upload-release (push) Has been skipped
2023-11-17 08:15:04 +00:00
66449c732a Update Release Workflow 2023-11-17 08:14:25 +00:00
622e30caa5 Separate Forgejo Actions Push And Release Workflow 2023-11-17 08:13:45 +00:00
c170618df9 Forgejo Actions Syntax Fixes And Tag Locking
Some checks failed
/ upload-release (push) Has been skipped
/ run-tests (push) Successful in 7s
/ build (push) Failing after 5s
2023-11-17 08:09:27 +00:00
3d2510162a Forgejo Actions Syntax Fixes
Some checks failed
/ run-tests (push) Successful in 2s
/ build (push) Failing after 56s
/ upload-release (push) Has been skipped
2023-11-17 08:02:27 +00:00
807821c195 Forgejo Actions Syntax Fixes 2023-11-17 08:01:57 +00:00
83dd012fee Syntax Fixes for Forgejo Actions 2023-11-17 07:59:41 +00:00
9274ab9972 Add Forgejo Actions File 2023-11-17 07:58:18 +00:00
22 changed files with 3294 additions and 2612 deletions

View file

@ -0,0 +1,146 @@
name: 'Build and Release Binary File'
author: 'Neshura'
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+'
jobs:
test:
runs-on: docker
container: forgejo.neshweb.net/ci-docker-images/rust-node:latest
steps:
-
name: Add Clippy
run: rustup component add clippy
-
name: Checking Out Repository Code
uses: https://code.forgejo.org/actions/checkout@v3
-
name: Set Up Cargo Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
-
name: Run Clippy
run: cargo clippy
-
name: Check if Version in Cargo.toml matches Tag
run: |
VERSION=$(cat Cargo.toml | grep -E "(^|\|)version =" | cut -f2- -d= | tr -d \" | tr -d " ")
if test $VERSION != "${{ github.ref_name }}"; then
echo "Expected Version is: '${{ github.ref_name }}' actual Version is: '$VERSION'";
exit 1
else
echo "Version is: '$VERSION'";
fi
build:
needs: test
if: success()
runs-on: docker
container: forgejo.neshweb.net/ci-docker-images/rust-node:latest
steps:
-
name: Checking Out Repository Code
uses: https://code.forgejo.org/actions/checkout@v3
-
name: Prepare build environment
run: mkdir dist
-
name: Compiling To Linux Target
run: |
cargo build -r
mv target/release/${{ github.event.repository.name }} dist/${{ github.event.repository.name }}-linux-amd64
-
name: Bundle .deb package
run: |
cargo deb
DEBIAN_REF=$(echo ${{ github.ref_name }} | tr - \~)
echo "DEBIAN_REF=$DEBIAN_REF" >> dist/build.env
DEBIAN_REV=-$(cat Cargo.toml | grep -E "(^|\|)revision =" | cut -f2- -d= | tr -d \" | tr -d " ")
echo "DEBIAN_REV=$DEBIAN_REV" >> dist/build.env
mv target/debian/${{ github.event.repository.name }}_"$DEBIAN_REF""$DEBIAN_REV"_amd64.deb dist/${{ github.event.repository.name }}_"$DEBIAN_REF""$DEBIAN_REV"_amd64.deb
-
name: Uploading Build Artifact
uses: actions/upload-artifact@v3
with:
name: release_blobs
path: dist
if-no-files-found: error
upload-generic-package:
needs: build
if: success()
runs-on: docker
steps:
-
name: Downloading All Build Artifacts
uses: actions/download-artifact@v3
-
name: Upload Binary
run: |
echo 'curl -v --user ${{ secrets.FORGEJO_USERNAME }}:${{ secrets.FORGEJO_TOKEN }} \
--upload-file release_blobs/${{ github.event.repository.name }}-linux-amd64 \
https://forgejo.neshweb.net/api/packages/${{ secrets.FORGEJO_USERNAME }}/generic/${{ github.event.repository.name }}/${{ github.ref_name }}/${{ github.event.repository.name }}-linux-amd64'
curl -v --user ${{ secrets.FORGEJO_USERNAME }}:${{ secrets.FORGEJO_TOKEN }} \
--upload-file release_blobs/${{ github.event.repository.name }}-linux-amd64 \
https://forgejo.neshweb.net/api/packages/${{ secrets.FORGEJO_USERNAME }}/generic/${{ github.event.repository.name }}/${{ github.ref_name }}/${{ github.event.repository.name }}-linux-amd64
upload-debian-package:
needs: build
if: success()
runs-on: docker
steps:
-
name: Downloading All Build Artifacts
uses: actions/download-artifact@v3
-
name: Upload Debian Package to staging
run: |
source release_blobs/build.env
echo 'curl -v --user ${{ secrets.FORGEJO_USERNAME }}:${{ secrets.FORGEJO_TOKEN }} \
--upload-file release_blobs/${{ github.event.repository.name }}_'"$DEBIAN_REF""$DEBIAN_REV"'_amd64.deb \
https://forgejo.neshweb.net/api/packages/${{ secrets.FORGEJO_USERNAME }}/debian/pool/bookworm/staging/upload'
curl -v --user ${{ secrets.FORGEJO_USERNAME }}:${{ secrets.FORGEJO_TOKEN }} \
--upload-file release_blobs/${{ github.event.repository.name }}_"$DEBIAN_REF""$DEBIAN_REV"_amd64.deb \
https://forgejo.neshweb.net/api/packages/${{ secrets.FORGEJO_USERNAME }}/debian/pool/bookworm/staging/upload
-
name: Upload Debian Package to main
if: (! contains(github.ref_name, '-rc'))
run: |
source release_blobs/build.env
echo 'curl -v --user ${{ secrets.FORGEJO_USERNAME }}:${{ secrets.FORGEJO_TOKEN }} \
--upload-file release_blobs/${{ github.event.repository.name }}_'"$DEBIAN_REF""$DEBIAN_REV"'_amd64.deb \
https://forgejo.neshweb.net/api/packages/${{ secrets.FORGEJO_USERNAME }}/debian/pool/bookworm/main/upload'
curl -v --user ${{ secrets.FORGEJO_USERNAME }}:${{ secrets.FORGEJO_TOKEN }} \
--upload-file release_blobs/${{ github.event.repository.name }}_"$DEBIAN_REF""$DEBIAN_REV"_amd64.deb \
https://forgejo.neshweb.net/api/packages/${{ secrets.FORGEJO_USERNAME }}/debian/pool/bookworm/main/upload
upload-release:
needs: build
if: success()
runs-on: docker
steps:
-
name: Downloading All Build Artifacts
uses: actions/download-artifact@v3
-
name: Filter out env files
run: rm release_blobs/build.env
-
name: Release New Version
uses: actions/forgejo-release@v2
with:
direction: upload
url: https://forgejo.neshweb.net
release-dir: release_blobs
token: ${{ secrets.FORGEJO_TOKEN }}
tag: ${{ github.ref_name }}

View file

@ -0,0 +1,67 @@
name: 'Build binary file and bundle packages'
author: 'Neshura'
on:
pull_request:
branches:
- main
jobs:
test:
runs-on: docker
container: forgejo.neshweb.net/ci-docker-images/rust-node:latest
steps:
-
name: Add Clippy
run: rustup component add clippy
-
name: Checking Out Repository Code
uses: https://code.forgejo.org/actions/checkout@v3
-
name: Set Up Cargo Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
-
name: Run Clippy
run: cargo clippy
build:
needs: test
if: success()
runs-on: docker
container: forgejo.neshweb.net/ci-docker-images/rust-node:latest
steps:
-
name: Checking Out Repository Code
uses: https://code.forgejo.org/actions/checkout@v3
-
name: Prepare build environment
run: mkdir dist
-
name: Compiling To Linux Target
run: |
cargo build -r
mv target/release/${{ github.event.repository.name }} dist/${{ github.event.repository.name }}-linux-amd64
-
name: Bundle .deb package
run: |
cargo deb
DEBIAN_REF=$(cat Cargo.toml | grep -E "(^|\|)version =" | cut -f2- -d= | tr -d \" | tr -d " " | tr - \~)
echo "DEBIAN_REF=$DEBIAN_REF" >> dist/build.env
DEBIAN_REV=-$(cat Cargo.toml | grep -E "(^|\|)revision =" | cut -f2- -d= | tr -d \" | tr -d " ")
echo "DEBIAN_REV=$DEBIAN_REV" >> dist/build.env
mv target/debian/${{ github.event.repository.name }}_"$DEBIAN_REF""$DEBIAN_REV"_amd64.deb dist/${{ github.event.repository.name }}_"$DEBIAN_REF""$DEBIAN_REV"_amd64.deb
-
name: Uploading Build Artifact
uses: actions/upload-artifact@v3
with:
name: release_blobs
path: dist
if-no-files-found: error

View file

@ -0,0 +1,34 @@
name: 'Run Tests on Code'
author: 'Neshura'
on:
push:
tags-ignore:
- '**'
branches:
- '**'
jobs:
run-tests:
runs-on: docker
container: forgejo.neshweb.net/ci-docker-images/rust-node:latest
steps:
-
name: Add Clippy
run: rustup component add clippy
-
name: Checking Out Repository Code
uses: https://code.forgejo.org/actions/checkout@v3
-
name: Set Up Cargo Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
-
name: Run Clippy
run: cargo clippy

6
.gitignore vendored
View file

@ -1,9 +1,7 @@
/secrets.json
/config.json
/config.toml
/posts.json
/.vscode
/.idea
/jnc_api_examples
/.directory
# Added by cargo

View file

@ -1,68 +0,0 @@
image: 3.10.8-slim-buster
variables:
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/linux/$CI_COMMIT_TAG/"
.deploy:
rules:
# Regex magic copied from Neshura/page-test, only deploys on x.y.z or higher (x.y) Tags
- if: $CI_COMMIT_TAG =~ /^((([\d])+\.){1,2}[\d]+)\s*$/ && $CI_COMMIT_TAG
stages:
- build
- upload
- release
## Docker steps
build:
image: rust:latest
stage: build
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH
CACHING:
script:
- echo "Compiling the code..."
- cargo build -r
- echo "Compile complete."
after_script:
- echo JOB_ID=$CI_JOB_ID >> job.env
- mkdir ./artifacts
- cp /builds/Neshura/ascendance-of-a-bookworm-bot/target/release/ascendance-of-a-bookworm-bot ./artifacts/
artifacts:
paths:
- ./artifacts/
reports:
dotenv: job.env
rules:
- !reference [.deploy, rules]
upload:
needs:
- job: build
artifacts: true
image: curlimages/curl:latest
stage: upload
script:
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file artifacts/ascendance-of-a-bookworm-bot "${PACKAGE_REGISTRY_URL}/ascendance-of-a-bookworm-bot"
rules:
- !reference [.deploy, rules]
Tag Release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- !reference [.deploy, rules]
script:
- apk add curl
- echo "running Release Job, attaching Artifact from Job $JOB_ID"
release:
tag_name: '$CI_COMMIT_TAG'
description: '$CI_COMMIT_TAG'
assets:
links:
- name: "ascendance-of-a-bookworm-bot"
url: "${PACKAGE_REGISTRY_URL}/ascendance-of-a-bookworm-bot"

674
COPYING Normal file
View file

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

1967
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,19 +1,35 @@
[package]
name = "ascendance-of-a-bookworm-bot"
version = "1.1.0"
authors = ["Neshura"]
name = "aob-lemmy-bot"
version = "3.2.0"
edition = "2021"
description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club"
license = "GPL-3.0-or-later"
[package.metadata.deb]
extended-description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club"
maintainer-scripts = "debian/"
revision = "1"
depends = ["libc6", "libssl3", "systemd"]
systemd-units = { enable = false }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chrono = "0.4.26"
lemmy_api_common = "0.18.2"
lemmy_db_schema = "0.18.2"
once_cell = "1.18.0"
reqwest = { version = "0.11.18", features = ["blocking", "json"] }
serde = "1.0.164"
serde_derive = "1.0.164"
serde_json = "1.0.97"
strum_macros = "0.25.0"
tokio = "1.32.0"
url = "2.4.0"
chrono = "^0.4"
lemmy_api_common = "0.19.5"
lemmy_db_schema = "0.19.5"
once_cell = "^1.19"
reqwest = { version = "^0.12", features = ["blocking", "json"] }
serde = "^1.0"
serde_derive = "^1.0"
serde_json = "^1.0"
strum_macros = "^0.26"
tokio = { version = "^1.37", features = ["rt", "rt-multi-thread", "macros"] }
url = "^2.5"
confy = "^0.6"
toml = "^0.8"
systemd-journal-logger = "^2.1.1"
log = "^0.4"
async-trait = "^0.1"
notify = "6.1.1"

View file

@ -1,59 +1,52 @@
# ascendance-of-a-bookworm-bot
**secrets.json**
```json
{
"lemmy": {
"username": "string",
"password": "string"
},
"reddit": {
"app_id": "string",
"app_secret": "string",
"refresh_token": "string",
"redirect_uri": "string"
},
"discord": {}
}
```
# aob-lemmy-bot
**config.toml**
```toml
[urls]
instance = "base URL of Lemmy Instance"
uptime_kuma = "Uptime Kuma Ping URL"
instance = "https://lemmy.example.org"
username = "BotUserName"
password = "BotPassword"
status_post_url = "PostUrlForStatusMonitoring"
config_reload_seconds = 10800
[settings]
config_reload = 360 # Time in Minutes between Config reloads
protected_communities = [ "community_where_pins_should_stay" ]
[[series]]
slug = "example-slug"
parted = false
[series.prepub_community]
name = "communityforprepubs"
[series.prepub_community.pin_settings]
pin_new_post_local = true
pin_new_post_community = true
[series.prepub_community.post_body]
body_type = "Custom"
body_content = """
Custom Text for the Post\n\n\
Can contain new lines and [links](https://join-lemmy.org)"""
[series.volume_community]
name = "communityforvolumes"
[series.volume_community.pin_settings]
pin_new_post_local = false
pin_new_post_community = true
[series.volume_community.post_body]
body_type = "Description"
[[feeds]]
id = 0 # incrementor, only used for correctly matching post history data
series_slug = "ascendance-of-a-bookworm" # series slug on J-Novel Club
[communities]
chapter = "aobprepub" # Community for Chapter Posts of the Series
volume = "aoblightnovel" # Community for Volume Posts of the Series
[[feeds]] # See previous example
id = 1
series_slug = "ascendance-of-a-bookworm-short-story-collection"
[communities]
chapter = "aobprepub"
volume = "aoblightnovel"
[[series]]
slug = "example-slug-2"
parted = true
[series.prepub_community]
name = "communityforprepubs"
[series.prepub_community.pin_settings]
pin_new_post_local = false
pin_new_post_community = false
[series.prepub_community.post_body]
body_type = "Custom"
body_content = "single line content"
[series.volume_community]
name = "communityforvolumes"
[series.volume_community.pin_settings]
pin_new_post_local = false
pin_new_post_community = false
[series.volume_community.post_body]
body_type = "None"
```
posts.json
```json
[
{
"id": number,
"title",
"last_volume_slug": "string",
"last_volume_time": "string",
"last_part_slug": "string",
"last_part_time": "string"
}
]

View file

@ -1,8 +0,0 @@
[Unit]
Description="Automod for bookwormstory.social"
[Service]
User=server
WorkingDirectory=/home/server
ExecStart=/usr/bin/screen -dmS automod /home/server/automod
Type=forking

13
debian/aob-lemmy-bot.service vendored Normal file
View file

@ -0,0 +1,13 @@
[Unit]
Description="Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club"
After=syslog.target
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/aob-lemmy-bot
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target

View file

@ -1,6 +0,0 @@
#!/bin/bash
## deploy to machine as automod.new
## stop automod service
## mv automod.new to automod
## restart automod service
## idea: websocket event?

View file

@ -1,411 +0,0 @@
{
"version": "https://jsonfeed.org/version/1",
"title": "Ascendance of a Bookworm",
"home_page_url": "https://j-novel.club/series/ascendance-of-a-bookworm",
"description": "A young woman who loves books dies and is reborn in another world as Myne, a sickly child from a poor family. Worst of all, there are almost no books in this world! So Myne decides that she'll just have to make her own and become a librarian.",
"author": {
"name": "J-Novel Club"
},
"items": [
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-6",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-6",
"title": "Ascendance of a Bookworm: Part 5 Volume 5 Part 6",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 5 Part 6 (available for subscribers)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64872b31036804ff1be232c8/bookworm5.5-cover-400.jpg",
"date_published": "2023-06-12T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-5",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-5",
"title": "Ascendance of a Bookworm: Part 5 Volume 5 Part 5",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 5 Part 5 (available for subscribers)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-647df642f839a63a784c8b24/bookworm5.5-cover-400.jpg",
"date_published": "2023-06-05T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-4",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-4",
"title": "Ascendance of a Bookworm: Part 5 Volume 5 Part 4",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 5 Part 4 (available for subscribers)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-6474c52538f2134856b56bbe/bookworm5.5-cover-400.jpg",
"date_published": "2023-05-29T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-3",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-3",
"title": "Ascendance of a Bookworm: Part 5 Volume 5 Part 3",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 5 Part 3 (available for subscribers)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-646b844e036804ff1be23118/bookworm5.5-cover-400.jpg",
"date_published": "2023-05-22T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-2",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-2",
"title": "Ascendance of a Bookworm: Part 5 Volume 5 Part 2",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 5 Part 2 (available for subscribers)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64624ef7a2ea846d6b3f5307/bookworm5.5-cover-400.jpg",
"date_published": "2023-05-15T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-1",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-5-part-1",
"title": "Ascendance of a Bookworm: Part 5 Volume 5 Part 1",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 5 Part 1 (free)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64594c97cabacabb2c498bfb/bookworm5.5-cover-400.jpg",
"date_published": "2023-05-08T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-8",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-8",
"title": "Ascendance of a Bookworm: Part 5 Volume 4 Part 8",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 4 Part 8 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64400ee2bbfa9b9015a3b4c2/bookworm5.4-cover-400.jpg",
"date_published": "2023-05-01T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-7",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-7",
"title": "Ascendance of a Bookworm: Part 5 Volume 4 Part 7",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 4 Part 7 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64400e5f6f9feb2622ff757a/bookworm5.4-cover-400.jpg",
"date_published": "2023-04-24T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-6",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-6",
"title": "Ascendance of a Bookworm: Part 5 Volume 4 Part 6",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 4 Part 6 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-643d5c02bbfa9b9015a3b46a/bookworm5.4-cover-400.jpg",
"date_published": "2023-04-17T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-5",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-5",
"title": "Ascendance of a Bookworm: Part 5 Volume 4 Part 5",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 4 Part 5 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64342367f2df38506778bf87/bookworm5.4-cover-400.jpg",
"date_published": "2023-04-10T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-4",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-4",
"title": "Ascendance of a Bookworm: Part 5 Volume 4 Part 4",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 4 Part 4 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-642b04fc89f12f4d2bf611ac/bookworm5.4-cover-400.jpg",
"date_published": "2023-04-03T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-3",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-3",
"title": "Ascendance of a Bookworm: Part 5 Volume 4 Part 3",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 4 Part 3 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-6421b4627686c3cd55fc00aa/bookworm5.4-cover-400.jpg",
"date_published": "2023-03-27T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-2",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-2",
"title": "Ascendance of a Bookworm: Part 5 Volume 4 Part 2",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 4 Part 2 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64188110e9be8e3e55d5c6a5/bookworm5.4-cover-400.jpg",
"date_published": "2023-03-20T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-1",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-4-part-1",
"title": "Ascendance of a Bookworm: Part 5 Volume 4 Part 1",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 4 Part 1 (free)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-640f67a67877a2862d88758b/bookworm5.4-cover-400.jpg",
"date_published": "2023-03-13T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-10",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-10",
"title": "Ascendance of a Bookworm: Part 5 Volume 3 Part 10",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 3 Part 10 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63f5f58e785e215d51f3969e/bookworm5.3-cover-400.jpg",
"date_published": "2023-03-06T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-9",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-9",
"title": "Ascendance of a Bookworm: Part 5 Volume 3 Part 9",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 3 Part 9 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63f5f49fd69a89450c0cf2d4/bookworm5.3-cover-400.jpg",
"date_published": "2023-02-27T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-8",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-8",
"title": "Ascendance of a Bookworm: Part 5 Volume 3 Part 8",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 3 Part 8 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63f3efb20179968f16229033/bookworm5.3-cover-400.jpg",
"date_published": "2023-02-20T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-7",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-7",
"title": "Ascendance of a Bookworm: Part 5 Volume 3 Part 7",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 3 Part 7 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63ea88e2d67ef0a916a929ca/bookworm5.3-cover-400.jpg",
"date_published": "2023-02-13T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-6",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-6",
"title": "Ascendance of a Bookworm: Part 5 Volume 3 Part 6",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 3 Part 6 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63e14f6c2f6ef88b59e0cc3d/bookworm5.3-cover-400.jpg",
"date_published": "2023-02-06T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-5",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-5",
"title": "Ascendance of a Bookworm: Part 5 Volume 3 Part 5",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 3 Part 5 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63d817bc552bedd02ef0f2d2/bookworm5.3-cover-400.jpg",
"date_published": "2023-01-30T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-4",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-4",
"title": "Ascendance of a Bookworm: Part 5 Volume 3 Part 4",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 3 Part 4 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63cef187c1f813e8051c11f6/bookworm5.3-cover-400.jpg",
"date_published": "2023-01-23T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-3",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-3",
"title": "Ascendance of a Bookworm: Part 5 Volume 3 Part 3",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 3 Part 3 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63c5c96cfcd981160ed7f4b9/bookworm5.3-cover-400.jpg",
"date_published": "2023-01-16T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-2",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-2",
"title": "Ascendance of a Bookworm: Part 5 Volume 3 Part 2",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 3 Part 2 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63bc72e9482b67ed0f4e130f/bookworm5.3-cover-400.jpg",
"date_published": "2023-01-09T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-1",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-3-part-1",
"title": "Ascendance of a Bookworm: Part 5 Volume 3 Part 1",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 3 Part 1 (free)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63af316e41fdb4b16fa9f3b5/bookworm5.3-cover-400.jpg",
"date_published": "2023-01-02T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-8",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-8",
"title": "Ascendance of a Bookworm: Part 5 Volume 2 Part 8",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 2 Part 8 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63971a23811dc9950fe219ad/bookworm5.2-cover-400.jpg",
"date_published": "2022-12-26T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-7",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-7",
"title": "Ascendance of a Bookworm: Part 5 Volume 2 Part 7",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 2 Part 7 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-639719efa6449c0010fb311e/bookworm5.2-cover-400.jpg",
"date_published": "2022-12-19T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-6",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-6",
"title": "Ascendance of a Bookworm: Part 5 Volume 2 Part 6",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 2 Part 6 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-6397050a75e261ab0f505a6b/bookworm5.2-cover-400.jpg",
"date_published": "2022-12-12T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-5",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-5",
"title": "Ascendance of a Bookworm: Part 5 Volume 2 Part 5",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 2 Part 5 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-638e67708fc63f8c3f1a524a/bookworm5.2-cover-400.jpg",
"date_published": "2022-12-05T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-4",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-4",
"title": "Ascendance of a Bookworm: Part 5 Volume 2 Part 4",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 2 Part 4 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-6384ed590517e1e171e6c551/bookworm5.2-cover-400.jpg",
"date_published": "2022-11-28T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-3",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-3",
"title": "Ascendance of a Bookworm: Part 5 Volume 2 Part 3",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 2 Part 3 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-637b9c13449c28d01bb4b4cd/bookworm5.2-cover-400.jpg",
"date_published": "2022-11-21T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-2",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-2",
"title": "Ascendance of a Bookworm: Part 5 Volume 2 Part 2",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 2 Part 2 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63729a99563cdce739e17427/bookworm5.2-cover-400.jpg",
"date_published": "2022-11-14T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-1",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-2-part-1",
"title": "Ascendance of a Bookworm: Part 5 Volume 2 Part 1",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 2 Part 1 (free)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-636942940f70ce58739b2844/bookworm5.2-cover-400.jpg",
"date_published": "2022-11-07T22:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-8",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-8",
"title": "Ascendance of a Bookworm: Part 5 Volume 1 Part 8",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 1 Part 8 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-634dbbabb2895e4e5862a45e/bookworm5.1-cover-400.jpg",
"date_published": "2022-10-31T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-7",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-7",
"title": "Ascendance of a Bookworm: Part 5 Volume 1 Part 7",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 1 Part 7 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-634dbb87a25e943074d2ede9/bookworm5.1-cover-400.jpg",
"date_published": "2022-10-24T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-6",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-6",
"title": "Ascendance of a Bookworm: Part 5 Volume 1 Part 6",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 1 Part 6 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-634dbab44f712abf7c52d3a0/bookworm5.1-cover-400.jpg",
"date_published": "2022-10-17T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-5",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-5",
"title": "Ascendance of a Bookworm: Part 5 Volume 1 Part 5",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 1 Part 5 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-63443bda3b3c7e893a05596b/bookworm5.1-cover-400.jpg",
"date_published": "2022-10-10T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-4",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-4",
"title": "Ascendance of a Bookworm: Part 5 Volume 1 Part 4",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 1 Part 4 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-633b2f6c95d05f661f46b179/bookworm5.1-cover-400.jpg",
"date_published": "2022-10-03T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-3",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-3",
"title": "Ascendance of a Bookworm: Part 5 Volume 1 Part 3",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 1 Part 3 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-6331af2e6d287a7b7268489d/bookworm5.1-cover-400.jpg",
"date_published": "2022-09-26T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-2",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-2",
"title": "Ascendance of a Bookworm: Part 5 Volume 1 Part 2",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 1 Part 2 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-6328d459853da3577cbdd6f9/bookworm5.1-cover-400.jpg",
"date_published": "2022-09-19T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-1",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-5-volume-1-part-1",
"title": "Ascendance of a Bookworm: Part 5 Volume 1 Part 1",
"summary": "Read Ascendance of a Bookworm: Part 5 Volume 1 Part 1 (free)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-631f9aed59b60299586f0b29/bookworm5.1-cover-400.jpg",
"date_published": "2022-09-12T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-8",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-8",
"title": "Ascendance of a Bookworm: Part 4 Volume 9 Part 8",
"summary": "Read Ascendance of a Bookworm: Part 4 Volume 9 Part 8 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-6303e4666164ffe71fb3039c/bookworm4.9-cover-400.jpg",
"date_published": "2022-09-05T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-7",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-7",
"title": "Ascendance of a Bookworm: Part 4 Volume 9 Part 7",
"summary": "Read Ascendance of a Bookworm: Part 4 Volume 9 Part 7 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-6303e45cbfd3ac0620743003/bookworm4.9-cover-400.jpg",
"date_published": "2022-08-29T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-6",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-6",
"title": "Ascendance of a Bookworm: Part 4 Volume 9 Part 6",
"summary": "Read Ascendance of a Bookworm: Part 4 Volume 9 Part 6 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-6303e3df95d05f661f46ae31/bookworm4.9-cover-400.jpg",
"date_published": "2022-08-22T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-5",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-5",
"title": "Ascendance of a Bookworm: Part 4 Volume 9 Part 5",
"summary": "Read Ascendance of a Bookworm: Part 4 Volume 9 Part 5 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-62fa9d2e3690f46d54265b03/bookworm4.9-cover-400.jpg",
"date_published": "2022-08-15T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-4",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-4",
"title": "Ascendance of a Bookworm: Part 4 Volume 9 Part 4",
"summary": "Read Ascendance of a Bookworm: Part 4 Volume 9 Part 4 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-62f16bb8a9f787ca5446a1b8/bookworm4.9-cover-400.jpg",
"date_published": "2022-08-08T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-3",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-3",
"title": "Ascendance of a Bookworm: Part 4 Volume 9 Part 3",
"summary": "Read Ascendance of a Bookworm: Part 4 Volume 9 Part 3 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-62e792b17d8cd29c54d666b6/bookworm4.9-cover-400.jpg",
"date_published": "2022-08-01T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-2",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-2",
"title": "Ascendance of a Bookworm: Part 4 Volume 9 Part 2",
"summary": "Read Ascendance of a Bookworm: Part 4 Volume 9 Part 2 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-62def2b5de7f5911540ea23e/bookworm4.9-cover-400.jpg",
"date_published": "2022-07-25T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-1",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-9-part-1",
"title": "Ascendance of a Bookworm: Part 4 Volume 9 Part 1",
"summary": "Read Ascendance of a Bookworm: Part 4 Volume 9 Part 1 (free)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-62d599c27d8cd29c54d665d5/bookworm4.9-cover-400.jpg",
"date_published": "2022-07-18T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-8-part-8",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-8-part-8",
"title": "Ascendance of a Bookworm: Part 4 Volume 8 Part 8",
"summary": "Read Ascendance of a Bookworm: Part 4 Volume 8 Part 8 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-62bb698fd440cc5d411b50b1/bookworm4.8-cover-400.jpg",
"date_published": "2022-07-11T21:00:00Z"
},
{
"id": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-8-part-7",
"url": "https://j-novel.club/read/ascendance-of-a-bookworm-part-4-volume-8-part-7",
"title": "Ascendance of a Bookworm: Part 4 Volume 8 Part 7",
"summary": "Read Ascendance of a Bookworm: Part 4 Volume 8 Part 7 (expired)",
"image": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-62ba0e44cbbd90be7aca1380/bookworm4.8-cover-400.jpg",
"date_published": "2022-07-04T21:00:00Z"
}
]
}

136
src/bot.rs Normal file
View file

@ -0,0 +1,136 @@
use crate::{config::{Config}, HTTP_CLIENT};
use crate::lemmy::{Lemmy};
use crate::post_history::{SeriesHistory};
use chrono::{DateTime, Duration, Utc};
use std::sync::{Arc, RwLock};
use notify::{Event, EventKind, event::{AccessKind, AccessMode}, RecursiveMode, Watcher};
use tokio::time::sleep;
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 {
($msg:tt) => {
match connected_to_journal() {
true => log::info!("[INFO] {}", $msg),
false => println!("[INFO] {}", $msg),
}
};
}
macro_rules! error {
($msg:tt) => {
match connected_to_journal() {
true => log::error!("[ERROR] {}", $msg),
false => eprintln!("[ERROR] {}", $msg),
}
};
}
pub(crate) struct Bot {
shared_config: Arc<RwLock<Config>>,
history: SeriesHistory,
run_start_time: DateTime<Utc>
}
enum Wait {
Absolute,
Buffer
}
impl Bot {
pub(crate) fn new() -> Self {
let config = Config::load();
let shared_config: Arc<RwLock<Config>> = Arc::new(RwLock::new(config));
let shared_config_copy = shared_config.clone();
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 history: SeriesHistory = SeriesHistory::load_history();
Bot { shared_config, history, run_start_time: Utc::now() }
}
pub(crate) async fn run(&mut self) {
loop {
let mut lemmy = match Lemmy::new(&self.shared_config).await {
Ok(data) => data,
Err(_) => continue,
};
lemmy.get_communities().await;
self.history = SeriesHistory::load_history();
let start: DateTime<Utc> = Utc::now();
while Utc::now() - start <= Duration::minutes(60) {
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;
debug!("Pinging Server");
self.ping_status().await;
debug!("Awaiting Timeout 2");
self.wait(30, Wait::Absolute).await;
}
lemmy.logout().await;
}
}
async fn ping_status(&self) {
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 duration: Duration = Duration::seconds(seconds);
let start_time: DateTime<Utc> = match start_time {
Wait::Absolute => Utc::now(),
Wait::Buffer => self.run_start_time,
};
while Utc::now() - start_time < duration {
sleep(Duration::milliseconds(100).to_std().unwrap()).await
}
}
}

298
src/config.rs Normal file
View file

@ -0,0 +1,298 @@
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
use chrono::{Timelike, Utc};
use crate::config::PostBody::Description;
use lemmy_db_schema::PostFeatureType;
use lemmy_db_schema::sensitive::SensitiveString;
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)]
pub(crate) struct Config {
pub(crate) instance: String,
username: SensitiveString,
password: SensitiveString,
pub(crate) status_post_url: Option<String>,
pub(crate) config_reload_seconds: u32,
pub(crate) protected_communities: Vec<String>,
pub(crate) series: Vec<SeriesConfig>,
}
impl Config {
pub(crate) fn load() -> Self {
let cfg: Self = match confy::load(env!("CARGO_PKG_NAME"), "config") {
Ok(data) => data,
Err(e) => panic!("config.toml not found: {e}"),
};
if cfg.instance.is_empty() {
panic!("bot instance not set!")
}
if cfg.username.is_empty() {
panic!("bot username not set!")
}
if cfg.password.is_empty() {
panic!("bot password not provided!")
}
cfg.series.iter().for_each(|series| {
if series.prepub_community.post_body == Description {
panic!("'Description' type Post Body only supported for Volumes!")
}
});
cfg
}
pub(crate) fn get_path() -> PathBuf {
confy::get_configuration_file_path(env!("CARGO_PKG_NAME"), "config").expect("Application will not without confy")
}
pub(crate) fn get_username(&self) -> SensitiveString {
self.username.clone()
}
pub(crate) fn get_password(&self) -> SensitiveString {
self.password.clone()
}
}
impl Default for Config {
fn default() -> Self {
Config {
instance: "".to_owned(),
username: SensitiveString::from("".to_owned()),
password: SensitiveString::from("".to_owned()),
status_post_url: None,
config_reload_seconds: 21600,
protected_communities: vec![],
series: vec![],
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub(crate) struct SeriesConfig {
pub(crate) slug: String,
pub(crate) parted: bool,
pub(crate) prepub_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)]
pub(crate) struct PostConfig {
pub(crate) name: String,
pub(crate) pin_settings: PinConfig,
pub(crate) post_body: PostBody,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub(crate) struct PinConfig {
pub(crate) pin_new_post_local: bool,
pub(crate) pin_new_post_community: bool,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "body_type", content = "body_content")]
pub(crate) enum PostBody {
None,
Description,
Custom(String),
}

View file

@ -1,421 +0,0 @@
use std::{
error::Error,
fs::{self, OpenOptions},
io::Write,
path::Path,
};
use chrono::{DateTime, Duration, Utc};
use lemmy_api_common::{
community::{ListCommunities, ListCommunitiesResponse},
post::CreatePost,
sensitive::Sensitive,
};
use lemmy_db_schema::{
newtypes::{CommunityId, LanguageId},
ListingType,
};
use serde_derive::{Deserialize, Serialize};
use tokio::time::sleep;
use url::Url;
use crate::{
feeds::{FeedChapterData, FeedSeriesData, FeedSetting, FeedVolumeData},
PostQueueMetadata, CLIENT,
};
macro_rules! api_url {
() => {
"https://labs.j-novel.club/app/v1/".to_string()
};
}
macro_rules! chapter_url {
() => {
"https://j-novel.club/read/".to_string()
};
}
macro_rules! volume_url_base {
() => {
"https://j-novel.club/series/".to_string()
};
}
macro_rules! pub_struct {
($name:ident {$($field:ident: $t:ty,)*}) => {
#[derive(Serialize, Deserialize, Clone, PartialEq)]
pub(crate) struct $name {
$(pub(crate) $field: $t), *
}
}
}
// Secrets structs
pub_struct!(Secrets {
lemmy: LemmyLogin,
reddit: RedditLogin,
});
impl Secrets {
pub(crate) fn init() -> Secrets {
let file_contents = match fs::read_to_string("secrets.json") {
Ok(data) => data,
Err(e) => panic!("ERROR: secrets.json could not be read:\n\n{:#?}", e),
};
let config_parse: Secrets = match serde_json::from_str(&file_contents) {
Ok(data) => data,
Err(e) => panic!("ERROR: secrets.json could not be parsed:\n\n{:#?}", e),
};
return config_parse;
}
pub(crate) fn load(&mut self) {
let file_contents = match fs::read_to_string("secrets.json") {
Ok(data) => data,
Err(e) => panic!("ERROR: secrets.json could not be read:\n\n{:#?}", e),
};
let config_parse: Secrets = match serde_json::from_str(&file_contents) {
Ok(data) => data,
Err(e) => panic!("ERROR: secrets.json could not be parsed:\n\n{:#?}", e),
};
*self = config_parse;
}
}
#[derive(Serialize, Deserialize, Clone, PartialEq)]
pub(crate) struct LemmyLogin {
pub(crate) username: String,
password: String,
}
impl LemmyLogin {
pub(crate) fn get_username(&self) -> Sensitive<String> {
return Sensitive::new(self.username.clone());
}
pub(crate) fn get_password(&self) -> Sensitive<String> {
return Sensitive::new(self.password.clone());
}
}
#[derive(Serialize, Deserialize, Clone, PartialEq)]
pub(crate) struct RedditLogin {
pub(crate) app_id: String,
app_secret: String,
refresh_token: String,
redirect_uri: String,
}
// Config structs
#[derive(Serialize, Deserialize, Clone, PartialEq)]
pub(crate) struct Config {
pub(crate) instance: String,
pub(crate) reddit_config: RedditConfig,
pub(crate) feeds: Vec<FeedSetting>,
pub(crate) uptime_kuma: Option<String>,
pub(crate) config_reload: Option<usize>,
}
impl Config {
pub(crate) fn init() -> Config {
let file_contents = match fs::read_to_string("config.json") {
Ok(data) => data,
Err(e) => panic!("ERROR: config.json could not be read:\n\n{:#?}", e),
};
let config_parse: Config = match serde_json::from_str(&file_contents) {
Ok(data) => data,
Err(e) => panic!("ERROR: config.json could not be parsed:\n\n{:#?}", e),
};
return config_parse;
}
pub(crate) fn load(&mut self) {
let file_contents = match fs::read_to_string("config.json") {
Ok(data) => data,
Err(e) => panic!("ERROR: config.json could not be read:\n\n{:#?}", e),
};
let config_parse: Config = match serde_json::from_str(&file_contents) {
Ok(data) => data,
Err(e) => panic!("ERROR: config.json could not be parsed:\n\n{:#?}", e),
};
*self = config_parse;
}
#[warn(unused_results)]
pub(crate) async fn fetch_infos(&self) -> Result<(), Box<dyn Error>> {
// Get Series Data
for feed in &self.feeds {
let res = CLIENT
.get(api_url!() + "series/" + &feed.series_slug + "?format=json")
.send()
.await?
.text()
.await?;
let data: FeedSeriesData = serde_json::from_str(&res).unwrap();
}
return Ok(());
}
#[warn(unused_results)]
pub(crate) async fn check_feeds(
&self,
post_history: &Vec<PrevPost>,
community_ids: &CommunitiesVector,
auth: &Sensitive<String>,
) -> Result<Vec<(CreatePost, PostQueueMetadata)>, Box<dyn Error>> {
let mut post_queue: Vec<(CreatePost, PostQueueMetadata)> = vec![];
for feed in &self.feeds {
let mut history_data: &PrevPost = &PrevPost {
id: feed.id,
last_volume_slug: None,
last_volume_time: None,
last_part_slug: None,
last_part_time: None,
};
for post in post_history {
if post.id == feed.id {
history_data = post;
break;
}
}
// Check for Volume Release
let res = CLIENT
.get(api_url!() + "series/" + &feed.series_slug + "/volumes?format=json")
.send()
.await?
.text()
.await?;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
struct FeedVolumeReturn {
volumes: Vec<FeedVolumeData>,
}
let mut data: FeedVolumeReturn = serde_json::from_str(&res).unwrap();
let current_volume_slug = data.volumes[&data.volumes.len() - 1].slug.clone();
let now = Utc::now();
data.volumes.reverse();
for volume in data.volumes {
let published = DateTime::parse_from_rfc3339(&volume.publishing).unwrap();
// Get First Volume that has valid Release Data
if now >= published {
if Some(volume.slug.clone()) != history_data.last_volume_slug {
if let Some(volume_community) = &feed.communities.volume {
let mut post_url = Url::parse(&(volume_url_base!() + &feed.series_slug))?;
post_url.set_fragment(Some(&("volume-".to_string() + &volume.number.to_string())));
let new_post = CreatePost {
name: volume.title.clone(),
community_id: community_ids.find(&volume_community),
url: Some(post_url),
body: Some(
"[Reddit](https://reddit.com/r/HonzukinoGekokujou)\n\n\
[Discord](https://discord.com/invite/fGefmzu)\n\n\
[#ascendanceofabookworm](https://mastodon.social/tags/ascendanceofabookworm)\n\n\
[#honzuki](https://mastodon.social/tags/honzuki)\n\n\
[#](https://mastodon.social/tags/%E6%9C%AC%E5%A5%BD%E3%81%8D%E3%81%AE%E4%B8%8B%E5%89%8B%E4%B8%8A)"
.into(),
),
honeypot: None,
nsfw: Some(false),
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
auth: auth.clone(),
};
post_queue.push((
new_post,
PostQueueMetadata {
id: feed.id,
series: feed.series_slug.clone(),
part: None,
volume: Some(volume.slug),
},
));
}
}
break;
}
}
if let Some(chapter_community) = &feed.communities.chapter {
// Check for Part Release
let res = CLIENT
.get(api_url!() + "volumes/" + &current_volume_slug + "/parts?format=json")
.send()
.await?
.text()
.await?;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
struct FeedChapterReturn {
parts: Vec<FeedChapterData>,
}
let mut data: FeedChapterReturn = serde_json::from_str(&res).unwrap();
data.parts.reverse();
for part in data.parts {
if Some(part.slug.clone()) != history_data.last_part_slug {
let new_post = CreatePost {
name: part.title.clone(),
community_id: community_ids.find(&chapter_community),
url: Some(Url::parse(&(chapter_url!() + &part.slug)).unwrap()),
body: Some(
"[Reddit](https://reddit.com/r/HonzukinoGekokujou)\n\n\
[Discord](https://discord.com/invite/fGefmzu)\n\n\
[#ascendanceofabookworm](https://mastodon.social/tags/ascendanceofabookworm)\n\n\
[#honzuki](https://mastodon.social/tags/honzuki)\n\n\
[#](https://mastodon.social/tags/%E6%9C%AC%E5%A5%BD%E3%81%8D%E3%81%AE%E4%B8%8B%E5%89%8B%E4%B8%8A)"
.into(),
),
honeypot: None,
nsfw: Some(false),
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
auth: auth.clone(),
};
post_queue.push((
new_post,
PostQueueMetadata {
id: feed.id,
series: feed.series_slug.clone(),
part: Some(part.slug),
volume: None,
},
));
}
break;
}
}
sleep(Duration::milliseconds(100).to_std().unwrap()).await; // Should prevent dos-ing J-Novel servers
}
return Ok(post_queue);
}
}
pub_struct!(RedditConfig {
user_agent: String,
subreddit: String,
});
//noinspection ALL
#[derive(Serialize, Deserialize, Clone, PartialEq, strum_macros::Display)]
#[allow(non_camel_case_types)]
pub(crate) enum LemmyCommunities {
aobwebnovel,
aobprepub,
aoblightnovel,
aobmanga,
metadiscussions,
}
// Posts structs
pub_struct!(PrevPost {
id: usize,
last_volume_slug: Option<String>,
last_volume_time: Option<String>,
last_part_slug: Option<String>,
last_part_time: Option<String>,
});
impl PrevPost {
pub(crate) fn load() -> Vec<PrevPost> {
let mut history;
if Path::new("posts.json").exists() {
let file_contents = match fs::read_to_string("posts.json") {
Ok(data) => data,
Err(e) => panic!("ERROR: posts.json could not be read:\n\n{:#?}", e),
};
if file_contents.len() > 0 {
let history_parse: Vec<PrevPost> = match serde_json::from_str(&file_contents) {
Ok(data) => data,
Err(e) => panic!("ERROR: posts.json could not be parsed:\n\n{:#?}", e),
};
history = history_parse;
} else {
history = [].to_vec()
}
} else {
let _ = fs::File::create("posts.json");
history = [].to_vec()
}
history.sort_by(|a, b| a.id.cmp(&b.id));
return history;
}
pub(crate) fn save(data: &Vec<PrevPost>) {
let mut file = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open("posts.json")
.unwrap();
let json_data = serde_json::to_string_pretty(&data).unwrap();
write!(&mut file, "{}", json_data).unwrap();
}
}
// Bot Helper Structs
pub_struct!(CommunitiesVector {
ids: Vec<(CommunityId, String)>,
});
impl CommunitiesVector {
pub(crate) fn new() -> CommunitiesVector {
CommunitiesVector { ids: vec![] }
}
#[warn(unused_results)]
pub(crate) async fn load(&mut self, auth: &Sensitive<String>, base: &String) -> Result<(), Box<dyn Error>> {
let params = ListCommunities {
auth: Some(auth.clone()),
type_: Some(ListingType::Local),
..Default::default()
};
let res = CLIENT
.get(base.clone() + "/api/v3/community/list")
.query(&params)
.send()
.await?
.text()
.await?;
let site_data: ListCommunitiesResponse = serde_json::from_str(&res).unwrap();
let mut ids = [].to_vec();
site_data.communities.iter().for_each(|entry| {
let new_id = (entry.community.id, entry.community.name.clone());
ids.push(new_id);
});
self.ids = ids;
return Ok(());
}
pub(crate) fn find(&self, name: &LemmyCommunities) -> CommunityId {
let mut ret_id = CommunityId(0);
self.ids.iter().for_each(|id| {
let id_name = &id.1;
if &name.to_string() == id_name {
ret_id = id.0;
}
});
return ret_id;
}
}

View file

@ -1,85 +0,0 @@
use serde_derive::{Deserialize, Serialize};
use crate::config::LemmyCommunities;
macro_rules! api_url {
() => {
"https://labs.j-novel.club/app/v1/".to_string()
};
}
#[derive(Serialize, Deserialize, Clone, PartialEq)]
pub(crate) struct FeedSetting {
pub(crate) id: usize,
pub(crate) series_slug: String,
pub(crate) communities: FeedCommunities,
pub(crate) reddit: Option<FeedRedditSettings>,
}
#[derive(Serialize, Deserialize, Clone, PartialEq)]
pub(crate) struct FeedCommunities {
pub(crate) chapter: Option<LemmyCommunities>,
pub(crate) volume: Option<LemmyCommunities>,
}
#[derive(Serialize, Deserialize, Clone, PartialEq)]
pub(crate) struct FeedRedditSettings {
pub(crate) enabled: bool,
pub(crate) flair: String,
}
// RSS Feed Structs
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct FeedData {
pub(crate) version: String,
pub(crate) title: String,
pub(crate) home_page_url: String,
pub(crate) description: String,
pub(crate) author: FeedAuthor,
pub(crate) items: Vec<FeedEntry>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct FeedSeriesData {
pub(crate) title: String,
pub(crate) slug: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct FeedVolumeData {
pub(crate) title: String,
pub(crate) slug: String,
pub(crate) number: u8,
pub(crate) publishing: String,
pub(crate) cover: FeedCoverData,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct FeedChapterData {
pub(crate) title: String,
pub(crate) slug: String,
pub(crate) cover: FeedCoverData,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct FeedCoverData {
#[serde(alias = "coverUrl")]
pub(crate) cover: String,
#[serde(alias = "thumbnailUrl")]
pub(crate) thumbnail: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct FeedAuthor {
pub(crate) name: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct FeedEntry {
pub(crate) id: String,
pub(crate) url: String,
pub(crate) title: String,
pub(crate) summary: String,
pub(crate) image: Option<String>,
pub(crate) date_published: String,
}

307
src/fetchers/jnovel.rs Normal file
View file

@ -0,0 +1,307 @@
use crate::{HTTP_CLIENT};
use chrono::{DateTime, Duration, Utc};
use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use std::ops::Sub;
use async_trait::async_trait;
use crate::fetchers::{FetcherTrait};
use crate::lemmy::{PartInfo, PostInfo, PostInfoInner, PostType};
use systemd_journal_logger::connected_to_journal;
use crate::lemmy::PartInfo::{NoParts, Part};
macro_rules! error {
($msg:tt) => {
match connected_to_journal() {
true => log::error!("[ERROR] {}", $msg),
false => eprintln!("[ERROR] {}", $msg),
}
};
}
macro_rules! info {
($msg:tt) => {
match connected_to_journal() {
true => log::info!("[INFO] {}", $msg),
false => println!("[INFO] {}", $msg),
}
};
}
static PAST_DAYS_ELIGIBLE: u8 = 4;
macro_rules! api_url {
() => {
"https://labs.j-novel.club/app/v2".to_owned()
};
}
macro_rules! jnc_base_url {
() => {
"https://j-novel.club".to_owned()
};
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
struct VolumesWrapper {
volumes: Vec<VolumeDetail>,
pagination: PaginationInfo,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
struct ChapterWrapper {
parts: Vec<ChapterDetail>,
pagination: PaginationInfo,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
struct PaginationInfo {
limit: usize,
skip: usize,
#[serde(alias = "lastPage")]
last_page: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct Cover {
#[serde(alias = "coverUrl")]
pub(crate) cover: String,
#[serde(alias = "thumbnailUrl")]
pub(crate) thumbnail: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct VolumeDetail {
pub(crate) title: String,
pub(crate) slug: String,
number: u8,
publishing: String,
#[serde(alias = "shortDescription")]
short_description: String,
cover: Cover,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub(crate) struct ChapterDetail {
pub(crate) title: String,
pub(crate) slug: String,
launch: String,
pub(crate) cover: Option<Cover>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub(crate) struct JNovelFetcher {
series_slug: String,
series_has_parts: bool
}
impl Default for JNovelFetcher {
fn default() -> Self {
Self {
series_slug: "".to_owned(),
series_has_parts: false,
}
}
}
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]
impl FetcherTrait for JNovelFetcher {
fn new() -> Self {
JNovelFetcher {
series_slug: "".to_owned(),
series_has_parts: false
}
}
async fn check_feed(&self) -> Result<Vec<PostInfo>, ()> {
let response = match HTTP_CLIENT
.get(api_url!() + "/series/" + self.series_slug.as_str() + "/volumes?format=json")
.send()
.await
{
Ok(data) => match data.text().await {
Ok(data) => data,
Err(e) => {
let err_msg = format!("While checking feed: {e}");
error!(err_msg);
return Err(());
}
},
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
return Err(());
}
};
let mut volume_brief_data: VolumesWrapper = match serde_json::from_str(&response) {
Ok(data) => data,
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
return Err(());
}
};
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
let mut volume_map: HashMap<u8, PostInfo> = HashMap::new();
let mut prepub_map: HashMap<u8, PostInfo> = HashMap::new();
for volume in volume_brief_data.volumes.iter() {
let publishing_date = DateTime::parse_from_rfc3339(&volume.publishing).unwrap();
if publishing_date < Utc::now().sub(Duration::days(PAST_DAYS_ELIGIBLE as i64)) {
match self.series_has_parts {
true => continue,
false => break,
}
}
let new_part_info: PartInfo;
if self.series_has_parts {
let mut part_number: Option<u8> = None;
let splits: Vec<&str> = volume.slug.split('-').collect();
for (index, split) in splits.clone().into_iter().enumerate() {
if split == "part" {
part_number = Some(
splits[index + 1]
.parse::<u8>()
.expect("Split Element after 'Part' should always be a number"),
);
break;
}
}
match part_number {
Some(number) => new_part_info = Part(number),
None => {
info!("No Part found, assuming 1");
new_part_info = Part(1);
}
}
} else {
new_part_info = NoParts;
}
let post_url = format!(
"{}/series/{}#volume-{}",
jnc_base_url!(),
self.series_slug.as_str(),
volume.number
);
let post_details = PostInfoInner {
title: volume.title.clone(),
url: post_url.clone(),
thumbnail: Some(volume.cover.thumbnail.clone())
};
let new_post_info = PostInfo {
post_type: Some(PostType::Volume),
part: Some(new_part_info),
description: Some(volume.short_description.clone()),
lemmy_info: post_details,
};
let part_id = new_part_info.as_u8();
if publishing_date <= Utc::now() {
volume_map
.entry(part_id)
.and_modify(|val| {
if *val < new_post_info {
*val = new_post_info.clone()
}
})
.or_insert(new_post_info);
}
if let Some(prepub_info) = get_latest_prepub(&volume.slug).await {
let prepub_post_info = PostInfo {
post_type: Some(PostType::Chapter),
part: Some(new_part_info),
lemmy_info: prepub_info,
description: None,
};
prepub_map
.entry(part_id)
.and_modify(|val| {
if *val < prepub_post_info {
*val = prepub_post_info.clone()
}
})
.or_insert(prepub_post_info);
}
}
let mut result_vec: Vec<PostInfo> = volume_map.values().cloned().collect();
let mut prepub_vec: Vec<PostInfo> = prepub_map.values().cloned().collect();
result_vec.append(&mut prepub_vec);
Ok(result_vec)
}
}
async fn get_latest_prepub(volume_slug: &str) -> Option<PostInfoInner> {
let response = match HTTP_CLIENT
.get(api_url!() + "/volumes/" + volume_slug + "/parts?format=json")
.send()
.await
{
Ok(data) => match data.text().await {
Ok(data) => data,
Err(e) => {
let err_msg = format!("While getting latest PrePub: {e}");
error!(err_msg);
return None;
}
},
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
return None;
}
};
let mut volume_prepub_parts_data: ChapterWrapper = match serde_json::from_str(&response) {
Ok(data) => data,
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
return None;
}
};
volume_prepub_parts_data.parts.reverse(); // Makes breaking out of the parts loop easier
let mut post_details: Option<PostInfoInner> = None;
for prepub_part in volume_prepub_parts_data.parts.iter() {
let publishing_date = DateTime::parse_from_rfc3339(&prepub_part.launch).unwrap();
if publishing_date > Utc::now() {
break;
} else if publishing_date < Utc::now().sub(Duration::days(PAST_DAYS_ELIGIBLE as i64)) {
continue;
}
let thumbnail = prepub_part.cover.as_ref().map(|cover| cover.thumbnail.clone());
let post_url = format!("{}/read/{}", jnc_base_url!(), prepub_part.slug);
post_details = Some(PostInfoInner {
title: prepub_part.title.clone(),
url: post_url.clone(),
thumbnail
});
}
post_details
}

33
src/fetchers/mod.rs Normal file
View file

@ -0,0 +1,33 @@
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;
#[async_trait]
pub(crate) trait FetcherTrait {
fn new() -> Self where Self: Sized;
async fn check_feed(&self) -> Result<Vec<PostInfo>, ()>;
}
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)
}

450
src/lemmy.rs Normal file
View file

@ -0,0 +1,450 @@
use std::cmp::Ordering;
use crate::config::{Config, PostBody, PostConfig, SeriesConfig};
use crate::{HTTP_CLIENT};
use lemmy_api_common::community::{ListCommunities, ListCommunitiesResponse};
use lemmy_api_common::lemmy_db_views::structs::PostView;
use lemmy_api_common::person::{Login, LoginResponse};
use lemmy_api_common::post::{CreatePost, FeaturePost, GetPosts, GetPostsResponse};
use lemmy_db_schema::newtypes::{CommunityId, LanguageId, PostId};
use lemmy_db_schema::{ListingType, PostFeatureType};
use reqwest::StatusCode;
use std::collections::HashMap;
use std::sync::{RwLock};
use lemmy_db_schema::sensitive::SensitiveString;
use serde::{Deserialize, Serialize};
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 {
($msg:tt) => {
match connected_to_journal() {
true => log::error!("[ERROR] {}", $msg),
false => eprintln!("[ERROR] {}", $msg),
}
};
}
pub(crate) struct Lemmy {
jwt_token: SensitiveString,
instance: String,
communities: HashMap<String, CommunityId>,
}
#[derive(Debug, Clone)]
pub(crate) struct PostInfoInner {
pub(crate) title: String,
pub(crate) url: String,
pub(crate) thumbnail: Option<String>
}
#[derive(Debug, Copy, Clone)]
pub(crate) enum PartInfo {
NoParts,
Part(u8),
}
impl PartInfo {
pub(crate) fn as_u8(&self) -> u8 {
match self {
PartInfo::Part(number) => *number,
PartInfo::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, 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(),
}
}
pub(crate) fn get_post_data(&self, series: &SeriesConfig, lemmy: &Lemmy) -> CreatePost {
let post_config = self.get_post_config(series);
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 {
pub(crate) fn get_community_id(&self, name: &str) -> CommunityId {
*self.communities.get(name).expect("Given community is invalid")
}
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
.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) {
let _ = self.post_data_json("/api/v3/user/logout", &"").await;
}
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 {
post_id,
featured: false,
feature_type: location,
};
self.feature(pin_params).await
}
pub(crate) async fn pin(&self, post_id: PostId, location: PostFeatureType) -> Option<PostView> {
let pin_params = FeaturePost {
post_id,
featured: true,
feature_type: location,
};
self.feature(pin_params).await
}
pub(crate) async fn get_community_pinned(&self, community: CommunityId) -> Option<Vec<PostView>> {
let list_params = GetPosts {
community_id: Some(community),
type_: Some(ListingType::Local),
..Default::default()
};
let response: String = match self.get_data_query("/api/v3/post/list", &list_params).await {
Some(data) => data,
None => return None,
};
let json_data: GetPostsResponse = match self.parse_json(&response).await {
Some(data) => data,
None => return None,
};
Some(json_data
.posts
.iter()
.filter(|post| post.post.featured_community)
.cloned()
.collect())
}
pub(crate) async fn get_local_pinned(&self) -> Option<Vec<PostView>> {
let list_params = GetPosts {
type_: Some(ListingType::Local),
..Default::default()
};
let response: String = match self.get_data_query("/api/v3/post/list", &list_params).await {
Some(data) => data,
None => return None,
};
let json_data: GetPostsResponse = match self.parse_json(&response).await {
Some(data) => data,
None => return None,
};
Some(json_data
.posts
.iter()
.filter(|post| post.post.featured_local)
.cloned()
.collect())
}
pub(crate) async fn get_communities(&mut self) {
let list_params = ListCommunities {
type_: Some(ListingType::Local),
..Default::default()
};
let response: String = match self.get_data_query("/api/v3/community/list", &list_params).await {
Some(data) => data,
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();
for community_view in json_data.communities {
let community = community_view.community;
communities.insert(community.name, community.id);
}
self.communities = communities;
}
async fn post_data_json<T: Serialize>(&self, route: &str, json: &T ) -> Option<String> {
let res = HTTP_CLIENT
.post(format!("{}{route}", &self.instance))
.bearer_auth(&self.jwt_token.to_string())
.json(&json)
.send()
.await;
self.extract_data(res).await
}
async fn get_data_query<T: Serialize>(&self, route: &str, param: &T ) -> Option<String> {
let res = HTTP_CLIENT
.get(format!("{}{route}", &self.instance))
.bearer_auth(&self.jwt_token.to_string())
.query(&param)
.send()
.await;
self.extract_data(res).await
}
async fn extract_data(&self, response: Result<reqwest::Response, reqwest::Error>) -> Option<String> {
match response {
Ok(data) => {
if data.status().is_success() {
match data.text().await {
Ok(data) => Some(data),
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);
None
}
},
Err(e) => {
let err_msg = format!("{e}");
error!(err_msg);
None
}
}
}
async fn parse_json<'a, T: Deserialize<'a>>(&self, response: &'a str) -> Option<T> {
match serde_json::from_str::<T>(response) {
Ok(data) => Some(data),
Err(e) => {
let err_msg = format!("while parsing JSON: {e} ");
error!(err_msg);
None
}
}
}
async fn parse_json_map<'a, T: Deserialize<'a>>(&self, response: &'a str) -> Option<T> {
debug!(response);
match serde_json::from_str::<HashMap<&str, T>>(response) {
Ok(mut data) => Some(data.remove("post_view").expect("Element should be present")),
Err(e) => {
let err_msg = format!("while parsing JSON HashMap: {e}");
error!(err_msg);
None
}
}
}
}

View file

@ -1,515 +1,41 @@
use chrono::{DateTime, Duration, NaiveDateTime, Utc};
use config::{CommunitiesVector, Config, LemmyCommunities, PrevPost, Secrets};
use lemmy_api_common::{
lemmy_db_views::structs::PostView,
person::{Login, LoginResponse},
post::{CreatePost, FeaturePost, GetPosts, GetPostsResponse},
sensitive::Sensitive,
};
use lemmy_db_schema::newtypes::PostId;
use lemmy_db_schema::{newtypes::CommunityId, ListingType, PostFeatureType, SortType};
use chrono::{Duration};
use log::{LevelFilter};
use once_cell::sync::Lazy;
use reqwest::{Client, StatusCode};
use std::{
collections::HashMap,
error::Error,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
vec,
};
use std::str::FromStr;
use std::time::UNIX_EPOCH;
use tokio::sync::Mutex;
use tokio::time::sleep;
use reqwest::Client;
use systemd_journal_logger::{JournalLog};
use crate::bot::Bot;
mod bot;
mod config;
mod feeds;
mod lemmy;
mod post_history;
mod fetchers;
pub static CLIENT: Lazy<Client> = Lazy::new(|| {
let client = Client::builder()
.timeout(Duration::seconds(30).to_std().unwrap())
.connect_timeout(Duration::seconds(30).to_std().unwrap())
pub static HTTP_CLIENT: Lazy<Client> = Lazy::new(|| {
Client::builder()
.timeout(Duration::seconds(10).to_std().unwrap())
.connect_timeout(Duration::seconds(10).to_std().unwrap())
.build()
.expect("build client");
client
.expect("build client")
});
struct PostQueueMetadata {
id: usize,
series: String,
part: Option<String>,
volume: Option<String>,
}
#[derive(Clone)]
struct Bot {
secrets: Secrets,
config: Config,
post_history: Vec<PrevPost>,
community_ids: CommunitiesVector,
auth: Sensitive<String>,
login_error: bool,
start_time: DateTime<Utc>,
message_queue: Vec<String>,
error_queue: Vec<String>,
}
impl Bot {
pub(crate) fn new() -> Bot {
Bot {
secrets: Secrets::init(),
config: Config::init(),
post_history: PrevPost::load(),
community_ids: CommunitiesVector::new(),
auth: Sensitive::new("".to_string()),
login_error: true,
start_time: Utc::now(),
message_queue: vec![],
error_queue: vec![],
}
}
/// Get JWT Token
///
/// * `return` : Returns true if token was successfully retrieved, false otherwise
#[warn(unused_results)]
pub(crate) async fn login(&mut self) -> Result<Sensitive<String>, Box<dyn Error>> {
let login_params = Login {
username_or_email: self.secrets.lemmy.get_username(),
password: self.secrets.lemmy.get_password(),
totp_2fa_token: None,
};
let res = CLIENT
.post(self.config.instance.clone() + "/api/v3/user/login")
.json(&login_params)
.send()
.await?;
return if res.status() == StatusCode::OK {
let data: &LoginResponse = &res.json().await.unwrap();
let jwt = match data.jwt.clone() {
Some(data) => data,
None => {
self.error_queue.push(format!("Error: Missing JWT Token"));
return Err(Box::try_from(format!("Error: Missing JWT Token")).unwrap());
}
};
self.auth = jwt.clone();
self.login_error = false;
Ok(jwt)
} else {
self.error_queue
.push(format!("Error Code: {:?}", res.status()));
Err(Box::new(res.error_for_status().unwrap_err()))
};
}
/// Make Post to Lemmy Instance
///
/// * `post_data` : Object of type [CreatePost] containing post info
/// * `return` : Returns true if Post was successful, false otherwise
#[warn(unused_results)]
pub(crate) async fn post(&mut self, post_data: &CreatePost) -> Result<PostView, Box<dyn Error>> {
let res = CLIENT
.post(self.config.instance.clone() + "/api/v3/post")
.json(post_data)
.send()
.await?;
// TODO: process res to get info about if post was successfully (mostly if jwt token was valid)
let ret: PostView = serde_json::from_str::<HashMap<&str, PostView>>(res.text().await?.as_str())?
.remove("post_view")
.unwrap();
return Ok(ret);
}
#[warn(unused_results)]
pub(crate) async fn pin_post(&mut self, new_post_id: &PostId, new_post_community: &CommunityId) -> Result<(bool, bool), Box<dyn Error>> {
let mut local_pins = true;
let mut community_pins = true;
// Unpin Old Posts
// Get Local Posts & Unpin The Other Post
let mut meta_community: CommunityId = CommunityId(15);
self.community_ids.ids.iter().for_each(|(id, name)| {
if name == &LemmyCommunities::metadiscussions.to_string() {
meta_community = id.clone();
}
});
let get_params = GetPosts {
auth: Some(self.auth.clone()),
..Default::default()
};
local_pins = self
.unpin_old_posts(get_params, PostFeatureType::Local, &meta_community)
.await?;
// Get Community Posts & Unpin The Other Post
let get_params = GetPosts {
auth: Some(self.auth.clone()),
community_id: Some(new_post_community.clone()),
..Default::default()
};
community_pins = self
.unpin_old_posts(get_params, PostFeatureType::Community, &meta_community)
.await?;
// Pin New Post
let pin_new_community = FeaturePost {
post_id: new_post_id.clone(),
featured: true,
feature_type: PostFeatureType::Community,
auth: self.auth.clone(),
};
match self.pin(pin_new_community).await {
Ok(_) => {}
Err(e) => {
self.message_queue
.push(format!("Error Unpinning Post: {:#?}", e));
community_pins = false;
}
};
let pin_new_local = FeaturePost {
post_id: new_post_id.clone(),
featured: true,
feature_type: PostFeatureType::Local,
auth: self.auth.clone(),
};
match self.pin(pin_new_local).await {
Ok(_) => {}
Err(e) => {
self.message_queue
.push(format!("Error Unpinning Post: {:#?}", e));
local_pins = false;
}
};
return Ok((community_pins, local_pins));
}
#[warn(unused_results)]
pub(crate) async fn unpin_old_posts(
&mut self,
get_params: GetPosts,
pin_scope: PostFeatureType,
meta_community: &CommunityId,
) -> Result<bool, Box<dyn Error>> {
let post_list_json = CLIENT
.get(self.config.instance.clone() + "/api/v3/post/list")
.query(&get_params)
.send()
.await?
.text()
.await?;
let post_list: GetPostsResponse = serde_json::from_str(post_list_json.as_str()).unwrap();
for post_view in post_list.posts {
if &post_view.community.id != meta_community && ( ( pin_scope == PostFeatureType::Local && post_view.post.featured_local ) || ( pin_scope == PostFeatureType::Community && post_view.post.featured_community ) ) {
let remove_local_pin = FeaturePost {
post_id: post_view.post.id,
featured: false,
feature_type: pin_scope,
auth: self.auth.clone(),
};
match self.pin(remove_local_pin).await {
Ok(_) => {}
Err(e) => {
self.message_queue
.push(format!("Error Unpinning Post: {:#?}", e));
return Err(Box::from(format!("{}", e)));
}
};
}
}
Ok(true)
}
pub(crate) async fn pin(&mut self, pin_data: FeaturePost) -> Result<bool, Box<dyn Error>> {
let res = CLIENT
.post(self.config.instance.clone() + "/api/v3/post/feature")
.json(&pin_data)
.send()
.await?;
let ret: PostView = serde_json::from_str::<HashMap<&str, PostView>>(res.text().await?.as_str())?
.remove("post_view")
.unwrap();
return Ok(ret.post.featured_local);
}
pub(crate) async fn idle(&mut self) {
let mut sleep_duration = Duration::seconds(30);
if Utc::now() - self.start_time > sleep_duration {
sleep_duration = Duration::seconds(60);
}
match reqwest::get("https://status.neshweb.net/api/push/7s1CjPPzrV?status=up&msg=OK&ping=").await {
Ok(_) => {}
Err(err) => self.error_queue.push(format!("{}", err)),
};
while Utc::now() - self.start_time < sleep_duration {
sleep(Duration::milliseconds(100).to_std().unwrap()).await;
}
}
}
async fn list_posts(auth: &Sensitive<String>, base: String) -> GetPostsResponse {
let params = GetPosts {
type_: Some(ListingType::Local),
sort: Some(SortType::New),
auth: Some(auth.clone()),
..Default::default()
};
let res = CLIENT
.get(base + "/api/v3/post/list")
.query(&params)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return serde_json::from_str(&res).unwrap();
}
async fn run_bot(bot: Arc<Mutex<Bot>>) {
let mut this = bot.lock().await.clone();
let now = Utc::now;
let mut config_reload_duration = this.config.config_reload.unwrap_or(360);
let mut config_reload_time = now() - Duration::minutes(config_reload_duration as i64 + 1); // Setting this to be in the future by default prevents unneeded code duplication
loop {
*bot.lock().await = this.clone();
this.start_time = now();
this.idle().await;
// After configured time passed reload config
if now() - config_reload_time >= Duration::minutes(config_reload_duration as i64) {
this.config.load();
this.secrets.load();
config_reload_duration = this.config.config_reload.unwrap_or(360);
let _ = this
.community_ids
.load(&this.auth, &this.config.instance)
.await;
this.message_queue
.push(format!("Config Reloaded at {}", now().naive_local()));
config_reload_time = now();
}
// Check if Login token is valid, if it is not get a new one
while this.login_error {
let _ = this.login().await;
}
// Perform Run
// Start the polling process
// Get all feed URLs (use cache)
let queue_data = match this
.config
.check_feeds(&this.post_history, &this.community_ids, &this.auth)
.await
{
Ok(data) => data,
Err(e) => {
this.error_queue.push(format!("{}", e));
continue;
}
};
this.message_queue
.push(format!("Checked Feeds at {}", now().naive_local()));
for queued_post in queue_data {
let (post, post_metadata) = queued_post;
this.message_queue.push(format!("Posting: {}", post.name));
// Perform Post and Pins
let post_data = match this.post(&post).await {
Ok(data) => data,
Err(e) => {
this.error_queue.push(format!("{}", e));
continue;
}
};
let _ = this
.pin_post(&post_data.post.id, &post_data.community.id)
.await;
// Update Post History
let mut index_exists = false;
if this.post_history.len() > post_metadata.id {
index_exists = true;
}
if let Some(part_slug) = post_metadata.part {
match index_exists {
true => {
this.post_history[post_metadata.id].last_part_slug = Some(part_slug);
this.post_history[post_metadata.id].last_part_time = Some(now().to_string());
}
false => {
let new_history = PrevPost {
id: post_metadata.id,
last_volume_slug: None,
last_volume_time: None,
last_part_slug: Some(part_slug),
last_part_time: Some(now().to_string()),
};
this.post_history.push(new_history);
}
}
}
if let Some(volume_slug) = post_metadata.volume {
match index_exists {
true => {
this.post_history[post_metadata.id].last_volume_slug = Some(volume_slug);
this.post_history[post_metadata.id].last_volume_time = Some(now().to_string());
}
false => {
let new_history = PrevPost {
id: post_metadata.id,
last_volume_slug: Some(volume_slug),
last_volume_time: Some(now().to_string()),
last_part_slug: None,
last_part_time: None,
};
this.post_history.push(new_history);
}
};
}
}
PrevPost::save(&this.post_history);
// Fix Queue Lengths and Update Mutex Data
while this.message_queue.len() > 5 {
this.message_queue.remove(0);
}
while this.error_queue.len() > 10 {
this.error_queue.remove(0);
}
this.idle().await;
}
}
async fn print_info(shutdown: Arc<AtomicBool>, bot: Arc<Mutex<Bot>>) {
while !shutdown.load(Ordering::Relaxed) {
let snapshot: tokio::sync::MutexGuard<'_, Bot> = bot.lock().await;
sleep(Duration::milliseconds(200).to_std().unwrap()).await;
print!("\x1B[2J\x1B[1;1H");
println!(
"##[Ascendance of a Bookworm Bot]## | Time: {}",
Utc::now().naive_local().format("%H:%M:%S")
);
println!("Instance: {}", snapshot.config.instance);
println!(
"Ran Last: {}",
snapshot
.start_time
.naive_local()
.format("%d/%m/%Y %H:%M:%S")
);
println!("{:#<1$}", "", 175);
snapshot.post_history.iter().for_each(|post| {
if post.last_part_time.is_some() && post.last_volume_time.is_some() {
let part_time = post.last_part_time.clone().unwrap();
let volume_time = post.last_volume_time.clone().unwrap();
let parsed_part_time = DateTime::<Utc>::from_str(&part_time).unwrap_or(DateTime::<Utc>::from(UNIX_EPOCH)).naive_local();
let parsed_volume_time = DateTime::<Utc>::from_str(&volume_time).unwrap_or(DateTime::<Utc>::from(UNIX_EPOCH)).naive_local();
let formatted_time;
if parsed_part_time > parsed_volume_time {
formatted_time = parsed_part_time;
}
else {
formatted_time = parsed_volume_time;
}
print!("| {} |", formatted_time.format("%d/%m/%Y %H:%M:%S"));
}
else if post.last_part_time.is_some() {
let part_time = post.last_part_time.clone().unwrap();
let formatted_time: NaiveDateTime = DateTime::<Utc>::from_str(&part_time).unwrap_or(DateTime::<Utc>::from(UNIX_EPOCH)).naive_local();
print!("| {} |", formatted_time.format("%d/%m/%Y %H:%M:%S"));
}
else if post.last_volume_time.is_some() {
let volume_time = post.last_volume_time.clone().unwrap();
let formatted_time = DateTime::<Utc>::from_str(&volume_time).unwrap_or(DateTime::<Utc>::from(UNIX_EPOCH)).naive_local();
print!("| {} |", formatted_time.format("%d/%m/%Y %H:%M:%S"));
}
else {
print!("| {:<1$} |", "", 19);
}
print!("{:<1$}", "", 2 - post.id.to_string().len());
print!("{}| ", post.id);
print!("{}", post.last_part_slug.clone().unwrap_or("N/A".to_string()));
print!("{:<1$}| ", "", 75 - post.last_part_slug.clone().unwrap_or("N/A".to_string()).len());
print!("{}", post.last_volume_slug.clone().unwrap_or("N/A".to_string()));
println!("{:<1$}| ", "", 70 - post.last_volume_slug.clone().unwrap_or("N/A".to_string()).len());
});
println!("{:#<1$}", "", 175);
for error in snapshot.error_queue.iter() {
println!("{}", error);
}
println!("{:#<1$}", "", 175);
for message in snapshot.message_queue.iter() {
println!("{}", message);
}
}
}
#[tokio::main]
async fn main() {
let shutdown = Arc::new(AtomicBool::new(false));
loop {
println!("Starting AoB Bot...");
let shutdown_clone = shutdown.clone();
let bot = Arc::new(Mutex::new(Bot::new()));
let bot_clone = bot.clone();
let bot_thread = tokio::spawn(async move { run_bot(bot).await });
let tui_thread = tokio::spawn(async move { print_info(shutdown_clone, bot_clone).await });
let _ = bot_thread.await;
tui_thread.abort();
println!("Bot crashed due to unknown Error, restarting thread after wait...");
sleep(Duration::seconds(10).to_std().unwrap()).await;
JournalLog::new()
.expect("Systemd-Logger crate error")
.install()
.expect("Systemd-Logger crate error");
match std::env::var("LOG_LEVEL") {
Ok(level) => {
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;
}

101
src/post_history.rs Normal file
View file

@ -0,0 +1,101 @@
use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use systemd_journal_logger::connected_to_journal;
macro_rules! info {
($msg:tt) => {
match connected_to_journal() {
true => log::info!("[INFO] {}", $msg),
false => println!("[INFO] {}", $msg),
}
};
}
macro_rules! error {
($msg:tt) => {
match connected_to_journal() {
true => log::error!("[ERROR] {}", $msg),
false => eprintln!("[ERROR] {}", $msg),
}
};
}
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
pub(crate) struct SeriesHistory {
pub(crate) series: HashMap<String, PostHistory>,
}
impl SeriesHistory {
pub(crate) fn load_history() -> Self {
let info_msg = "Loading History";
info!(info_msg);
match confy::load(env!("CARGO_PKG_NAME"), "history") {
Ok(data) => data,
Err(e) => panic!("history.toml not found: {e}"),
}
}
pub(crate) fn save_history(&self) {
let info_msg = "Saving History";
info!(info_msg);
if let Err(e) = confy::store(env!("CARGO_PKG_NAME"), "history", self) {
let err_msg = format!("Unexpected error saving to history.toml: {e}");
error!(err_msg);
}
}
pub(crate) fn check_for_post(&self, series: &str, part: &str, title: &str) -> bool {
if let Some(series_map) = self.series.get(series) {
if let Some(part_info) = series_map.parts.get(part) {
return part_info.volume == title || part_info.chapter == title;
}
}
false
}
pub(crate) fn get_series(&self, series: &str) -> PostHistory {
match self.series.get(series) {
Some(history) => history.clone(),
None => PostHistory {
parts: HashMap::new(),
},
}
}
pub(crate) fn set_series(&mut self, series: &str, data: PostHistory) {
self.series
.entry(series.to_owned())
.and_modify(|val| *val = data.clone())
.or_insert(data);
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct PostHistory {
pub(crate) parts: HashMap<String, PostHistoryInner>,
}
impl PostHistory {
pub(crate) fn get_part(&self, part: &str) -> PostHistoryInner {
match self.parts.get(part) {
Some(history) => history.clone(),
None => PostHistoryInner {
volume: "".to_owned(),
chapter: "".to_owned(),
},
}
}
pub(crate) fn set_part(&mut self, part: &str, data: PostHistoryInner) {
self.parts
.entry(part.to_owned())
.and_modify(|val| *val = data.clone())
.or_insert(data);
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct PostHistoryInner {
pub(crate) volume: String,
pub(crate) chapter: String,
}