Compare commits

...

133 Commits

Author SHA1 Message Date
Sheldan
ce6a2da5d1 [OPB-xxx] updating docker compose file version 2024-03-27 00:31:02 +01:00
release-bot
0220254c84 [maven-release-plugin] prepare for next development iteration 2024-03-26 23:17:42 +00:00
release-bot
e369802bda [maven-release-plugin] prepare release oneplusbot-1.6.23 2024-03-26 23:17:40 +00:00
Sheldan
718445bbd6 [OPB-xxx] upgrading abstracto version
enabling experience leaderboard dashboard deployment
2024-03-27 00:13:23 +01:00
release-bot
6b777c9f20 Commit from GitHub Actions (Publishes a new version of OnePlusBot) 2024-03-17 12:56:15 +00:00
release-bot
d254f111b4 [maven-release-plugin] prepare for next development iteration 2024-03-17 12:52:21 +00:00
release-bot
fef4b0ad01 [maven-release-plugin] prepare release oneplusbot-1.6.22 2024-03-17 12:52:19 +00:00
Sheldan
ac93e11a47 [OPB-xxx] remove not accurate technology section 2024-03-17 13:49:31 +01:00
Sheldan
5bfe4a4aeb [OPB-xxx] upgrading abstracto version 2024-03-17 13:22:36 +01:00
Sheldan
216c578e08 [OPB-xxx] restructuring to use local postgres container for dev purposes
adding debug options to local dev version
removing deprecated flag from tilt file
2024-03-17 13:22:05 +01:00
release-bot
568cc85907 Commit from GitHub Actions (Publishes a new version of OnePlusBot) 2024-03-06 22:04:45 +00:00
release-bot
b19b3a9840 [maven-release-plugin] prepare for next development iteration 2024-03-06 21:59:09 +00:00
release-bot
54359e513e [maven-release-plugin] prepare release oneplusbot-1.6.21 2024-03-06 21:59:07 +00:00
Sheldan
65a86d2a52 [OPB-xxx] updating abstracto version to 1.5.26 2024-03-06 22:53:27 +01:00
release-bot
704d18e2f6 Commit from GitHub Actions (Publishes a new version of OnePlusBot) 2024-02-19 00:51:52 +00:00
release-bot
82d889019c [maven-release-plugin] prepare for next development iteration 2024-02-19 00:47:28 +00:00
release-bot
921789cd0b [maven-release-plugin] prepare release oneplusbot-1.6.20 2024-02-19 00:47:26 +00:00
Sheldan
716e65eeae [OPB-xxx] adding creation of release to release job
removing old release job
2024-02-19 01:44:20 +01:00
Sheldan
66fb06b594 [OPB-xxx] upating abstracto version
removing not needed dbchangelog.xsd files
2024-02-19 01:42:41 +01:00
release-bot
3ff8fed7fd Commit from GitHub Actions (Publishes a new version of OnePlusBot) 2024-02-09 22:42:28 +00:00
release-bot
c07aa25b92 [maven-release-plugin] prepare for next development iteration 2024-02-09 22:38:23 +00:00
release-bot
69b2cb38b3 [maven-release-plugin] prepare release oneplusbot-1.6.19 2024-02-09 22:38:22 +00:00
Sheldan
c82d975299 [OPB-xxx] updating abstracto version 2024-02-09 23:29:15 +01:00
release-bot
590b6e88f8 Commit from GitHub Actions (Publishes a new version of OnePlusBot) 2024-02-03 20:08:57 +00:00
release-bot
952af32bdb [maven-release-plugin] prepare for next development iteration 2024-02-03 20:03:36 +00:00
release-bot
24a6b6159a [maven-release-plugin] prepare release oneplusbot-1.6.18 2024-02-03 20:03:34 +00:00
Sheldan
1a81c27790 [OPB-xxx] removing app version from chart 2024-02-03 21:00:11 +01:00
Sheldan
37492335a4 [OPB-xxx] adding missed version to update in release job 2024-02-03 20:59:27 +01:00
Sheldan
2826ffdcad [OPB-xxx] adding *.tgz to gitignore 2024-02-03 20:58:24 +01:00
release-bot
b5a5061bb4 Commit from GitHub Actions (Publishes a new version of OnePlusBot) 2024-02-03 19:56:48 +00:00
release-bot
6ef01eb88b [maven-release-plugin] prepare for next development iteration 2024-02-03 19:52:47 +00:00
release-bot
7e6b99cf48 [maven-release-plugin] prepare release oneplusbot-1.6.17 2024-02-03 19:52:46 +00:00
Sheldan
af4d43192f [OPB-xxx] updating abstracto version 2024-02-03 20:48:58 +01:00
Sheldan
622b05430f [OPB-xxx] adding manual release pipeline
updating abstracto version
2024-02-03 20:47:33 +01:00
Sheldan
8736a9fe3f [maven-release-plugin] prepare for next development iteration 2023-12-29 00:50:45 +01:00
Sheldan
f92ef50fcf [maven-release-plugin] prepare release oneplusbot-1.6.16 2023-12-29 00:50:41 +01:00
Sheldan
656ca113f3 [OPB-xxx] updating abstracto version and preparing for release 2023-12-29 00:28:05 +01:00
Sheldan
4bb2d2ca5e [maven-release-plugin] prepare for next development iteration 2023-12-28 22:56:55 +01:00
Sheldan
47957d10e9 [maven-release-plugin] prepare release oneplusbot-1.6.15 2023-12-28 22:56:52 +01:00
Sheldan
19f2c885e4 [OPB-xxx] updating abstracto version and preparing for release 2023-12-28 22:46:37 +01:00
Sheldan
591e8f1586 [maven-release-plugin] prepare for next development iteration 2023-12-27 11:22:21 +01:00
Sheldan
36ac023eea [maven-release-plugin] prepare release oneplusbot-1.6.14 2023-12-27 11:22:17 +01:00
Sheldan
be13313000 [OPB-xxx] updating abstracto version and preparing for release 2023-12-27 11:20:31 +01:00
Sheldan
b6180614ff [maven-release-plugin] prepare for next development iteration 2023-12-25 19:05:57 +01:00
Sheldan
e4434fcb25 [maven-release-plugin] prepare release oneplusbot-1.6.13 2023-12-25 19:05:52 +01:00
Sheldan
b3bbd20da0 [OPB-xxx] preparing for release 2023-12-25 19:05:11 +01:00
Sheldan
fe50e1331b [OPB-xxx] updating abstracto version
enabling giveaway and image generation feature
2023-12-25 19:04:22 +01:00
Sheldan
e77c448824 [maven-release-plugin] prepare for next development iteration 2023-11-14 23:23:48 +01:00
Sheldan
8cc2ed5e96 [maven-release-plugin] prepare release oneplusbot-1.6.12 2023-11-14 23:23:43 +01:00
Sheldan
aaf4afe92e [OPB-xxx] preparing for release 2023-11-14 23:23:05 +01:00
Sheldan
17e24b14f4 [OPB-xxx] enabling to configure database pool sizes externally 2023-11-14 23:22:13 +01:00
Sheldan
ae88377d30 [maven-release-plugin] prepare for next development iteration 2023-11-08 21:26:14 +01:00
Sheldan
4e645885f3 [maven-release-plugin] prepare release oneplusbot-1.6.11 2023-11-08 21:26:09 +01:00
Sheldan
77bb7b043b [OPB-3] adding daily job to check for new news posts
updating to abstracto 1.5.12
preparing for release
2023-11-08 21:25:09 +01:00
Sheldan
9f8d4ebcc8 [maven-release-plugin] prepare for next development iteration 2023-09-26 23:21:45 +02:00
Sheldan
021d07bf47 [maven-release-plugin] prepare release oneplusbot-1.6.10 2023-09-26 23:21:41 +02:00
Sheldan
0a7eda239f [OPB-xxx] removing discriminators 2023-09-26 23:19:55 +02:00
Sheldan
a8587d29af [OPB-xxx] prepare for release 2023-09-26 23:19:07 +02:00
Sheldan
e38f5c8382 [OPB-xxx] fixing app name in log dashboard 2023-09-23 22:05:31 +02:00
Sheldan
3ab491b5f3 [maven-release-plugin] prepare for next development iteration 2023-09-23 21:36:02 +02:00
Sheldan
ed85b1955f [maven-release-plugin] prepare release oneplusbot-1.6.9 2023-09-23 21:35:57 +02:00
Sheldan
f83042c84f [OPB-xxx] updating versions 2023-09-23 21:35:31 +02:00
Sheldan
b11b49e5c4 [OPB-xxx] fixing globally unique ids for grafana dashbaords 2023-09-23 21:34:44 +02:00
Sheldan
9d1382019f [maven-release-plugin] prepare for next development iteration 2023-09-23 19:17:30 +02:00
Sheldan
6e25ac91cb [maven-release-plugin] prepare release oneplusbot-1.6.8 2023-09-23 19:17:26 +02:00
Sheldan
44e3f8656c [OPB-xxx] fixing chart and image name to not be the same 2023-09-23 19:16:40 +02:00
Sheldan
c8a6f67af5 [maven-release-plugin] prepare for next development iteration 2023-09-23 18:27:28 +02:00
Sheldan
a39942beef [maven-release-plugin] prepare release oneplusbot-1.6.7 2023-09-23 18:27:23 +02:00
Sheldan
ca36645197 [OPB-xxx] fixing release job
updating version
2023-09-23 18:22:24 +02:00
Sheldan
e177b5f559 [maven-release-plugin] prepare for next development iteration 2023-09-23 18:16:15 +02:00
Sheldan
9f11ec5ffa [maven-release-plugin] prepare release oneplusbot-1.6.6 2023-09-23 18:16:11 +02:00
Sheldan
5378a4038b [OPB-xxx] adding configuration and changing structure for k8s deployment 2023-09-23 18:02:39 +02:00
Sheldan
d448dfbf9b [OPB-xxx] adding missing parameters for docker compose deployment 2023-07-10 00:57:13 +02:00
Sheldan
f0b548a97e [maven-release-plugin] prepare for next development iteration 2023-02-15 00:56:36 +01:00
Sheldan
b0c2c24dce [maven-release-plugin] prepare release oneplusbot-1.6.5 2023-02-15 00:56:27 +01:00
Sheldan
658683c013 [OPB-xxx] prepare for release 2023-02-15 00:55:04 +01:00
Sheldan
8c8cadefdd [maven-release-plugin] prepare for next development iteration 2023-02-04 20:47:40 +01:00
Sheldan
8e9a7004a2 [maven-release-plugin] prepare release oneplusbot-1.6.4 2023-02-04 20:47:36 +01:00
Sheldan
29fb53fb7a [OPB-xxx] prepare for release 2023-02-04 20:45:26 +01:00
Sheldan
6d23fffc77 [maven-release-plugin] prepare for next development iteration 2022-12-21 19:08:01 +01:00
Sheldan
d816a8a48c [maven-release-plugin] prepare release oneplusbot-1.6.3 2022-12-21 19:07:56 +01:00
Sheldan
386011d2e9 [OPB-xxx] updating abstracto version
preparing for release
2022-12-21 19:03:59 +01:00
Sheldan
015609f9d2 [maven-release-plugin] prepare for next development iteration 2022-10-16 13:50:44 +02:00
Sheldan
35a6f0aeeb [maven-release-plugin] prepare release oneplusbot-1.6.2 2022-10-16 13:50:40 +02:00
Sheldan
743195b137 [OPB-xxx] updating to new version of abstracto
preparing for release
2022-10-16 13:46:02 +02:00
Sheldan
9f35781f2d [OPB-xxx] upgrading to new JDA alpha 2022-09-18 15:54:04 +02:00
Sheldan
dbf131abfe [maven-release-plugin] prepare for next development iteration 2022-08-29 00:28:20 +02:00
Sheldan
05dbb1fc2f [maven-release-plugin] prepare release oneplusbot-1.6.1 2022-08-29 00:28:16 +02:00
Sheldan
47284686d6 [OPB-xxx] updating abstracto version to 1.4.3 2022-08-29 00:26:02 +02:00
Sheldan
46ef5435c7 [maven-release-plugin] prepare for next development iteration 2022-08-01 23:32:38 +02:00
Sheldan
bcfaf1c928 [maven-release-plugin] prepare release oneplusbot-1.6.0 2022-08-01 23:32:34 +02:00
Sheldan
124d45ba5b Merge branch 'master' into feature/JDA-5
# Conflicts:
#	pom.xml
2022-08-01 23:27:48 +02:00
Sheldan
4cdaf87412 [OPB-xxx] updating versions and classes 2022-08-01 23:26:50 +02:00
Sheldan
13cf06e1dc [OPB-xxx] preparing new release 2022-08-01 21:41:37 +02:00
Sheldan
e8ae0f430d [OPB-xxx] preparing new release 2022-08-01 21:39:25 +02:00
Sheldan
cda9d1a2b8 [OPB-xxx] updating terraform module version 2022-07-14 20:02:39 +02:00
Sheldan
653246f3ee [OPB-xxx] adding terraform config 2022-07-14 01:59:45 +02:00
Sheldan
0879c7cc93 [OPB-xxx] creating issue templates 2022-05-31 00:22:13 +02:00
Sheldan
4ea878dd42 [maven-release-plugin] prepare for next development iteration 2022-04-07 23:25:07 +02:00
Sheldan
562f5ae9e1 [maven-release-plugin] prepare release oneplusbot-1.5.10 2022-04-07 23:25:03 +02:00
Sheldan
92925d176f Updating to new Abstracto version 1.3.12 2022-04-07 23:12:02 +02:00
Sheldan
6a5f45c416 [maven-release-plugin] prepare for next development iteration 2021-12-24 14:25:23 +01:00
Sheldan
c7e8fd315f [maven-release-plugin] prepare release oneplusbot-1.5.9 2021-12-24 14:25:19 +01:00
Sheldan
95ad8fdd3a [OPB-xxx] preparing for release 2021-12-24 13:53:01 +01:00
Sheldan
51775b454e [OPB-41] adding seasonal lights effect 2021-12-23 23:44:45 +01:00
Sheldan
aa4de8f571 [OPB-42] aligning templates with new multi embed support 2021-12-08 16:40:35 +01:00
Sheldan
eae07fd07c [maven-release-plugin] prepare for next development iteration 2021-10-26 00:07:29 +02:00
Sheldan
c492640cd7 [maven-release-plugin] prepare release oneplusbot-1.5.8 2021-10-26 00:07:23 +02:00
Sheldan
2c49cf2918 [OPB-40] adding warning threshold notification
restructured template module structure and naming
2021-10-25 00:15:51 +02:00
Sheldan
60ac314ecc [OPB-39] fixing faq export not properly exporting image only embeds
fixing requiring alias values if the key is present
2021-09-28 21:26:28 +02:00
Sheldan
c82ef9ac18 Merge pull request #1 from AnonymousWP/master
Fixed typo in the help output of `updateNews`
2021-09-18 14:55:42 +02:00
AnonymousWP
6369ae7c01 Fixed typo in the help output of updateNews 2021-09-18 14:50:17 +02:00
Sheldan
f9b2174f84 [maven-release-plugin] prepare for next development iteration 2021-09-06 02:21:16 +02:00
Sheldan
d5c8509ab0 [maven-release-plugin] prepare release oneplusbot-1.5.7 2021-09-06 02:21:12 +02:00
Sheldan
eaddea63b3 [OPB-xxx] preparing for release 2021-09-06 02:15:38 +02:00
Sheldan
7dc141a8a4 [OPB-xxx] adding logging dashboard to grafana 2021-09-06 01:34:23 +02:00
Sheldan
6652c90edb [OPB-37] fixing loki data source in docker compose config 2021-08-22 19:09:28 +02:00
Sheldan
d7f5fc21d6 [OPB-38] fixing json validation 2021-08-22 18:39:41 +02:00
Sheldan
bf98d5db3a [maven-release-plugin] prepare for next development iteration 2021-08-10 00:21:38 +02:00
Sheldan
57fb34920d [maven-release-plugin] prepare release oneplusbot-1.5.6 2021-08-10 00:21:31 +02:00
Sheldan
3f959f3bbb [OPB-37] adding loki log collector
upgrading to newer abstracto version
adding some info to readme
2021-08-09 23:42:23 +02:00
Sheldan
0380720ec8 [maven-release-plugin] prepare for next development iteration 2021-07-26 02:08:06 +02:00
Sheldan
5bea74cb22 [maven-release-plugin] prepare release oneplusbot-1.5.5 2021-07-26 02:07:58 +02:00
Sheldan
1b970ba0a8 [OPB-xxx] updating to hotfix and preparing for release 2021-07-26 01:46:13 +02:00
Sheldan
a707b10cfd [maven-release-plugin] prepare for next development iteration 2021-07-25 20:58:31 +02:00
Sheldan
124d29769e [maven-release-plugin] prepare release oneplusbot-1.5.4 2021-07-25 20:58:23 +02:00
Sheldan
d1aa2d5276 [OPB-xxx] preparing for release 2021-07-25 20:37:33 +02:00
Sheldan
4d569d4ec0 [OPB-32] fixing always exporting user ID in faq config when in reality it was bot ID
sorting faq commands and channel groups in export response alphabetically
2021-07-25 16:31:27 +02:00
Sheldan
81e58c3f7b [OPB-36] adding oneplus bot stats dashboard
restructuring oneplus bot status dashboard to include jda events and remove less relevant metrics
2021-07-25 15:25:30 +02:00
Sheldan
c04041cb35 [maven-release-plugin] prepare for next development iteration 2021-07-21 23:59:17 +02:00
Sheldan
37e566a957 [maven-release-plugin] prepare release oneplusbot-1.5.3 2021-07-21 23:59:09 +02:00
Sheldan
f7ca31a0c8 [OPB-xxx] update to newer abstracto version 2021-07-21 23:51:30 +02:00
Sheldan
8da31831b0 [maven-release-plugin] prepare for next development iteration 2021-07-14 02:40:28 +02:00
403 changed files with 4705 additions and 14052 deletions

4
.env Normal file
View File

@@ -0,0 +1,4 @@
REGISTRY_PREFIX=harbor.sheldan.dev/oneplus-bot/
ABSTRACTO_PREFIX=harbor.sheldan.dev/abstracto/
VERSION=1.6.22
ABSTRACTO_VERSION=1.5.32

42
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@@ -0,0 +1,42 @@
name: Bug Report
description: Found a bug that needs fixing?
body:
- type: checkboxes
attributes:
label: General Troubleshooting
description: You confirm to have made the following checks first.
options:
- label: I have checked for similar issues on the Issue-tracker.
required: true
- label: I have updated to the latest version
required: true
- label: I have checked the branches or the maintainers' PRs for upcoming bug fixes.
required: true
- type: textarea
attributes:
label: "Description"
description: "General information about the bug"
placeholder: "..."
validations:
required: true
- type: textarea
attributes:
label: "Steps to reproduce"
description: "What happened when the bug occurred?"
placeholder: "1. ..."
validations:
required: true
- type: textarea
attributes:
label: "Expected behaviour"
description: "What should happen?"
placeholder: "It should..."
validations:
required: true
- type: textarea
attributes:
label: "Actual behaviour"
description: "What did happen instead?"
placeholder: "It actually ..."
validations:
required: true

36
.github/ISSUE_TEMPLATE/feature.yml vendored Normal file
View File

@@ -0,0 +1,36 @@
name: Feature request
description: Want some functionality added?
body:
- type: checkboxes
attributes:
label: General Information
description: You confirm to have made the following checks first.
options:
- label: I have checked for similar issues on the Issue-tracker.
required: true
- label: I have updated to the latest version
required: true
- label: I have checked the branches or the maintainers' PRs for upcoming features fixes.
required: true
- type: textarea
attributes:
label: "Description"
description: "General description of the feature"
placeholder: "..."
validations:
required: true
- type: textarea
attributes:
label: "Feature worth and general use"
description: "Why should this exist?"
placeholder: "..."
validations:
required: true
- type: textarea
attributes:
label: "Suggestions for implementation"
description: "Any ideas about what the feature should behave/look like? Commands?"
placeholder: "It should..."
validations:
required: false

View File

@@ -17,11 +17,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
- uses: actions/checkout@v3
with:
java-version: 1.8
persist-credentials: false
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 17
- name: Build with Maven
run: mvn -s settings.xml -B install --file pom.xml
env:

View File

@@ -1,38 +0,0 @@
name: Publish package to GitHub Packages
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- name: Set up Java for publishing to GitHub Packages
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Load current version
id: version
run: echo "version=$(mvn -s settings.xml --file pom.xml -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_ENV
- name: Publish to GitHub Packages
run: mvn -s settings.xml --file pom.xml -B deploy -Dmaven.wagon.http.pool=false -DskipTests=true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
user: Sheldan
token: ${{ secrets.ABSTRACTO_PAT }}
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v1
with:
registry: docker.pkg.github.com
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push deployment container
working-directory: ./deployment/image-packaging/src/main/docker
run: docker-compose build && docker-compose push
env:
REGISTRY_PREFIX: docker.pkg.github.com/sheldan/oneplusbot/
VERSION: ${{ env.version }}
ABSTRACTO_VERSION: 1.3.3
ABSTRACTO_REGISTRY_PREFIX: docker.pkg.github.com/sheldan/abstracto/

91
.github/workflows/release_manual.yaml vendored Normal file
View File

@@ -0,0 +1,91 @@
name: Publishes a new version of OnePlusBot
on: workflow_dispatch
permissions:
packages: write
contents: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: master
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 17
- name: Load current version
id: version
run: echo "version=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec | cut -d- -f1)" >> $GITHUB_ENV
- name: Create a Release
uses: elgohr/Github-Release-Action@v5
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
title: Release of version ${{ env.version }}
- name: Release maven packages
uses: qcastel/github-actions-maven-release@v1.12.41
env:
JAVA_HOME: /usr/lib/jvm/java-17-openjdk/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
abstractoUser: Sheldan
abstractoToken: ${{ secrets.ABSTRACTO_PAT }}
with:
git-release-bot-name: "release-bot"
git-release-bot-email: "release-bot@sheldan.dev"
release-branch-name: master
maven-args: "-Dmaven.javadoc.skip=true -s settings.xml -DskipTests"
access-token: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Harbor
uses: docker/login-action@v2
with:
registry: harbor.sheldan.dev
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_TOKEN }}
- name: Update Chart version file
uses: fjogeleit/yaml-update-action@v0.13.2
with:
valueFile: 'deployment/helm/oneplus-bot/Chart.yaml'
propertyPath: 'version'
value: ${{ env.version }}
commitChange: false
- name: Update value files version
uses: fjogeleit/yaml-update-action@v0.13.2
with:
valueFile: 'deployment/helm/oneplus-bot/values.yaml'
commitChange: false
changes: |
{
"bot.tag": "${{ env.version }}",
"templateDeploymentData.tag": "${{ env.version }}",
"dbConfigDeploymentData.tag": "${{ env.version }}",
"privateRestApi.tag": "${{ env.version }}"
}
- name: Update .env version
run:
sed -i '3s/.*/VERSION=${{ env.version }}/' .env
- name: Load env file
id: dotenv
uses: falti/dotenv-action@v1.0.4
with:
path: .env
- name: Build and push Docker containers
run: docker-compose build && docker-compose push
env:
REGISTRY_PREFIX: ${{ steps.dotenv.outputs.registry_prefix }}
VERSION: ${{ steps.dotenv.outputs.version }}
- name: Helm package and push
working-directory: ./deployment/helm/
run: |-
helm registry login -u '${{ secrets.HARBOR_USERNAME }}' -p '${{ secrets.HARBOR_TOKEN }}' harbor.sheldan.dev
helm package oneplus-bot
helm push oneplus-bot*.tgz oci://harbor.sheldan.dev/oneplus-bot
- name: Fix file permissions
run:
sudo chmod -R ugo+rwX . # https://github.com/actions/checkout/issues/164
- name: Commit updated versions
uses: EndBug/add-and-commit@v9
with:
author_name: "release-bot"
author_email: "release-bot@sheldan.dev"

3
.gitignore vendored
View File

@@ -20,6 +20,9 @@ target/
*.zip
*.tar.gz
*.rar
*.tgz
Chart.lock
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

3
.tiltignore Normal file
View File

@@ -0,0 +1,3 @@
*.tgz
tilt/oneplusbot-dev/tmpcharts/
tilt/oneplusbot-dev/charts/*.tgz

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 Sheldan
Copyright (c) 2022 Sheldan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,6 +1,6 @@
# r/oneplus Discord bot privacy policy
Last updated: 04.07.2021
Last updated: 06.09.2021
## Description
@@ -75,6 +75,7 @@ The detailed list of what information is stored and processed is the following:
* this was used for the message used to update the status of a suggestion, but this is currently disabled
* the author of the suggestion and the message which has been posted in the suggestions channel
* every suggestion will be deleted completely from the database a few days after it has reached a final state (rejected, denied, accepted)
* whether you voted for a suggestion and which decision you took
### Leveling system
* the amount of messages which were considered for the leveling system

View File

@@ -1,11 +1,13 @@
# r/oneplus Discord server bot
This repository contains the rewrite of the [Bot](https://github.com/Rithari/OnePlusBot), which is still in use. The features will be gradually be ported
and most of them will be in [abstracto](https://github.com/Sheldan/abstracto), but some of the features need to be customized, as they are r/oneplus specific.
This repository contains the rewrite of the [Bot](https://github.com/Rithari/OnePlusBot). It is developed by customizing [abstracto](https://github.com/Sheldan/abstracto), because some features are r/oneplus specific.
The migration of the existing data from the database is handled via one time migration, and can be found [here](https://github.com/Sheldan/OnePlusBot-migration).
The FAQ configuration can be found [here](https://github.com/Sheldan/OnePlusBot-faq/).
Custom features which were ported
- [x] FAQ
- [x] Setup channel handling
- [x] Referral link handling

44
Tiltfile Normal file
View File

@@ -0,0 +1,44 @@
allow_k8s_contexts('k8s-cluster')
load('ext://restart_process', 'docker_build_with_restart')
registry = 'harbor.sheldan.dev/oneplus-bot/'
abstracto_registry = 'harbor.sheldan.dev/abstracto/'
local_resource(
'oneplus-bot-java-compile',
'mvn install && ' +
'rm -rf application/executable/target/jar-staging && ' +
'unzip -o application/executable/target/oneplus-bot-exec.jar -d application/executable/target/jar-staging && ' +
'rsync --delete --inplace --checksum -r application/executable/target/jar-staging/ application/executable/target/jar && ' +
'mkdir application/executable/target/jar/snapshots && ' +
'rsync --delete --inplace --checksum -r application/executable/target/jar/BOOT-INF/lib/*-SNAPSHOT.jar application/executable/target/jar/snapshots && ' +
'rm -f application/executable/target/jar/BOOT-INF/lib/*-SNAPSHOT.jar ',
deps=['pom.xml'])
docker_build_with_restart(
registry + 'oneplus-bot-image',
'./application/executable/target/jar',
entrypoint=['java', '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005', '-cp', '.:./lib/*', 'dev.sheldan.oneplus.bot.executable.Application'],
dockerfile='./application/executable/Dockerfile',
live_update=[
sync('./application/executable/target/jar/BOOT-INF/lib', '/app/lib'),
sync('./application/executable/target/jar/META-INF', '/app/META-INF'),
sync('./application/executable/target/jar/BOOT-INF/classes', '/app'),
sync('./application/executable/target/jar/snapshots', '/app/lib')
],
)
docker_build(registry + 'oneplus-bot-db-data', 'deployment/image-packaging/src/main/docker/db-data/')
docker_build(registry + 'oneplus-bot-template-data', 'deployment/image-packaging/src/main/docker/template-data/')
docker_build(registry + 'oneplus-bot-private-rest-api', 'deployment/image-packaging/src/main/docker/private-rest-api/', build_args={'REGISTRY_PREFIX': abstracto_registry})
docker_build(registry + 'oneplus-bot-rest-api', 'deployment/image-packaging/src/main/docker/rest-api/', build_args={'REGISTRY_PREFIX': abstracto_registry})
local('cd tilt/oneplusbot-dev && helm dep up')
k8s_yaml(helm('tilt/oneplusbot-dev', values=
['./../OnePlusBot-environments/argocd/apps/oneplus-bot/values/local/values.yaml',
'secrets://./../OnePlusBot-environments/argocd/apps/oneplus-bot/values/local/values.secrets.yaml']
))
local_resource('fetch-packages', 'mvn install -f deployment/image-packaging/pom.xml', auto_init=False, trigger_mode = TRIGGER_MODE_MANUAL)
k8s_resource('chart-oneplus-bot', port_forwards='5005:5005')

View File

@@ -0,0 +1,10 @@
FROM amazoncorretto:17.0.8-alpine3.18
RUN apk add entr
WORKDIR /app
ADD BOOT-INF/lib/ /app/lib
ADD snapshots/ /app/lib
ADD META-INF /app/META-INF
ADD BOOT-INF/classes /app
ENTRYPOINT java -cp .:./lib/* dev.sheldan.oneplus.bot.executable.Application

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.oneplus.bot.application</groupId>
<artifactId>application</artifactId>
<version>1.5.2</version>
<version>1.6.24-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>executable</artifactId>
@@ -14,6 +14,7 @@
</properties>
<build>
<finalName>oneplus-bot</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
@@ -150,6 +151,16 @@
<artifactId>experience-tracking-impl</artifactId>
</dependency>
<dependency>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>giveaway-impl</artifactId>
</dependency>
<dependency>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>image-generation-impl</artifactId>
</dependency>
<dependency>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>moderation-impl</artifactId>
@@ -191,6 +202,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
<artifactId>seasonal</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,18 @@
package dev.sheldan.oneplus.bot.executable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((authorize) -> authorize
.anyRequest().permitAll());
return http.build();
}
}

View File

@@ -1,21 +0,0 @@
spring.datasource.url=jdbc:postgresql://localhost:5432/abstracto
spring.datasource.username= abstracto
spring.datasource.password= abstracto
spring.jpa.properties.hibernate.default_schema=abstracto
spring.quartz.jdbc.initialize-schema=never
spring.jpa.hibernate.ddl-auto = none
spring.jpa.show-sql = false
spring.jpa.properties.hibernate.format_sql = true
log4j.logger.org.hibernate.SQL=trace
log4j.logger.org.hibernate.type.descriptor.sql=trace
log4j.logger.org.hibernate.type=trace
management.metrics.tags.application=oneplus-bot
spring.security.user.name=abstracto
spring.security.user.password=password
spring.security.user.roles=USER
spring.application.name=OnePlusBot

View File

@@ -1,11 +1,14 @@
spring.datasource.url=jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
spring.datasource.username= ${DB_USER}
spring.datasource.password= ${DB_PASS}
spring.jpa.hibernate.default_schema=${DB_NAME}
spring.datasource.hikari.maximum-pool-size=${hikariPoolSize}
spring.jpa.hibernate.default_schema=${DB_SCHEMA}
spring.jpa.properties.hibernate.default_schema=${DB_SCHEMA}
spring.quartz.jdbc.initialize-schema=never
management.metrics.tags.application=oneplus-bot
spring.security.user.name= ${REST_USER_NAME}
spring.security.user.password= ${REST_PASSWORD}
spring.security.user.roles=USER
management.metrics.tags.application=OnePlusBot
management.endpoint.health.probes.enabled=true
management.health.livenessState.enabled=true
management.health.readinessState.enabled=true
spring.application.name=OnePlusBot
spring.application.name=OnePlusBot
spring.main.allow-circular-references=true

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.oneplus.bot.application.custom</groupId>
<artifactId>oneplus-bot-customizations</artifactId>
<version>1.5.2</version>
<version>1.6.24-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="seedData/data.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="dynamic_activity-insertion">
<insert tableName="activity">
<column name="type" value="STREAMING"/>

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="activity.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="1.5.1/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>oneplus-bot-customizations</artifactId>
<groupId>dev.sheldan.oneplus.bot.application.custom</groupId>
<version>1.5.2</version>
<version>1.6.24-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -2,6 +2,7 @@ package dev.sheldan.oneplus.bot.custom.moderation.config;
import dev.sheldan.abstracto.core.config.FeatureConfig;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.config.PostTargetEnum;
import dev.sheldan.abstracto.moderation.config.feature.ModerationFeatureConfig;
import dev.sheldan.oneplus.bot.custom.moderation.service.ModModeServiceBean;
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,6 +15,8 @@ import java.util.List;
@Component
public class ModerationCustomFeature implements FeatureConfig {
public static final String WARN_NOTIFICATION_THRESHOLD = "warnNotificationThreshold";
@Autowired
private ModerationFeatureConfig moderationFeatureConfig;
@@ -27,9 +30,14 @@ public class ModerationCustomFeature implements FeatureConfig {
return Arrays.asList(moderationFeatureConfig);
}
@Override
public List<PostTargetEnum> getRequiredPostTargets() {
return Arrays.asList(ModerationCustomPostTarget.WARN_THRESHOLD_NOTIFICATION);
}
@Override
public List<String> getRequiredSystemConfigKeys() {
return Arrays.asList(ModModeServiceBean.MODMODE_ROLE_CONFIG_KEY,
ModModeServiceBean.MODMODE_CHANGED_ROLE_COLOR_CONFIG_KEY);
ModModeServiceBean.MODMODE_CHANGED_ROLE_COLOR_CONFIG_KEY, WARN_NOTIFICATION_THRESHOLD);
}
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.oneplus.bot.custom.moderation.config;
import dev.sheldan.abstracto.core.config.PostTargetEnum;
import lombok.Getter;
@Getter
public enum ModerationCustomPostTarget implements PostTargetEnum {
WARN_THRESHOLD_NOTIFICATION("warnThresholdNotification");
private String key;
ModerationCustomPostTarget(String key) {
this.key = key;
}
}

View File

@@ -0,0 +1,98 @@
package dev.sheldan.oneplus.bot.custom.moderation.listener;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
import dev.sheldan.abstracto.core.models.ServerUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.models.template.display.ChannelDisplay;
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
import dev.sheldan.abstracto.core.service.*;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.moderation.listener.WarningCreatedListener;
import dev.sheldan.abstracto.moderation.model.listener.WarningCreatedEventModel;
import dev.sheldan.abstracto.moderation.service.management.WarnManagementService;
import dev.sheldan.oneplus.bot.custom.moderation.config.ModerationCustomFeature;
import dev.sheldan.oneplus.bot.custom.moderation.config.ModerationCustomFeatureDefinition;
import dev.sheldan.oneplus.bot.custom.moderation.config.ModerationCustomPostTarget;
import dev.sheldan.oneplus.bot.custom.moderation.model.template.WarningThresholdNotificationModel;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Component
@Slf4j
public class WarningAddedListener implements WarningCreatedListener {
@Autowired
private ConfigService configService;
@Autowired
private WarnManagementService warnManagementService;
@Autowired
private UserInServerManagementService userInServerManagementService;
@Autowired
private ChannelService channelService;
@Autowired
private PostTargetService postTargetService;
@Autowired
private TemplateService templateService;
public static final String WARN_THRESHOLD_NOTIFICATION_TEMPLATE_KEY = "warning_threshold_notification";
@Override
public DefaultListenerResult execute(WarningCreatedEventModel model) {
Long warnNotificationAmount = configService.getLongValueOrConfigDefault(ModerationCustomFeature.WARN_NOTIFICATION_THRESHOLD, model.getServerId());
ServerUser warnedUser = ServerUser
.builder()
.userId(model.getWarnedUserId())
.serverId(model.getServerId())
.build();
AUserInAServer warnedUserInAServer = userInServerManagementService.loadOrCreateUser(warnedUser);
List<Long> activeWarnsForUser = warnManagementService.getActiveWarnsForUser(warnedUserInAServer)
.stream().map(warning -> warning.getWarnId().getId()).collect(Collectors.toList());
Set<Long> warnIds = new HashSet<>(activeWarnsForUser);
// we cant be sure we receive the newly persisted warning yet, sadly
warnIds.add(model.getWarningId());
if(warnIds.size() == warnNotificationAmount) {
Long serverId = model.getServerId();
Long channelId = model.getWarningChannelId();
Long warnedUserId = model.getWarnedUserId();
GuildMessageChannel channel = channelService.getMessageChannelFromServer(serverId, channelId);
WarningThresholdNotificationModel notificationModel = WarningThresholdNotificationModel
.builder()
.channelDisplay(ChannelDisplay.fromChannel(channel))
.memberDisplay(MemberDisplay.fromAUserInAServer(warnedUserInAServer))
.messageId(model.getWarningMessageId())
.warnCount(warnIds.size())
.build();
MessageToSend messageToSend = templateService.renderEmbedTemplate(WARN_THRESHOLD_NOTIFICATION_TEMPLATE_KEY, notificationModel, serverId);
FutureUtils.toSingleFutureGeneric(postTargetService.sendEmbedInPostTarget(messageToSend, ModerationCustomPostTarget.WARN_THRESHOLD_NOTIFICATION, serverId))
.thenAccept(unused -> log.info("Warn threshold notification sent for user {} in server {}.", warnedUserId, serverId))
.exceptionally(throwable -> {
log.error("Failed to sent warn threshold notification for user {} in server {}.", warnedUserId, serverId, throwable);
return null;
});
}
return DefaultListenerResult.PROCESSED;
}
@Override
public FeatureDefinition getFeature() {
return ModerationCustomFeatureDefinition.MODERATION_CUSTOM;
}
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.oneplus.bot.custom.moderation.model.template;
import dev.sheldan.abstracto.core.models.template.display.ChannelDisplay;
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
import lombok.Builder;
import lombok.Getter;
@Builder
@Getter
public class WarningThresholdNotificationModel {
private MemberDisplay memberDisplay;
private Integer warnCount;
private ChannelDisplay channelDisplay;
private Long messageId;
}

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="seedData/data.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<property name="moderationCustomFeature" value="(SELECT id FROM feature WHERE key = 'moderationCustom')"/>
<property name="moderationModule" value="(SELECT id FROM module WHERE name = 'moderation')"/>
<changeSet author="Sheldan" id="moderationCustom_modmode-commands">

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="feature.xml" relativeToChangelogFile="true"/>
<include file="command.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="moderation_custom_feature-insertion">
<insert tableName="feature">
<column name="key" value="moderationCustom"/>

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="1.5.2/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -5,4 +5,9 @@ abstracto.systemConfigs.modModeRoleId.name=modModeRoleId
abstracto.systemConfigs.modModeRoleId.longValue=0
abstracto.systemConfigs.modModeNewRoleColor.name=modModeNewRoleColor
abstracto.systemConfigs.modModeNewRoleColor.stringValue=0,0,0
abstracto.systemConfigs.modModeNewRoleColor.stringValue=0,0,0
abstracto.systemConfigs.warnNotificationThreshold.name=warnNotificationThreshold
abstracto.systemConfigs.warnNotificationThreshold.longValue=3
abstracto.postTargets.warnThresholdNotification.name=warnThresholdNotification

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.oneplus.bot.application</groupId>
<artifactId>application</artifactId>
<version>1.5.2</version>
<version>1.6.24-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.oneplus.bot.application.custom</groupId>
<artifactId>oneplus-bot-customizations</artifactId>
<version>1.5.2</version>
<version>1.6.24-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="starboard-custom-seedData/data.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="feature.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="starboard_custom_feature-insertion">
<insert tableName="feature">
<column name="key" value="starboardNotification"/>

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="1.0-starboard-custom/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>oneplus-bot-modules</artifactId>
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
<version>1.5.2</version>
<version>1.6.24-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -17,7 +17,8 @@ import dev.sheldan.oneplus.bot.modules.faq.config.FAQFeatureDefinition;
import dev.sheldan.oneplus.bot.modules.faq.config.FAQModuleDefinition;
import dev.sheldan.oneplus.bot.modules.faq.models.command.faq.FAQResponseModel;
import dev.sheldan.oneplus.bot.modules.faq.service.FAQResponseServiceBean;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -50,7 +51,7 @@ public class FAQ extends AbstractConditionableCommand {
String commandName;
if(!parameters.isEmpty()) {
commandName = (String) parameters.get(0);
TextChannel channel;
GuildMessageChannel channel;
if (parameters.size() == 2) {
channel = (TextChannel) parameters.get(1);
} else {

View File

@@ -66,6 +66,7 @@ public class ImportFAQ extends AbstractConditionableCommand {
AServer server = serverManagementService.loadServer(commandContext.getGuild());
List<FaqCommandConfig> commands = faqServiceBean.loadFAQCommandsFromJson(jsonContent);
faqServiceBean.createOrUpdateFAQCommands(commands, server);
return CompletableFuture.completedFuture(CommandResult.fromSuccess());
} else {
List<String> errors = jsonValidationService.getDetailedException(result.getExceptions())
@@ -73,8 +74,8 @@ public class ImportFAQ extends AbstractConditionableCommand {
.map(ValidationException::getMessage)
.collect(Collectors.toList());
channelService.sendTextToChannel(String.join("\n", errors), commandContext.getChannel());
return CompletableFuture.completedFuture(CommandResult.fromError("Incorrect faq config."));
}
return CompletableFuture.completedFuture(CommandResult.fromSuccess());
} catch (IOException e) {
log.error("IO Exception when loading input file.", e);
throw new AbstractoTemplatedException("Failed to load json config.", "failed_to_set_template_exception", e);

View File

@@ -1,6 +1,7 @@
package dev.sheldan.oneplus.bot.modules.faq.converter;
import com.google.gson.Gson;
import dev.sheldan.abstracto.core.service.BotService;
import dev.sheldan.oneplus.bot.modules.faq.models.command.config.*;
import dev.sheldan.oneplus.bot.modules.faq.models.database.FAQChannelGroupCommand;
import dev.sheldan.oneplus.bot.modules.faq.models.database.FAQCommand;
@@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@@ -18,9 +20,16 @@ public class FAQCommandConfigConverter {
@Autowired
private Gson gson;
@Autowired
private BotService botService;
public String serializeCommands(List<FAQCommand> asList) {
Long botId = botService.getInstance().getSelfUser().getIdLong();
asList.sort(Comparator.comparing(FAQCommand::getName));
List<FaqCommandConfig> config = asList.stream().map(faqCommand -> {
List<FaqCommandResponseConfig> commandResponseConfigs = convertGroupCommands(faqCommand.getGroupResponses());
List<FAQChannelGroupCommand> responses = faqCommand.getGroupResponses();
responses.sort(Comparator.comparing(groupCommand -> groupCommand.getChannelGroup().getChannelGroup().getGroupName()));
List<FaqCommandResponseConfig> commandResponseConfigs = convertGroupCommands(responses, botId);
List<String> aliases;
if(faqCommand.getAliases() != null) {
aliases = faqCommand.getAliases().stream().map(faqCommandAlias -> faqCommandAlias.getId().getAlias()).collect(Collectors.toList());
@@ -39,9 +48,9 @@ public class FAQCommandConfigConverter {
return gson.toJson(config);
}
private List<FaqCommandResponseConfig> convertGroupCommands(List<FAQChannelGroupCommand> responses) {
private List<FaqCommandResponseConfig> convertGroupCommands(List<FAQChannelGroupCommand> responses, Long botUserId) {
return responses.stream().map(faqChannelGroupCommand -> {
List<FaqCommandResponseMessageConfig> responseConfigs = convertCommandResponses(faqChannelGroupCommand.getResponses());
List<FaqCommandResponseMessageConfig> responseConfigs = convertCommandResponses(faqChannelGroupCommand.getResponses(), botUserId);
return FaqCommandResponseConfig
.builder()
.channelGroupName(faqChannelGroupCommand.getChannelGroup().getChannelGroup().getGroupName())
@@ -50,13 +59,15 @@ public class FAQCommandConfigConverter {
}).collect(Collectors.toList());
}
private List<FaqCommandResponseMessageConfig> convertCommandResponses(List<FAQCommandResponse> responses) {
return responses.stream().map(this::convertCommandResponse).collect(Collectors.toList());
private List<FaqCommandResponseMessageConfig> convertCommandResponses(List<FAQCommandResponse> responses, Long botUserId) {
return responses.stream().map(response -> convertCommandResponse(response, botUserId)).collect(Collectors.toList());
}
private FaqCommandResponseMessageConfig convertCommandResponse(FAQCommandResponse response) {
private FaqCommandResponseMessageConfig convertCommandResponse(FAQCommandResponse response, Long botUserId) {
FaqCommandResponseEmbedConfig embedConfig = null;
if(response.getDescription() != null) {
// one of those must not be null, for it to be considered a proper embed
if(response.getDescription() != null || response.getImageURL() != null) {
boolean useBot = response.getAuthorUserId().equals(botUserId);
FaqCommandResponseEmbedColorConfig colorConfig = FaqCommandResponseEmbedColorConfig
.builder()
.red(response.getRed())
@@ -65,8 +76,8 @@ public class FAQCommandConfigConverter {
.build();
FaqCommandResponseEmbedAuthorConfig authorConfig = FaqCommandResponseEmbedAuthorConfig
.builder()
.userId(response.getAuthorUserId())
.useBot(null)
.userId(useBot ? null : response.getAuthorUserId())
.useBot(useBot)
.build();
embedConfig = FaqCommandResponseEmbedConfig
.builder()

View File

@@ -3,7 +3,7 @@ package dev.sheldan.oneplus.bot.modules.faq.models.database;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import lombok.*;
import javax.persistence.*;
import jakarta.persistence.*;
import java.time.Instant;
@Builder

View File

@@ -3,7 +3,7 @@ package dev.sheldan.oneplus.bot.modules.faq.models.database;
import dev.sheldan.oneplus.bot.modules.faq.models.database.embed.ChannelGroupCommandId;
import lombok.*;
import javax.persistence.*;
import jakarta.persistence.*;
import java.io.Serializable;
import java.time.Instant;
import java.util.ArrayList;

View File

@@ -3,7 +3,7 @@ package dev.sheldan.oneplus.bot.modules.faq.models.database;
import dev.sheldan.abstracto.core.models.database.AServer;
import lombok.*;
import javax.persistence.*;
import jakarta.persistence.*;
import java.io.Serializable;
import java.time.Instant;
import java.util.ArrayList;

View File

@@ -3,7 +3,7 @@ package dev.sheldan.oneplus.bot.modules.faq.models.database;
import dev.sheldan.oneplus.bot.modules.faq.models.database.embed.FAQCommandAliasId;
import lombok.*;
import javax.persistence.*;
import jakarta.persistence.*;
import java.io.Serializable;
import java.time.Instant;

View File

@@ -3,7 +3,7 @@ package dev.sheldan.oneplus.bot.modules.faq.models.database;
import dev.sheldan.oneplus.bot.modules.faq.models.database.embed.CommandResponseId;
import lombok.*;
import javax.persistence.*;
import jakarta.persistence.*;
import java.time.Instant;
@Builder

View File

@@ -2,8 +2,8 @@ package dev.sheldan.oneplus.bot.modules.faq.models.database.embed;
import lombok.*;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import java.io.Serializable;
@Embeddable

View File

@@ -2,8 +2,8 @@ package dev.sheldan.oneplus.bot.modules.faq.models.database.embed;
import lombok.*;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import java.io.Serializable;
@Embeddable

View File

@@ -2,8 +2,8 @@ package dev.sheldan.oneplus.bot.modules.faq.models.database.embed;
import lombok.*;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import java.io.Serializable;
@Embeddable

View File

@@ -22,10 +22,8 @@ import dev.sheldan.oneplus.bot.modules.faq.service.management.FAQChannelGroupCom
import dev.sheldan.oneplus.bot.modules.faq.service.management.FAQCommandAliasManagementService;
import dev.sheldan.oneplus.bot.modules.faq.service.management.FAQCommandManagementServiceBean;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.ISnowflake;
import net.dv8tion.jda.api.entities.SelfUser;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -67,7 +65,7 @@ public class FAQResponseServiceBean {
@Autowired
private FAQResponseServiceBean self;
public CompletableFuture<FAQResponseModel> loadFAQResponse(String commandName, TextChannel textChannel) {
public CompletableFuture<FAQResponseModel> loadFAQResponse(String commandName, GuildMessageChannel textChannel) {
AServer server = serverManagementService.loadServer(textChannel.getGuild().getIdLong());
Optional<FAQCommand> faqCommandOptional = faqCommandManagementServiceBean.findByNameAndServer(commandName, server);
if(!faqCommandOptional.isPresent()) {

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
<include file="seedData/data.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="faq_channel_group_type-insertion">
<insert tableName="channel_group_type">
<column name="group_type_key" value="faq"/>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<property name="faqFeature" value="(SELECT id FROM feature WHERE key = 'faq')"/>
<property name="faqModule" value="(SELECT id FROM module WHERE name = 'faqModule')"/>
<changeSet author="Sheldan" id="faq-commands" >

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="feature.xml" relativeToChangelogFile="true"/>
<include file="module.xml" relativeToChangelogFile="true"/>
<include file="command.xml" relativeToChangelogFile="true"/>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="faq_feature-insertion">
<insert tableName="feature">
<column name="key" value="faq"/>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="faq-module-insertion">
<insert tableName="module">
<column name="name" value="faqModule"/>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="faq_channel_group-table">
<createTable tableName="faq_channel_group">
<column name="id" type="BIGINT">

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="faq_channel_group_command-table">
<createTable tableName="faq_channel_group_command">
<column name="channel_group_id" type="BIGINT">

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="faq_command-table">
<createTable tableName="faq_command">
<column name="id" type="BIGINT" autoIncrement="true">

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="faq_command_alias-table">
<createTable tableName="faq_command_alias">
<column name="command_id" type="BIGINT">

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="faq_command_response-table">
<createTable tableName="faq_command_response">
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="faq_channel_group.xml" relativeToChangelogFile="true"/>
<include file="faq_command.xml" relativeToChangelogFile="true"/>
<include file="faq_command_alias.xml" relativeToChangelogFile="true"/>

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="1.4.4/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -3,143 +3,124 @@
"type": "array",
"minItems": 1,
"maxItems": 30,
"items": [
{
"type": "object",
"properties": {
"faqCommandName": {
"items": {
"type": "object",
"properties": {
"faqCommandName": {
"type": "string",
"minLength": 1,
"maxLength": 30,
"pattern": "\\w*"
},
"global": {
"default": false,
"type": "boolean"
},
"aliases": {
"type": "array",
"minItems": 0,
"maxItems": 20,
"items": {
"type": "string",
"minLength": 1,
"maxLength": 30,
"pattern": "\\w*"
},
"global": {
"default": false,
"type": "boolean"
},
"aliases": {
"type": "array",
"minItems": 1,
"maxItems": 20,
"items": {
"type": "string",
"minLength": 1,
"maxLength": 30,
"pattern": "\\w*"
}
},
"responses": {
"type": "array",
"minItems": 1,
"maxItems": 255,
"items": {
"type": "object",
"properties": {
"channelGroupName": {
"type": "string",
"minLength": 1,
"maxLength": 20,
"pattern": "\\w*"
},
"messages": {
"type": "array",
"minItems": 1,
"maxItems": 3,
"items": [
{
}
},
"responses": {
"type": "array",
"minItems": 1,
"maxItems": 255,
"items": {
"type": "object",
"properties": {
"channelGroupName": {
"type": "string",
"minLength": 1,
"maxLength": 20,
"pattern": "\\w*"
},
"messages": {
"type": "array",
"minItems": 1,
"maxItems": 3,
"items": {
"type": "object",
"properties": {
"position": {
"type": "number",
"minimum": 0,
"maximum": 2
},
"additionalMessage": {
"type": "string",
"minLength": 1,
"maxLength": 2000
},
"embed": {
"type": "object",
"properties": {
"position": {
"type": "number",
"minimum": 0,
"maximum": 2
},
"additionalMessage": {
"description": {
"type": "string",
"minLength": 1,
"maxLength": 2000
},
"embed": {
"imageUrl": {
"type": "string",
"minLength": 1,
"maxLength": 2000,
"pattern": "\\s*https?:\/\/\\S+"
},
"color": {
"type": "object",
"properties": {
"description": {
"type": "string",
"minLength": 1,
"maxLength": 2000
"red": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
},
"imageUrl": {
"type": "string",
"minLength": 1,
"maxLength": 2000,
"pattern": "\\s*https?:\/\/\\S+"
"green": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
},
"color": {
"type": "object",
"properties": {
"red": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
},
"green": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
},
"blue": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
}
},
"required": [
"red",
"green",
"blue"
]
"blue": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
}
},
"required": [
"red",
"green",
"blue"
]
},
"author": {
"type": "object",
"properties": {
"userId": {
"minimum": 1,
"maximum": 18446744073709551615,
"type": "integer"
},
"author": {
"type": "object",
"properties": {
"userId": {
"minimum": 1,
"maximum": 18446744073709551615,
"type": "integer"
},
"useBot": {
"type": "boolean"
}
},
"additionalProperties": false,
"anyOf": [
{
"required": [
"userId"
]
},
{
"required": [
"useBot"
]
}
]
"useBot": {
"type": "boolean"
}
},
"additionalProperties": false,
"anyOf": [
{
"required": [
"description",
"author"
"userId"
]
},
{
"required": [
"imageUrl",
"author"
"useBot"
]
}
]
@@ -149,41 +130,56 @@
"anyOf": [
{
"required": [
"additionalMessage",
"position"
"description",
"author"
]
},
{
"required": [
"embed",
"position"
]
},
{
"required": [
"additionalMessage",
"embed",
"position"
"imageUrl",
"author"
]
}
]
}
},
"additionalProperties": false,
"anyOf": [
{
"required": [
"additionalMessage",
"position"
]
},
{
"required": [
"embed",
"position"
]
},
{
"required": [
"additionalMessage",
"embed",
"position"
]
}
]
}
},
"additionalProperties": false,
"required": [
"channelGroupName",
"messages"
]
}
}
},
"additionalProperties": false,
"required": [
"channelGroupName",
"messages"
]
}
},
"additionalProperties": false,
"required": [
"faqCommandName",
"responses"
]
}
]
}
},
"additionalProperties": false,
"required": [
"faqCommandName",
"responses"
]
}
}

View File

@@ -3,16 +3,22 @@
<parent>
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
<artifactId>oneplus-bot-modules</artifactId>
<version>1.5.2</version>
<version>1.6.24-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>news</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>dev.sheldan.abstracto.scheduling</groupId>
<artifactId>scheduling-int</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
<build>
<plugins>

View File

@@ -11,6 +11,8 @@ import java.util.List;
@Component
public class NewsFeature implements FeatureConfig {
public static final String NEWS_FORUM_POST_NOTIFICATION_SERVER_ID_ENV_NAME = "NEWS_FORUM_POST_NOTIFICATION_SERVER_ID";
@Override
public FeatureDefinition getFeature() {
return NewsFeatureDefinition.NEWS;
@@ -18,6 +20,6 @@ public class NewsFeature implements FeatureConfig {
@Override
public List<PostTargetEnum> getRequiredPostTargets() {
return Arrays.asList(NewsPostTarget.NEWS_TARGET);
return Arrays.asList(NewsPostTarget.NEWS_TARGET, NewsPostTarget.FORUM_POST_NOTIFICATION);
}
}

View File

@@ -5,7 +5,7 @@ import lombok.Getter;
@Getter
public enum NewsPostTarget implements PostTargetEnum {
NEWS_TARGET("news");
NEWS_TARGET("news"), FORUM_POST_NOTIFICATION("forumPostNotification");
private String key;

View File

@@ -0,0 +1,31 @@
package dev.sheldan.oneplus.bot.modules.news.job;
import dev.sheldan.oneplus.bot.modules.news.service.NewsSourceServiceBean;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;
@Slf4j
@DisallowConcurrentExecution
@Component
@PersistJobDataAfterExecution
public class CheckForNewsPosts extends QuartzJobBean {
@Autowired
private NewsSourceServiceBean newsSourceServiceBean;
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
try {
log.info("Executing news post check job.");
newsSourceServiceBean.checkForNewThreads();
} catch (Exception exception) {
log.error("Failed to execute news post check job.", exception);
}
}
}

View File

@@ -0,0 +1,24 @@
package dev.sheldan.oneplus.bot.modules.news.model;
import dev.sheldan.oneplus.bot.modules.news.model.forum.ForumPost;
import lombok.Builder;
import lombok.Getter;
@Builder
@Getter
public class ForumPostNotificationEntry {
private Long postId;
private String subject;
private String content;
private Long creatorId;
public static ForumPostNotificationEntry fromPost(ForumPost forumPost) {
return ForumPostNotificationEntry
.builder()
.postId(forumPost.getId())
.subject(forumPost.getSubject())
.content(forumPost.getContent())
.creatorId(forumPost.getSource().getUserId())
.build();
}
}

View File

@@ -0,0 +1,12 @@
package dev.sheldan.oneplus.bot.modules.news.model;
import lombok.Builder;
import lombok.Getter;
import java.util.List;
@Getter
@Builder
public class ForumPostNotificationModel {
private List<ForumPostNotificationEntry> entries;
}

View File

@@ -0,0 +1,30 @@
package dev.sheldan.oneplus.bot.modules.news.model.database;
import jakarta.persistence.*;
import lombok.*;
import java.time.Instant;
@Builder
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "news_forum_post")
@Getter
@Setter
@EqualsAndHashCode
public class NewsForumPost {
@Id
@Column(name = "id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "creator_id", nullable = false)
private NewsSource creator;
@Column(name = "created")
private Instant created;
@Column(name = "updated")
private Instant updated;
}

View File

@@ -5,7 +5,7 @@ import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import lombok.*;
import javax.persistence.*;
import jakarta.persistence.*;
import java.time.Instant;
@Builder

View File

@@ -0,0 +1,29 @@
package dev.sheldan.oneplus.bot.modules.news.model.database;
import jakarta.persistence.*;
import lombok.*;
import java.time.Instant;
@Builder
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "news_source")
@Getter
@Setter
@EqualsAndHashCode
public class NewsSource {
@Id
@Column(name = "user_id")
private Long userId;
@Column(name = "thread_count")
private Long threadCount;
@Column(name = "created")
private Instant created;
@Column(name = "updated")
private Instant updated;
}

View File

@@ -0,0 +1,24 @@
package dev.sheldan.oneplus.bot.modules.news.model.forum;
import dev.sheldan.oneplus.bot.modules.news.model.database.NewsSource;
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder
public class ForumPost {
private Long id;
private String subject;
private String content;
private NewsSource source;
public static ForumPost fromRow(NewsForumPostDataRow dataRow, NewsSource newsSource) {
return ForumPost
.builder()
.subject(dataRow.getSubject())
.id(dataRow.getId())
.content(dataRow.getContent())
.source(newsSource)
.build();
}
}

View File

@@ -0,0 +1,12 @@
package dev.sheldan.oneplus.bot.modules.news.model.forum;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import java.util.List;
@Getter
public class NewsForumPostData {
@SerializedName("rows")
private List<NewsForumPostDataRow> rows;
}

View File

@@ -0,0 +1,16 @@
package dev.sheldan.oneplus.bot.modules.news.model.forum;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
@Getter
public class NewsForumPostDataRow {
@SerializedName("id")
private Long id;
@SerializedName("subject")
private String subject;
@SerializedName("content")
private String content;
}

View File

@@ -0,0 +1,11 @@
package dev.sheldan.oneplus.bot.modules.news.model.forum;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
@Getter
public class NewsForumPostResponse {
@SerializedName("data")
private NewsForumPostData newsForumPostData;
}

View File

@@ -0,0 +1,12 @@
package dev.sheldan.oneplus.bot.modules.news.model.forum;
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Getter;
@Builder
@Getter
public class NewsSourceResponse {
@SerializedName("data")
private NewsSourceUserData user;
}

View File

@@ -0,0 +1,12 @@
package dev.sheldan.oneplus.bot.modules.news.model.forum;
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Getter;
@Builder
@Getter
public class NewsSourceUserData {
@SerializedName("userStatVO")
private NewsSourceUserStats userStats;
}

View File

@@ -0,0 +1,12 @@
package dev.sheldan.oneplus.bot.modules.news.model.forum;
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Getter;
@Builder
@Getter
public class NewsSourceUserStats {
@SerializedName("threadCount")
private Long threadCount;
}

View File

@@ -0,0 +1,9 @@
package dev.sheldan.oneplus.bot.modules.news.repository;
import dev.sheldan.oneplus.bot.modules.news.model.database.NewsForumPost;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface NewsForumPostRepository extends JpaRepository<NewsForumPost, Long> {
}

View File

@@ -0,0 +1,9 @@
package dev.sheldan.oneplus.bot.modules.news.repository;
import dev.sheldan.oneplus.bot.modules.news.model.database.NewsSource;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface NewsResourceRepository extends JpaRepository<NewsSource, Long> {
}

View File

@@ -0,0 +1,85 @@
package dev.sheldan.oneplus.bot.modules.news.service;
import com.google.gson.Gson;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.oneplus.bot.modules.news.model.database.NewsSource;
import dev.sheldan.oneplus.bot.modules.news.model.forum.ForumPost;
import dev.sheldan.oneplus.bot.modules.news.model.forum.NewsForumPostResponse;
import dev.sheldan.oneplus.bot.modules.news.model.forum.NewsSourceResponse;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Component
public class ForumApiClient {
@Autowired
private OkHttpClient okHttpClient;
@Autowired
private Gson gson;
@Value("${abstracto.feature.news.userURL}")
private String userRequestURL;
@Value("${abstracto.feature.news.threadURL}")
private String threadInfoUrl;
public Long getCurrentThreadCount(NewsSource newsSource) {
Request request = new Request.Builder()
.url(String.format(userRequestURL, newsSource.getUserId()))
.get()
.build();
Response response;
try {
response = okHttpClient.newCall(request).execute();
if(!response.isSuccessful()) {
throw new AbstractoRunTimeException(String.format("Failed to load user info for id %s", newsSource.getUserId()));
}
NewsSourceResponse newsSourceResponse = gson.fromJson(response.body().string(), NewsSourceResponse.class);
if (newsSourceResponse.getUser() != null
&& newsSourceResponse.getUser().getUserStats() != null
&& newsSourceResponse.getUser().getUserStats().getThreadCount() != null) {
return newsSourceResponse.getUser().getUserStats().getThreadCount();
}
} catch (IOException e) {
throw new AbstractoRunTimeException(e);
}
return 0L;
}
public List<ForumPost> getPostsOfSource(NewsSource source) {
Request request = new Request.Builder()
.url(String.format(threadInfoUrl, source.getUserId()))
.get()
.build();
Response response;
try {
response = okHttpClient.newCall(request).execute();
if(!response.isSuccessful()) {
throw new AbstractoRunTimeException(String.format("Failed to load thread info for id %s", source.getUserId()));
}
NewsForumPostResponse newsSourceResponse = gson.fromJson(response.body().string(), NewsForumPostResponse.class);
if (newsSourceResponse.getNewsForumPostData() != null
&& newsSourceResponse.getNewsForumPostData().getRows() != null) {
return newsSourceResponse
.getNewsForumPostData()
.getRows()
.stream()
.map(dataRow -> ForumPost.fromRow(dataRow, source))
.toList();
}
} catch (IOException e) {
throw new AbstractoRunTimeException(e);
}
return new ArrayList<>();
}
}

View File

@@ -12,7 +12,7 @@ import dev.sheldan.oneplus.bot.modules.news.model.database.NewsPost;
import dev.sheldan.oneplus.bot.modules.news.service.management.NewsPostManagementServiceBean;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -113,7 +113,7 @@ public class NewsServiceBean {
log.info("Updating news post {} with new content based on message from user {} in server {}.",
newsPost.getSourceMessageId(), updatedMessage.getIdLong(), updatedMessage.getGuild().getId());
MessageToSend messageToSend = templateService.renderEmbedTemplate(MESSAGE_TEMPLATE_KEY, model, serverId);
TextChannel newsChannel = channelService.getTextChannelFromServer(serverId, newsPost.getNewsChannel().getId());
GuildMessageChannel newsChannel = channelService.getMessageChannelFromServer(serverId, newsPost.getNewsChannel().getId());
return channelService.editMessageInAChannelFuture(messageToSend, newsChannel, newsPost.getNewsMessageId())
.thenApply(message -> null);
}

View File

@@ -0,0 +1,144 @@
package dev.sheldan.oneplus.bot.modules.news.service;
import dev.sheldan.abstracto.core.service.PostTargetService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.oneplus.bot.modules.news.config.NewsPostTarget;
import dev.sheldan.oneplus.bot.modules.news.model.ForumPostNotificationEntry;
import dev.sheldan.oneplus.bot.modules.news.model.ForumPostNotificationModel;
import dev.sheldan.oneplus.bot.modules.news.model.database.NewsForumPost;
import dev.sheldan.oneplus.bot.modules.news.model.database.NewsSource;
import dev.sheldan.oneplus.bot.modules.news.model.forum.ForumPost;
import dev.sheldan.oneplus.bot.modules.news.service.management.NewsForumPostManagementServiceBean;
import dev.sheldan.oneplus.bot.modules.news.service.management.NewsSourceManagementServiceBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static dev.sheldan.oneplus.bot.modules.news.config.NewsFeature.NEWS_FORUM_POST_NOTIFICATION_SERVER_ID_ENV_NAME;
@Component
@Slf4j
public class NewsSourceServiceBean {
@Autowired
private ForumApiClient forumApiClient;
@Autowired
private NewsSourceManagementServiceBean newsSourceManagementServiceBean;
@Autowired
private NewsForumPostManagementServiceBean newsForumPostManagementServiceBean;
@Autowired
private PostTargetService postTargetService;
@Autowired
private TemplateService templateService;
@Autowired
private NewsSourceServiceBean self;
private static final String NEWS_FORUM_POST_NOTIFICATION_TEMPLATE_KEY = "newsForumPost_notification";
public void checkForNewThreads() {
Long targetServerId = Long.parseLong(System.getenv(NEWS_FORUM_POST_NOTIFICATION_SERVER_ID_ENV_NAME));
List<ForumPost> newForumPosts = getNewForumPosts();
log.info("Found {} new forum posts.", newForumPosts.size());
if(newForumPosts.isEmpty()) {
return;
}
List<ForumPostNotificationEntry> entries = new ArrayList<>();
newForumPosts.forEach(forumPost -> entries.add(ForumPostNotificationEntry.fromPost(forumPost)));
ForumPostNotificationModel model = ForumPostNotificationModel
.builder()
.entries(entries)
.build();
MessageToSend messageToSend = templateService.renderEmbedTemplate(NEWS_FORUM_POST_NOTIFICATION_TEMPLATE_KEY, model, targetServerId);
FutureUtils.toSingleFutureGeneric(postTargetService.sendEmbedInPostTarget(messageToSend, NewsPostTarget.FORUM_POST_NOTIFICATION, targetServerId))
.thenAccept(unused -> {
log.info("Sent news forum post notification.");
self.persistForumPostsAndThreadCount(entries);
}).exceptionally(throwable -> {
log.error("Failed to send news forum post notification.", throwable);
return null;
});
}
@Transactional
public void persistForumPostsAndThreadCount(List<ForumPostNotificationEntry> entries) {
Map<Long, NewsSource> sourceMap = newsSourceManagementServiceBean.loadNewsSources()
.stream()
.collect(Collectors.toMap(NewsSource::getUserId, Function.identity()));
entries.forEach(forumPostNotificationEntry ->
newsForumPostManagementServiceBean.createPost(sourceMap.get(forumPostNotificationEntry.getCreatorId()), forumPostNotificationEntry.getPostId()));
sourceMap.values().forEach(newsSource -> {
Long currentThreadCount = forumApiClient.getCurrentThreadCount(newsSource);
newsSource.setThreadCount(currentThreadCount);
});
}
private boolean hasThreadCountChanged(NewsSource newsSource) {
Long currentThreadCount = forumApiClient.getCurrentThreadCount(newsSource);
return !currentThreadCount.equals(newsSource.getThreadCount());
}
private List<ForumPost> getNewForumPosts() {
List<NewsSource> newsSources = newsSourceManagementServiceBean.loadNewsSources();
log.info("Total news source count: {}", newsSources.size());
List<NewsSource> sourcesWithChangedThreadCount = newsSources
.stream()
.filter(this::hasThreadCountChanged)
.toList();
log.info("News sources with new thread count: {}", sourcesWithChangedThreadCount.size());
List<ForumPost> currentForumPosts = sourcesWithChangedThreadCount
.stream()
.map(newsSource -> forumApiClient.getPostsOfSource(newsSource))
.flatMap(Collection::stream)
.toList();
log.info("Total amount of incoming forum posts: {}", currentForumPosts.size());
if(currentForumPosts.isEmpty()) {
return new ArrayList<>();
}
Set<Long> incomingForumPostIds = currentForumPosts
.stream()
.map(ForumPost::getId)
.collect(Collectors.toSet());
List<NewsForumPost> existingNewsForumPosts = newsForumPostManagementServiceBean.getAllPosts();
log.info("Total amount of existing and tracked forum posts: {}", existingNewsForumPosts.size());
Set<Long> existingForumPostIds = existingNewsForumPosts
.stream()
.map(NewsForumPost::getId)
.collect(Collectors.toSet());
incomingForumPostIds.removeAll(existingForumPostIds);
if(incomingForumPostIds.isEmpty()) {
return new ArrayList<>();
}
Map<Long, ForumPost> incomingPostMap = currentForumPosts
.stream()
.collect(Collectors.toMap(ForumPost::getId, Function.identity()));
return incomingForumPostIds.stream().map(incomingPostMap::get).toList();
}
}

View File

@@ -0,0 +1,30 @@
package dev.sheldan.oneplus.bot.modules.news.service.management;
import dev.sheldan.oneplus.bot.modules.news.model.database.NewsForumPost;
import dev.sheldan.oneplus.bot.modules.news.model.database.NewsSource;
import dev.sheldan.oneplus.bot.modules.news.repository.NewsForumPostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class NewsForumPostManagementServiceBean {
@Autowired
private NewsForumPostRepository repository;
public List<NewsForumPost> getAllPosts() {
return repository.findAll();
}
public NewsForumPost createPost(NewsSource creator, Long id) {
NewsForumPost post = NewsForumPost
.builder()
.creator(creator)
.id(id)
.build();
return repository.save(post);
}
}

View File

@@ -6,12 +6,12 @@ import dev.sheldan.abstracto.core.service.management.UserInServerManagementServi
import dev.sheldan.oneplus.bot.modules.news.exception.NewsPostNotFoundException;
import dev.sheldan.oneplus.bot.modules.news.model.database.NewsPost;
import dev.sheldan.oneplus.bot.modules.news.repository.NewsPostRepository;
import jakarta.persistence.*;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.persistence.EntityManager;
import java.time.Instant;
import java.util.List;
import java.util.Optional;

View File

@@ -0,0 +1,20 @@
package dev.sheldan.oneplus.bot.modules.news.service.management;
import dev.sheldan.oneplus.bot.modules.news.model.database.NewsSource;
import dev.sheldan.oneplus.bot.modules.news.repository.NewsResourceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class NewsSourceManagementServiceBean {
@Autowired
private NewsResourceRepository newsResourceRepository;
public List<NewsSource> loadNewsSources() {
return newsResourceRepository.findAll();
}
}

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="news-update/update.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="rename-news-module">
<update tableName="module">
<column name="name" value="newsModule" />

View File

@@ -1,10 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="module.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="news-tables/tables.xml" relativeToChangelogFile="true"/>
<include file="news-seedData/data.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<property name="newsFeature" value="(SELECT id FROM feature WHERE key = 'news')"/>
<property name="newsModule" value="(SELECT id FROM module WHERE name = 'news')"/>
<changeSet author="Sheldan" id="news-commands" >

View File

@@ -1,11 +1,7 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="feature.xml" relativeToChangelogFile="true"/>
<include file="module.xml" relativeToChangelogFile="true"/>
<include file="command.xml" relativeToChangelogFile="true"/>

Some files were not shown because too many files have changed in this diff Show More