mirror of
https://github.com/Sheldan/Sissi.git
synced 2026-01-26 19:21:43 +00:00
Compare commits
227 Commits
sissi-1.3.
...
da30a120d7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da30a120d7 | ||
|
|
49875b2467 | ||
|
|
2236710086 | ||
|
|
99b266e94a | ||
|
|
974ab230ac | ||
|
|
e5239f971c | ||
|
|
23db0b7c9e | ||
|
|
8167accd34 | ||
|
|
375045f508 | ||
|
|
3f4d5510d8 | ||
|
|
ba67f65bea | ||
|
|
1b7c2263ae | ||
|
|
f065bf5244 | ||
|
|
e036fd0867 | ||
|
|
96960d77ac | ||
|
|
3894d4567e | ||
|
|
503fd2520d | ||
|
|
58d6b12a67 | ||
|
|
4128274a7d | ||
|
|
3b498c5d3f | ||
|
|
c6bdcaa84c | ||
|
|
90f3dd0ae9 | ||
|
|
cd482d640f | ||
|
|
ae2f88daa3 | ||
|
|
c13f40fd3b | ||
|
|
37147a866f | ||
|
|
9a7d0613b1 | ||
|
|
7e60447ae6 | ||
|
|
e4a899a125 | ||
|
|
ce8341e69a | ||
|
|
fa6333fa49 | ||
|
|
3393dea591 | ||
|
|
3c3bdfaed9 | ||
|
|
172e3c4190 | ||
|
|
52b86804b9 | ||
|
|
de8d9982f3 | ||
|
|
29e1b22783 | ||
|
|
5852d4837e | ||
|
|
b345fa5502 | ||
|
|
d6470e3714 | ||
|
|
b4cebe2b41 | ||
|
|
f3dd85d7d5 | ||
|
|
db318afb2b | ||
|
|
ddd710d1c2 | ||
|
|
81824db1f1 | ||
|
|
0390d7c8ca | ||
|
|
61412f434c | ||
|
|
12e69a18fb | ||
|
|
170ddd9c33 | ||
|
|
de8bbdcbee | ||
|
|
b5bf53fb6a | ||
|
|
159326dde3 | ||
|
|
7124d4e1d8 | ||
|
|
c6f20d617d | ||
|
|
7449c05462 | ||
|
|
6bd0f0eaa2 | ||
|
|
9b8a3bcc1e | ||
|
|
7b11a88256 | ||
|
|
30289e1166 | ||
|
|
0bab3bbe69 | ||
|
|
6f75c76fc4 | ||
|
|
0d9aa4ae64 | ||
|
|
c6b0bf582b | ||
|
|
dcd94ba5c0 | ||
|
|
98ae8ada8b | ||
|
|
96d3918a4d | ||
|
|
0d6f71baac | ||
|
|
d3421a6f95 | ||
|
|
0722bd6320 | ||
|
|
a910870259 | ||
|
|
18cc97600f | ||
|
|
a1ea57a0f3 | ||
|
|
23b554c93f | ||
|
|
5671c5019a | ||
|
|
fbb0876c7f | ||
|
|
bbaee9a47a | ||
|
|
b9f2a06173 | ||
|
|
55ba69bb0f | ||
|
|
9ed71b8660 | ||
|
|
28cf141a02 | ||
|
|
03ca4d128d | ||
|
|
ff2029819d | ||
|
|
a26503650e | ||
|
|
7a37f7e040 | ||
|
|
0073d5b069 | ||
|
|
c210e34437 | ||
|
|
7a43b23d68 | ||
|
|
7c15648e75 | ||
|
|
d629bf633f | ||
|
|
4115037141 | ||
|
|
5d02bb99d4 | ||
|
|
96bdc3d089 | ||
|
|
71546fcc89 | ||
|
|
22c330c7e4 | ||
|
|
fd402a966a | ||
|
|
b3029deea4 | ||
|
|
24b23c445f | ||
|
|
a9c44e24f1 | ||
|
|
7deee4008d | ||
|
|
2ab922cc84 | ||
|
|
c6a7b60e41 | ||
|
|
49974648b6 | ||
|
|
cd7580f45d | ||
|
|
076afb35b4 | ||
|
|
f901aeaefc | ||
|
|
6b37de3db5 | ||
|
|
0b80e351a5 | ||
|
|
3fe47ab682 | ||
|
|
9b69fe5f2d | ||
|
|
953eb1b4ff | ||
|
|
876dd82d87 | ||
|
|
454d66c71e | ||
|
|
87f72a077d | ||
|
|
62c27d1461 | ||
|
|
3b2bbb1dce | ||
|
|
8f40a95cbe | ||
|
|
5e9518de71 | ||
|
|
0ecab3b21b | ||
|
|
5e0e546eb4 | ||
|
|
ade0d4e57d | ||
|
|
26b08c593c | ||
|
|
888f2bd402 | ||
|
|
eb369d9116 | ||
|
|
f2acdbdd81 | ||
|
|
d65f6d380f | ||
|
|
30d45952be | ||
|
|
068cbdb33c | ||
|
|
effca93b7a | ||
|
|
ac815b5972 | ||
|
|
e6cccef48d | ||
|
|
4f35aa56f4 | ||
|
|
66204ca061 | ||
|
|
2960173517 | ||
|
|
b810c25613 | ||
|
|
583c2cc4be | ||
|
|
0c36564331 | ||
|
|
d7bd458bed | ||
|
|
bbcd77e3c8 | ||
|
|
ec166167f4 | ||
|
|
d5b4835d1f | ||
|
|
41304551e4 | ||
|
|
279959f256 | ||
|
|
7cc0e8e21c | ||
|
|
87e9122c41 | ||
|
|
f22cc03e14 | ||
|
|
84b103cfba | ||
|
|
a015e01c40 | ||
|
|
981db7b43f | ||
|
|
65560991bc | ||
|
|
b914ba035f | ||
|
|
d3e77f17ec | ||
|
|
9498458165 | ||
|
|
03a112fb43 | ||
|
|
782773fef5 | ||
|
|
5076e79c1d | ||
|
|
ac1baa4734 | ||
|
|
2c508665be | ||
|
|
1023951a76 | ||
|
|
a1923427a0 | ||
|
|
4c8ca91712 | ||
|
|
f78ab3372e | ||
|
|
c70815f25d | ||
|
|
7ee3653ab9 | ||
|
|
bb60d767a7 | ||
|
|
5a34447abe | ||
|
|
bbcfcfcc6f | ||
|
|
75187cae00 | ||
|
|
710a039707 | ||
|
|
b7dcb72e7a | ||
|
|
ead142cf5d | ||
|
|
11bf8cc9bc | ||
|
|
1083f93d2c | ||
|
|
6de38d3bea | ||
|
|
9de6eb4b8b | ||
|
|
df1392bf84 | ||
|
|
6e065de915 | ||
|
|
a1820aea67 | ||
|
|
09c113c6bc | ||
|
|
d080292e85 | ||
|
|
0e9ea8cf1a | ||
|
|
5d1037f66d | ||
|
|
eb6251aae0 | ||
|
|
caccf8b405 | ||
|
|
5390c0e53e | ||
|
|
8732064764 | ||
|
|
46833e024f | ||
|
|
e459ef77f3 | ||
|
|
a827d7e946 | ||
|
|
85da8684a4 | ||
|
|
52c3c5bcc8 | ||
|
|
a3c1b0537e | ||
|
|
127ff821d1 | ||
|
|
7e3b23aec0 | ||
|
|
c0ced48ff2 | ||
|
|
b5dfb59458 | ||
|
|
c89e8591f0 | ||
|
|
507ac7b043 | ||
|
|
d64abb4cce | ||
|
|
e56999da19 | ||
|
|
06dc90a51e | ||
|
|
1842094036 | ||
|
|
b2d55c3236 | ||
|
|
b88ed34ed2 | ||
|
|
939ea35f39 | ||
|
|
5c718bfa5e | ||
|
|
0efee9e7aa | ||
|
|
f1f56b03d4 | ||
|
|
725afbd115 | ||
|
|
015ff303b7 | ||
|
|
55d25697ce | ||
|
|
cdcfd5c8f8 | ||
|
|
42c307d962 | ||
|
|
3fbb635b4a | ||
|
|
53761fba98 | ||
|
|
d0280ea116 | ||
|
|
bb605133bd | ||
|
|
194f18ee22 | ||
|
|
4e1196a405 | ||
|
|
672ad9b9e4 | ||
|
|
fd548b7bfe | ||
|
|
888246cbbc | ||
|
|
a26114331f | ||
|
|
2ae472ae94 | ||
|
|
4cf1e0c1f1 | ||
|
|
6d1d70e664 | ||
|
|
2c9f38952c | ||
|
|
b801fc82c6 |
4
.env
Normal file
4
.env
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
REGISTRY_PREFIX=harbor.sheldan.dev/sissi/
|
||||||
|
ABSTRACTO_PREFIX=harbor.sheldan.dev/abstracto/
|
||||||
|
VERSION=1.4.33
|
||||||
|
ABSTRACTO_VERSION=1.5.18
|
||||||
11
.github/workflows/build.yml
vendored
11
.github/workflows/build.yml
vendored
@@ -17,11 +17,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Set up JDK 1.8
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
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
|
- name: Build with Maven
|
||||||
run: mvn -s settings.xml -B install --file pom.xml
|
run: mvn -s settings.xml -B install --file pom.xml
|
||||||
env:
|
env:
|
||||||
|
|||||||
37
.github/workflows/release.yml
vendored
37
.github/workflows/release.yml
vendored
@@ -6,13 +6,14 @@ jobs:
|
|||||||
publish:
|
publish:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Set up Java for publishing to GitHub Packages
|
- name: Set up Java for publishing to GitHub Packages
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
java-version: 1.8
|
distribution: 'corretto'
|
||||||
|
java-version: 17
|
||||||
- name: Load current version
|
- name: Load current version
|
||||||
id: 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
|
run: echo "version=$(mvn -s settings.xml --file pom.xml -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_ENV
|
||||||
@@ -22,17 +23,25 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
user: Sheldan
|
user: Sheldan
|
||||||
token: ${{ secrets.ABSTRACTO_PAT }}
|
token: ${{ secrets.ABSTRACTO_PAT }}
|
||||||
- name: Login to GitHub Packages Docker Registry
|
- name: Login to Harbor
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: docker.pkg.github.com
|
registry: harbor.sheldan.dev
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ secrets.HARBOR_USERNAME }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.HARBOR_TOKEN }}
|
||||||
- name: Push deployment container
|
- name: Load env files
|
||||||
working-directory: ./deployment/image-packaging/src/main/docker
|
id: dotenv
|
||||||
|
uses: falti/dotenv-action@v1.0.4
|
||||||
|
with:
|
||||||
|
path: .env
|
||||||
|
- name: Push container
|
||||||
run: docker-compose build && docker-compose push
|
run: docker-compose build && docker-compose push
|
||||||
env:
|
env:
|
||||||
REGISTRY_PREFIX: docker.pkg.github.com/sheldan/sissi/
|
REGISTRY_PREFIX: ${{ steps.dotenv.outputs.registry_prefix }}
|
||||||
VERSION: ${{ env.version }}
|
VERSION: ${{ steps.dotenv.outputs.version }}
|
||||||
ABSTRACTO_VERSION: 1.4.6
|
- name: Helm push
|
||||||
ABSTRACTO_REGISTRY_PREFIX: docker.pkg.github.com/sheldan/abstracto/
|
working-directory: ./deployment/helm/
|
||||||
|
run: |-
|
||||||
|
helm registry login -u '${{ secrets.HARBOR_USERNAME }}' -p '${{ secrets.HARBOR_TOKEN }}' harbor.sheldan.dev
|
||||||
|
helm package sissi
|
||||||
|
helm push sissi*.tgz oci://harbor.sheldan.dev/sissi
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2022 Sheldan
|
Copyright (c) 2023 Sheldan
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
4
README
Normal file
4
README
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
Attributions:
|
||||||
|
Code for debra module has been inspired with approval of zinnsoldat91 by: https://github.com/zinnsoldat91/spendenbot. The code has been adapted to fit into the structure.
|
||||||
47
Tiltfile
Normal file
47
Tiltfile
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
allow_k8s_contexts('k8s-cluster')
|
||||||
|
|
||||||
|
load('ext://restart_process', 'docker_build_with_restart')
|
||||||
|
registry = 'harbor.sheldan.dev/sissi/'
|
||||||
|
abstracto_registry = 'harbor.sheldan.dev/abstracto/'
|
||||||
|
|
||||||
|
local_resource(
|
||||||
|
'sissi-java-compile',
|
||||||
|
' mvn install && ' +
|
||||||
|
' rm -rf application/executable/target/jar-staging && ' +
|
||||||
|
' unzip -o application/executable/target/sissi-exec.jar -d application/executable/target/jar-staging && ' +
|
||||||
|
' rsync --delete --delete-excluded --inplace --checksum --exclude="*-SNAPSHOT.jar" -r application/executable/target/jar-staging/ application/executable/target/jar && ' +
|
||||||
|
' rm -rf application/executable/target/jar/snapshots && ' +
|
||||||
|
' mkdir application/executable/target/jar/snapshots && ' +
|
||||||
|
' rsync --delete --delete-excluded --inplace --checksum --include="*/" --include="*-SNAPSHOT.jar" --exclude="*" -r application/executable/target/jar-staging/BOOT-INF/lib/ application/executable/target/jar/snapshots',
|
||||||
|
deps=['pom.xml'], auto_init=False, trigger_mode = TRIGGER_MODE_MANUAL)
|
||||||
|
|
||||||
|
docker_build_with_restart(
|
||||||
|
registry + 'sissi-bot',
|
||||||
|
'./application/executable/target/jar',
|
||||||
|
entrypoint=['java', '-noverify', '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005', '-cp', '.:./lib/*', 'dev.sheldan.sissi.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 + 'sissi-db-data', 'deployment/image-packaging/src/main/docker/db-data/')
|
||||||
|
docker_build(registry + 'sissi-debra-rest-api', 'python/modules/debra-rest-api/', dockerfile='python/modules/debra-rest-api/docker/Dockerfile')
|
||||||
|
update_settings(suppress_unused_image_warnings=[registry + "sissi-debra-rest-api"]) # only used in docker image building
|
||||||
|
docker_build(registry + 'sissi-image-gen-api', 'python/modules/image-gen-api/', dockerfile='python/modules/image-gen-api/docker/Dockerfile')
|
||||||
|
update_settings(suppress_unused_image_warnings=[registry + "sissi-image-gen-api"]) # only used in docker image building
|
||||||
|
docker_build(registry + 'sissi-rest-api', 'deployment/image-packaging/src/main/docker/rest-api/', build_args={'REGISTRY_PREFIX': abstracto_registry, 'SISSI_REGISTRY_PREFIX': registry})
|
||||||
|
docker_build(registry + 'sissi-private-rest-api', 'deployment/image-packaging/src/main/docker/private-rest-api/', build_args={'REGISTRY_PREFIX': abstracto_registry, 'SISSI_REGISTRY_PREFIX': registry})
|
||||||
|
docker_build(registry + 'sissi-template-data', 'deployment/image-packaging/src/main/docker/template-data/')
|
||||||
|
|
||||||
|
|
||||||
|
k8s_yaml(helm('deployment/helm/sissi', values=
|
||||||
|
['./../Sissi-environments/argocd/apps/sissi/values/local/values.yaml',
|
||||||
|
'secrets://./../Sissi-environments/argocd/apps/sissi/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-sissi', port_forwards='5005:5005')
|
||||||
10
application/executable/Dockerfile
Normal file
10
application/executable/Dockerfile
Normal 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.sissi.executable.Application
|
||||||
@@ -3,17 +3,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>dev.sheldan.sissi.application</groupId>
|
<groupId>dev.sheldan.sissi.application</groupId>
|
||||||
<artifactId>application</artifactId>
|
<artifactId>application</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.4.34-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>executable</artifactId>
|
<artifactId>executable</artifactId>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<finalName>sissi</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -75,6 +71,11 @@
|
|||||||
<artifactId>webservices-impl</artifactId>
|
<artifactId>webservices-impl</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||||
|
<artifactId>twitch-impl</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||||
<artifactId>utility-impl</artifactId>
|
<artifactId>utility-impl</artifactId>
|
||||||
@@ -120,6 +121,31 @@
|
|||||||
<artifactId>modmail-impl</artifactId>
|
<artifactId>modmail-impl</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||||
|
<artifactId>experience-tracking-impl</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||||
|
<artifactId>logging-impl</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||||
|
<artifactId>statistic-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>
|
||||||
|
|
||||||
<!-- sissi modules -->
|
<!-- sissi modules -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -134,6 +160,18 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.sheldan.sissi.application.module</groupId>
|
||||||
|
<artifactId>rss-news</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.sheldan.sissi.application.module</groupId>
|
||||||
|
<artifactId>debra</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- sissi customizations -->
|
<!-- sissi customizations -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -142,6 +180,12 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.sheldan.sissi.application.module.custom</groupId>
|
||||||
|
<artifactId>image-generation-custom</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package dev.sheldan.sissi.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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=sissi
|
|
||||||
spring.security.user.name=abstracto
|
|
||||||
spring.security.user.password=password
|
|
||||||
spring.security.user.roles=USER
|
|
||||||
|
|
||||||
spring.application.name=Sissi
|
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
spring.datasource.url=jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
|
spring.datasource.url=jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
|
||||||
spring.datasource.username= ${DB_USER}
|
spring.datasource.username= ${DB_USER}
|
||||||
spring.datasource.password= ${DB_PASS}
|
spring.datasource.password= ${DB_PASS}
|
||||||
spring.jpa.hibernate.default_schema=${DB_NAME}
|
spring.datasource.hikari.maximum-pool-size=${hikariPoolSize}
|
||||||
|
spring.jpa.hibernate.default_schema=abstracto
|
||||||
|
spring.jpa.properties.hibernate.default_schema=abstracto
|
||||||
spring.quartz.jdbc.initialize-schema=never
|
spring.quartz.jdbc.initialize-schema=never
|
||||||
management.metrics.tags.application=Sissi
|
management.metrics.tags.application=Sissi
|
||||||
spring.security.user.name= ${REST_USER_NAME}
|
management.endpoint.health.probes.enabled=true
|
||||||
spring.security.user.password= ${REST_PASSWORD}
|
management.health.livenessState.enabled=true
|
||||||
spring.security.user.roles=USER
|
management.health.readinessState.enabled=true
|
||||||
|
spring.application.name=Sissi
|
||||||
|
|
||||||
spring.application.name=Sissi
|
spring.main.allow-circular-references=true
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>dev.sheldan.sissi</groupId>
|
<groupId>dev.sheldan.sissi</groupId>
|
||||||
<artifactId>sissi</artifactId>
|
<artifactId>sissi</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.4.34-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -22,6 +22,18 @@
|
|||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.jena</groupId>
|
||||||
|
<artifactId>apache-jena-libs</artifactId>
|
||||||
|
<version>${apache-jena.version}</version>
|
||||||
|
<scope>import</scope>
|
||||||
|
<type>pom</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.apptasticsoftware</groupId>
|
||||||
|
<artifactId>rssreader</artifactId>
|
||||||
|
<version>${rssreader.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>dev.sheldan.sissi.application.module.custom</groupId>
|
||||||
|
<artifactId>sissi-customizations</artifactId>
|
||||||
|
<version>1.4.34-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>image-generation-custom</artifactId>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||||
|
<artifactId>image-generation-int</artifactId>
|
||||||
|
<version>${abstracto.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||||
|
<artifactId>core-int</artifactId>
|
||||||
|
<version>${abstracto.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@@ -1,19 +1,18 @@
|
|||||||
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
|
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
|
||||||
<id>docker-compose</id>
|
<id>liquibase</id>
|
||||||
<formats>
|
<formats>
|
||||||
<format>zip</format>
|
<format>zip</format>
|
||||||
</formats>
|
</formats>
|
||||||
<includeBaseDirectory>false</includeBaseDirectory>
|
<includeBaseDirectory>false</includeBaseDirectory>
|
||||||
<fileSets>
|
<fileSets>
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<outputDirectory>./docker-compose</outputDirectory>
|
<outputDirectory>.</outputDirectory>
|
||||||
<directory>${project.basedir}/src/main/resources/</directory>
|
<directory>${project.basedir}/src/main/resources/migrations</directory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>**/*</include>
|
<include>**/*</include>
|
||||||
</includes>
|
</includes>
|
||||||
<filtered>true</filtered>
|
|
||||||
</fileSet>
|
</fileSet>
|
||||||
</fileSets>
|
</fileSets>
|
||||||
</assembly>
|
</assembly>
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package dev.sheldan.sissi.module.custom.imagegeneration.command;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.CommandAlternative;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.CommandRegistry;
|
||||||
|
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||||
|
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||||
|
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||||
|
import dev.sheldan.abstracto.core.templating.model.AttachedFile;
|
||||||
|
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||||
|
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||||
|
import dev.sheldan.abstracto.core.utils.FileService;
|
||||||
|
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||||
|
import dev.sheldan.abstracto.imagegeneration.config.ImageGenerationFeatureConfig;
|
||||||
|
import dev.sheldan.sissi.module.custom.imagegeneration.service.ImageGenerationService;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class OrangeSunDogeCommandAlternative implements CommandAlternative {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ImageGenerationService imageGenerationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TemplateService templateService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ChannelService channelService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FileService fileService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandRegistry commandRegistry;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FeatureFlagService featureFlagService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ImageGenerationFeatureConfig imageGenerationFeatureConfig;
|
||||||
|
|
||||||
|
private static final String DOGE_ORANGE_SUN_RESPONSE_TEMPLATE_KEY = "doge_orangeSun_response";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldExecute(UnParsedCommandParameter parameter, Guild guild, Message message) {
|
||||||
|
String contentStripped = message.getContentRaw();
|
||||||
|
String[] parameters = contentStripped.split(" ");
|
||||||
|
return parameters.length == 1 && featureFlagService.isFeatureEnabled(imageGenerationFeatureConfig, guild.getIdLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(UnParsedCommandParameter parameter, Message message) {
|
||||||
|
String contentStripped = message.getContentRaw();
|
||||||
|
List<String> parameters = Arrays.asList(contentStripped.split(" "));
|
||||||
|
String inputText = commandRegistry.getCommandName(parameters.get(0), message.getGuild().getIdLong());
|
||||||
|
File triggeredGifFile = imageGenerationService.getOrangeSunDogeImage(inputText);
|
||||||
|
MessageToSend messageToSend = templateService.renderEmbedTemplate(DOGE_ORANGE_SUN_RESPONSE_TEMPLATE_KEY, new Object());
|
||||||
|
// template support does not support binary files
|
||||||
|
AttachedFile file = AttachedFile
|
||||||
|
.builder()
|
||||||
|
.file(triggeredGifFile)
|
||||||
|
.fileName("doge.png")
|
||||||
|
.build();
|
||||||
|
messageToSend.getAttachedFiles().add(file);
|
||||||
|
FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, message.getGuildChannel()))
|
||||||
|
.thenAccept(unused -> fileService.safeDeleteIgnoreException(messageToSend.getAttachedFiles().get(0).getFile()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getPriority() {
|
||||||
|
return ListenerPriority.LOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package dev.sheldan.sissi.module.custom.imagegeneration.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@PropertySource("classpath:custom-image-generation-config.properties")
|
||||||
|
public class CustomImageGenerationConfig {
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package dev.sheldan.sissi.module.custom.imagegeneration.service;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
|
import dev.sheldan.abstracto.core.service.HttpService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ImageGenerationService {
|
||||||
|
|
||||||
|
@Value("${abstracto.feature.imagegeneration.doge.orangeSun.url}")
|
||||||
|
private String dogeOrangeSunUrl;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HttpService httpService;
|
||||||
|
|
||||||
|
public File getOrangeSunDogeImage(String inputText) {
|
||||||
|
try {
|
||||||
|
return httpService.downloadFileToTempFile(dogeOrangeSunUrl.replace("{1}", inputText));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new AbstractoRunTimeException(String.format("Failed to download orange doge image for url %s with error %s", inputText, e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
abstracto.feature.imagegeneration.doge.orangeSun.url=http://${PRIVATE_REST_API_HOST}:${PRIVATE_REST_API_PORT}/memes/doge/orangeSun/?text={1}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>dev.sheldan.sissi.application.module.custom</groupId>
|
<groupId>dev.sheldan.sissi.application.module.custom</groupId>
|
||||||
<artifactId>sissi-customizations</artifactId>
|
<artifactId>sissi-customizations</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.4.34-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>application</artifactId>
|
<artifactId>application</artifactId>
|
||||||
<groupId>dev.sheldan.sissi.application</groupId>
|
<groupId>dev.sheldan.sissi.application</groupId>
|
||||||
<version>1.3.4</version>
|
<version>1.4.34-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>moderation-custom</module>
|
<module>moderation-custom</module>
|
||||||
|
<module>image-generation-custom</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
55
application/sissi-modules/debra/pom.xml
Normal file
55
application/sissi-modules/debra/pom.xml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>dev.sheldan.sissi.application</groupId>
|
||||||
|
<artifactId>sissi-modules</artifactId>
|
||||||
|
<version>1.4.34-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>dev.sheldan.sissi.application.module</groupId>
|
||||||
|
<artifactId>debra</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.ehcache</groupId>
|
||||||
|
<artifactId>ehcache</artifactId>
|
||||||
|
<classifier>jakarta</classifier>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context-support</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<descriptors>
|
||||||
|
<descriptor>src/main/assembly/liquibase.xml</descriptor>
|
||||||
|
</descriptors>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
|
||||||
|
<id>liquibase</id>
|
||||||
|
<formats>
|
||||||
|
<format>zip</format>
|
||||||
|
</formats>
|
||||||
|
<includeBaseDirectory>false</includeBaseDirectory>
|
||||||
|
<fileSets>
|
||||||
|
<fileSet>
|
||||||
|
<outputDirectory>.</outputDirectory>
|
||||||
|
<directory>${project.basedir}/src/main/resources/migrations</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
</fileSet>
|
||||||
|
</fileSets>
|
||||||
|
</assembly>
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.api;
|
||||||
|
|
||||||
|
import dev.sheldan.sissi.module.debra.model.api.*;
|
||||||
|
import dev.sheldan.sissi.module.debra.service.DonationService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static dev.sheldan.sissi.module.debra.config.DebraFeatureConfig.DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "/debra")
|
||||||
|
public class DebraDonationStatusController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DonationService donationService;
|
||||||
|
|
||||||
|
@GetMapping(value = "/latestDonations", produces = "application/json")
|
||||||
|
public DonationStats getLatestDonations() {
|
||||||
|
Long serverId = Long.parseLong(System.getenv(DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME));
|
||||||
|
DonationsResponse donationResponse = donationService.getSynchronizedCachedDonationAmount(serverId);
|
||||||
|
List<DonationInfo> donations = donationService.getLatestDonations(donationResponse, Integer.MAX_VALUE)
|
||||||
|
.stream()
|
||||||
|
.map(DonationInfo::fromDonationItemModel)
|
||||||
|
.toList();
|
||||||
|
return DonationStats
|
||||||
|
.builder()
|
||||||
|
.totalAmount(donationResponse.getPage().getCollected())
|
||||||
|
.donations(donations)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/highestDonations", produces = "application/json")
|
||||||
|
public DonationStats getHighestDonations() {
|
||||||
|
Long serverId = Long.parseLong(System.getenv(DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME));
|
||||||
|
DonationsResponse donationResponse = donationService.getSynchronizedCachedDonationAmount(serverId);
|
||||||
|
List<DonationInfo> donations = donationService.getHighestDonations(donationResponse, Integer.MAX_VALUE)
|
||||||
|
.stream()
|
||||||
|
.map(DonationInfo::fromDonationItemModel)
|
||||||
|
.toList();
|
||||||
|
return DonationStats
|
||||||
|
.builder()
|
||||||
|
.totalAmount(donationResponse.getPage().getCollected())
|
||||||
|
.donations(donations)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/campaignInfo", produces = "application/json")
|
||||||
|
public CampaignInfo getCampaignInfo() {
|
||||||
|
Long serverId = Long.parseLong(System.getenv(DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME));
|
||||||
|
DonationsResponse donationResponse = donationService.getSynchronizedCachedDonationAmount(serverId);
|
||||||
|
|
||||||
|
Description pageObject = donationResponse.getPage();
|
||||||
|
return CampaignInfo
|
||||||
|
.builder()
|
||||||
|
.collected(pageObject.getCollected())
|
||||||
|
.collectedNet(pageObject.getCollectedNet())
|
||||||
|
.donationCount(donationResponse.getDonationCount())
|
||||||
|
.currency(pageObject.getCurrency())
|
||||||
|
.percent(pageObject.getPercent())
|
||||||
|
.displayName(pageObject.getDisplayName())
|
||||||
|
.slug(pageObject.getSlug())
|
||||||
|
.target(pageObject.getTarget())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.api;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||||
|
import dev.sheldan.sissi.module.debra.config.DebraFeatureConfig;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.api.DonationsResponse;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.api.EndlessStreamInfo;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.database.EndlessStream;
|
||||||
|
import dev.sheldan.sissi.module.debra.service.DonationService;
|
||||||
|
import dev.sheldan.sissi.module.debra.service.management.EndlessStreamManagementServiceBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
|
||||||
|
import static dev.sheldan.sissi.module.debra.config.DebraFeatureConfig.DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "/stream")
|
||||||
|
public class EndlessStreamController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EndlessStreamManagementServiceBean endlessStreamManagementServiceBean;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DonationService donationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigService configService;
|
||||||
|
|
||||||
|
@GetMapping(value = "/endlessStream/{id}", produces = "application/json")
|
||||||
|
public EndlessStreamInfo getLatestDonations(@PathVariable("id") Long id) {
|
||||||
|
Long serverId = Long.parseLong(System.getenv(DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME));
|
||||||
|
EndlessStream endlessStream = endlessStreamManagementServiceBean.getEndlessStream(id);
|
||||||
|
DonationsResponse donationInfo = donationService.getSynchronizedCachedDonationAmount(serverId);
|
||||||
|
BigDecimal collectedAmount = donationInfo.getPage().getCollected();
|
||||||
|
Long minuteRate = configService.getLongValueOrConfigDefault(DebraFeatureConfig.ENDLESS_STREAM_MINUTE_RATE, serverId);
|
||||||
|
Instant endDate = endlessStream.getStartTime().plus(collectedAmount.multiply(new BigDecimal(minuteRate)).toBigInteger().longValue(), ChronoUnit.MINUTES);
|
||||||
|
return EndlessStreamInfo
|
||||||
|
.builder()
|
||||||
|
.startDate(endlessStream.getStartTime())
|
||||||
|
.endDate(endDate)
|
||||||
|
.donationAmount(collectedAmount.longValue())
|
||||||
|
.minuteRate(minuteRate)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.commands;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||||
|
import dev.sheldan.sissi.module.debra.config.DebraFeatureDefinition;
|
||||||
|
import dev.sheldan.sissi.module.debra.config.DebraSlashCommandNames;
|
||||||
|
import dev.sheldan.sissi.module.debra.service.DonationService;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DebraInfoButton extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
private static final String DEBRA_INFO_BUTTON = "debraInfoButton";
|
||||||
|
private static final String DEBRA_INFO_BUTTON_RESPONSE_TEMPLATE_KEY = "debraInfoButton_response";
|
||||||
|
private static final String TARGET_CHANNEL_PARAMETER_KEY = "targetChannel";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SlashCommandParameterService slashCommandParameterService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DonationService donationService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
|
GuildMessageChannel targetChannel = slashCommandParameterService.getCommandOption(TARGET_CHANNEL_PARAMETER_KEY, event, GuildMessageChannel.class);
|
||||||
|
return donationService.sendDebraInfoButtonMessage(targetChannel)
|
||||||
|
.thenCompose(unused -> interactionService.replyEmbed(DEBRA_INFO_BUTTON_RESPONSE_TEMPLATE_KEY, event))
|
||||||
|
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandConfiguration getConfiguration() {
|
||||||
|
HelpInfo helpInfo = HelpInfo
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||||
|
.builder()
|
||||||
|
.enabled(true)
|
||||||
|
.rootCommandName(DebraSlashCommandNames.DEBRA_INTERNAL)
|
||||||
|
.commandName("debrainfobutton")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Parameter targetChannelParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(TARGET_CHANNEL_PARAMETER_KEY)
|
||||||
|
.type(GuildMessageChannel.class)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
List<Parameter> parameters = Arrays.asList(targetChannelParameter);
|
||||||
|
|
||||||
|
return CommandConfiguration.builder()
|
||||||
|
.name(DEBRA_INFO_BUTTON)
|
||||||
|
.module(UtilityModuleDefinition.UTILITY)
|
||||||
|
.templated(true)
|
||||||
|
.slashCommandConfig(slashCommandConfig)
|
||||||
|
.async(true)
|
||||||
|
.slashCommandOnly(true)
|
||||||
|
.parameters(parameters)
|
||||||
|
.supportsEmbedException(true)
|
||||||
|
.causesReaction(false)
|
||||||
|
.help(helpInfo)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return DebraFeatureDefinition.DEBRA;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.commands;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||||
|
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||||
|
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.sissi.module.debra.config.DebraFeatureDefinition;
|
||||||
|
import dev.sheldan.sissi.module.debra.config.DebraSlashCommandNames;
|
||||||
|
import dev.sheldan.sissi.module.debra.converter.DonationConverter;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.api.DonationsResponse;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.commands.DonationsModel;
|
||||||
|
import dev.sheldan.sissi.module.debra.service.DonationService;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Donations extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
private static final String DONATIONS_COMMAND_NAME = "donations";
|
||||||
|
private static final String DONATIONS_RESPONSE_TEMPLATE_KEY = "donations_response";
|
||||||
|
private static final String SELECTION_PARAMETER = "type";
|
||||||
|
private static final String SELECTION_VALUE_PARAMETER = "parametervalue";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ChannelService channelService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DonationService donationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TemplateService templateService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DonationConverter donationConverter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SlashCommandParameterService slashCommandParameterService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||||
|
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||||
|
MessageToSend messageToSend;
|
||||||
|
if(parameters.isEmpty()) {
|
||||||
|
messageToSend = getDonationMessageToSend(commandContext.getGuild().getIdLong(), null, null);
|
||||||
|
} else {
|
||||||
|
String type = (String) parameters.get(0);
|
||||||
|
Integer selectionValue = (Integer) parameters.get(1);
|
||||||
|
Integer top = null;
|
||||||
|
Integer latest = null;
|
||||||
|
switch (type) {
|
||||||
|
case "top": top = selectionValue; break;
|
||||||
|
default:
|
||||||
|
case "latest" :
|
||||||
|
latest = selectionValue; break;
|
||||||
|
}
|
||||||
|
messageToSend = getDonationMessageToSend(commandContext.getGuild().getIdLong(), top, latest);
|
||||||
|
}
|
||||||
|
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||||
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
|
String selectionType = null;
|
||||||
|
if(slashCommandParameterService.hasCommandOption(SELECTION_PARAMETER, event)) {
|
||||||
|
selectionType = slashCommandParameterService.getCommandOption(SELECTION_PARAMETER, event, String.class);
|
||||||
|
}
|
||||||
|
Integer selectionValue = 5;
|
||||||
|
if(slashCommandParameterService.hasCommandOption(SELECTION_VALUE_PARAMETER, event)) {
|
||||||
|
selectionValue = slashCommandParameterService.getCommandOption(SELECTION_VALUE_PARAMETER, event, Integer.class);
|
||||||
|
}
|
||||||
|
if(selectionValue > 20) {
|
||||||
|
selectionValue = 5;
|
||||||
|
}
|
||||||
|
Integer top = null;
|
||||||
|
Integer latest = null;
|
||||||
|
if(selectionType != null) {
|
||||||
|
switch (selectionType) {
|
||||||
|
case "top": top = selectionValue; break;
|
||||||
|
default:
|
||||||
|
case "latest" :
|
||||||
|
latest = selectionValue; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageToSend messageToSend = getDonationMessageToSend(event.getGuild().getIdLong(), top, latest);
|
||||||
|
return interactionService.replyMessageToSend(messageToSend, event)
|
||||||
|
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
private MessageToSend getDonationMessageToSend(Long serverId, Integer top, Integer latest) {
|
||||||
|
DonationsModel donationModel;
|
||||||
|
DonationsResponse donationResponse = donationService.fetchCurrentDonationAmount(serverId);
|
||||||
|
donationModel = donationConverter.convertDonationResponse(donationResponse);
|
||||||
|
if(top != null) {
|
||||||
|
donationModel.setDonations(donationService.getHighestDonations(donationResponse, top));
|
||||||
|
donationModel.setType(DonationsModel.DonationType.TOP);
|
||||||
|
} else if(latest != null) {
|
||||||
|
donationModel.setType(DonationsModel.DonationType.LATEST);
|
||||||
|
donationModel.setDonations(donationService.getLatestDonations(donationResponse, latest));
|
||||||
|
} else {
|
||||||
|
donationModel.setDonations(new ArrayList<>());
|
||||||
|
}
|
||||||
|
return templateService.renderEmbedTemplate(DONATIONS_RESPONSE_TEMPLATE_KEY, donationModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandConfiguration getConfiguration() {
|
||||||
|
HelpInfo helpInfo = HelpInfo
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||||
|
.builder()
|
||||||
|
.enabled(true)
|
||||||
|
.rootCommandName(DebraSlashCommandNames.DEBRA)
|
||||||
|
.commandName(DONATIONS_COMMAND_NAME)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Parameter selectionParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(SELECTION_PARAMETER)
|
||||||
|
.optional(true)
|
||||||
|
.type(String.class)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
Parameter selectionValueParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(SELECTION_VALUE_PARAMETER)
|
||||||
|
.optional(true)
|
||||||
|
.type(Integer.class)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
List<Parameter> parameters = Arrays.asList(selectionParameter, selectionValueParameter);
|
||||||
|
|
||||||
|
return CommandConfiguration.builder()
|
||||||
|
.name(DONATIONS_COMMAND_NAME)
|
||||||
|
.module(UtilityModuleDefinition.UTILITY)
|
||||||
|
.templated(true)
|
||||||
|
.slashCommandConfig(slashCommandConfig)
|
||||||
|
.async(true)
|
||||||
|
.parameters(parameters)
|
||||||
|
.supportsEmbedException(true)
|
||||||
|
.causesReaction(false)
|
||||||
|
.help(helpInfo)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return DebraFeatureDefinition.DEBRA;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.config;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.ehcache.config.builders.CacheManagerBuilder;
|
||||||
|
import org.ehcache.jsr107.Eh107Configuration;
|
||||||
|
import org.ehcache.xml.XmlConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
|
@EnableCaching
|
||||||
|
public class CacheConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JCacheManagerCustomizer cacheManagerCustomizer() {
|
||||||
|
URL myUrl = getClass().getResource("/donation-cache-config.xml");
|
||||||
|
XmlConfiguration xmlConfig = new XmlConfiguration(myUrl);
|
||||||
|
org.ehcache.CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(xmlConfig);
|
||||||
|
return cm -> {
|
||||||
|
myCacheManager.getRuntimeConfiguration().getCacheConfigurations().entrySet().forEach(cacheConfiguration -> {
|
||||||
|
javax.cache.configuration.Configuration<?, ?> jConfiguration = Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration.getValue());
|
||||||
|
log.info("Creating custom cache: " + cacheConfiguration.getKey());
|
||||||
|
cm.createCache(cacheConfiguration.getKey(), jConfiguration);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.config;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DebraFeatureConfig implements FeatureConfig {
|
||||||
|
|
||||||
|
public static final String DEBRA_DONATION_NOTIFICATION_DELAY_CONFIG_KEY = "debraDonationNotificationDelayMillis";
|
||||||
|
public static final String ENDLESS_STREAM_MINUTE_RATE = "endlessStreamMinuteRate";
|
||||||
|
public static final String DEBRA_DONATION_API_FETCH_SIZE_KEY = "debraDonationApiFetchSize";
|
||||||
|
public static final String DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME = "DEBRA_DONATION_NOTIFICATION_SERVER_ID";
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return DebraFeatureDefinition.DEBRA;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PostTargetEnum> getRequiredPostTargets() {
|
||||||
|
return Arrays.asList(DebraPostTarget.DEBRA_DONATION_NOTIFICATION, DebraPostTarget.DEBRA_DONATION_NOTIFICATION2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getRequiredSystemConfigKeys() {
|
||||||
|
return Arrays.asList(DEBRA_DONATION_NOTIFICATION_DELAY_CONFIG_KEY, DEBRA_DONATION_API_FETCH_SIZE_KEY, ENDLESS_STREAM_MINUTE_RATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.config;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum DebraFeatureDefinition implements FeatureDefinition {
|
||||||
|
DEBRA("debra");
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
DebraFeatureDefinition(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.config;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum DebraPostTarget implements PostTargetEnum {
|
||||||
|
DEBRA_DONATION_NOTIFICATION("debraDonationNotification"), DEBRA_DONATION_NOTIFICATION2("debraDonationNotification2");
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
DebraPostTarget(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@PropertySource("classpath:debra.properties")
|
||||||
|
public class DebraPropertieSource {
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.config;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ConfigurationProperties(prefix = "sissi.debra")
|
||||||
|
public class DebraProperties {
|
||||||
|
private String websocketURL;
|
||||||
|
private String donationAPIUrl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.config;
|
||||||
|
|
||||||
|
public class DebraSlashCommandNames {
|
||||||
|
public static final String DEBRA = "debra";
|
||||||
|
public static final String DEBRA_INTERNAL = "debrainternal";
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.converter;
|
||||||
|
|
||||||
|
import dev.sheldan.sissi.module.debra.model.api.Donation;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.api.DonationsResponse;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.commands.DonationItemModel;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.commands.DonationsModel;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DonationConverter {
|
||||||
|
public DonationItemModel convertDonation(Donation donation) {
|
||||||
|
return DonationItemModel
|
||||||
|
.builder()
|
||||||
|
.donationAmount(donation.getAmount())
|
||||||
|
.firstName(donation.getFirstname())
|
||||||
|
.lastName(donation.getLastname())
|
||||||
|
.anonymous(BooleanUtils.toBoolean(donation.getAnonym()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DonationsModel convertDonationResponse(DonationsResponse response) {
|
||||||
|
return DonationsModel
|
||||||
|
.builder()
|
||||||
|
.totalAmount(response.getPage().getCollected())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.exception;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
|
||||||
|
|
||||||
|
public class DonationAmountNotFoundException extends AbstractoTemplatableException {
|
||||||
|
@Override
|
||||||
|
public String getTemplateName() {
|
||||||
|
return "donation_amount_not_found_exception";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getTemplateModel() {
|
||||||
|
return new Object();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.listener;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListener;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListenerModel;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListenerResult;
|
||||||
|
import dev.sheldan.abstracto.core.service.MessageService;
|
||||||
|
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.sissi.module.debra.config.DebraFeatureDefinition;
|
||||||
|
import dev.sheldan.sissi.module.debra.service.DonationService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class DebraInfoButtonClickedListener implements ButtonClickedListener {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageService messageService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TemplateService templateService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
|
private static final String DEBRA_INFO_MESSAGE_TEMPLATE_KEY = "debraInfoMessage";
|
||||||
|
private static final String DEBRA_INFO_MESSAGE_RESPONSE_TEMPLATE_KEY = "debraInfoMessage_response";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ButtonClickedListenerResult execute(ButtonClickedListenerModel model) {
|
||||||
|
MessageToSend messageToSend = templateService.renderEmbedTemplate(DEBRA_INFO_MESSAGE_TEMPLATE_KEY, new Object(), model.getServerId());
|
||||||
|
messageService.sendMessageToSendToUser(model.getEvent().getUser(), messageToSend).thenAccept(interactionHook -> {
|
||||||
|
log.info("Send debra info message to user {}", model.getEvent().getUser().getIdLong());
|
||||||
|
}).exceptionally(throwable -> {
|
||||||
|
log.error("Failed to send debra info message to user {}", model.getEvent().getUser().getIdLong(), throwable);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
MessageToSend responseMessageToSend = templateService.renderEmbedTemplate(DEBRA_INFO_MESSAGE_RESPONSE_TEMPLATE_KEY, new Object(), model.getServerId());
|
||||||
|
FutureUtils.toSingleFutureGeneric(interactionService.sendMessageToInteraction(responseMessageToSend, model.getEvent().getInteraction().getHook()))
|
||||||
|
.thenAccept(interactionHook -> {
|
||||||
|
log.info("Send debra info message response to user {}", model.getEvent().getUser().getIdLong());
|
||||||
|
}).exceptionally(throwable -> {
|
||||||
|
log.error("Failed to send debra info message response to user {}", model.getEvent().getUser().getIdLong(), throwable);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
return ButtonClickedListenerResult.ACKNOWLEDGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean handlesEvent(ButtonClickedListenerModel model) {
|
||||||
|
return model.getOrigin().equals(DonationService.DEBRA_INFO_BUTTON_ORIGIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return DebraFeatureDefinition.DEBRA;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getPriority() {
|
||||||
|
return ListenerPriority.MEDIUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.listener;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.listener.AsyncStartupListener;
|
||||||
|
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||||
|
import dev.sheldan.sissi.module.debra.config.DebraProperties;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.listener.DonationResponseModel;
|
||||||
|
import dev.sheldan.sissi.module.debra.service.DonationService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import okhttp3.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static dev.sheldan.sissi.module.debra.config.DebraFeatureConfig.DEBRA_DONATION_NOTIFICATION_DELAY_CONFIG_KEY;
|
||||||
|
import static dev.sheldan.sissi.module.debra.config.DebraFeatureConfig.DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class WebsocketListener extends WebSocketListener implements AsyncStartupListener {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DonationService donationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DebraProperties debraProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigService configService;
|
||||||
|
|
||||||
|
private WebSocket webSocketObj;
|
||||||
|
private OkHttpClient clientObj;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOpen(WebSocket webSocket, Response response) {
|
||||||
|
log.info("Connected to donation websocket.");
|
||||||
|
super.onOpen(webSocket, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(WebSocket webSocket, String text) {
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
log.info("Handling received message on websocket.");
|
||||||
|
try {
|
||||||
|
Long targetServerId = Long.parseLong(System.getenv(DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME));
|
||||||
|
Long delayMillis = configService.getLongValueOrConfigDefault(DEBRA_DONATION_NOTIFICATION_DELAY_CONFIG_KEY, targetServerId);
|
||||||
|
log.info("Waiting {} milli seconds to send notification.", delayMillis);
|
||||||
|
Thread.sleep(delayMillis);
|
||||||
|
log.info("Loading new donation amount and sending notification.");
|
||||||
|
DonationResponseModel donation = donationService.parseDonationFromMessage(text);
|
||||||
|
donationService.sendDonationNotification(donation).thenAccept(unused -> {
|
||||||
|
log.info("Successfully notified about donation.");
|
||||||
|
}).exceptionally(throwable -> {
|
||||||
|
log.error("Failed to notify about donation.", throwable);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
} catch (Exception exception) {
|
||||||
|
log.error("Failed to handle websocket message.", exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(WebSocket webSocket, Throwable t, @Nullable Response response) {
|
||||||
|
log.warn("Websocket connection failed...", t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClosing(WebSocket webSocket, int code, String reason) {
|
||||||
|
log.info("Closing websocket connection. It was closed with code {} and reason {}.", code, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
if(clientObj != null) {
|
||||||
|
clientObj.connectionPool().evictAll();
|
||||||
|
clientObj.dispatcher().executorService().shutdownNow();
|
||||||
|
}
|
||||||
|
clientObj = new OkHttpClient.Builder()
|
||||||
|
.readTimeout(0, TimeUnit.MILLISECONDS)
|
||||||
|
.retryOnConnectionFailure(true)
|
||||||
|
.build();
|
||||||
|
startConnection(clientObj);
|
||||||
|
clientObj.dispatcher().executorService().shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startConnection(OkHttpClient client) {
|
||||||
|
log.info("Starting websocket connection.");
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(debraProperties.getWebsocketURL())
|
||||||
|
.build();
|
||||||
|
this.webSocketObj = client.newWebSocket(request, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.api;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Getter
|
||||||
|
public class CampaignInfo {
|
||||||
|
private BigInteger donationCount;
|
||||||
|
private BigDecimal collected;
|
||||||
|
private BigDecimal target;
|
||||||
|
private String currency;
|
||||||
|
private String slug;
|
||||||
|
private String displayName;
|
||||||
|
private BigDecimal collectedNet;
|
||||||
|
private BigDecimal percent;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.api;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class Description {
|
||||||
|
@SerializedName("collected")
|
||||||
|
private BigDecimal collected;
|
||||||
|
@SerializedName("target")
|
||||||
|
private BigDecimal target;
|
||||||
|
@SerializedName("currency")
|
||||||
|
private String currency;
|
||||||
|
@SerializedName("slug")
|
||||||
|
private String slug;
|
||||||
|
@SerializedName("displayname")
|
||||||
|
private String displayName;
|
||||||
|
@SerializedName("collectednet")
|
||||||
|
private BigDecimal collectedNet;
|
||||||
|
@SerializedName("percent")
|
||||||
|
private BigDecimal percent;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.api;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class Donation {
|
||||||
|
@SerializedName("amount")
|
||||||
|
private BigDecimal amount;
|
||||||
|
@SerializedName("currency")
|
||||||
|
private String currency;
|
||||||
|
@SerializedName("text")
|
||||||
|
private String text;
|
||||||
|
@SerializedName("anonym")
|
||||||
|
private Integer anonym;
|
||||||
|
@SerializedName("firstname")
|
||||||
|
private String firstname;
|
||||||
|
@SerializedName("lastname")
|
||||||
|
private String lastname;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.api;
|
||||||
|
|
||||||
|
import dev.sheldan.sissi.module.debra.model.commands.DonationItemModel;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class DonationInfo {
|
||||||
|
private String firstName;
|
||||||
|
private BigDecimal donationAmount;
|
||||||
|
private Boolean anonymous;
|
||||||
|
|
||||||
|
public static DonationInfo fromDonationItemModel(DonationItemModel donationItemModel) {
|
||||||
|
return DonationInfo
|
||||||
|
.builder()
|
||||||
|
.donationAmount(donationItemModel.getDonationAmount())
|
||||||
|
.anonymous(donationItemModel.getAnonymous())
|
||||||
|
.firstName(donationItemModel.getFirstName())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.api;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
public class DonationStats {
|
||||||
|
private List<DonationInfo> donations;
|
||||||
|
private BigDecimal totalAmount;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.api;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class DonationsResponse {
|
||||||
|
@SerializedName("page")
|
||||||
|
private Description page;
|
||||||
|
@SerializedName("donation_count")
|
||||||
|
private BigInteger donationCount;
|
||||||
|
@SerializedName("donations")
|
||||||
|
private List<Donation> donations;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.api;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Getter
|
||||||
|
public class EndlessStreamInfo {
|
||||||
|
private Instant endDate;
|
||||||
|
private Instant startDate;
|
||||||
|
private Long donationAmount;
|
||||||
|
private Long minuteRate;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.commands;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.interaction.button.ButtonPayload;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class DebraInfoButtonPayload implements ButtonPayload {
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.commands;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
public class DebraInfoModel {
|
||||||
|
private String buttonId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.commands;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class DonationItemModel {
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private BigDecimal donationAmount;
|
||||||
|
private Boolean anonymous;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.commands;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
@Setter
|
||||||
|
public class DonationsModel {
|
||||||
|
private BigDecimal totalAmount;
|
||||||
|
private DonationType type;
|
||||||
|
private List<DonationItemModel> donations;
|
||||||
|
|
||||||
|
public enum DonationType {
|
||||||
|
LATEST, TOP
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.database;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table(name = "endless_stream")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class EndlessStream {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "start_time")
|
||||||
|
private Instant startTime;
|
||||||
|
|
||||||
|
@Column(name = "created")
|
||||||
|
private Instant created;
|
||||||
|
|
||||||
|
@Column(name = "updated")
|
||||||
|
private Instant updated;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.listener;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
public class DonationNotificationModel {
|
||||||
|
private DonationResponseModel donation;
|
||||||
|
private BigDecimal totalDonationAmount;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.model.listener;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
@ToString
|
||||||
|
public class DonationResponseModel {
|
||||||
|
private String donatorName;
|
||||||
|
private BigDecimal amount;
|
||||||
|
private String message;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.repository;
|
||||||
|
|
||||||
|
import dev.sheldan.sissi.module.debra.model.database.EndlessStream;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface EndlessStreamRepository extends JpaRepository<EndlessStream, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.service;
|
||||||
|
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public class BigDecimalGsonAdapter implements JsonDeserializer<BigDecimal> {
|
||||||
|
@Override
|
||||||
|
public BigDecimal deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
try {
|
||||||
|
return new BigDecimal(json.getAsString()
|
||||||
|
.replace(".", "")
|
||||||
|
.replace(',', '.'));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new JsonParseException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.service;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.ComponentPayloadService;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.ComponentService;
|
||||||
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||||
|
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||||
|
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||||
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
|
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.sissi.module.debra.exception.DonationAmountNotFoundException;
|
||||||
|
import dev.sheldan.sissi.module.debra.config.DebraPostTarget;
|
||||||
|
import dev.sheldan.sissi.module.debra.config.DebraProperties;
|
||||||
|
import dev.sheldan.sissi.module.debra.converter.DonationConverter;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.api.Donation;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.api.DonationsResponse;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.commands.DebraInfoButtonPayload;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.commands.DebraInfoModel;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.commands.DonationItemModel;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.commands.DonationsModel;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.listener.DonationResponseModel;
|
||||||
|
import dev.sheldan.sissi.module.debra.model.listener.DonationNotificationModel;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static dev.sheldan.sissi.module.debra.config.DebraFeatureConfig.DEBRA_DONATION_API_FETCH_SIZE_KEY;
|
||||||
|
import static dev.sheldan.sissi.module.debra.config.DebraFeatureConfig.DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class DonationService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PostTargetService postTargetService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DebraProperties debraProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TemplateService templateService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OkHttpClient okHttpClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DonationConverter donationConverter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigService configService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ChannelService channelService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ComponentService componentService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ComponentPayloadService componentPayloadService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ServerManagementService serverManagementService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DonationService self;
|
||||||
|
|
||||||
|
private static final String DEBRA_DONATION_NOTIFICATION_TEMPLATE_KEY = "debra_donation_notification";
|
||||||
|
|
||||||
|
private static final Pattern MESSAGE_PATTERN = Pattern.compile("(.*) hat (\\d{1,9},\\d{2}) Euro gespendet!<br \\/>Vielen Dank!<br \\/>Nachricht:<br \\/>(.*)");
|
||||||
|
|
||||||
|
private static final String DEBRA_INFO_BUTTON_MESSAGE_TEMPLATE_KEY = "debraInfoButton";
|
||||||
|
public static final String DEBRA_INFO_BUTTON_ORIGIN = "DEBRA_INFO_BUTTON";
|
||||||
|
|
||||||
|
public DonationResponseModel parseDonationFromMessage(String message) {
|
||||||
|
Matcher matcher = MESSAGE_PATTERN.matcher(message);
|
||||||
|
if (matcher.find()) {
|
||||||
|
String donatorName = matcher.group(1);
|
||||||
|
String amountString = matcher.group(2);
|
||||||
|
BigDecimal amount = new BigDecimal(amountString.replace(',', '.'));
|
||||||
|
String donationMessage = Optional.ofNullable(matcher.group(3)).map(msg -> msg.replaceAll("(<br>)+", " ")).map(String::trim).orElse("");
|
||||||
|
return DonationResponseModel
|
||||||
|
.builder()
|
||||||
|
.message(donationMessage)
|
||||||
|
.donatorName(donatorName)
|
||||||
|
.amount(amount)
|
||||||
|
.build();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("String in wrong format");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DonationItemModel> getHighestDonations(DonationsResponse response, Integer maxCount) {
|
||||||
|
List<Donation> topDonations = response
|
||||||
|
.getDonations()
|
||||||
|
.stream()
|
||||||
|
.sorted(Comparator.comparing(Donation::getAmount)
|
||||||
|
.reversed())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return topDonations
|
||||||
|
.stream()
|
||||||
|
.limit(maxCount)
|
||||||
|
.map(donation -> donationConverter.convertDonation(donation))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DonationItemModel> getLatestDonations(DonationsResponse response, Integer maxCount) {
|
||||||
|
return response
|
||||||
|
.getDonations()
|
||||||
|
.stream()
|
||||||
|
.limit(maxCount)
|
||||||
|
.map(donation -> donationConverter.convertDonation(donation))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized DonationsResponse getSynchronizedCachedDonationAmount(Long serverId) {
|
||||||
|
return self.getCachedDonationAmount(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cacheable(value = "donation-cache")
|
||||||
|
public synchronized DonationsResponse getCachedDonationAmount(Long serverId) {
|
||||||
|
return self.fetchCurrentDonationAmount(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DonationsResponse fetchCurrentDonationAmount(Long serverId) {
|
||||||
|
try {
|
||||||
|
Long fetchSize = configService.getLongValueOrConfigDefault(DEBRA_DONATION_API_FETCH_SIZE_KEY, serverId);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(String.format(debraProperties.getDonationAPIUrl(), fetchSize))
|
||||||
|
.get()
|
||||||
|
.build();
|
||||||
|
Response response = okHttpClient.newCall(request).execute();
|
||||||
|
if(!response.isSuccessful()) {
|
||||||
|
log.error("Failed to retrieve donation response. Response had code {} with body {} and headers {}.",
|
||||||
|
response.code(), response.body().string(), response.headers());
|
||||||
|
throw new DonationAmountNotFoundException();
|
||||||
|
}
|
||||||
|
Gson gson = getGson();
|
||||||
|
return gson.fromJson(response.body().string(), DonationsResponse.class);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
throw new AbstractoRunTimeException(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Gson getGson() {
|
||||||
|
return new GsonBuilder()
|
||||||
|
.registerTypeAdapter(BigDecimal.class, new BigDecimalGsonAdapter())
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private DonationsModel getDonationInfoModel(Long serverId) {
|
||||||
|
return donationConverter.convertDonationResponse(fetchCurrentDonationAmount(serverId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<Void> sendDonationNotification(DonationResponseModel donation) throws IOException {
|
||||||
|
Long targetServerId = Long.parseLong(System.getenv(DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME));
|
||||||
|
DonationsModel donationInfoModel = getDonationInfoModel(targetServerId);
|
||||||
|
DonationNotificationModel model = DonationNotificationModel
|
||||||
|
.builder()
|
||||||
|
.donation(donation)
|
||||||
|
.totalDonationAmount(donationInfoModel.getTotalAmount())
|
||||||
|
.build();
|
||||||
|
MessageToSend messageToSend = templateService.renderEmbedTemplate(DEBRA_DONATION_NOTIFICATION_TEMPLATE_KEY, model);
|
||||||
|
List<CompletableFuture<Message>> firstMessage = postTargetService.sendEmbedInPostTarget(messageToSend, DebraPostTarget.DEBRA_DONATION_NOTIFICATION, targetServerId);
|
||||||
|
List<CompletableFuture<Message>> secondMessage = postTargetService.sendEmbedInPostTarget(messageToSend, DebraPostTarget.DEBRA_DONATION_NOTIFICATION2, targetServerId);
|
||||||
|
firstMessage.addAll(secondMessage);
|
||||||
|
return FutureUtils.toSingleFutureGeneric(firstMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<Void> sendDebraInfoButtonMessage(GuildMessageChannel guildMessageChannel) {
|
||||||
|
String buttonId = componentService.generateComponentId();
|
||||||
|
DebraInfoModel model = DebraInfoModel
|
||||||
|
.builder()
|
||||||
|
.buttonId(buttonId)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
MessageToSend messageToSend = templateService.renderEmbedTemplate(DEBRA_INFO_BUTTON_MESSAGE_TEMPLATE_KEY, model, guildMessageChannel.getGuild().getIdLong());
|
||||||
|
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, guildMessageChannel)).thenAccept(unused -> {
|
||||||
|
self.persistButtonPayload(guildMessageChannel, buttonId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void persistButtonPayload(GuildMessageChannel guildMessageChannel, String buttonId) {
|
||||||
|
DebraInfoButtonPayload payload = DebraInfoButtonPayload
|
||||||
|
.builder()
|
||||||
|
.build();
|
||||||
|
AServer server = serverManagementService.loadServer(guildMessageChannel.getGuild().getIdLong());
|
||||||
|
componentPayloadService.createButtonPayload(buttonId, payload, DEBRA_INFO_BUTTON_ORIGIN, server);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package dev.sheldan.sissi.module.debra.service.management;
|
||||||
|
|
||||||
|
import dev.sheldan.sissi.module.debra.model.database.EndlessStream;
|
||||||
|
import dev.sheldan.sissi.module.debra.repository.EndlessStreamRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class EndlessStreamManagementServiceBean {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EndlessStreamRepository endlessStreamRepository;
|
||||||
|
|
||||||
|
public EndlessStream getEndlessStream(Long id) {
|
||||||
|
return endlessStreamRepository.getReferenceById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
abstracto.featureFlags.debra.featureName=debra
|
||||||
|
abstracto.featureFlags.debra.enabled=false
|
||||||
|
|
||||||
|
abstracto.postTargets.debraDonationNotification.name=debraDonationNotification
|
||||||
|
abstracto.postTargets.debraDonationNotification2.name=debraDonationNotification2
|
||||||
|
|
||||||
|
sissi.debra.websocketURL=ws://spenden.baba.fm:8765/
|
||||||
|
sissi.debra.donationAPIUrl=https://www.altruja.de/api/page/discord-gg-austria-fuer-debra-2023?details=1&num=%s&ort=0
|
||||||
|
|
||||||
|
abstracto.systemConfigs.debraDonationNotificationDelayMillis.name=debraDonationNotificationDelayMillis
|
||||||
|
abstracto.systemConfigs.debraDonationNotificationDelayMillis.longValue=60000
|
||||||
|
|
||||||
|
abstracto.systemConfigs.endlessStreamMinuteRate.name=endlessStreamMinuteRate
|
||||||
|
abstracto.systemConfigs.endlessStreamMinuteRate.longValue=1
|
||||||
|
|
||||||
|
abstracto.systemConfigs.debraDonationApiFetchSize.name=debraDonationApiFetchSize
|
||||||
|
abstracto.systemConfigs.debraDonationApiFetchSize.longValue=1000
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<config
|
||||||
|
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
|
||||||
|
xmlns='http://www.ehcache.org/v3'
|
||||||
|
xsi:schemaLocation="
|
||||||
|
http://www.ehcache.org/v3
|
||||||
|
http://www.ehcache.org/schema/ehcache-core-3.8-1.xsd">
|
||||||
|
<cache uses-template="default" alias="donation-cache">
|
||||||
|
<expiry>
|
||||||
|
<ttl unit="seconds">120</ttl>
|
||||||
|
</expiry>
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<heap unit="entries">5</heap>
|
||||||
|
</resources>
|
||||||
|
</cache>
|
||||||
|
<cache-template name="default">
|
||||||
|
<expiry>
|
||||||
|
<ttl unit="seconds">600</ttl>
|
||||||
|
</expiry>
|
||||||
|
<resources>
|
||||||
|
<heap>50</heap>
|
||||||
|
</resources>
|
||||||
|
</cache-template>
|
||||||
|
</config>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?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" >
|
||||||
|
<include file="seedData/data.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?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" >
|
||||||
|
<property name="utilityModule" value="(SELECT id FROM module WHERE name = 'utility')"/>
|
||||||
|
<property name="debraFeature" value="(SELECT id FROM feature WHERE key = 'debra')"/>
|
||||||
|
|
||||||
|
<changeSet author="Sheldan" id="debra-commands">
|
||||||
|
<insert tableName="command">
|
||||||
|
<column name="name" value="donations"/>
|
||||||
|
<column name="module_id" valueComputed="${utilityModule}"/>
|
||||||
|
<column name="feature_id" valueComputed="${debraFeature}"/>
|
||||||
|
</insert>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?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" >
|
||||||
|
<include file="feature.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="command.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?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" >
|
||||||
|
<changeSet author="Sheldan" id="debra_feature-insertion">
|
||||||
|
<insert tableName="feature">
|
||||||
|
<column name="key" value="debra"/>
|
||||||
|
</insert>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?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" >
|
||||||
|
<include file="seedData/data.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?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" >
|
||||||
|
<property name="utilityModule" value="(SELECT id FROM module WHERE name = 'utility')"/>
|
||||||
|
<property name="debraFeature" value="(SELECT id FROM feature WHERE key = 'debra')"/>
|
||||||
|
|
||||||
|
<changeSet author="Sheldan" id="debraInfoButton-command">
|
||||||
|
<insert tableName="command">
|
||||||
|
<column name="name" value="debraInfoButton"/>
|
||||||
|
<column name="module_id" valueComputed="${utilityModule}"/>
|
||||||
|
<column name="feature_id" valueComputed="${debraFeature}"/>
|
||||||
|
</insert>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?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" >
|
||||||
|
<include file="command.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?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" >
|
||||||
|
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?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" >
|
||||||
|
<changeSet author="Sheldan" id="endless_stream-table">
|
||||||
|
<createTable tableName="endless_stream">
|
||||||
|
<column name="id" autoIncrement="true" type="BIGINT">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="start_time" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||||
|
</createTable>
|
||||||
|
<sql>
|
||||||
|
DROP TRIGGER IF EXISTS endless_stream_update_trigger ON endless_stream;
|
||||||
|
CREATE TRIGGER endless_stream_update_trigger BEFORE UPDATE ON endless_stream FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||||
|
</sql>
|
||||||
|
<sql>
|
||||||
|
DROP TRIGGER IF EXISTS endless_stream_insert_trigger ON endless_stream;
|
||||||
|
CREATE TRIGGER endless_stream_insert_trigger BEFORE INSERT ON endless_stream FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||||
|
</sql>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?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" >
|
||||||
|
<include file="endless_stream.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
|||||||
|
<?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" >
|
||||||
|
<include file="1.3.6/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="1.4.21/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="1.4.29/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>dev.sheldan.sissi.application</groupId>
|
<groupId>dev.sheldan.sissi.application</groupId>
|
||||||
<artifactId>sissi-modules</artifactId>
|
<artifactId>sissi-modules</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.4.34-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
package dev.sheldan.sissi.module.meetup.commands;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||||
|
import dev.sheldan.sissi.module.meetup.config.MeetupFeatureDefinition;
|
||||||
|
import dev.sheldan.sissi.module.meetup.config.MeetupSlashCommandNames;
|
||||||
|
import dev.sheldan.sissi.module.meetup.exception.NotMeetupOrganizerException;
|
||||||
|
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
||||||
|
import dev.sheldan.sissi.module.meetup.service.MeetupServiceBean;
|
||||||
|
import dev.sheldan.sissi.module.meetup.service.management.MeetupManagementServiceBean;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ChangeMeetup extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
private static final String CHANGE_MEETUP_COMMAND = "changeMeetup";
|
||||||
|
private static final String MEETUP_ID_PARAMETER = "meetupId";
|
||||||
|
private static final String MEETUP_NEW_VALUE_PARAMETER = "newValue";
|
||||||
|
private static final String MEETUP_PROPERTY_PARAMETER = "property";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SlashCommandParameterService slashCommandParameterService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MeetupManagementServiceBean meetupManagementServiceBean;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MeetupServiceBean meetupServiceBean;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||||
|
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||||
|
Long meetupId = (Long) parameters.get(0);
|
||||||
|
Meetup meetup = meetupManagementServiceBean.getMeetup(meetupId, commandContext.getGuild().getIdLong());
|
||||||
|
if(!meetup.getOrganizer().getUserReference().getId().equals(commandContext.getAuthor().getIdLong())) {
|
||||||
|
throw new NotMeetupOrganizerException();
|
||||||
|
}
|
||||||
|
String property = (String) parameters.get(1);
|
||||||
|
MeetupProperty propertyEnum = MeetupProperty.valueOf(property);
|
||||||
|
String newValue = (String) parameters.get(2);
|
||||||
|
return updateMeetup(meetup, propertyEnum, newValue).thenApply(unused -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompletableFuture<Void> updateMeetup(Meetup meetup, MeetupProperty propertyEnum, String newValue) {
|
||||||
|
CompletableFuture<Void> future;
|
||||||
|
switch (propertyEnum) {
|
||||||
|
case TOPIC:
|
||||||
|
future = meetupServiceBean.changeMeetupTopic(meetup, newValue);
|
||||||
|
break;
|
||||||
|
case LOCATION:
|
||||||
|
future = meetupServiceBean.changeMeetupLocation(meetup, newValue);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case DESCRIPTION:
|
||||||
|
future = meetupServiceBean.changeMeetupDescription(meetup, newValue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
|
Long meetupId = slashCommandParameterService.getCommandOption(MEETUP_ID_PARAMETER, event, Integer.class).longValue();
|
||||||
|
Meetup meetup = meetupManagementServiceBean.getMeetup(meetupId, event.getGuild().getIdLong());
|
||||||
|
if(!meetup.getOrganizer().getUserReference().getId().equals(event.getMember().getIdLong())) {
|
||||||
|
throw new NotMeetupOrganizerException();
|
||||||
|
}
|
||||||
|
String newValue = slashCommandParameterService.getCommandOption(MEETUP_NEW_VALUE_PARAMETER, event, String.class);
|
||||||
|
String property = slashCommandParameterService.getCommandOption(MEETUP_PROPERTY_PARAMETER, event, String.class);
|
||||||
|
MeetupProperty propertyEnum = MeetupProperty.valueOf(property);
|
||||||
|
return updateMeetup(meetup, propertyEnum, newValue)
|
||||||
|
.thenCompose(commandResult -> interactionService.replyEmbed("changeMeetup_response", event))
|
||||||
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandConfiguration getConfiguration() {
|
||||||
|
Parameter meetupIdParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(MEETUP_ID_PARAMETER)
|
||||||
|
.type(Long.class)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
List<String> meetupProperties = Arrays
|
||||||
|
.stream(MeetupProperty.values())
|
||||||
|
.map(Enum::name)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Parameter meetupPropertyParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(MEETUP_PROPERTY_PARAMETER)
|
||||||
|
.type(String.class)
|
||||||
|
.choices(meetupProperties)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Parameter newValueParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(MEETUP_NEW_VALUE_PARAMETER)
|
||||||
|
.type(String.class)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
List<Parameter> parameters = Arrays.asList(meetupIdParameter, meetupPropertyParameter, newValueParameter);
|
||||||
|
HelpInfo helpInfo = HelpInfo
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||||
|
.builder()
|
||||||
|
.enabled(true)
|
||||||
|
.rootCommandName(MeetupSlashCommandNames.MEETUP)
|
||||||
|
.commandName("changeMeetup")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return CommandConfiguration.builder()
|
||||||
|
.name(CHANGE_MEETUP_COMMAND)
|
||||||
|
.module(UtilityModuleDefinition.UTILITY)
|
||||||
|
.templated(true)
|
||||||
|
.async(true)
|
||||||
|
.slashCommandConfig(slashCommandConfig)
|
||||||
|
.supportsEmbedException(true)
|
||||||
|
.causesReaction(true)
|
||||||
|
.parameters(parameters)
|
||||||
|
.help(helpInfo)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return MeetupFeatureDefinition.MEETUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum MeetupProperty {
|
||||||
|
DESCRIPTION, TOPIC, LOCATION
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand
|
|||||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.validator.MaxStringLengthValidator;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
@@ -71,7 +72,9 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
|||||||
private static final String MEETUP_TIME_PARAMETER = "meetupTime";
|
private static final String MEETUP_TIME_PARAMETER = "meetupTime";
|
||||||
private static final String TOPIC_PARAMETER = "topic";
|
private static final String TOPIC_PARAMETER = "topic";
|
||||||
private static final String DESCRIPTION_PARAMETER = "description";
|
private static final String DESCRIPTION_PARAMETER = "description";
|
||||||
|
private static final String LOCATION_PARAMETER = "location";
|
||||||
private static final String CONFIRMATION_TEMPLATE = "createMeetup_confirmation";
|
private static final String CONFIRMATION_TEMPLATE = "createMeetup_confirmation";
|
||||||
|
private static final String DEFAULT_LOCATION_STRING = "\"\"";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||||
@@ -86,7 +89,7 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
|||||||
}
|
}
|
||||||
AUserInAServer organizer = userInServerManagementService.loadOrCreateUser(commandContext.getAuthor());
|
AUserInAServer organizer = userInServerManagementService.loadOrCreateUser(commandContext.getAuthor());
|
||||||
AChannel meetupChannel = channelManagementService.loadChannel(commandContext.getChannel().getIdLong());
|
AChannel meetupChannel = channelManagementService.loadChannel(commandContext.getChannel().getIdLong());
|
||||||
Meetup meetup = meetupManagementServiceBean.createMeetup(meetupTime, meetupTopic, description, organizer, meetupChannel);
|
Meetup meetup = meetupManagementServiceBean.createMeetup(meetupTime, meetupTopic, description, organizer, meetupChannel, DEFAULT_LOCATION_STRING);
|
||||||
String confirmationId = componentService.generateComponentId();
|
String confirmationId = componentService.generateComponentId();
|
||||||
String cancelId = componentService.generateComponentId();
|
String cancelId = componentService.generateComponentId();
|
||||||
MeetupConfirmationModel model = MeetupConfirmationModel
|
MeetupConfirmationModel model = MeetupConfirmationModel
|
||||||
@@ -95,6 +98,7 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
|||||||
.guildId(commandContext.getGuild().getIdLong())
|
.guildId(commandContext.getGuild().getIdLong())
|
||||||
.description(description)
|
.description(description)
|
||||||
.topic(meetupTopic)
|
.topic(meetupTopic)
|
||||||
|
.location(meetup.getLocation())
|
||||||
.confirmationId(confirmationId)
|
.confirmationId(confirmationId)
|
||||||
.cancelId(cancelId)
|
.cancelId(cancelId)
|
||||||
.meetupId(meetup.getId().getId())
|
.meetupId(meetup.getId().getId())
|
||||||
@@ -117,10 +121,17 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
|||||||
} else {
|
} else {
|
||||||
description = "";
|
description = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String location;
|
||||||
|
if(slashCommandParameterService.hasCommandOption(LOCATION_PARAMETER, event)) {
|
||||||
|
location = slashCommandParameterService.getCommandOption(LOCATION_PARAMETER, event, String.class);
|
||||||
|
} else {
|
||||||
|
location = DEFAULT_LOCATION_STRING;
|
||||||
|
}
|
||||||
Instant meetupTime = Instant.ofEpochSecond(time);
|
Instant meetupTime = Instant.ofEpochSecond(time);
|
||||||
AUserInAServer organizer = userInServerManagementService.loadOrCreateUser(event.getMember());
|
AUserInAServer organizer = userInServerManagementService.loadOrCreateUser(event.getMember());
|
||||||
AChannel meetupChannel = channelManagementService.loadChannel(event.getChannel().getIdLong());
|
AChannel meetupChannel = channelManagementService.loadChannel(event.getChannel().getIdLong());
|
||||||
Meetup meetup = meetupManagementServiceBean.createMeetup(meetupTime, topic, description, organizer, meetupChannel);
|
Meetup meetup = meetupManagementServiceBean.createMeetup(meetupTime, topic, description, organizer, meetupChannel, location);
|
||||||
String confirmationId = componentService.generateComponentId();
|
String confirmationId = componentService.generateComponentId();
|
||||||
String cancelId = componentService.generateComponentId();
|
String cancelId = componentService.generateComponentId();
|
||||||
MeetupConfirmationModel model = MeetupConfirmationModel
|
MeetupConfirmationModel model = MeetupConfirmationModel
|
||||||
@@ -129,6 +140,7 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
|||||||
.guildId(event.getGuild().getIdLong())
|
.guildId(event.getGuild().getIdLong())
|
||||||
.description(description)
|
.description(description)
|
||||||
.topic(topic)
|
.topic(topic)
|
||||||
|
.location(meetup.getLocation())
|
||||||
.confirmationId(confirmationId)
|
.confirmationId(confirmationId)
|
||||||
.cancelId(cancelId)
|
.cancelId(cancelId)
|
||||||
.meetupId(meetup.getId().getId())
|
.meetupId(meetup.getId().getId())
|
||||||
@@ -166,7 +178,17 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
|||||||
.type(String.class)
|
.type(String.class)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
List<Parameter> parameters = Arrays.asList(timeParameter, topicParameter, descriptionParameter);
|
Parameter locationParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(LOCATION_PARAMETER)
|
||||||
|
.remainder(true)
|
||||||
|
.optional(true)
|
||||||
|
.slashCommandOnly(true)
|
||||||
|
.type(String.class)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
List<Parameter> parameters = Arrays.asList(timeParameter, topicParameter, descriptionParameter, locationParameter);
|
||||||
HelpInfo helpInfo = HelpInfo
|
HelpInfo helpInfo = HelpInfo
|
||||||
.builder()
|
.builder()
|
||||||
.templated(true)
|
.templated(true)
|
||||||
|
|||||||
@@ -49,19 +49,19 @@ public class ListMeetups extends AbstractConditionableCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||||
MessageToSend messageToSend = getMessageToSend(commandContext.getGuild().getIdLong());
|
MessageToSend messageToSend = getMessageToSend(commandContext.getGuild().getIdLong(), commandContext.getChannel().getIdLong());
|
||||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||||
.thenApply(unused -> CommandResult.fromIgnored());
|
.thenApply(unused -> CommandResult.fromIgnored());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
return interactionService.replyMessageToSend(getMessageToSend(event.getGuild().getIdLong()), event)
|
return interactionService.replyMessageToSend(getMessageToSend(event.getGuild().getIdLong(), event.getChannel().getIdLong()), event)
|
||||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
private MessageToSend getMessageToSend(Long serverId) {
|
private MessageToSend getMessageToSend(Long serverId, Long channelId) {
|
||||||
List<Meetup> meetups = meetupManagementServiceBean.getIncomingMeetups();
|
List<Meetup> meetups = meetupManagementServiceBean.getIncomingMeetups(serverId, channelId);
|
||||||
List<MeetupListItemModel> listItems = meetups
|
List<MeetupListItemModel> listItems = meetups
|
||||||
.stream()
|
.stream()
|
||||||
.map(MeetupListItemModel::fromMeetup)
|
.map(MeetupListItemModel::fromMeetup)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import dev.sheldan.sissi.module.meetup.config.MeetupFeatureDefinition;
|
|||||||
import dev.sheldan.sissi.module.meetup.config.MeetupSlashCommandNames;
|
import dev.sheldan.sissi.module.meetup.config.MeetupSlashCommandNames;
|
||||||
import dev.sheldan.sissi.module.meetup.exception.NotMeetupOrganizerException;
|
import dev.sheldan.sissi.module.meetup.exception.NotMeetupOrganizerException;
|
||||||
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
||||||
|
import dev.sheldan.sissi.module.meetup.model.database.MeetupDecision;
|
||||||
import dev.sheldan.sissi.module.meetup.service.MeetupServiceBean;
|
import dev.sheldan.sissi.module.meetup.service.MeetupServiceBean;
|
||||||
import dev.sheldan.sissi.module.meetup.service.management.MeetupManagementServiceBean;
|
import dev.sheldan.sissi.module.meetup.service.management.MeetupManagementServiceBean;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
@@ -24,6 +25,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class NotifyMeetupParticipants extends AbstractConditionableCommand {
|
public class NotifyMeetupParticipants extends AbstractConditionableCommand {
|
||||||
@@ -42,6 +44,7 @@ public class NotifyMeetupParticipants extends AbstractConditionableCommand {
|
|||||||
|
|
||||||
private static final String MEETUP_ID_PARAMETER = "meetupId";
|
private static final String MEETUP_ID_PARAMETER = "meetupId";
|
||||||
private static final String NOTIFICATION_MESSAGE_PARAMETER = "notificationMessage";
|
private static final String NOTIFICATION_MESSAGE_PARAMETER = "notificationMessage";
|
||||||
|
private static final String NOTIFICATION_MEETUP_DECISION = "decision";
|
||||||
private static final String NOTIFY_MEETUP_PARTICIPANTS_COMMAND = "notifyMeetupParticipants";
|
private static final String NOTIFY_MEETUP_PARTICIPANTS_COMMAND = "notifyMeetupParticipants";
|
||||||
private static final String NOTIFY_MEETUP_PARTICIPANTS_RESPONSE = "notifyMeetupParticipants_response";
|
private static final String NOTIFY_MEETUP_PARTICIPANTS_RESPONSE = "notifyMeetupParticipants_response";
|
||||||
|
|
||||||
@@ -54,7 +57,7 @@ public class NotifyMeetupParticipants extends AbstractConditionableCommand {
|
|||||||
throw new NotMeetupOrganizerException();
|
throw new NotMeetupOrganizerException();
|
||||||
}
|
}
|
||||||
String notificationMessage = (String) parameters.get(1);
|
String notificationMessage = (String) parameters.get(1);
|
||||||
return meetupServiceBean.notifyMeetupParticipants(meetup, notificationMessage)
|
return meetupServiceBean.notifyMeetupParticipants(meetup, notificationMessage, null)
|
||||||
.thenApply(unused -> CommandResult.fromSuccess());
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,8 +68,12 @@ public class NotifyMeetupParticipants extends AbstractConditionableCommand {
|
|||||||
if(!meetup.getOrganizer().getUserReference().getId().equals(event.getMember().getIdLong())) {
|
if(!meetup.getOrganizer().getUserReference().getId().equals(event.getMember().getIdLong())) {
|
||||||
throw new NotMeetupOrganizerException();
|
throw new NotMeetupOrganizerException();
|
||||||
}
|
}
|
||||||
|
MeetupDecision toNotify = null;
|
||||||
|
if(slashCommandParameterService.hasCommandOption(NOTIFICATION_MEETUP_DECISION, event)) {
|
||||||
|
toNotify = MeetupDecision.valueOf(slashCommandParameterService.getCommandOption(NOTIFICATION_MEETUP_DECISION, event, String.class));
|
||||||
|
}
|
||||||
String notificationMessage = slashCommandParameterService.getCommandOption(NOTIFICATION_MESSAGE_PARAMETER, event, String.class);
|
String notificationMessage = slashCommandParameterService.getCommandOption(NOTIFICATION_MESSAGE_PARAMETER, event, String.class);
|
||||||
return meetupServiceBean.notifyMeetupParticipants(meetup, notificationMessage)
|
return meetupServiceBean.notifyMeetupParticipants(meetup, notificationMessage, toNotify)
|
||||||
.thenCompose(unused -> interactionService.replyEmbed(NOTIFY_MEETUP_PARTICIPANTS_RESPONSE, event))
|
.thenCompose(unused -> interactionService.replyEmbed(NOTIFY_MEETUP_PARTICIPANTS_RESPONSE, event))
|
||||||
.thenApply(unused -> CommandResult.fromSuccess());
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
}
|
}
|
||||||
@@ -88,7 +95,22 @@ public class NotifyMeetupParticipants extends AbstractConditionableCommand {
|
|||||||
.remainder(true)
|
.remainder(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
List<Parameter> parameters = Arrays.asList(meetupIdParameter, notificationMessage);
|
List<String> meetupDecisions = Arrays
|
||||||
|
.stream(MeetupDecision.values())
|
||||||
|
.map(Enum::name)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Parameter meetupDecisionChoice = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(NOTIFICATION_MEETUP_DECISION)
|
||||||
|
.type(String.class)
|
||||||
|
.optional(true)
|
||||||
|
.choices(meetupDecisions)
|
||||||
|
.slashCommandOnly(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
List<Parameter> parameters = Arrays.asList(meetupIdParameter, notificationMessage, meetupDecisionChoice);
|
||||||
HelpInfo helpInfo = HelpInfo
|
HelpInfo helpInfo = HelpInfo
|
||||||
.builder()
|
.builder()
|
||||||
.templated(true)
|
.templated(true)
|
||||||
|
|||||||
@@ -2,8 +2,14 @@ package dev.sheldan.sissi.module.meetup.config;
|
|||||||
|
|
||||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static dev.sheldan.sissi.module.meetup.config.MeetupFeatureMode.ATTACH_ICS_FILE;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class MeetupFeatureConfig implements FeatureConfig {
|
public class MeetupFeatureConfig implements FeatureConfig {
|
||||||
@Override
|
@Override
|
||||||
@@ -11,4 +17,8 @@ public class MeetupFeatureConfig implements FeatureConfig {
|
|||||||
return MeetupFeatureDefinition.MEETUP;
|
return MeetupFeatureDefinition.MEETUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FeatureMode> getAvailableModes() {
|
||||||
|
return Arrays.asList(ATTACH_ICS_FILE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.sissi.module.meetup.config;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum MeetupFeatureMode implements FeatureMode {
|
||||||
|
ATTACH_ICS_FILE("attachIcsFile");
|
||||||
|
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
MeetupFeatureMode(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,6 @@ import org.springframework.stereotype.Component;
|
|||||||
@PersistJobDataAfterExecution
|
@PersistJobDataAfterExecution
|
||||||
public class MeetupCleanupJob extends QuartzJobBean {
|
public class MeetupCleanupJob extends QuartzJobBean {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MeetupServiceBean meetupServiceBean;
|
private MeetupServiceBean meetupServiceBean;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import dev.sheldan.abstracto.core.service.MessageService;
|
|||||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||||
|
import dev.sheldan.abstracto.core.utils.FileService;
|
||||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||||
import dev.sheldan.sissi.module.meetup.config.MeetupFeatureDefinition;
|
import dev.sheldan.sissi.module.meetup.config.MeetupFeatureDefinition;
|
||||||
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
||||||
@@ -76,6 +77,9 @@ public class MeetupConfirmationListener implements ButtonClickedListener {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MeetupComponentManagementServiceBean meetupComponentManagementServiceBean;
|
private MeetupComponentManagementServiceBean meetupComponentManagementServiceBean;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FileService fileService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ButtonClickedListenerResult execute(ButtonClickedListenerModel model) {
|
public ButtonClickedListenerResult execute(ButtonClickedListenerModel model) {
|
||||||
MeetupConfirmationPayload payload = (MeetupConfirmationPayload) model.getDeserializedPayload();
|
MeetupConfirmationPayload payload = (MeetupConfirmationPayload) model.getDeserializedPayload();
|
||||||
@@ -104,6 +108,10 @@ public class MeetupConfirmationListener implements ButtonClickedListener {
|
|||||||
messageModel.setNoId(noButtonId);
|
messageModel.setNoId(noButtonId);
|
||||||
messageModel.setMaybeId(maybeButtonId);
|
messageModel.setMaybeId(maybeButtonId);
|
||||||
messageModel.setNoTimeId(noTimeButtonId);
|
messageModel.setNoTimeId(noTimeButtonId);
|
||||||
|
meetup.setYesButtonId(yesButtonId);
|
||||||
|
meetup.setMaybeButtonId(maybeButtonId);
|
||||||
|
meetup.setNoTimeButtonId(noTimeButtonId);
|
||||||
|
meetup.setNotInterestedButtonId(noButtonId);
|
||||||
messageModel.setCancelled(false);
|
messageModel.setCancelled(false);
|
||||||
Long meetupId = payload.getMeetupId();
|
Long meetupId = payload.getMeetupId();
|
||||||
Long serverId = payload.getGuildId();
|
Long serverId = payload.getGuildId();
|
||||||
@@ -111,6 +119,9 @@ public class MeetupConfirmationListener implements ButtonClickedListener {
|
|||||||
List<CompletableFuture<Message>> messageFutures = channelService.sendMessageToSendToChannel(messageToSend, model.getEvent().getMessageChannel());
|
List<CompletableFuture<Message>> messageFutures = channelService.sendMessageToSendToChannel(messageToSend, model.getEvent().getMessageChannel());
|
||||||
FutureUtils.toSingleFutureGeneric(messageFutures).thenAccept(unused -> {
|
FutureUtils.toSingleFutureGeneric(messageFutures).thenAccept(unused -> {
|
||||||
messageService.deleteMessage(model.getEvent().getMessage());
|
messageService.deleteMessage(model.getEvent().getMessage());
|
||||||
|
messageToSend.getAttachedFiles().forEach(attachedFile -> {
|
||||||
|
fileService.safeDeleteIgnoreException(attachedFile.getFile());
|
||||||
|
});
|
||||||
Message meetupMessage = messageFutures.get(0).join();
|
Message meetupMessage = messageFutures.get(0).join();
|
||||||
messageService.pinMessage(meetupMessage);
|
messageService.pinMessage(meetupMessage);
|
||||||
self.persistPayloads(meetupId, serverId, yesButtonId, noButtonId, maybeButtonId, noTimeButtonId, meetupMessage);
|
self.persistPayloads(meetupId, serverId, yesButtonId, noButtonId, maybeButtonId, noTimeButtonId, meetupMessage);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public class MeetupConfirmationModel {
|
|||||||
private MemberDisplay organizer;
|
private MemberDisplay organizer;
|
||||||
private Instant meetupTime;
|
private Instant meetupTime;
|
||||||
private Long meetupId;
|
private Long meetupId;
|
||||||
|
private String location;
|
||||||
private String topic;
|
private String topic;
|
||||||
private String description;
|
private String description;
|
||||||
private Long guildId;
|
private Long guildId;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import dev.sheldan.abstracto.core.models.database.AServer;
|
|||||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -43,6 +43,26 @@ public class Meetup {
|
|||||||
@Column(name = "message_id")
|
@Column(name = "message_id")
|
||||||
private Long messageId;
|
private Long messageId;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Column(name = "location")
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Column(name = "yes_button_id")
|
||||||
|
private String yesButtonId;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Column(name = "maybe_button_id")
|
||||||
|
private String maybeButtonId;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Column(name = "no_time_button_id")
|
||||||
|
private String noTimeButtonId;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Column(name = "not_interested_button_id")
|
||||||
|
private String notInterestedButtonId;
|
||||||
|
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
fetch = FetchType.LAZY,
|
fetch = FetchType.LAZY,
|
||||||
orphanRemoval = true,
|
orphanRemoval = true,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import dev.sheldan.abstracto.core.models.database.ComponentPayload;
|
|||||||
import dev.sheldan.sissi.module.meetup.model.database.embed.MeetupComponentId;
|
import dev.sheldan.sissi.module.meetup.model.database.embed.MeetupComponentId;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
|||||||
import dev.sheldan.sissi.module.meetup.model.database.embed.MeetupParticipationId;
|
import dev.sheldan.sissi.module.meetup.model.database.embed.MeetupParticipationId;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package dev.sheldan.sissi.module.meetup.model.database.embed;
|
|||||||
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Embeddable;
|
import jakarta.persistence.Embeddable;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Embeddable
|
@Embeddable
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package dev.sheldan.sissi.module.meetup.model.database.embed;
|
|||||||
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Embeddable;
|
import jakarta.persistence.Embeddable;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Embeddable
|
@Embeddable
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package dev.sheldan.sissi.module.meetup.model.template;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
@Setter
|
||||||
|
public class MeetupIcsModel {
|
||||||
|
private Boolean attachIcsFile;
|
||||||
|
private String iceFileName;
|
||||||
|
private String icsFormattedCreationTime;
|
||||||
|
private String icsFormattedStartTime;
|
||||||
|
private String icsFormattedEndTime;
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@ public class MeetupMessageModel {
|
|||||||
private String topic;
|
private String topic;
|
||||||
private String description;
|
private String description;
|
||||||
private Instant meetupTime;
|
private Instant meetupTime;
|
||||||
|
private String location;
|
||||||
|
private String decodedLocation;
|
||||||
private MemberDisplay organizer;
|
private MemberDisplay organizer;
|
||||||
private Long meetupId;
|
private Long meetupId;
|
||||||
private String yesId;
|
private String yesId;
|
||||||
@@ -26,4 +28,5 @@ public class MeetupMessageModel {
|
|||||||
private List<MemberDisplay> maybeParticipants;
|
private List<MemberDisplay> maybeParticipants;
|
||||||
private List<MemberDisplay> noTimeParticipants;
|
private List<MemberDisplay> noTimeParticipants;
|
||||||
private List<MemberDisplay> declinedParticipants;
|
private List<MemberDisplay> declinedParticipants;
|
||||||
|
private MeetupIcsModel meetupIcsModel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,7 @@ import java.util.List;
|
|||||||
public class MeetupNotificationModel {
|
public class MeetupNotificationModel {
|
||||||
private List<MemberDisplay> participants;
|
private List<MemberDisplay> participants;
|
||||||
private String notificationMessage;
|
private String notificationMessage;
|
||||||
|
private Long meetupMessageId;
|
||||||
|
private String meetupTopic;
|
||||||
|
private Long meetupId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import java.util.List;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface MeetupRepository extends JpaRepository<Meetup, ServerSpecificId> {
|
public interface MeetupRepository extends JpaRepository<Meetup, ServerSpecificId> {
|
||||||
List<Meetup> findByMeetupTimeLessThan(Instant date);
|
List<Meetup> findByMeetupTimeLessThan(Instant date);
|
||||||
List<Meetup> findByMeetupTimeGreaterThan(Instant date);
|
List<Meetup> findByMeetupTimeGreaterThanAndStateAndServer_IdAndMeetupChannel_Id(Instant date, MeetupState state, Long serverId, Long channelId);
|
||||||
List<Meetup> findByMeetupTimeGreaterThanAndState(Instant date, MeetupState state);
|
|
||||||
List<Meetup> findByState(MeetupState state);
|
List<Meetup> findByState(MeetupState state);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package dev.sheldan.sissi.module.meetup.service;
|
package dev.sheldan.sissi.module.meetup.service;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.interaction.ComponentPayloadManagementService;
|
import dev.sheldan.abstracto.core.interaction.ComponentPayloadManagementService;
|
||||||
import dev.sheldan.abstracto.core.interaction.ComponentPayloadService;
|
import dev.sheldan.abstracto.core.interaction.ComponentPayloadService;
|
||||||
import dev.sheldan.abstracto.core.models.ServerChannelMessage;
|
import dev.sheldan.abstracto.core.models.ServerChannelMessage;
|
||||||
@@ -9,9 +10,12 @@ import dev.sheldan.abstracto.core.service.*;
|
|||||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||||
|
import dev.sheldan.abstracto.core.utils.FileService;
|
||||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||||
import dev.sheldan.abstracto.scheduling.model.JobParameters;
|
import dev.sheldan.abstracto.scheduling.model.JobParameters;
|
||||||
import dev.sheldan.abstracto.scheduling.service.SchedulerService;
|
import dev.sheldan.abstracto.scheduling.service.SchedulerService;
|
||||||
|
import dev.sheldan.sissi.module.meetup.config.MeetupFeatureDefinition;
|
||||||
|
import dev.sheldan.sissi.module.meetup.config.MeetupFeatureMode;
|
||||||
import dev.sheldan.sissi.module.meetup.model.command.MeetupChangeTimeConfirmationModel;
|
import dev.sheldan.sissi.module.meetup.model.command.MeetupChangeTimeConfirmationModel;
|
||||||
import dev.sheldan.sissi.module.meetup.model.command.MeetupConfirmationModel;
|
import dev.sheldan.sissi.module.meetup.model.command.MeetupConfirmationModel;
|
||||||
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
||||||
@@ -20,6 +24,7 @@ import dev.sheldan.sissi.module.meetup.model.database.MeetupParticipant;
|
|||||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupState;
|
import dev.sheldan.sissi.module.meetup.model.database.MeetupState;
|
||||||
import dev.sheldan.sissi.module.meetup.model.payload.MeetupChangeTimeConfirmationPayload;
|
import dev.sheldan.sissi.module.meetup.model.payload.MeetupChangeTimeConfirmationPayload;
|
||||||
import dev.sheldan.sissi.module.meetup.model.payload.MeetupConfirmationPayload;
|
import dev.sheldan.sissi.module.meetup.model.payload.MeetupConfirmationPayload;
|
||||||
|
import dev.sheldan.sissi.module.meetup.model.template.MeetupIcsModel;
|
||||||
import dev.sheldan.sissi.module.meetup.model.template.MeetupMessageModel;
|
import dev.sheldan.sissi.module.meetup.model.template.MeetupMessageModel;
|
||||||
import dev.sheldan.sissi.module.meetup.model.template.MeetupNotificationModel;
|
import dev.sheldan.sissi.module.meetup.model.template.MeetupNotificationModel;
|
||||||
import dev.sheldan.sissi.module.meetup.model.template.MeetupTimeChangedNotificationModel;
|
import dev.sheldan.sissi.module.meetup.model.template.MeetupTimeChangedNotificationModel;
|
||||||
@@ -33,7 +38,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -75,6 +86,9 @@ public class MeetupServiceBean {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MeetupServiceBean self;
|
private MeetupServiceBean self;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FileService fileService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ChannelService channelService;
|
private ChannelService channelService;
|
||||||
|
|
||||||
@@ -87,11 +101,16 @@ public class MeetupServiceBean {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SchedulerService schedulerService;
|
private SchedulerService schedulerService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FeatureModeService featureModeService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MeetupParticipatorManagementServiceBean meetupParticipatorManagementServiceBean;
|
private MeetupParticipatorManagementServiceBean meetupParticipatorManagementServiceBean;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MeetupComponentManagementServiceBean meetupComponentManagementServiceBean;
|
private MeetupComponentManagementServiceBean meetupComponentManagementServiceBean;
|
||||||
|
private static final String ICS_TIME_STAMP_FORMAT = "yMMdd'T'kkmmss'Z'";
|
||||||
|
private static final DateTimeFormatter ICS_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(ICS_TIME_STAMP_FORMAT);
|
||||||
|
|
||||||
public void storeMeetupConfirmation(MeetupConfirmationModel model) {
|
public void storeMeetupConfirmation(MeetupConfirmationModel model) {
|
||||||
AServer server = serverManagementService.loadServer(model.getGuildId());
|
AServer server = serverManagementService.loadServer(model.getGuildId());
|
||||||
@@ -122,6 +141,22 @@ public class MeetupServiceBean {
|
|||||||
componentPayloadService.createButtonPayload(model.getCancelId(), confirmationPayload, MEETUP_CHANGE_TIME_CONFIRMATION_BUTTON, server);
|
componentPayloadService.createButtonPayload(model.getCancelId(), confirmationPayload, MEETUP_CHANGE_TIME_CONFIRMATION_BUTTON, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MeetupIcsModel getMeetupICSModel(Meetup meetup) {
|
||||||
|
ZonedDateTime startTime = meetup.getMeetupTime().atZone(ZoneId.of("UTC"));
|
||||||
|
ZonedDateTime endTime = meetup.getMeetupTime().plus(1, ChronoUnit.HOURS).atZone(ZoneId.of("UTC"));
|
||||||
|
String icsFormattedStartTime = startTime.format(ICS_DATE_TIME_FORMATTER);
|
||||||
|
String icsFormattedEndTime = endTime.format(ICS_DATE_TIME_FORMATTER);
|
||||||
|
String icsFormattedMeetupCreationTime = Instant.now().atZone(ZoneId.of("UTC"))
|
||||||
|
.format(ICS_DATE_TIME_FORMATTER);
|
||||||
|
boolean attachIcsFile = featureModeService.featureModeActive(MeetupFeatureDefinition.MEETUP, meetup.getServer().getId(), MeetupFeatureMode.ATTACH_ICS_FILE);
|
||||||
|
return MeetupIcsModel
|
||||||
|
.builder()
|
||||||
|
.attachIcsFile(attachIcsFile)
|
||||||
|
.icsFormattedCreationTime(icsFormattedMeetupCreationTime)
|
||||||
|
.icsFormattedStartTime(icsFormattedStartTime)
|
||||||
|
.icsFormattedEndTime(icsFormattedEndTime)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
public MeetupMessageModel getMeetupMessageModel(Meetup meetup) {
|
public MeetupMessageModel getMeetupMessageModel(Meetup meetup) {
|
||||||
List<MeetupParticipant> allParticipants = meetup.getParticipants();
|
List<MeetupParticipant> allParticipants = meetup.getParticipants();
|
||||||
@@ -141,10 +176,17 @@ public class MeetupServiceBean {
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(meetupParticipator -> meetupParticipator.getDecision().equals(MeetupDecision.NO_TIME))
|
.filter(meetupParticipator -> meetupParticipator.getDecision().equals(MeetupDecision.NO_TIME))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
String rawLocation = java.net.URLDecoder.decode(meetup.getLocation(), StandardCharsets.UTF_8);
|
||||||
return MeetupMessageModel
|
return MeetupMessageModel
|
||||||
.builder()
|
.builder()
|
||||||
.description(meetup.getDescription())
|
.description(meetup.getDescription())
|
||||||
.topic(meetup.getTopic())
|
.topic(meetup.getTopic())
|
||||||
|
.location(meetup.getLocation())
|
||||||
|
.decodedLocation(rawLocation)
|
||||||
|
.noTimeId(meetup.getNoTimeButtonId())
|
||||||
|
.yesId(meetup.getYesButtonId())
|
||||||
|
.maybeId(meetup.getMaybeButtonId())
|
||||||
|
.noId(meetup.getNotInterestedButtonId())
|
||||||
.meetupTime(meetup.getMeetupTime())
|
.meetupTime(meetup.getMeetupTime())
|
||||||
.meetupId(meetup.getId().getId())
|
.meetupId(meetup.getId().getId())
|
||||||
.participants(getMemberDisplays(participating))
|
.participants(getMemberDisplays(participating))
|
||||||
@@ -153,6 +195,7 @@ public class MeetupServiceBean {
|
|||||||
.maybeParticipants(getMemberDisplays(maybe))
|
.maybeParticipants(getMemberDisplays(maybe))
|
||||||
.cancelled(meetup.getState().equals(MeetupState.CANCELLED))
|
.cancelled(meetup.getState().equals(MeetupState.CANCELLED))
|
||||||
.organizer(MemberDisplay.fromAUserInAServer(meetup.getOrganizer()))
|
.organizer(MemberDisplay.fromAUserInAServer(meetup.getOrganizer()))
|
||||||
|
.meetupIcsModel(getMeetupICSModel(meetup))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,8 +293,8 @@ public class MeetupServiceBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Void> notifyMeetupParticipants(Meetup meetup, String message) {
|
public CompletableFuture<Void> notifyMeetupParticipants(Meetup meetup, String message, MeetupDecision toNotify) {
|
||||||
List<MeetupDecision> decisionsToBeNotified = Arrays.asList(MeetupDecision.MAYBE, MeetupDecision.YES);
|
List<MeetupDecision> decisionsToBeNotified = toNotify == null ? Arrays.asList(MeetupDecision.MAYBE, MeetupDecision.YES) : Arrays.asList(toNotify);
|
||||||
List<MemberDisplay> participants = meetup
|
List<MemberDisplay> participants = meetup
|
||||||
.getParticipants()
|
.getParticipants()
|
||||||
.stream()
|
.stream()
|
||||||
@@ -262,6 +305,9 @@ public class MeetupServiceBean {
|
|||||||
MeetupNotificationModel model = MeetupNotificationModel
|
MeetupNotificationModel model = MeetupNotificationModel
|
||||||
.builder()
|
.builder()
|
||||||
.notificationMessage(message)
|
.notificationMessage(message)
|
||||||
|
.meetupId(meetup.getId().getId())
|
||||||
|
.meetupMessageId(meetup.getMessageId())
|
||||||
|
.meetupTopic(meetup.getTopic())
|
||||||
.participants(participants)
|
.participants(participants)
|
||||||
.build();
|
.build();
|
||||||
MessageChannel channel = channelService.getMessageChannelFromServer(meetup.getServer().getId(), meetup.getMeetupChannel().getId());
|
MessageChannel channel = channelService.getMessageChannelFromServer(meetup.getServer().getId(), meetup.getMeetupChannel().getId());
|
||||||
@@ -379,8 +425,43 @@ public class MeetupServiceBean {
|
|||||||
|
|
||||||
MessageToSend updatedMeetupMessage = getMeetupMessage(meetupMessageModel);
|
MessageToSend updatedMeetupMessage = getMeetupMessage(meetupMessageModel);
|
||||||
GuildMessageChannel meetupChannel = channelService.getMessageChannelFromServer(serverId, meetup.getMeetupChannel().getId());
|
GuildMessageChannel meetupChannel = channelService.getMessageChannelFromServer(serverId, meetup.getMeetupChannel().getId());
|
||||||
return channelService.editEmbedMessageInAChannel(updatedMeetupMessage.getEmbeds().get(0), meetupChannel, meetup.getMessageId())
|
return channelService.editMessageInAChannelFuture(updatedMeetupMessage, meetupChannel, meetup.getMessageId())
|
||||||
.thenAccept(message -> log.info("Updated message of meetup {} in channel {} in server {}.", meetupId, meetup.getMeetupChannel().getId(), serverId))
|
.thenAccept(message -> log.info("Updated message of meetup {} in channel {} in server {}.", meetupId, meetup.getMeetupChannel().getId(), serverId))
|
||||||
|
.thenAccept(unused -> fileService.safeDeleteIgnoreException(updatedMeetupMessage.getAttachedFiles().get(0).getFile()))
|
||||||
|
.exceptionally(throwable -> {
|
||||||
|
log.info("Failed to update message of meetup {} in channel {} in server {}.", meetupId, meetup.getMeetupChannel().getId(), serverId, throwable);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<Void> changeMeetupDescription(Meetup meetup, String newDescription) {
|
||||||
|
meetup.setDescription(newDescription);
|
||||||
|
return updateMeetupMessage(meetup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<Void> changeMeetupLocation(Meetup meetup, String newLocation) {
|
||||||
|
try {
|
||||||
|
meetup.setLocation(URLEncoder.encode(newLocation, StandardCharsets.UTF_8.toString()));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new AbstractoRunTimeException(e);
|
||||||
|
}
|
||||||
|
return updateMeetupMessage(meetup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<Void> changeMeetupTopic(Meetup meetup, String newTopic) {
|
||||||
|
meetup.setTopic(newTopic);
|
||||||
|
return updateMeetupMessage(meetup);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompletableFuture<Void> updateMeetupMessage(Meetup meetup) {
|
||||||
|
Long meetupId = meetup.getId().getId();
|
||||||
|
Long serverId = meetup.getId().getServerId();
|
||||||
|
MeetupMessageModel meetupMessageModel = getMeetupMessageModel(meetup);
|
||||||
|
MessageToSend updatedMeetupMessage = getMeetupMessage(meetupMessageModel);
|
||||||
|
GuildMessageChannel meetupChannel = channelService.getMessageChannelFromServer(serverId, meetup.getMeetupChannel().getId());
|
||||||
|
return channelService.editMessageInAChannelFuture(updatedMeetupMessage, meetupChannel, meetup.getMessageId())
|
||||||
|
.thenAccept(message -> log.info("Updated message of meetup {} in channel {} in server {}.", meetupId, meetup.getMeetupChannel().getId(), serverId))
|
||||||
|
.thenAccept(unused -> fileService.safeDeleteIgnoreException(updatedMeetupMessage.getAttachedFiles().get(0).getFile()))
|
||||||
.exceptionally(throwable -> {
|
.exceptionally(throwable -> {
|
||||||
log.info("Failed to update message of meetup {} in channel {} in server {}.", meetupId, meetup.getMeetupChannel().getId(), serverId, throwable);
|
log.info("Failed to update message of meetup {} in channel {} in server {}.", meetupId, meetup.getMeetupChannel().getId(), serverId, throwable);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package dev.sheldan.sissi.module.meetup.service.management;
|
package dev.sheldan.sissi.module.meetup.service.management;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||||
@@ -12,6 +13,9 @@ import dev.sheldan.sissi.module.meetup.repository.MeetupRepository;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -26,22 +30,28 @@ public class MeetupManagementServiceBean {
|
|||||||
|
|
||||||
public static final String MEETUP_COUNTER_KEY = "meetup";
|
public static final String MEETUP_COUNTER_KEY = "meetup";
|
||||||
|
|
||||||
public Meetup createMeetup(Instant timeStamp, String topic, String description, AUserInAServer organizer, AChannel meetupChannel) {
|
public Meetup createMeetup(Instant timeStamp, String topic, String description, AUserInAServer organizer, AChannel meetupChannel, String location) {
|
||||||
if(timeStamp.isBefore(Instant.now())) {
|
if(timeStamp.isBefore(Instant.now())) {
|
||||||
throw new MeetupPastTimeException();
|
throw new MeetupPastTimeException();
|
||||||
}
|
}
|
||||||
Long meetupId = counterService.getNextCounterValue(organizer.getServerReference(), MEETUP_COUNTER_KEY);
|
Long meetupId = counterService.getNextCounterValue(organizer.getServerReference(), MEETUP_COUNTER_KEY);
|
||||||
Meetup meetup = Meetup
|
Meetup meetup = null;
|
||||||
.builder()
|
try {
|
||||||
.meetupTime(timeStamp)
|
meetup = Meetup
|
||||||
.description(description)
|
.builder()
|
||||||
.topic(topic)
|
.meetupTime(timeStamp)
|
||||||
.organizer(organizer)
|
.description(description)
|
||||||
.server(organizer.getServerReference())
|
.topic(topic)
|
||||||
.meetupChannel(meetupChannel)
|
.location(URLEncoder.encode(location, StandardCharsets.UTF_8.toString()))
|
||||||
.state(MeetupState.NEW)
|
.organizer(organizer)
|
||||||
.id(new ServerSpecificId(organizer.getServerReference().getId(), meetupId))
|
.server(organizer.getServerReference())
|
||||||
.build();
|
.meetupChannel(meetupChannel)
|
||||||
|
.state(MeetupState.NEW)
|
||||||
|
.id(new ServerSpecificId(organizer.getServerReference().getId(), meetupId))
|
||||||
|
.build();
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new AbstractoRunTimeException(e);
|
||||||
|
}
|
||||||
return meetupRepository.save(meetup);
|
return meetupRepository.save(meetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,12 +72,8 @@ public class MeetupManagementServiceBean {
|
|||||||
return meetupRepository.findByState(MeetupState.CANCELLED);
|
return meetupRepository.findByState(MeetupState.CANCELLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Meetup> getFutureMeetups() {
|
public List<Meetup> getIncomingMeetups(Long serverId, Long channelId) {
|
||||||
return meetupRepository.findByMeetupTimeGreaterThan(Instant.now());
|
return meetupRepository.findByMeetupTimeGreaterThanAndStateAndServer_IdAndMeetupChannel_Id(Instant.now(), MeetupState.CONFIRMED, serverId, channelId);
|
||||||
}
|
|
||||||
|
|
||||||
public List<Meetup> getIncomingMeetups() {
|
|
||||||
return meetupRepository.findByMeetupTimeGreaterThanAndState(Instant.now(), MeetupState.CONFIRMED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteMeetups(List<Meetup> meetups) {
|
public void deleteMeetups(List<Meetup> meetups) {
|
||||||
|
|||||||
@@ -5,4 +5,8 @@ abstracto.systemConfigs.meetupEarlyReminderSeconds.name=meetupEarlyReminderSecon
|
|||||||
abstracto.systemConfigs.meetupEarlyReminderSeconds.longValue=604800
|
abstracto.systemConfigs.meetupEarlyReminderSeconds.longValue=604800
|
||||||
|
|
||||||
abstracto.systemConfigs.meetupLateReminderSeconds.name=meetupLateReminderSeconds
|
abstracto.systemConfigs.meetupLateReminderSeconds.name=meetupLateReminderSeconds
|
||||||
abstracto.systemConfigs.meetupLateReminderSeconds.longValue=86400
|
abstracto.systemConfigs.meetupLateReminderSeconds.longValue=86400
|
||||||
|
|
||||||
|
abstracto.featureModes.attachIcsFile.featureName=meetup
|
||||||
|
abstracto.featureModes.attachIcsFile.mode=attachIcsFile
|
||||||
|
abstracto.featureModes.attachIcsFile.enabled=false
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?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" >
|
||||||
|
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="seedData/data.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?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" >
|
||||||
|
<property name="utilityModule" value="(SELECT id FROM module WHERE name = 'utility')"/>
|
||||||
|
<property name="meetupFeature" value="(SELECT id FROM feature WHERE key = 'meetup')"/>
|
||||||
|
|
||||||
|
<changeSet author="Sheldan" id="meetup-change_command">
|
||||||
|
<insert tableName="command">
|
||||||
|
<column name="name" value="changeMeetup"/>
|
||||||
|
<column name="module_id" valueComputed="${utilityModule}"/>
|
||||||
|
<column name="feature_id" valueComputed="${meetupFeature}"/>
|
||||||
|
</insert>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?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" >
|
||||||
|
<include file="command.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?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" >
|
||||||
|
<changeSet author="Sheldan" id="meetup-add_info_columns">
|
||||||
|
<addColumn tableName="meetup">
|
||||||
|
<column name="location" type="VARCHAR(100)" />
|
||||||
|
</addColumn>
|
||||||
|
<addColumn tableName="meetup">
|
||||||
|
<column name="yes_button_id" type="VARCHAR(100)" />
|
||||||
|
</addColumn>
|
||||||
|
<addColumn tableName="meetup">
|
||||||
|
<column name="maybe_button_id" type="VARCHAR(100)" />
|
||||||
|
</addColumn>
|
||||||
|
<addColumn tableName="meetup">
|
||||||
|
<column name="no_time_button_id" type="VARCHAR(100)" />
|
||||||
|
</addColumn>
|
||||||
|
<addColumn tableName="meetup">
|
||||||
|
<column name="not_interested_button_id" type="VARCHAR(100)" />
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?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" >
|
||||||
|
<include file="meetup.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -8,4 +8,5 @@
|
|||||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
<include file="1.1.0/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.1.0/collection.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="1.2.0/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.2.0/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="1.3.18/collection.xml" relativeToChangelogFile="true"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>dev.sheldan.sissi.application</groupId>
|
<groupId>dev.sheldan.sissi.application</groupId>
|
||||||
<artifactId>application</artifactId>
|
<artifactId>application</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.4.34-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -13,6 +13,8 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>quotes</module>
|
<module>quotes</module>
|
||||||
<module>meetup</module>
|
<module>meetup</module>
|
||||||
|
<module>debra</module>
|
||||||
|
<module>rss-news</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>dev.sheldan.sissi.application</groupId>
|
<groupId>dev.sheldan.sissi.application</groupId>
|
||||||
<artifactId>sissi-modules</artifactId>
|
<artifactId>sissi-modules</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.4.34-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
|
|||||||
import dev.sheldan.sissi.module.quotes.exception.QuoteNotFoundException;
|
import dev.sheldan.sissi.module.quotes.exception.QuoteNotFoundException;
|
||||||
import dev.sheldan.sissi.module.quotes.model.database.Quote;
|
import dev.sheldan.sissi.module.quotes.model.database.Quote;
|
||||||
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
@@ -28,7 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -38,6 +39,7 @@ public class QuoteSearch extends AbstractConditionableCommand {
|
|||||||
|
|
||||||
private static final String QUOTE_SEARCH_COMMAND = "quoteSearch";
|
private static final String QUOTE_SEARCH_COMMAND = "quoteSearch";
|
||||||
private static final String QUERY_PARAMETER = "query";
|
private static final String QUERY_PARAMETER = "query";
|
||||||
|
private static final String MEMBER_PARAMETER = "member";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private QuoteServiceBean quoteServiceBean;
|
private QuoteServiceBean quoteServiceBean;
|
||||||
@@ -80,7 +82,14 @@ public class QuoteSearch extends AbstractConditionableCommand {
|
|||||||
String query = slashCommandParameterService.getCommandOption(QUERY_PARAMETER, event, String.class);
|
String query = slashCommandParameterService.getCommandOption(QUERY_PARAMETER, event, String.class);
|
||||||
AServer server = serverManagementService.loadServer(event.getGuild().getIdLong());
|
AServer server = serverManagementService.loadServer(event.getGuild().getIdLong());
|
||||||
|
|
||||||
Optional<Quote> possibleQuote = quoteServiceBean.searchQuote(query, server);
|
Optional<Quote> possibleQuote;
|
||||||
|
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER, event)) {
|
||||||
|
Member targetMember = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER, event, Member.class);
|
||||||
|
possibleQuote = quoteServiceBean.searchQuote(query, server, targetMember);
|
||||||
|
} else {
|
||||||
|
possibleQuote = quoteServiceBean.searchQuote(query, server);
|
||||||
|
}
|
||||||
|
|
||||||
Quote quoteToDisplay = possibleQuote.orElseThrow(QuoteNotFoundException::new);
|
Quote quoteToDisplay = possibleQuote.orElseThrow(QuoteNotFoundException::new);
|
||||||
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
|
||||||
.thenCompose(messageToSend -> self.replyMessage(event, messageToSend))
|
.thenCompose(messageToSend -> self.replyMessage(event, messageToSend))
|
||||||
@@ -100,7 +109,17 @@ public class QuoteSearch extends AbstractConditionableCommand {
|
|||||||
.name(QUERY_PARAMETER)
|
.name(QUERY_PARAMETER)
|
||||||
.type(String.class)
|
.type(String.class)
|
||||||
.build();
|
.build();
|
||||||
List<Parameter> parameters = Collections.singletonList(searchParameter);
|
|
||||||
|
Parameter memberParameter = Parameter
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.name(MEMBER_PARAMETER)
|
||||||
|
.slashCommandOnly(true)
|
||||||
|
.optional(true)
|
||||||
|
.type(Member.class)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
List<Parameter> parameters = Arrays.asList(searchParameter, memberParameter);
|
||||||
HelpInfo helpInfo = HelpInfo
|
HelpInfo helpInfo = HelpInfo
|
||||||
.builder()
|
.builder()
|
||||||
.templated(true)
|
.templated(true)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user