Compare commits
No commits in common. "main" and "2.0.1" have entirely different histories.
28 changed files with 4436 additions and 2840 deletions
|
@ -5,34 +5,16 @@ on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- '[0-9]+.[0-9]+.[0-9]+'
|
- '[0-9]+.[0-9]+.[0-9]+'
|
||||||
- '[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+'
|
- '[0-9]+.[0-9]+.[0-9]+rc[0-9]+'
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
run-tests:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container: forgejo.neshweb.net/ci-docker-images/rust-node:latest
|
|
||||||
steps:
|
steps:
|
||||||
-
|
- name: Checking Out Repository Code
|
||||||
name: Add Clippy
|
|
||||||
run: rustup component add clippy
|
|
||||||
-
|
|
||||||
name: Checking Out Repository Code
|
|
||||||
uses: https://code.forgejo.org/actions/checkout@v3
|
uses: https://code.forgejo.org/actions/checkout@v3
|
||||||
-
|
- name: Placeholder
|
||||||
name: Set Up Cargo Cache
|
run: echo Placeholder Job
|
||||||
uses: actions/cache@v3
|
- name: Check if Version in Cargo.toml matches Tag
|
||||||
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: |
|
run: |
|
||||||
VERSION=$(cat Cargo.toml | grep -E "(^|\|)version =" | cut -f2- -d= | tr -d \" | tr -d " ")
|
VERSION=$(cat Cargo.toml | grep -E "(^|\|)version =" | cut -f2- -d= | tr -d \" | tr -d " ")
|
||||||
if test $VERSION != "${{ github.ref_name }}"; then
|
if test $VERSION != "${{ github.ref_name }}"; then
|
||||||
|
@ -46,84 +28,27 @@ jobs:
|
||||||
needs: test
|
needs: test
|
||||||
if: success()
|
if: success()
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container: forgejo.neshweb.net/ci-docker-images/rust-node:latest
|
container: rust:latest
|
||||||
steps:
|
steps:
|
||||||
|
-
|
||||||
|
name: Installing Node
|
||||||
|
run: apt update && apt install -y nodejs
|
||||||
-
|
-
|
||||||
name: Checking Out Repository Code
|
name: Checking Out Repository Code
|
||||||
uses: https://code.forgejo.org/actions/checkout@v3
|
uses: https://code.forgejo.org/actions/checkout@v3
|
||||||
-
|
|
||||||
name: Prepare build environment
|
|
||||||
run: mkdir dist
|
|
||||||
-
|
-
|
||||||
name: Compiling To Linux Target
|
name: Compiling To Linux Target
|
||||||
run: |
|
run: |
|
||||||
cargo build -r
|
cargo build -r
|
||||||
mv target/release/${{ github.event.repository.name }} dist/${{ github.event.repository.name }}-linux-amd64
|
mv target/release/ascendance-of-a-bookworm-bot bookworm-bot-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
|
name: Uploading Build Artifact
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: release_blobs
|
name: bookworm-bot-linux-amd64
|
||||||
path: dist
|
path: bookworm-bot-linux-amd64
|
||||||
if-no-files-found: error
|
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:
|
upload-release:
|
||||||
needs: build
|
needs: build
|
||||||
if: success()
|
if: success()
|
||||||
|
@ -133,14 +58,25 @@ jobs:
|
||||||
name: Downloading All Build Artifacts
|
name: Downloading All Build Artifacts
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
-
|
-
|
||||||
name: Filter out env files
|
name: Rearrange Artifact Paths
|
||||||
run: rm release_blobs/build.env
|
run: |
|
||||||
|
mkdir release
|
||||||
|
mv bookworm-bot-linux-amd64/bookworm-bot-linux-amd64 release/bookworm-bot-linux-amd64
|
||||||
|
-
|
||||||
|
name: Upload Artifacts As Generic Packages
|
||||||
|
run: |
|
||||||
|
echo 'curl -v --user ${{ secrets.FORGEJO_USERNAME }}:${{ secrets.FORGEJO_TOKEN }} \
|
||||||
|
--upload-file release/bookworm-bot-linux-amd64 \
|
||||||
|
https://forgejo.neshweb.net/api/packages/${{ secrets.FORGEJO_USERNAME }}/generic/${{ github.event.repository.name }}/${{ github.ref_name }}/bookworm-bot-linux-amd64'
|
||||||
|
curl -v --user ${{ secrets.FORGEJO_USERNAME }}:${{ secrets.FORGEJO_TOKEN }} \
|
||||||
|
--upload-file release/bookworm-bot-linux-amd64 \
|
||||||
|
https://forgejo.neshweb.net/api/packages/${{ secrets.FORGEJO_USERNAME }}/generic/${{ github.event.repository.name }}/${{ github.ref_name }}/bookworm-bot-linux-amd64
|
||||||
-
|
-
|
||||||
name: Release New Version
|
name: Release New Version
|
||||||
uses: actions/forgejo-release@v2
|
uses: actions/forgejo-release@v1
|
||||||
with:
|
with:
|
||||||
direction: upload
|
direction: upload
|
||||||
url: https://forgejo.neshweb.net
|
url: https://forgejo.neshweb.net
|
||||||
release-dir: release_blobs
|
release-dir: release
|
||||||
token: ${{ secrets.FORGEJO_TOKEN }}
|
token: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
tag: ${{ github.ref_name }}
|
tag: ${{ github.ref_name }}
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
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
|
|
|
@ -10,25 +10,7 @@ on:
|
||||||
jobs:
|
jobs:
|
||||||
run-tests:
|
run-tests:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container: forgejo.neshweb.net/ci-docker-images/rust-node:latest
|
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Add Clippy
|
name: Placeholder
|
||||||
run: rustup component add clippy
|
run: echo Placeholder Job
|
||||||
-
|
|
||||||
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
|
|
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -1,7 +1,11 @@
|
||||||
|
/secrets.json
|
||||||
|
/config.json
|
||||||
|
/config.toml
|
||||||
|
/.env
|
||||||
|
/posts.json
|
||||||
|
/history.toml
|
||||||
/.vscode
|
/.vscode
|
||||||
/.idea
|
/.idea
|
||||||
/jnc_api_examples
|
|
||||||
/.directory
|
|
||||||
|
|
||||||
# Added by cargo
|
# Added by cargo
|
||||||
|
|
||||||
|
|
674
COPYING
674
COPYING
|
@ -1,674 +0,0 @@
|
||||||
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>.
|
|
1490
Cargo.lock
generated
1490
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
45
Cargo.toml
45
Cargo.toml
|
@ -1,35 +1,22 @@
|
||||||
[package]
|
[package]
|
||||||
authors = ["Neshura"]
|
name = "ascendance-of-a-bookworm-bot"
|
||||||
name = "aob-lemmy-bot"
|
version = "2.0.1"
|
||||||
version = "3.2.0"
|
|
||||||
edition = "2021"
|
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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "^0.4"
|
chrono = "^0.4.26"
|
||||||
lemmy_api_common = "0.19.5"
|
lemmy_api_common = "^0.18.2"
|
||||||
lemmy_db_schema = "0.19.5"
|
lemmy_db_schema = "^0.18.2"
|
||||||
once_cell = "^1.19"
|
once_cell = "^1.18.0"
|
||||||
reqwest = { version = "^0.12", features = ["blocking", "json"] }
|
reqwest = { version = "^0.11.18", features = ["blocking", "json"] }
|
||||||
serde = "^1.0"
|
serde = "^1.0.164"
|
||||||
serde_derive = "^1.0"
|
serde_derive = "^1.0.164"
|
||||||
serde_json = "^1.0"
|
serde_json = "^1.0.97"
|
||||||
strum_macros = "^0.26"
|
strum_macros = "^0.25.0"
|
||||||
tokio = { version = "^1.37", features = ["rt", "rt-multi-thread", "macros"] }
|
tokio = { version = "^1.32.0", features = ["rt", "rt-multi-thread", "macros"] }
|
||||||
url = "^2.5"
|
url = "^2.4.0"
|
||||||
confy = "^0.6"
|
confy = "0.5.1"
|
||||||
toml = "^0.8"
|
dotenv = "0.15.0"
|
||||||
systemd-journal-logger = "^2.1.1"
|
toml = "0.8.8"
|
||||||
log = "^0.4"
|
|
||||||
async-trait = "^0.1"
|
|
||||||
notify = "6.1.1"
|
|
||||||
|
|
97
README.md
97
README.md
|
@ -1,52 +1,59 @@
|
||||||
# aob-lemmy-bot
|
# 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": {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
**config.toml**
|
**config.toml**
|
||||||
```toml
|
```toml
|
||||||
instance = "https://lemmy.example.org"
|
[urls]
|
||||||
username = "BotUserName"
|
instance = "base URL of Lemmy Instance"
|
||||||
password = "BotPassword"
|
uptime_kuma = "Uptime Kuma Ping URL"
|
||||||
status_post_url = "PostUrlForStatusMonitoring"
|
|
||||||
config_reload_seconds = 10800
|
|
||||||
|
|
||||||
protected_communities = [ "community_where_pins_should_stay" ]
|
[settings]
|
||||||
|
config_reload = 360 # Time in Minutes between Config reloads
|
||||||
|
|
||||||
[[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"
|
|
||||||
|
|
||||||
[[series]]
|
[[feeds]]
|
||||||
slug = "example-slug-2"
|
id = 0 # incrementor, only used for correctly matching post history data
|
||||||
parted = true
|
series_slug = "ascendance-of-a-bookworm" # series slug on J-Novel Club
|
||||||
[series.prepub_community]
|
|
||||||
name = "communityforprepubs"
|
[communities]
|
||||||
[series.prepub_community.pin_settings]
|
chapter = "aobprepub" # Community for Chapter Posts of the Series
|
||||||
pin_new_post_local = false
|
volume = "aoblightnovel" # Community for Volume Posts of the Series
|
||||||
pin_new_post_community = false
|
|
||||||
[series.prepub_community.post_body]
|
|
||||||
body_type = "Custom"
|
[[feeds]] # See previous example
|
||||||
body_content = "single line content"
|
id = 1
|
||||||
[series.volume_community]
|
series_slug = "ascendance-of-a-bookworm-short-story-collection"
|
||||||
name = "communityforvolumes"
|
|
||||||
[series.volume_community.pin_settings]
|
[communities]
|
||||||
pin_new_post_local = false
|
chapter = "aobprepub"
|
||||||
pin_new_post_community = false
|
volume = "aoblightnovel"
|
||||||
[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"
|
||||||
|
}
|
||||||
|
]
|
8
automod.service
Normal file
8
automod.service
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[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
13
debian/aob-lemmy-bot.service
vendored
|
@ -1,13 +0,0 @@
|
||||||
[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
|
|
6
deploy.sh
Normal file
6
deploy.sh
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
## deploy to machine as automod.new
|
||||||
|
## stop automod service
|
||||||
|
## mv automod.new to automod
|
||||||
|
## restart automod service
|
||||||
|
## idea: websocket event?
|
411
jnc_api_examples/jnovel-example.json
Normal file
411
jnc_api_examples/jnovel-example.json
Normal file
|
@ -0,0 +1,411 @@
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
34
jnc_api_examples/series.json
Normal file
34
jnc_api_examples/series.json
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"id": "",
|
||||||
|
"legacyId": "5c8df1ef2f5f17684dd287b6",
|
||||||
|
"type": "NOVEL",
|
||||||
|
"status": "DEFAULT",
|
||||||
|
"title": "Ascendance of a Bookworm",
|
||||||
|
"shortTitle": "honzuki",
|
||||||
|
"originalTitle": "本好きの下剋上 ~司書になるためには手段を選んでいられません~",
|
||||||
|
"slug": "ascendance-of-a-bookworm",
|
||||||
|
"hidden": false,
|
||||||
|
"created": "2019-03-17T07:06:23.137Z",
|
||||||
|
"description": "A certain college girl who's loved books ever since she was a little girl dies in an accident and is reborn in another world she knows nothing about. She is now Myne, the sickly five-year-old daughter of a poor soldier. To make things worse, the world she's been reborn in has a very low literacy rate and books mostly don't exist. She'd have to pay an enormous amount of money to buy one.\n\nMyne resolves herself: If there aren't any books, she'll just have to make them! Her goal is to become a librarian. This story begins with her quest to make books so she can live surrounded by them!\n\nDive into this biblio-fantasy written for book lovers and bookworms!",
|
||||||
|
"shortDescription": "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.",
|
||||||
|
"tags": [
|
||||||
|
"books",
|
||||||
|
"reincarnation",
|
||||||
|
"fantasy",
|
||||||
|
"book loving",
|
||||||
|
"reading isekai",
|
||||||
|
"medieval",
|
||||||
|
"invention",
|
||||||
|
"cute",
|
||||||
|
"anime",
|
||||||
|
"available in print"
|
||||||
|
],
|
||||||
|
"cover": {
|
||||||
|
"originalUrl": "",
|
||||||
|
"coverUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Serie-5c8df1ef2f5f17684dd287b6/honzuki1_cover_400.jpg",
|
||||||
|
"thumbnailUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Serie-5c8df1ef2f5f17684dd287b6/honzuki1_thumbnail_240.jpg"
|
||||||
|
},
|
||||||
|
"following": true,
|
||||||
|
"catchup": false,
|
||||||
|
"rentals": true
|
||||||
|
}
|
1483
jnc_api_examples/series_volumes.json
Normal file
1483
jnc_api_examples/series_volumes.json
Normal file
File diff suppressed because it is too large
Load diff
169
jnc_api_examples/volume.json
Normal file
169
jnc_api_examples/volume.json
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
{
|
||||||
|
"parts": [
|
||||||
|
{
|
||||||
|
"id": "",
|
||||||
|
"legacyId": "64eceac855956e4370016f2a",
|
||||||
|
"title": "Ascendance of a Bookworm: Part 5 Volume 7 Part 1",
|
||||||
|
"originalTitle": "",
|
||||||
|
"slug": "ascendance-of-a-bookworm-part-5-volume-7-part-1",
|
||||||
|
"number": 229,
|
||||||
|
"preview": true,
|
||||||
|
"hidden": false,
|
||||||
|
"created": "2023-08-28T18:43:20.218Z",
|
||||||
|
"expiration": null,
|
||||||
|
"launch": "2023-08-28T21:00:00Z",
|
||||||
|
"cover": {
|
||||||
|
"originalUrl": "",
|
||||||
|
"coverUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64eceac855956e4370016f2a/bookworm5.7-cover-400.jpg",
|
||||||
|
"thumbnailUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64eceac855956e4370016f2a/bookworm5.7-thumbnail-240.jpg"
|
||||||
|
},
|
||||||
|
"progress": 0.9767,
|
||||||
|
"totalMangaPages": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "",
|
||||||
|
"legacyId": "64f60ed440d3b4be53892ab1",
|
||||||
|
"title": "Ascendance of a Bookworm: Part 5 Volume 7 Part 2",
|
||||||
|
"originalTitle": "",
|
||||||
|
"slug": "ascendance-of-a-bookworm-part-5-volume-7-part-2",
|
||||||
|
"number": 230,
|
||||||
|
"preview": false,
|
||||||
|
"hidden": false,
|
||||||
|
"created": "2023-09-04T17:07:32.765Z",
|
||||||
|
"expiration": null,
|
||||||
|
"launch": "2023-09-04T21:00:00Z",
|
||||||
|
"cover": {
|
||||||
|
"originalUrl": "",
|
||||||
|
"coverUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64f60ed440d3b4be53892ab1/bookworm5.7-cover-400.jpg",
|
||||||
|
"thumbnailUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64f60ed440d3b4be53892ab1/bookworm5.7-thumbnail-240.jpg"
|
||||||
|
},
|
||||||
|
"progress": 0.9268,
|
||||||
|
"totalMangaPages": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "",
|
||||||
|
"legacyId": "64ff408d17922cf052397ce1",
|
||||||
|
"title": "Ascendance of a Bookworm: Part 5 Volume 7 Part 3",
|
||||||
|
"originalTitle": "",
|
||||||
|
"slug": "ascendance-of-a-bookworm-part-5-volume-7-part-3",
|
||||||
|
"number": 231,
|
||||||
|
"preview": false,
|
||||||
|
"hidden": false,
|
||||||
|
"created": "2023-09-11T16:30:05.687Z",
|
||||||
|
"expiration": null,
|
||||||
|
"launch": "2023-09-11T21:00:00Z",
|
||||||
|
"cover": {
|
||||||
|
"originalUrl": "",
|
||||||
|
"coverUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64ff408d17922cf052397ce1/bookworm5.7-cover-400.jpg",
|
||||||
|
"thumbnailUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-64ff408d17922cf052397ce1/bookworm5.7-thumbnail-240.jpg"
|
||||||
|
},
|
||||||
|
"progress": 0.9756,
|
||||||
|
"totalMangaPages": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "",
|
||||||
|
"legacyId": "65086e7e08440cd82809c5cf",
|
||||||
|
"title": "Ascendance of a Bookworm: Part 5 Volume 7 Part 4",
|
||||||
|
"originalTitle": "",
|
||||||
|
"slug": "ascendance-of-a-bookworm-part-5-volume-7-part-4",
|
||||||
|
"number": 232,
|
||||||
|
"preview": false,
|
||||||
|
"hidden": false,
|
||||||
|
"created": "2023-09-18T15:36:30.308Z",
|
||||||
|
"expiration": null,
|
||||||
|
"launch": "2023-09-18T21:00:00Z",
|
||||||
|
"cover": {
|
||||||
|
"originalUrl": "",
|
||||||
|
"coverUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-65086e7e08440cd82809c5cf/bookworm5.7-cover-400.jpg",
|
||||||
|
"thumbnailUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-65086e7e08440cd82809c5cf/bookworm5.7-thumbnail-240.jpg"
|
||||||
|
},
|
||||||
|
"progress": 0.9697,
|
||||||
|
"totalMangaPages": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "",
|
||||||
|
"legacyId": "65119f4b348941b225eed9aa",
|
||||||
|
"title": "Ascendance of a Bookworm: Part 5 Volume 7 Part 5",
|
||||||
|
"originalTitle": "",
|
||||||
|
"slug": "ascendance-of-a-bookworm-part-5-volume-7-part-5",
|
||||||
|
"number": 233,
|
||||||
|
"preview": false,
|
||||||
|
"hidden": false,
|
||||||
|
"created": "2023-09-25T14:55:07.171Z",
|
||||||
|
"expiration": null,
|
||||||
|
"launch": "2023-09-25T21:00:00Z",
|
||||||
|
"cover": {
|
||||||
|
"originalUrl": "",
|
||||||
|
"coverUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-65119f4b348941b225eed9aa/bookworm5.7-cover-400.jpg",
|
||||||
|
"thumbnailUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-65119f4b348941b225eed9aa/bookworm5.7-thumbnail-240.jpg"
|
||||||
|
},
|
||||||
|
"progress": 0.9697,
|
||||||
|
"totalMangaPages": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "",
|
||||||
|
"legacyId": "651ae1f4e77d3ff76425bf44",
|
||||||
|
"title": "Ascendance of a Bookworm: Part 5 Volume 7 Part 6",
|
||||||
|
"originalTitle": "",
|
||||||
|
"slug": "ascendance-of-a-bookworm-part-5-volume-7-part-6",
|
||||||
|
"number": 234,
|
||||||
|
"preview": false,
|
||||||
|
"hidden": false,
|
||||||
|
"created": "2023-10-02T15:29:56.535Z",
|
||||||
|
"expiration": null,
|
||||||
|
"launch": "2023-10-02T21:00:00Z",
|
||||||
|
"cover": {
|
||||||
|
"originalUrl": "",
|
||||||
|
"coverUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-651ae1f4e77d3ff76425bf44/bookworm5.7-cover-400.jpg",
|
||||||
|
"thumbnailUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-651ae1f4e77d3ff76425bf44/bookworm5.7-thumbnail-240.jpg"
|
||||||
|
},
|
||||||
|
"progress": 0.9756,
|
||||||
|
"totalMangaPages": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "",
|
||||||
|
"legacyId": "651d52b371f1269e36326ccc",
|
||||||
|
"title": "Ascendance of a Bookworm: Part 5 Volume 7 Part 7",
|
||||||
|
"originalTitle": "",
|
||||||
|
"slug": "ascendance-of-a-bookworm-part-5-volume-7-part-7",
|
||||||
|
"number": 235,
|
||||||
|
"preview": false,
|
||||||
|
"hidden": false,
|
||||||
|
"created": "2023-10-04T11:55:31.144Z",
|
||||||
|
"expiration": null,
|
||||||
|
"launch": "2023-10-09T21:00:00Z",
|
||||||
|
"cover": {
|
||||||
|
"originalUrl": "",
|
||||||
|
"coverUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-651d52b371f1269e36326ccc/bookworm5.7-cover-400.jpg",
|
||||||
|
"thumbnailUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-651d52b371f1269e36326ccc/bookworm5.7-thumbnail-240.jpg"
|
||||||
|
},
|
||||||
|
"progress": 0.9268,
|
||||||
|
"totalMangaPages": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "",
|
||||||
|
"legacyId": "651d537e63004f476f0c016b",
|
||||||
|
"title": "Ascendance of a Bookworm: Part 5 Volume 7 Part 8",
|
||||||
|
"originalTitle": "",
|
||||||
|
"slug": "ascendance-of-a-bookworm-part-5-volume-7-part-8",
|
||||||
|
"number": 236,
|
||||||
|
"preview": false,
|
||||||
|
"hidden": false,
|
||||||
|
"created": "2023-10-04T11:58:54.616Z",
|
||||||
|
"expiration": null,
|
||||||
|
"launch": "2023-10-16T21:00:00Z",
|
||||||
|
"cover": {
|
||||||
|
"originalUrl": "",
|
||||||
|
"coverUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-651d537e63004f476f0c016b/bookworm5.7-cover-400.jpg",
|
||||||
|
"thumbnailUrl": "https://d2dq7ifhe7bu0f.cloudfront.net/Part-651d537e63004f476f0c016b/bookworm5.7-thumbnail-240.jpg"
|
||||||
|
},
|
||||||
|
"progress": 0.973,
|
||||||
|
"totalMangaPages": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pagination": {
|
||||||
|
"limit": 0,
|
||||||
|
"skip": 0,
|
||||||
|
"lastPage": true
|
||||||
|
}
|
||||||
|
}
|
136
src/bot.rs
136
src/bot.rs
|
@ -1,136 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
218
src/bot/mod.rs
Normal file
218
src/bot/mod.rs
Normal file
|
@ -0,0 +1,218 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::error::Error;
|
||||||
|
use std::sync::{Arc};
|
||||||
|
use chrono::{DateTime, Duration, Timelike, Utc};
|
||||||
|
use lemmy_db_schema::newtypes::{CommunityId, LanguageId};
|
||||||
|
use lemmy_db_schema::PostFeatureType;
|
||||||
|
use tokio::sync::{RwLock, RwLockWriteGuard};
|
||||||
|
use crate::{jnovel, lemmy, Message, SharedData};
|
||||||
|
use crate::config::{Config, PostBody, SeriesConfig};
|
||||||
|
use crate::jnovel::PostInfo;
|
||||||
|
use crate::lemmy::{CustomCreatePost, Lemmy};
|
||||||
|
use crate::post_history::SeriesHistory;
|
||||||
|
use tokio::time::sleep;
|
||||||
|
|
||||||
|
pub(crate) async fn run(data: Arc<RwLock<SharedData>>){
|
||||||
|
let credentials = match lemmy::Credentials::set_credentials() {
|
||||||
|
Ok(creds) => creds,
|
||||||
|
Err(e) => panic!("{}", e.to_string()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut last_reload: DateTime<Utc>;
|
||||||
|
let mut lemmy: Lemmy;
|
||||||
|
let mut login_error: bool;
|
||||||
|
let mut communities = HashMap::new();
|
||||||
|
{
|
||||||
|
let mut shared_data = data.write().await;
|
||||||
|
|
||||||
|
// Errors during bot init are likely unrecoverable and therefore should panic the bot
|
||||||
|
// Does not really matter since the bot will get restarted anyway but this way the uptime url logs a downtime
|
||||||
|
shared_data.config = match Config::load() {
|
||||||
|
Ok(data) => data,
|
||||||
|
Err(e) => panic!("{}", e),
|
||||||
|
};
|
||||||
|
last_reload = Utc::now();
|
||||||
|
|
||||||
|
lemmy = match lemmy::login(&credentials, shared_data.config.instance.as_str()).await {
|
||||||
|
Ok(data) => data,
|
||||||
|
Err(e) => panic!("{}", e),
|
||||||
|
};
|
||||||
|
login_error = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while Utc::now().naive_local().second() != 30 {
|
||||||
|
sleep(Duration::milliseconds(100).to_std().unwrap()).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {
|
||||||
|
idle(&data).await;
|
||||||
|
|
||||||
|
let mut shared_data = data.write().await;
|
||||||
|
|
||||||
|
shared_data.start = Utc::now();
|
||||||
|
|
||||||
|
if shared_data.start - last_reload > Duration::seconds(shared_data.config.config_reload_seconds as i64) {
|
||||||
|
shared_data.config = match Config::load() {
|
||||||
|
Ok(data) => data,
|
||||||
|
Err(e) => panic!("{}", e),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if login_error {
|
||||||
|
lemmy = match lemmy::login(&credentials, shared_data.config.instance.as_str()).await {
|
||||||
|
Ok(data) => data,
|
||||||
|
Err(e) => {
|
||||||
|
shared_data.messages.push(Message::Error(format!("{}", e)));
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
};
|
||||||
|
login_error = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if shared_data.start - last_reload > Duration::seconds(shared_data.config.config_reload_seconds as i64) {
|
||||||
|
communities = match lemmy.get_communities().await {
|
||||||
|
Ok(data) => data,
|
||||||
|
Err(e) => {
|
||||||
|
login_error = true;
|
||||||
|
shared_data.messages.push(Message::Error(format!("{}", e)));
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
};
|
||||||
|
last_reload = Utc::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_data.post_history = match SeriesHistory::load_history() {
|
||||||
|
Ok(data) => data,
|
||||||
|
Err(e) => {
|
||||||
|
login_error = true;
|
||||||
|
shared_data.messages.push(Message::Warning(format!("{}", e)));
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for series in shared_data.config.series.clone() {
|
||||||
|
match handle_series(&series, &communities, &lemmy, &mut shared_data).await {
|
||||||
|
Ok(data) => data,
|
||||||
|
Err(e) => {
|
||||||
|
login_error = true;
|
||||||
|
shared_data.messages.push(Message::Warning(format!("{}", e)));
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = shared_data.downgrade();
|
||||||
|
|
||||||
|
idle(&data).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn idle(data: &Arc<RwLock<SharedData>>) {
|
||||||
|
let read = data.read().await;
|
||||||
|
let mut sleep_duration = Duration::seconds(30);
|
||||||
|
if Utc::now() - read.start > sleep_duration {
|
||||||
|
sleep_duration = Duration::seconds(60);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(status_url) = read.config.status_post_url.clone() {
|
||||||
|
match reqwest::get(status_url).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => {
|
||||||
|
let mut write = data.write().await;
|
||||||
|
write.messages.push(Message::Error(format!("{}", e)))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
while Utc::now() - read.start < sleep_duration {
|
||||||
|
sleep(Duration::milliseconds(100).to_std().unwrap()).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_series<'a>(
|
||||||
|
series: &SeriesConfig,
|
||||||
|
communities: &HashMap<String, CommunityId>,
|
||||||
|
lemmy: &Lemmy,
|
||||||
|
data: &mut RwLockWriteGuard<'a, SharedData>,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
|
let mut post_list = match jnovel::check_feed(series.slug.as_str(), series.parted).await {
|
||||||
|
Ok(data) => data,
|
||||||
|
Err(e) => panic!("{:#?}", e),
|
||||||
|
};
|
||||||
|
|
||||||
|
for (index, post_info) in post_list.clone().iter().enumerate() { // todo .clone() likely not needed
|
||||||
|
let post_part_info = post_info.get_part_info();
|
||||||
|
let post_lemmy_info = post_info.get_lemmy_info();
|
||||||
|
|
||||||
|
if data.post_history.check_for_post(series.slug.as_str(), post_part_info.as_string().as_str(), post_lemmy_info.title.as_str()) {
|
||||||
|
data.messages.push(Message::Info(format!("Skipping '{}' since already posted", post_lemmy_info.title)));
|
||||||
|
post_list.remove(index);
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
let post_series_config = match post_info {
|
||||||
|
PostInfo::Chapter {..} => {&series.prepub_community},
|
||||||
|
PostInfo::Volume {..} => {&series.volume_community}
|
||||||
|
};
|
||||||
|
|
||||||
|
let community_id = *communities
|
||||||
|
.get(post_series_config.name.as_str())
|
||||||
|
.expect("Given community is invalid");
|
||||||
|
|
||||||
|
let post_body = match &post_series_config.post_body {
|
||||||
|
PostBody::None => None,
|
||||||
|
PostBody::Description => post_info.get_description(),
|
||||||
|
PostBody::Custom(text) => Some(text.clone()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let post_data = CustomCreatePost {
|
||||||
|
name: post_lemmy_info.title,
|
||||||
|
community_id,
|
||||||
|
url: Some(post_lemmy_info.url),
|
||||||
|
body: post_body,
|
||||||
|
honeypot: None,
|
||||||
|
nsfw: None,
|
||||||
|
language_id: Some(LanguageId(37)), // TODO get this id once every few hours per API request, the ordering of IDs suggests that the EN Id might change in the future
|
||||||
|
};
|
||||||
|
|
||||||
|
let post_id = lemmy.post(post_data).await?;
|
||||||
|
|
||||||
|
if post_series_config.pin_settings.pin_new_post_community {
|
||||||
|
let pinned_posts = lemmy.get_community_pinned(community_id).await?;
|
||||||
|
if !pinned_posts.is_empty() {
|
||||||
|
let community_pinned_post = &pinned_posts[0];
|
||||||
|
lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Community).await?;
|
||||||
|
}
|
||||||
|
lemmy.pin(post_id, PostFeatureType::Community).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if post_series_config.pin_settings.pin_new_post_local {
|
||||||
|
let pinned_posts = lemmy.get_local_pinned().await?;
|
||||||
|
if !pinned_posts.is_empty() {
|
||||||
|
let community_pinned_post = &pinned_posts[0];
|
||||||
|
lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Local).await?;
|
||||||
|
}
|
||||||
|
lemmy.pin(post_id, PostFeatureType::Local).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut series_history = data.post_history.get_series(series.slug.as_str());
|
||||||
|
let mut part_history = series_history.get_part(post_part_info.as_string().as_str());
|
||||||
|
|
||||||
|
match post_info {
|
||||||
|
PostInfo::Chapter {..} => {
|
||||||
|
part_history.chapter = post_info.get_lemmy_info().title
|
||||||
|
},
|
||||||
|
PostInfo::Volume {..} => {
|
||||||
|
part_history.volume = post_info.get_lemmy_info().title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
series_history.set_part(post_part_info.as_string().as_str(), part_history);
|
||||||
|
data.post_history.set_series(series.slug.as_str(), series_history);
|
||||||
|
let _ = data.post_history.save_history();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
298
src/config.rs
298
src/config.rs
|
@ -1,298 +0,0 @@
|
||||||
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),
|
|
||||||
}
|
|
67
src/config/mod.rs
Normal file
67
src/config/mod.rs
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
use std::{error::Error};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use crate::config::PostBody::Description;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
|
pub(crate) struct Config {
|
||||||
|
pub(crate) instance: String,
|
||||||
|
pub(crate) status_post_url: Option<String>,
|
||||||
|
pub(crate) config_reload_seconds: u32,
|
||||||
|
pub(crate) series: Vec<SeriesConfig>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub(crate) fn load() -> Result<Self, Box<dyn Error>> {
|
||||||
|
let cfg: Self = confy::load_path("./config.toml")?;
|
||||||
|
if cfg.instance.is_empty() {
|
||||||
|
panic!("config.toml not found!")
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.series.iter().for_each(|series| {
|
||||||
|
if series.prepub_community.post_body == Description {
|
||||||
|
panic!("'Description' type Post Body only supported for Volumes!")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Ok(cfg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Config {
|
||||||
|
fn default() -> Self {
|
||||||
|
Config {
|
||||||
|
instance: "".to_string(),
|
||||||
|
status_post_url: None,
|
||||||
|
config_reload_seconds: 21600,
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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),
|
||||||
|
}
|
|
@ -1,307 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
356
src/jnovel/mod.rs
Normal file
356
src/jnovel/mod.rs
Normal file
|
@ -0,0 +1,356 @@
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::error::Error;
|
||||||
|
use std::ops::Sub;
|
||||||
|
use chrono::{DateTime, Duration, Utc};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use url::Url;
|
||||||
|
use crate::{HTTP_CLIENT};
|
||||||
|
use crate::jnovel::PartInfo::{NoParts, Part};
|
||||||
|
use crate::jnovel::PostInfo::{Chapter, Volume};
|
||||||
|
|
||||||
|
static PAST_DAYS_ELIGIBLE: u8 = 4;
|
||||||
|
|
||||||
|
macro_rules! api_url {
|
||||||
|
() => {
|
||||||
|
"https://labs.j-novel.club/app/v1".to_string()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! jnc_base_url {
|
||||||
|
() => {
|
||||||
|
"https://j-novel.club".to_string()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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,
|
||||||
|
pub(crate) number: u8,
|
||||||
|
pub(crate) publishing: String,
|
||||||
|
#[serde(alias = "shortDescription")]
|
||||||
|
pub(crate) short_description: String,
|
||||||
|
pub(crate) cover: Cover,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
|
pub(crate) struct ChapterDetail {
|
||||||
|
pub(crate) title: String,
|
||||||
|
pub(crate) slug: String,
|
||||||
|
pub(crate) launch: String,
|
||||||
|
pub(crate) cover: Option<Cover>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub(crate) struct LemmyPostInfo {
|
||||||
|
pub(crate) title: String,
|
||||||
|
pub(crate) url: Url,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub(crate) enum PartInfo {
|
||||||
|
NoParts,
|
||||||
|
Part(u8),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartInfo {
|
||||||
|
pub(crate) fn as_u8(&self) -> u8 {
|
||||||
|
match self {
|
||||||
|
Part(number) => *number,
|
||||||
|
NoParts => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn as_string(&self) -> String {
|
||||||
|
self.as_u8().to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for PartInfo {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
let self_numeric = self.as_u8();
|
||||||
|
let other_numeric = other.as_u8();
|
||||||
|
self_numeric == other_numeric
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for PartInfo {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
|
if self.gt(other) { Some(Ordering::Greater) }
|
||||||
|
else if self.eq(other) { Some(Ordering::Equal) }
|
||||||
|
else { Some(Ordering::Less) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lt(&self, other: &Self) -> bool {
|
||||||
|
let self_numeric = self.as_u8();
|
||||||
|
let other_numeric = other.as_u8();
|
||||||
|
|
||||||
|
self_numeric < other_numeric
|
||||||
|
}
|
||||||
|
|
||||||
|
fn le(&self, other: &Self) -> bool {
|
||||||
|
!self.gt(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gt(&self, other: &Self) -> bool {
|
||||||
|
let self_numeric = self.as_u8();
|
||||||
|
let other_numeric = other.as_u8();
|
||||||
|
|
||||||
|
self_numeric > other_numeric
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ge(&self, other: &Self) -> bool {
|
||||||
|
!self.lt(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub(crate) enum PostInfo {
|
||||||
|
Chapter { part: PartInfo, lemmy_info: LemmyPostInfo },
|
||||||
|
Volume { part: PartInfo, description: String, lemmy_info: LemmyPostInfo },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostInfo {
|
||||||
|
pub(crate) fn get_part_info(&self) -> PartInfo {
|
||||||
|
match self {
|
||||||
|
Chapter {part: part_info, ..} => *part_info,
|
||||||
|
Volume {part: part_info, ..} => *part_info
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_lemmy_info(&self) -> LemmyPostInfo {
|
||||||
|
match self {
|
||||||
|
Chapter {lemmy_info, ..} => lemmy_info.clone(),
|
||||||
|
Volume {lemmy_info, ..} => lemmy_info.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_description(&self) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
Chapter {..} => None,
|
||||||
|
Volume {description, ..} => Some(description.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for PostInfo {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
let self_part = match self {
|
||||||
|
Chapter {part, ..} => part,
|
||||||
|
Volume {part, ..} => part,
|
||||||
|
};
|
||||||
|
|
||||||
|
let other_part = match other {
|
||||||
|
Chapter {part, ..} => part,
|
||||||
|
Volume {part, ..} => part,
|
||||||
|
};
|
||||||
|
|
||||||
|
self_part.eq(other_part)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for 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 {
|
||||||
|
let self_part = match self {
|
||||||
|
Chapter {part, ..} => part,
|
||||||
|
Volume {part, ..} => part,
|
||||||
|
};
|
||||||
|
|
||||||
|
let other_part = match other {
|
||||||
|
Chapter {part, ..} => part,
|
||||||
|
Volume {part, ..} => part,
|
||||||
|
};
|
||||||
|
|
||||||
|
self_part < other_part
|
||||||
|
}
|
||||||
|
|
||||||
|
fn le(&self, other: &Self) -> bool {
|
||||||
|
!self.gt(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gt(&self, other: &Self) -> bool {
|
||||||
|
let self_part = match self {
|
||||||
|
Chapter {part, ..} => part,
|
||||||
|
Volume {part, ..} => part,
|
||||||
|
};
|
||||||
|
|
||||||
|
let other_part = match other {
|
||||||
|
Chapter {part, ..} => part,
|
||||||
|
Volume {part, ..} => part,
|
||||||
|
};
|
||||||
|
|
||||||
|
self_part > other_part
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ge(&self, other: &Self) -> bool {
|
||||||
|
!self.lt(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn check_feed(series_slug: &str, series_has_parts: bool) -> Result<Vec<PostInfo>, Box<dyn Error>> {
|
||||||
|
let response = HTTP_CLIENT
|
||||||
|
.get(api_url!() + "/series/" + series_slug + "/volumes?format=json")
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut volume_brief_data: VolumesWrapper = serde_json::from_str(&response)?;
|
||||||
|
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 series_has_parts {
|
||||||
|
true => continue,
|
||||||
|
false => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let new_part_info: PartInfo;
|
||||||
|
|
||||||
|
if 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 => {
|
||||||
|
println!("No Part found, assuming 1");
|
||||||
|
new_part_info = Part(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_part_info = NoParts;
|
||||||
|
}
|
||||||
|
|
||||||
|
let post_url = format!("{}/series/{series_slug}#volume-{}", jnc_base_url!(), volume.number);
|
||||||
|
let post_details = LemmyPostInfo {
|
||||||
|
title: volume.title.clone(),
|
||||||
|
url: Url::parse(&post_url).unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let new_post_info = Volume {
|
||||||
|
part: new_part_info,
|
||||||
|
description: 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 = Chapter {
|
||||||
|
part: new_part_info,
|
||||||
|
lemmy_info: prepub_info
|
||||||
|
};
|
||||||
|
|
||||||
|
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) -> Result<Option<LemmyPostInfo>, Box<dyn Error>> {
|
||||||
|
let response = HTTP_CLIENT
|
||||||
|
.get(api_url!() + "/volumes/" + volume_slug + "/parts?format=json")
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut volume_prepub_parts_data: ChapterWrapper = serde_json::from_str(&response)?;
|
||||||
|
volume_prepub_parts_data.parts.reverse(); // Makes breaking out of the parts loop easier
|
||||||
|
|
||||||
|
let mut post_details: Option<LemmyPostInfo> = 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 post_url = format!("{}/read/{}", jnc_base_url!(), prepub_part.slug);
|
||||||
|
post_details = Some(LemmyPostInfo {
|
||||||
|
title: prepub_part.title.clone(),
|
||||||
|
url: Url::parse(&post_url).unwrap(),
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(post_details)
|
||||||
|
}
|
450
src/lemmy.rs
450
src/lemmy.rs
|
@ -1,450 +0,0 @@
|
||||||
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", ¶ms).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(¶m)
|
|
||||||
.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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
342
src/lemmy/mod.rs
Normal file
342
src/lemmy/mod.rs
Normal file
|
@ -0,0 +1,342 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::env;
|
||||||
|
use std::env::VarError;
|
||||||
|
use std::error::Error;
|
||||||
|
use lemmy_api_common::community::{ListCommunities};
|
||||||
|
use lemmy_api_common::person::{Login, LoginResponse};
|
||||||
|
use lemmy_api_common::post::{GetPosts};
|
||||||
|
use lemmy_api_common::sensitive::Sensitive;
|
||||||
|
use lemmy_db_schema::newtypes::{CommunityId, InstanceId, LanguageId, PersonId, PostId};
|
||||||
|
use lemmy_db_schema::{ListingType, PostFeatureType, SubscribedType};
|
||||||
|
use reqwest::StatusCode;
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use url::Url;
|
||||||
|
use crate::HTTP_CLIENT;
|
||||||
|
|
||||||
|
pub(crate) struct Credentials {
|
||||||
|
username: String,
|
||||||
|
password: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Credentials {
|
||||||
|
pub(crate) fn get_username(&self) -> Sensitive<String> {
|
||||||
|
Sensitive::new(self.username.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_password(&self) -> Sensitive<String> {
|
||||||
|
Sensitive::new(self.password.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn set_credentials() -> Result<Self, VarError> {
|
||||||
|
let username = env::var("LEMMY_USERNAME")?;
|
||||||
|
let password = env::var("LEMMY_PASSWORD")?;
|
||||||
|
Ok(Credentials {
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) struct Lemmy {
|
||||||
|
jwt_token: Sensitive<String>,
|
||||||
|
instance: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn login(credentials: &Credentials, instance: &str) -> Result<Lemmy, Box<dyn Error>> {
|
||||||
|
let login_params = Login {
|
||||||
|
username_or_email: credentials.get_username(),
|
||||||
|
password: credentials.get_password(),
|
||||||
|
totp_2fa_token: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let response = HTTP_CLIENT
|
||||||
|
.post(instance.to_string() + "/api/v3/user/login")
|
||||||
|
.json(&login_params)
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
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: instance.to_string(),
|
||||||
|
}),
|
||||||
|
None => panic!("Login did not return JWT token. Are the credentials valid?")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
status => panic!("Unexpected HTTP Status '{}' during Login", status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Lemmy {
|
||||||
|
pub(crate) async fn post(&self, post: CustomCreatePost) -> Result<PostId, Box<dyn Error>> {
|
||||||
|
let response = HTTP_CLIENT
|
||||||
|
.post(format!("{}/api/v3/post", &self.instance))
|
||||||
|
.bearer_auth(&self.jwt_token.to_string())
|
||||||
|
.json(&post)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let json_data = serde_json::from_str::<HashMap<&str, CustomPostView>>(&response)?
|
||||||
|
.remove("post_view")
|
||||||
|
.expect("Element should be present");
|
||||||
|
|
||||||
|
Ok(json_data.post.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn feature(&self, params: CustomFeaturePost) -> Result<CustomPostView, Box<dyn Error>> {
|
||||||
|
let response = HTTP_CLIENT
|
||||||
|
.post(format!("{}/api/v3/post/feature", &self.instance))
|
||||||
|
.bearer_auth(&self.jwt_token.to_string())
|
||||||
|
.json(¶ms)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let json_data = serde_json::from_str::<HashMap<&str, CustomPostView>>(&response)?
|
||||||
|
.remove("post_view")
|
||||||
|
.expect("Element should be present");
|
||||||
|
Ok(json_data)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn unpin(&self, post_id: PostId, location: PostFeatureType) -> Result<CustomPostView, Box<dyn Error>> {
|
||||||
|
let pin_params = CustomFeaturePost {
|
||||||
|
post_id,
|
||||||
|
featured: false,
|
||||||
|
feature_type: location,
|
||||||
|
};
|
||||||
|
self.feature(pin_params).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn pin(&self, post_id: PostId, location: PostFeatureType) -> Result<CustomPostView, Box<dyn Error>> {
|
||||||
|
let pin_params = CustomFeaturePost {
|
||||||
|
post_id,
|
||||||
|
featured: true,
|
||||||
|
feature_type: location,
|
||||||
|
};
|
||||||
|
self.feature(pin_params).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_community_pinned(&self, community: CommunityId) -> Result<Vec<CustomPostView>, Box<dyn Error>> {
|
||||||
|
let list_params = GetPosts {
|
||||||
|
community_id: Some(community),
|
||||||
|
type_: Some(ListingType::Local),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let response = HTTP_CLIENT
|
||||||
|
.get(format!("{}/api/v3/post/list", &self.instance))
|
||||||
|
.bearer_auth(&self.jwt_token.to_string())
|
||||||
|
.query(&list_params)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let json_data: CustomGetPostsResponse = serde_json::from_str(&response)?;
|
||||||
|
|
||||||
|
Ok(json_data.posts.iter().filter(|post| {
|
||||||
|
post.post.featured_community
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
.collect()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_local_pinned(&self) -> Result<Vec<CustomPostView>, Box<dyn Error>> {
|
||||||
|
let list_params = GetPosts {
|
||||||
|
type_: Some(ListingType::Local),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let response = HTTP_CLIENT
|
||||||
|
.get(format!("{}/api/v3/post/list", &self.instance))
|
||||||
|
.bearer_auth(&self.jwt_token.to_string())
|
||||||
|
.query(&list_params)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let json_data: CustomGetPostsResponse = serde_json::from_str(&response)?;
|
||||||
|
|
||||||
|
Ok(json_data.posts.iter().filter(|post| {
|
||||||
|
post.post.featured_local
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
.collect()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_communities(&self) -> Result<HashMap<String, CommunityId>, Box<dyn Error>> {
|
||||||
|
let list_params = ListCommunities {
|
||||||
|
type_: Some(ListingType::Local),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let response = HTTP_CLIENT
|
||||||
|
.get(format!("{}/api/v3/community/list", &self.instance))
|
||||||
|
.bearer_auth(&self.jwt_token.to_string())
|
||||||
|
.query(&list_params)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let json_data: CustomListCommunitiesResponse = serde_json::from_str(&response)?;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(communities)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomCreatePost {
|
||||||
|
pub(crate) name: String,
|
||||||
|
pub(crate) community_id: CommunityId,
|
||||||
|
pub(crate) url: Option<Url>,
|
||||||
|
pub(crate) body: Option<String>,
|
||||||
|
pub(crate) honeypot: Option<String>,
|
||||||
|
pub(crate) nsfw: Option<bool>,
|
||||||
|
pub(crate) language_id: Option<LanguageId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomFeaturePost {
|
||||||
|
pub(crate) post_id: PostId,
|
||||||
|
pub(crate) featured: bool,
|
||||||
|
pub(crate) feature_type: PostFeatureType,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomListCommunitiesResponse {
|
||||||
|
pub(crate) communities: Vec<CustomCommunityView>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomCommunityView {
|
||||||
|
pub(crate) community: CustomCommunity,
|
||||||
|
pub(crate) subscribed: SubscribedType,
|
||||||
|
pub(crate) blocked: bool,
|
||||||
|
pub(crate) counts: CustomCommunityAggregates
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomCommunity {
|
||||||
|
pub(crate) actor_id: String,
|
||||||
|
pub(crate) banner: Option<String>,
|
||||||
|
pub(crate) deleted: bool,
|
||||||
|
pub(crate) description: Option<String>,
|
||||||
|
pub(crate) hidden: bool,
|
||||||
|
pub(crate) icon: Option<String>,
|
||||||
|
pub(crate) id: CommunityId,
|
||||||
|
pub(crate) instance_id: i32,
|
||||||
|
pub(crate) local: bool,
|
||||||
|
pub(crate) name: String,
|
||||||
|
pub(crate) nsfw: bool,
|
||||||
|
pub(crate) posting_restricted_to_mods: bool,
|
||||||
|
pub(crate) published: String,
|
||||||
|
pub(crate) removed: bool,
|
||||||
|
pub(crate) title: String,
|
||||||
|
pub(crate) updated: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomCommunityAggregates {
|
||||||
|
pub(crate) comments: i64,
|
||||||
|
pub(crate) community_id: i32,
|
||||||
|
pub(crate) posts: i64,
|
||||||
|
pub(crate) published: String,
|
||||||
|
pub(crate) subscribers: i64,
|
||||||
|
pub(crate) users_active_day: i64,
|
||||||
|
pub(crate) users_active_half_year: i64,
|
||||||
|
pub(crate) users_active_month: i64,
|
||||||
|
pub(crate) users_active_week: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomPostView {
|
||||||
|
pub(crate) community: CustomCommunity,
|
||||||
|
pub(crate) counts: CustomPostAggregates,
|
||||||
|
pub(crate) creator: CustomPerson,
|
||||||
|
pub(crate) creator_banned_from_community: bool,
|
||||||
|
pub(crate) creator_blocked: bool,
|
||||||
|
pub(crate) creator_is_admin: bool,
|
||||||
|
pub(crate) creator_is_moderator: bool,
|
||||||
|
pub(crate) my_vote: Option<i16>,
|
||||||
|
pub(crate) post: CustomPost,
|
||||||
|
pub(crate) read: bool,
|
||||||
|
pub(crate) saved: bool,
|
||||||
|
pub(crate) subscribed: SubscribedType,
|
||||||
|
pub(crate) unread_comments: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomPostAggregates {
|
||||||
|
pub(crate) comments: i64,
|
||||||
|
pub(crate) downvotes: i64,
|
||||||
|
pub(crate) post_id: PostId,
|
||||||
|
pub(crate) published: String,
|
||||||
|
pub(crate) score: i64,
|
||||||
|
pub(crate) upvotes: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomPerson {
|
||||||
|
pub(crate) actor_id: String,
|
||||||
|
pub(crate) avatar: Option<String>,
|
||||||
|
pub(crate) ban_expires: Option<String>,
|
||||||
|
pub(crate) banned: bool,
|
||||||
|
pub(crate) banner: Option<String>,
|
||||||
|
pub(crate) bio: Option<String>,
|
||||||
|
pub(crate) bot_account: bool,
|
||||||
|
pub(crate) deleted: bool,
|
||||||
|
pub(crate) display_name: Option<String>,
|
||||||
|
pub(crate) id: PersonId,
|
||||||
|
pub(crate) instance_id : InstanceId,
|
||||||
|
pub(crate) local: bool,
|
||||||
|
pub(crate) matrix_user_id: Option<String>,
|
||||||
|
pub(crate) name: String,
|
||||||
|
pub(crate) published: String,
|
||||||
|
pub(crate) updated: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomPost {
|
||||||
|
pub(crate) id: PostId,
|
||||||
|
pub(crate) name: String,
|
||||||
|
pub(crate) url: Option<String>,
|
||||||
|
pub(crate) body: Option<String>,
|
||||||
|
pub(crate) creator_id: PersonId,
|
||||||
|
pub(crate) community_id: CommunityId,
|
||||||
|
pub(crate) removed: bool,
|
||||||
|
pub(crate) locked: bool,
|
||||||
|
pub(crate) published: String,
|
||||||
|
pub(crate) updated: Option<String>,
|
||||||
|
pub(crate) deleted: bool,
|
||||||
|
pub(crate) nsfw: bool,
|
||||||
|
pub(crate) embed_title: Option<String>,
|
||||||
|
pub(crate) embed_description: Option<String>,
|
||||||
|
pub(crate) thumbnail_url: Option<String>,
|
||||||
|
pub(crate) ap_id: String,
|
||||||
|
pub(crate) local: bool,
|
||||||
|
pub(crate) embed_video_url: Option<String>,
|
||||||
|
pub(crate) language_id: LanguageId,
|
||||||
|
pub(crate) featured_community: bool,
|
||||||
|
pub(crate) featured_local: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub(crate) struct CustomGetPostsResponse {
|
||||||
|
pub(crate) posts: Vec<CustomPostView>,
|
||||||
|
}
|
104
src/main.rs
104
src/main.rs
|
@ -1,41 +1,93 @@
|
||||||
use chrono::{Duration};
|
use chrono::{DateTime, Duration, Utc};
|
||||||
use log::{LevelFilter};
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use reqwest::Client;
|
use reqwest::{Client};
|
||||||
use systemd_journal_logger::{JournalLog};
|
use std::{collections::HashMap, vec};
|
||||||
use crate::bot::Bot;
|
use std::fmt::Debug;
|
||||||
|
use std::sync::{Arc};
|
||||||
|
use tokio::sync::{RwLock};
|
||||||
|
use dotenv::dotenv;
|
||||||
|
use strum_macros::Display;
|
||||||
|
use tokio::time::sleep;
|
||||||
|
use crate::config::Config;
|
||||||
|
use crate::post_history::{SeriesHistory};
|
||||||
|
|
||||||
mod bot;
|
|
||||||
mod config;
|
mod config;
|
||||||
|
mod jnovel;
|
||||||
|
mod bot;
|
||||||
mod lemmy;
|
mod lemmy;
|
||||||
|
mod tui;
|
||||||
mod post_history;
|
mod post_history;
|
||||||
mod fetchers;
|
|
||||||
|
|
||||||
pub static HTTP_CLIENT: Lazy<Client> = Lazy::new(|| {
|
pub static HTTP_CLIENT: Lazy<Client> = Lazy::new(|| {
|
||||||
Client::builder()
|
Client::builder()
|
||||||
.timeout(Duration::seconds(10).to_std().unwrap())
|
.timeout(Duration::seconds(30).to_std().unwrap())
|
||||||
.connect_timeout(Duration::seconds(10).to_std().unwrap())
|
.connect_timeout(Duration::seconds(30).to_std().unwrap())
|
||||||
.build()
|
.build()
|
||||||
.expect("build client")
|
.expect("build client")
|
||||||
});
|
});
|
||||||
|
|
||||||
#[tokio::main]
|
#[derive(Clone, Debug)]
|
||||||
async fn main() {
|
pub(crate) struct SharedData {
|
||||||
JournalLog::new()
|
messages: Vec<Message>,
|
||||||
.expect("Systemd-Logger crate error")
|
config: Config,
|
||||||
.install()
|
post_history: SeriesHistory,
|
||||||
.expect("Systemd-Logger crate error");
|
start: DateTime<Utc>,
|
||||||
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();
|
impl SharedData {
|
||||||
bot.run().await;
|
pub(crate) fn new() -> Self {
|
||||||
|
SharedData {
|
||||||
|
messages: vec![],
|
||||||
|
config: Config {
|
||||||
|
instance: "".to_string(),
|
||||||
|
status_post_url: None,
|
||||||
|
config_reload_seconds: 0,
|
||||||
|
series: vec![],
|
||||||
|
},
|
||||||
|
post_history: SeriesHistory {
|
||||||
|
series: HashMap::new(),
|
||||||
|
},
|
||||||
|
start: Utc::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_messages(&self, errors: bool, warnings: bool, infos: bool) -> Vec<Message> {
|
||||||
|
self.messages.iter().filter(|msg| {
|
||||||
|
match msg {
|
||||||
|
Message::Error(_) => errors,
|
||||||
|
Message::Warning(_) => warnings,
|
||||||
|
Message::Info(_) => infos,
|
||||||
|
}
|
||||||
|
}).cloned().collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Display)]
|
||||||
|
pub(crate) enum Message {
|
||||||
|
Info(String),
|
||||||
|
Warning(String),
|
||||||
|
Error(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
dotenv().ok();
|
||||||
|
let mut data = SharedData::new();
|
||||||
|
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let write_data = Arc::new(RwLock::new(data.clone()));
|
||||||
|
let read_data = write_data.clone();
|
||||||
|
let persistent_data = write_data.clone();
|
||||||
|
|
||||||
|
let tui_thread = tokio::spawn(async move { tui::run(read_data).await });
|
||||||
|
let bot_thread = tokio::spawn(async move { bot::run(write_data).await });
|
||||||
|
|
||||||
|
let _ = bot_thread.await;
|
||||||
|
tui_thread.abort();
|
||||||
|
|
||||||
|
data = persistent_data.read().await.clone();
|
||||||
|
data.messages.push(Message::Error("Bot crashed due to unknown Error, restarting thread after wait...".to_string()));
|
||||||
|
sleep(Duration::seconds(5).to_std().expect("Conversion should always work since static")).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,101 +0,0 @@
|
||||||
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,
|
|
||||||
}
|
|
107
src/post_history/mod.rs
Normal file
107
src/post_history/mod.rs
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fs;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::Path;
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
|
pub(crate) struct SeriesHistory {
|
||||||
|
pub(crate) series: HashMap<String, PostHistory>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SeriesHistory {
|
||||||
|
pub(crate) fn load_history() -> Result<Self, Box<dyn Error>> {
|
||||||
|
match Path::new("history.toml").exists() {
|
||||||
|
true => {
|
||||||
|
let file_contents: String = fs::read_to_string("history.toml")?;
|
||||||
|
|
||||||
|
let history: Result<SeriesHistory, toml::de::Error> = match file_contents.len() {
|
||||||
|
0 => return Ok(SeriesHistory {
|
||||||
|
series: HashMap::new(),
|
||||||
|
}),
|
||||||
|
_ => toml::from_str(file_contents.as_str()),
|
||||||
|
};
|
||||||
|
|
||||||
|
match history {
|
||||||
|
Ok(data) => Ok(data),
|
||||||
|
Err(e) => Err(Box::new(e))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
false => {
|
||||||
|
Ok(SeriesHistory {
|
||||||
|
series: HashMap::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn save_history(&self) -> std::io::Result<usize> {
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.read(true)
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.open("history.toml")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let json_data = toml::to_string_pretty(&self).unwrap();
|
||||||
|
|
||||||
|
file.write(json_data.as_bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
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_string()).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_string(),
|
||||||
|
chapter: "".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn set_part(&mut self, part: &str, data: PostHistoryInner) {
|
||||||
|
self.parts.entry(part.to_string()).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,
|
||||||
|
}
|
88
src/tui/mod.rs
Normal file
88
src/tui/mod.rs
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
use std::ops::Deref;
|
||||||
|
use std::sync::{Arc};
|
||||||
|
use chrono::{Duration, Utc};
|
||||||
|
use tokio::sync::{RwLock, RwLockReadGuard};
|
||||||
|
use tokio::time::sleep;
|
||||||
|
use crate::{SharedData};
|
||||||
|
|
||||||
|
pub(crate) async fn run<'a>(shared_data: Arc<RwLock<SharedData>>) {
|
||||||
|
let mut min_len_series: u32 = 0;
|
||||||
|
let mut min_len_slug: u32 = 0;
|
||||||
|
println!("TUI restarted");
|
||||||
|
loop {
|
||||||
|
let snapshot_data = shared_data.read().await;
|
||||||
|
sleep(Duration::milliseconds(250).to_std().unwrap()).await;
|
||||||
|
print_info(snapshot_data, &mut min_len_series, &mut min_len_slug).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn print_info<'a>(data: RwLockReadGuard<'a, SharedData>, min_len_series: &mut u32, min_len_slug: &mut u32) {
|
||||||
|
let mut local_min_len_series = *min_len_series.deref() as usize;
|
||||||
|
let mut local_min_len_slug = *min_len_slug.deref() as usize;
|
||||||
|
let separator_width = local_min_len_slug + local_min_len_series + 44; // 44 should account for length of every other string
|
||||||
|
|
||||||
|
print!("\x1B[2J\x1B[1;1H");
|
||||||
|
println!(
|
||||||
|
"##[Ascendance of a Bookworm Bot]## | Time: {}",
|
||||||
|
Utc::now().naive_local().format("%H:%M:%S")
|
||||||
|
);
|
||||||
|
println!("Instance: {}", data.config.instance);
|
||||||
|
println!(
|
||||||
|
"Ran Last: {}",
|
||||||
|
data
|
||||||
|
.start
|
||||||
|
.naive_local()
|
||||||
|
.format("%d/%m/%Y %H:%M:%S")
|
||||||
|
);
|
||||||
|
println!("{:#<1$}", "", separator_width);
|
||||||
|
data.post_history.series.iter().for_each(|(series, post_history)| {
|
||||||
|
|
||||||
|
if series.len() > local_min_len_series {
|
||||||
|
local_min_len_series = series.len() + 1;
|
||||||
|
*min_len_series = local_min_len_series as u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
let series_config = data.config.series
|
||||||
|
.iter()
|
||||||
|
.find(|ser| {&ser.slug == series})
|
||||||
|
.expect("Config should not parse without this");
|
||||||
|
post_history.parts.iter().for_each(|(part, part_history)| {
|
||||||
|
|
||||||
|
if part_history.volume.len() > local_min_len_slug {
|
||||||
|
local_min_len_slug = part_history.chapter.len() + 1;
|
||||||
|
*min_len_slug = local_min_len_slug as u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
print!("{series}");
|
||||||
|
print!("{:<1$}| ", "", local_min_len_series - series.len());
|
||||||
|
print!("Part {part}");
|
||||||
|
print!("{:<1$}| Volume | ", "", 2-part.len());
|
||||||
|
print!("{}", part_history.volume);
|
||||||
|
print!("{:<1$}| ", "", local_min_len_slug - part_history.volume.len());
|
||||||
|
print!("{}", series_config.volume_community.name);
|
||||||
|
println!("{:<1$}|", "", 20 - series_config.volume_community.name.len());
|
||||||
|
|
||||||
|
if part_history.chapter.len() > local_min_len_slug {
|
||||||
|
local_min_len_slug = part_history.chapter.len() + 1;
|
||||||
|
*min_len_slug = local_min_len_slug as u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
print!("{series}");
|
||||||
|
print!("{:<1$}| ", "", local_min_len_series - series.len());
|
||||||
|
print!("Part {part}");
|
||||||
|
print!("{:<1$}| Chapter | ", "", 2-part.len());
|
||||||
|
print!("{}", part_history.chapter);
|
||||||
|
print!("{:<1$}| ", "", local_min_len_slug - part_history.chapter.len());
|
||||||
|
print!("{}", series_config.prepub_community.name);
|
||||||
|
println!("{:<1$}|", "", 20 - series_config.prepub_community.name.len());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
println!("{:#<1$}", "", separator_width);
|
||||||
|
for error in data.get_messages(true, true, false).iter() {
|
||||||
|
println!("{}", error);
|
||||||
|
}
|
||||||
|
println!("{:#<1$}", "", separator_width);
|
||||||
|
for message in data.get_messages(false, false, false).iter() {
|
||||||
|
println!("{}", message);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue