mirror of
https://github.com/Sheldan/Sissi.git
synced 2026-01-03 16:27:48 +00:00
Compare commits
158 Commits
sissi-1.1.
...
sissi-1.4.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
10255daa29 | ||
|
|
f0d7e98f70 | ||
|
|
dfcfdd53c3 | ||
|
|
4a75447b7e | ||
|
|
bce5c89ad1 | ||
|
|
686afb88f6 | ||
|
|
1abce06e2f | ||
|
|
69011ddac7 | ||
|
|
177934d1c9 | ||
|
|
44e38ca1de | ||
|
|
cc23eaf2d6 | ||
|
|
d7f9a62a62 | ||
|
|
af8f2c10ff | ||
|
|
a2818241f6 | ||
|
|
af8bf920c0 | ||
|
|
b4d3aaac15 | ||
|
|
01c86558cd | ||
|
|
08bab02451 | ||
|
|
84359fcdac | ||
|
|
c006665a0c | ||
|
|
4e29134fa5 | ||
|
|
249a3e3d19 | ||
|
|
7f8c429a04 | ||
|
|
d74c10c618 | ||
|
|
0ec7d83191 | ||
|
|
4bfa706e7c | ||
|
|
2485bf4113 | ||
|
|
48e2e705c2 | ||
|
|
f688a066b4 | ||
|
|
1e8a01dccc | ||
|
|
e7fb1857b0 | ||
|
|
b5498ab79a | ||
|
|
1f5aebef1c | ||
|
|
b0bb0e02d1 | ||
|
|
9bc4ec0253 | ||
|
|
533c9e3a63 | ||
|
|
6ae631c78d |
11
.github/workflows/build.yml
vendored
11
.github/workflows/build.yml
vendored
@@ -17,11 +17,14 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
java-version: 1.8
|
||||
persist-credentials: false
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'corretto'
|
||||
java-version: 17
|
||||
- name: Build with Maven
|
||||
run: mvn -s settings.xml -B install --file pom.xml
|
||||
env:
|
||||
|
||||
36
.github/workflows/release.yml
vendored
36
.github/workflows/release.yml
vendored
@@ -6,13 +6,14 @@ jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Set up Java for publishing to GitHub Packages
|
||||
uses: actions/setup-java@v1
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: 1.8
|
||||
distribution: 'corretto'
|
||||
java-version: 17
|
||||
- name: Load current version
|
||||
id: version
|
||||
run: echo "version=$(mvn -s settings.xml --file pom.xml -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_ENV
|
||||
@@ -22,17 +23,26 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
user: Sheldan
|
||||
token: ${{ secrets.ABSTRACTO_PAT }}
|
||||
- name: Login to GitHub Packages Docker Registry
|
||||
uses: docker/login-action@v1
|
||||
- name: Login to Harbor
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: docker.pkg.github.com
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Push deployment container
|
||||
registry: harbor.sheldan.dev
|
||||
username: ${{ secrets.HARBOR_USERNAME }}
|
||||
password: ${{ secrets.HARBOR_TOKEN }}
|
||||
- name: Load env files
|
||||
id: dotenv
|
||||
uses: falti/dotenv-action@v1.0.4
|
||||
with:
|
||||
path: ./deployment/image-packaging/src/main/docker/.env
|
||||
- name: Push container
|
||||
working-directory: ./deployment/image-packaging/src/main/docker
|
||||
run: docker-compose build && docker-compose push
|
||||
env:
|
||||
REGISTRY_PREFIX: docker.pkg.github.com/sheldan/sissi/
|
||||
VERSION: ${{ env.version }}
|
||||
ABSTRACTO_VERSION: 1.4.0.RC2
|
||||
ABSTRACTO_REGISTRY_PREFIX: docker.pkg.github.com/sheldan/abstracto/
|
||||
REGISTRY_PREFIX: ${{ steps.dotenv.outputs.registry_prefix }}
|
||||
VERSION: ${{ steps.dotenv.outputs.version }}
|
||||
- name: Helm push
|
||||
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
|
||||
|
||||
Copyright (c) 2022 Sheldan
|
||||
Copyright (c) 2023 Sheldan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
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.
|
||||
37
Tiltfile
Normal file
37
Tiltfile
Normal file
@@ -0,0 +1,37 @@
|
||||
allow_k8s_contexts('k8s-cluster')
|
||||
|
||||
load('ext://restart_process', 'docker_build_with_restart')
|
||||
registry = 'harbor.sheldan.dev/sissi/'
|
||||
|
||||
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 --inplace --checksum -r application/executable/target/jar-staging/ application/executable/target/jar && ' +
|
||||
'mkdir application/executable/target/jar/snapshots && ' +
|
||||
'rsync --delete --inplace --checksum -r application/executable/target/jar/BOOT-INF/lib/*-SNAPSHOT.jar application/executable/target/jar/snapshots && ' +
|
||||
'rm -f application/executable/target/jar/BOOT-INF/lib/*-SNAPSHOT.jar ',
|
||||
deps=['pom.xml'])
|
||||
|
||||
docker_build_with_restart(
|
||||
registry + 'sissi',
|
||||
'./application/executable/target/jar',
|
||||
entrypoint=['java', '-noverify', '-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-template-data', 'deployment/image-packaging/src/main/docker/template-data/')
|
||||
|
||||
|
||||
k8s_yaml(helm('deployment/helm/sissi', values=
|
||||
['./../Sissi-environments/values/local/values.yaml',
|
||||
'secrets://./../Sissi-environments/values/local/values.secrets.yaml']
|
||||
))
|
||||
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,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.sissi.application</groupId>
|
||||
<artifactId>application</artifactId>
|
||||
<version>1.1.0.RC1</version>
|
||||
<version>1.4.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>executable</artifactId>
|
||||
@@ -14,6 +14,7 @@
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<finalName>sissi</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -70,11 +71,78 @@
|
||||
<artifactId>link-embed-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>webservices-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>twitch-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>utility-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>remind-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>suggestion-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>starboard-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>moderation-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>entertainment-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>assignable-roles-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>custom-command-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>modmail-impl</artifactId>
|
||||
</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>
|
||||
|
||||
<!-- sissi modules -->
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.sissi.application.module</groupId>
|
||||
<artifactId>quotes</artifactId>
|
||||
@@ -87,6 +155,20 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.sissi.application.module</groupId>
|
||||
<artifactId>debra</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- sissi customizations -->
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.sissi.application.module.custom</groupId>
|
||||
<artifactId>moderation-custom</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</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,13 @@
|
||||
spring.datasource.url=jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
|
||||
spring.datasource.username= ${DB_USER}
|
||||
spring.datasource.password= ${DB_PASS}
|
||||
spring.jpa.hibernate.default_schema=${DB_NAME}
|
||||
spring.jpa.hibernate.default_schema=abstracto
|
||||
spring.jpa.properties.hibernate.default_schema=abstracto
|
||||
spring.quartz.jdbc.initialize-schema=never
|
||||
management.metrics.tags.application=Sissi
|
||||
spring.security.user.name= ${REST_USER_NAME}
|
||||
spring.security.user.password= ${REST_PASSWORD}
|
||||
spring.security.user.roles=USER
|
||||
management.endpoint.health.probes.enabled=true
|
||||
management.health.livenessState.enabled=true
|
||||
management.health.readinessState.enabled=true
|
||||
spring.application.name=Sissi
|
||||
|
||||
spring.application.name=Sissi
|
||||
spring.main.allow-circular-references=true
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.sissi</groupId>
|
||||
<artifactId>sissi</artifactId>
|
||||
<version>1.1.0.RC1</version>
|
||||
<version>1.4.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -26,8 +26,9 @@
|
||||
</dependencyManagement>
|
||||
|
||||
<modules>
|
||||
<module>executable</module>
|
||||
<module>sissi-modules</module>
|
||||
<module>sissi-customizations</module>
|
||||
<module>executable</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
|
||||
42
application/sissi-customizations/moderation-custom/pom.xml
Normal file
42
application/sissi-customizations/moderation-custom/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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.module.custom</groupId>
|
||||
<artifactId>sissi-customizations</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>moderation-custom</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>moderation-int</artifactId>
|
||||
<version>${abstracto.version}</version>
|
||||
</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>
|
||||
@@ -1,19 +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>docker-compose</id>
|
||||
<id>liquibase</id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<outputDirectory>./docker-compose</outputDirectory>
|
||||
<directory>${project.basedir}/src/main/resources/</directory>
|
||||
<outputDirectory>.</outputDirectory>
|
||||
<directory>${project.basedir}/src/main/resources/migrations</directory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
<filtered>true</filtered>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
@@ -0,0 +1,95 @@
|
||||
package dev.sheldan.sissi.module.custom.moderation.commands;
|
||||
|
||||
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.abstracto.moderation.config.ModerationModuleDefinition;
|
||||
import dev.sheldan.sissi.module.custom.moderation.config.ModerationCustomFeatureDefinition;
|
||||
import dev.sheldan.sissi.module.custom.moderation.config.ModerationCustomSlashCommandNames;
|
||||
import dev.sheldan.sissi.module.custom.moderation.service.ModModeServiceBean;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class ModMode extends AbstractConditionableCommand {
|
||||
|
||||
public static final String NEW_STATE_PARAMETER = "newState";
|
||||
public static final String MOD_MODE_COMMAND = "modMode";
|
||||
public static final String MOD_MODE_RESPONSE = "modMode_response";
|
||||
|
||||
@Autowired
|
||||
private ModModeServiceBean modModeServiceBean;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
Boolean newState = (Boolean) commandContext.getParameters().getParameters().get(0);
|
||||
return modModeServiceBean.setModModeTo(commandContext.getGuild(), newState)
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
Boolean newState = slashCommandParameterService.getCommandOption(NEW_STATE_PARAMETER, event, Boolean.class);
|
||||
return modModeServiceBean.setModModeTo(event.getGuild(), newState)
|
||||
.thenApply(unused -> interactionService.replyEmbed(MOD_MODE_RESPONSE, event))
|
||||
.thenApply(interactionHookCompletableFuture -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
|
||||
Parameter memberParameter = Parameter
|
||||
.builder()
|
||||
.templated(true)
|
||||
.name(NEW_STATE_PARAMETER)
|
||||
.type(Boolean.class)
|
||||
.build();
|
||||
List<Parameter> parameters = Collections.singletonList(memberParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(ModerationCustomSlashCommandNames.MODERATION)
|
||||
.commandName(MOD_MODE_COMMAND)
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(MOD_MODE_COMMAND)
|
||||
.async(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.module(ModerationModuleDefinition.MODERATION)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return ModerationCustomFeatureDefinition.MODERATION_CUSTOM;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package dev.sheldan.sissi.module.custom.moderation.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.ReportReactionFeatureConfig;
|
||||
import dev.sheldan.sissi.module.custom.moderation.service.ModModeServiceBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static dev.sheldan.sissi.module.custom.moderation.listener.ReactionReportReactionListener.REACTION_REPORT_REACTION_AMOUNT_CONFIG_KEY;
|
||||
|
||||
@Component
|
||||
public class ModerationCustomFeature implements FeatureConfig {
|
||||
|
||||
@Autowired
|
||||
private ReportReactionFeatureConfig reportReactionFeatureConfig;
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return ModerationCustomFeatureDefinition.MODERATION_CUSTOM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureConfig> getRequiredFeatures() {
|
||||
return Arrays.asList(reportReactionFeatureConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRequiredSystemConfigKeys() {
|
||||
return Arrays.asList(REACTION_REPORT_REACTION_AMOUNT_CONFIG_KEY, ModModeServiceBean.MODMODE_ROLE_CONFIG_KEY,
|
||||
ModModeServiceBean.MODMODE_CHANGED_ROLE_COLOR_CONFIG_KEY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.sissi.module.custom.moderation.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum ModerationCustomFeatureDefinition implements FeatureDefinition {
|
||||
MODERATION_CUSTOM("moderationCustom");
|
||||
|
||||
private String key;
|
||||
|
||||
ModerationCustomFeatureDefinition(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.sheldan.sissi.module.custom.moderation.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:moderation-custom.properties")
|
||||
public class ModerationCustomProperties {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package dev.sheldan.sissi.module.custom.moderation.config;
|
||||
|
||||
public class ModerationCustomSlashCommandNames {
|
||||
public static final String MODERATION = "moderation";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.sissi.module.custom.moderation.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
|
||||
|
||||
public class ModRoleNotFoundException extends AbstractoTemplatableException {
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "mod_role_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package dev.sheldan.sissi.module.custom.moderation.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.service.ReactionService;
|
||||
import dev.sheldan.abstracto.moderation.listener.ReportMessageCreatedListener;
|
||||
import dev.sheldan.abstracto.moderation.model.listener.ReportMessageCreatedModel;
|
||||
import dev.sheldan.sissi.module.custom.moderation.config.ModerationCustomFeatureDefinition;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ReactionReportReactionListener implements ReportMessageCreatedListener {
|
||||
|
||||
public static final String REACTION_REPORT_REACTION_AMOUNT_CONFIG_KEY = "reportReactionAmount";
|
||||
public static final String REACTION_REPORT_EMOTE_PREFIX = "reactionReport";
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private ReactionService reactionService;
|
||||
|
||||
@Override
|
||||
public DefaultListenerResult execute(ReportMessageCreatedModel model) {
|
||||
if(model.getReportMessage() == null) {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
Long reactionAmount = configService.getLongValueOrConfigDefault(REACTION_REPORT_REACTION_AMOUNT_CONFIG_KEY, model.getServerId());
|
||||
for (int i = 0; i < reactionAmount; i++) {
|
||||
String emoteKey = buildReactionEmoteName(i + 1);
|
||||
reactionService.addReactionToMessageAsync(emoteKey,
|
||||
model.getServerId(), model.getReportMessage().getChannelId(), model.getReportMessage().getMessageId())
|
||||
.thenAccept(unused -> log.info("Added reaction emote {} on report message {} in channel {} in server {}",
|
||||
emoteKey, model.getReportMessage().getMessageId(), model.getReportMessage().getChannelId(), model.getServerId()))
|
||||
.exceptionally(throwable -> {
|
||||
log.info("Failed to add reaction emote {} on report message {} in channel {} in server {}",
|
||||
emoteKey, model.getReportMessage().getMessageId(), model.getReportMessage().getChannelId(), model.getServerId());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return ModerationCustomFeatureDefinition.MODERATION_CUSTOM;
|
||||
}
|
||||
|
||||
private String buildReactionEmoteName(Integer position) {
|
||||
return REACTION_REPORT_EMOTE_PREFIX + position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package dev.sheldan.sissi.module.custom.moderation.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.sissi.module.custom.moderation.exception.ModRoleNotFoundException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ModModeServiceBean {
|
||||
public static final String MODMODE_ROLE_CONFIG_KEY = "modModeRoleId";
|
||||
public static final String MODMODE_CHANGED_ROLE_COLOR_CONFIG_KEY = "modModeNewRoleColor";
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
public CompletableFuture<Void> setModModeTo(Guild guild, Boolean newState) {
|
||||
if(Boolean.TRUE.equals(newState)) {
|
||||
return enableModMode(guild);
|
||||
} else {
|
||||
return disableModMoe(guild);
|
||||
}
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> enableModMode(Guild guild) {
|
||||
Color colorToSet = getColorFromConfig(MODMODE_CHANGED_ROLE_COLOR_CONFIG_KEY, guild);
|
||||
return setModRoleTo(guild, colorToSet);
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> disableModMoe(Guild guild) {
|
||||
return setModRoleTo(guild, null);
|
||||
}
|
||||
|
||||
private Color getColorFromConfig(String key, Guild guild) {
|
||||
String colorString = configService.getStringValueOrConfigDefault(key, guild.getIdLong());
|
||||
String[] parts = colorString.split(",");
|
||||
return new Color(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> setModRoleTo(Guild guild, Color color) {
|
||||
Long roleId = configService.getLongValue(MODMODE_ROLE_CONFIG_KEY, guild.getIdLong());
|
||||
Role modRole = guild.getRoleById(roleId);
|
||||
if(modRole != null) {
|
||||
return modRole.getManager().setColor(color).submit();
|
||||
} else {
|
||||
throw new ModRoleNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,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="default_emote.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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="moderation_custom_reaction_message_default_emote-insert">
|
||||
<insert tableName="default_emote">
|
||||
<column name="emote_key" value="reactionReport1"/>
|
||||
<column name="name" value="♂️"/>
|
||||
</insert>
|
||||
<insert tableName="default_emote">
|
||||
<column name="emote_key" value="reactionReport2"/>
|
||||
<column name="name" value="📣"/>
|
||||
</insert>
|
||||
<insert tableName="default_emote">
|
||||
<column name="emote_key" value="reactionReport3"/>
|
||||
<column name="name" value="🤫"/>
|
||||
</insert>
|
||||
<insert tableName="default_emote">
|
||||
<column name="emote_key" value="reactionReport4"/>
|
||||
<column name="name" value="🔨"/>
|
||||
</insert>
|
||||
<insert tableName="default_emote">
|
||||
<column name="emote_key" value="reactionReport5"/>
|
||||
<column name="name" value="⚠️"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
</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="moderation_custom_feature-insertion">
|
||||
<insert tableName="feature">
|
||||
<column name="key" value="moderationCustom"/>
|
||||
</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,18 @@
|
||||
<?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="moderationCustomFeature" value="(SELECT id FROM feature WHERE key = 'moderationCustom')"/>
|
||||
<property name="moderationModule" value="(SELECT id FROM module WHERE name = 'moderation')"/>
|
||||
<changeSet author="Sheldan" id="moderationCustom_modmode-commands">
|
||||
<insert tableName="command">
|
||||
<column name="name" value="modMode"/>
|
||||
<column name="module_id" valueComputed="${moderationModule}"/>
|
||||
<column name="feature_id" valueComputed="${moderationCustomFeature}"/>
|
||||
</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>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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="1.1.0/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.2.1/collection.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,11 @@
|
||||
abstracto.featureFlags.moderationCustom.featureName=moderationCustom
|
||||
abstracto.featureFlags.moderationCustom.enabled=false
|
||||
|
||||
abstracto.systemConfigs.reportReactionAmount.name=reportReactionAmount
|
||||
abstracto.systemConfigs.reportReactionAmount.longValue=5
|
||||
|
||||
abstracto.systemConfigs.modModeRoleId.name=modModeRoleId
|
||||
abstracto.systemConfigs.modModeRoleId.longValue=0
|
||||
|
||||
abstracto.systemConfigs.modModeNewRoleColor.name=modModeNewRoleColor
|
||||
abstracto.systemConfigs.modModeNewRoleColor.stringValue=0,0,0
|
||||
19
application/sissi-customizations/pom.xml
Normal file
19
application/sissi-customizations/pom.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?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>
|
||||
<artifactId>application</artifactId>
|
||||
<groupId>dev.sheldan.sissi.application</groupId>
|
||||
<version>1.4.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>dev.sheldan.sissi.application.module.custom</groupId>
|
||||
<artifactId>sissi-customizations</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>moderation-custom</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
||||
42
application/sissi-modules/debra/pom.xml
Normal file
42
application/sissi-modules/debra/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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.7</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>
|
||||
</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,15 @@
|
||||
package dev.sheldan.sissi.module.debra;
|
||||
|
||||
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,184 @@
|
||||
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;
|
||||
try {
|
||||
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<>());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new AbstractoRunTimeException("Failed to load donation amount.", e);
|
||||
}
|
||||
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,31 @@
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
@@ -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,5 @@
|
||||
package dev.sheldan.sissi.module.debra.config;
|
||||
|
||||
public class DebraSlashCommandNames {
|
||||
public static final String DEBRA = "debra";
|
||||
}
|
||||
@@ -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,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 lombok.Setter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class Description {
|
||||
private BigDecimal collected;
|
||||
private BigDecimal target;
|
||||
private String currency;
|
||||
private String slug;
|
||||
private String displayName;
|
||||
private BigDecimal collectedNet;
|
||||
private BigDecimal percent;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package dev.sheldan.sissi.module.debra.model.api;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class Donation {
|
||||
private BigDecimal amount;
|
||||
private String currency;
|
||||
private String text;
|
||||
private Integer anonym;
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.sheldan.sissi.module.debra.model.api;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class DonationsResponse {
|
||||
private Description page;
|
||||
private BigInteger donationCount;
|
||||
private List<Donation> donations;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.sissi.module.debra.model.commands;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Getter
|
||||
@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,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,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,151 @@
|
||||
package dev.sheldan.sissi.module.debra.service;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.sissi.module.debra.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.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 okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
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;
|
||||
|
||||
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 \\/>(.*)");
|
||||
|
||||
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 DonationsResponse fetchCurrentDonationAmount(Long serverId) throws IOException {
|
||||
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()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.error("Failed to retrieve urban dictionary definition. Response had code {} with body {}.",
|
||||
response.code(), response.body());
|
||||
}
|
||||
throw new DonationAmountNotFoundException();
|
||||
}
|
||||
Gson gson = getGson();
|
||||
|
||||
return gson.fromJson(response.body().string(), DonationsResponse.class);
|
||||
}
|
||||
|
||||
private Gson getGson() {
|
||||
return new GsonBuilder()
|
||||
.registerTypeAdapter(BigDecimal.class, new BigDecimalGsonAdapter())
|
||||
.create();
|
||||
}
|
||||
|
||||
private DonationsModel getDonationInfoModel(Long serverId) throws IOException {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
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-fuer-debra-2022?details=1&num=%s&ort=0
|
||||
|
||||
abstracto.systemConfigs.debraDonationNotificationDelayMillis.name=debraDonationNotificationDelayMillis
|
||||
abstracto.systemConfigs.debraDonationNotificationDelayMillis.longValue=60000
|
||||
|
||||
abstracto.systemConfigs.debraDonationApiFetchSize.name=debraDonationApiFetchSize
|
||||
abstracto.systemConfigs.debraDonationApiFetchSize.longValue=1000
|
||||
@@ -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>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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="1.3.6/collection.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.sissi.application</groupId>
|
||||
<artifactId>sissi-modules</artifactId>
|
||||
<version>1.1.0.RC1</version>
|
||||
<version>1.4.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
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.abstracto.core.utils.FutureUtils;
|
||||
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;
|
||||
|
||||
@Component
|
||||
public class CancelMeetup extends AbstractConditionableCommand {
|
||||
|
||||
private static final String MEETUP_ID_PARAMETER = "meetupId";
|
||||
private static final String CANCEL_MEETUP_COMMAND = "cancelMeetup";
|
||||
private static final String CANCEL_MEETUP_RESPONSE = "cancelMeetup_response";
|
||||
|
||||
@Autowired
|
||||
private MeetupServiceBean meetupServiceBean;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private MeetupManagementServiceBean meetupManagementServiceBean;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
Long meetupId = (Long) commandContext.getParameters().getParameters().get(0);
|
||||
Meetup meetup = meetupManagementServiceBean.getMeetup(meetupId, commandContext.getGuild().getIdLong());
|
||||
if(!meetup.getOrganizer().getUserReference().getId().equals(commandContext.getAuthor().getIdLong())) {
|
||||
throw new NotMeetupOrganizerException();
|
||||
}
|
||||
return meetupServiceBean.cancelMeetup(meetup)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
event.deferReply().queue();
|
||||
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();
|
||||
}
|
||||
return meetupServiceBean.cancelMeetup(meetup)
|
||||
.thenCompose(unused -> FutureUtils.toSingleFutureGeneric(interactionService.sendMessageToInteraction(CANCEL_MEETUP_RESPONSE, new Object(), event.getHook())))
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter meetupIdParameter = Parameter
|
||||
.builder()
|
||||
.templated(true)
|
||||
.name(MEETUP_ID_PARAMETER)
|
||||
.type(Long.class)
|
||||
.build();
|
||||
|
||||
List<Parameter> parameters = Arrays.asList(meetupIdParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(MeetupSlashCommandNames.MEETUP)
|
||||
.commandName("cancel")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(CANCEL_MEETUP_COMMAND)
|
||||
.module(UtilityModuleDefinition.UTILITY)
|
||||
.templated(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return MeetupFeatureDefinition.MEETUP;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
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.ComponentService;
|
||||
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.meetup.config.MeetupFeatureDefinition;
|
||||
import dev.sheldan.sissi.module.meetup.config.MeetupSlashCommandNames;
|
||||
import dev.sheldan.sissi.module.meetup.exception.MeetupPastTimeException;
|
||||
import dev.sheldan.sissi.module.meetup.exception.NotMeetupOrganizerException;
|
||||
import dev.sheldan.sissi.module.meetup.model.command.MeetupChangeTimeConfirmationModel;
|
||||
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.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class ChangeMeetupTime extends AbstractConditionableCommand {
|
||||
|
||||
private static final String CHANGE_MEETUP_TIME_COMMAND = "changeMeetupTime";
|
||||
private static final String MEETUP_ID_PARAMETER = "meetupId";
|
||||
private static final String MEETUP_NEW_TIMESTAMP_PARAMETER = "newTimeStamp";
|
||||
private static final String CHANGE_MEETUP_TIME_CONFIRMATION = "changeMeetupTime_confirmation";
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private MeetupManagementServiceBean meetupManagementServiceBean;
|
||||
|
||||
@Autowired
|
||||
private ComponentService componentService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private MeetupServiceBean meetupServiceBean;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@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();
|
||||
}
|
||||
Long newTimestamp = (Long) parameters.get(1);
|
||||
Instant newMeetupTime = Instant.ofEpochSecond(newTimestamp);
|
||||
if(newMeetupTime.isBefore(Instant.now())) {
|
||||
throw new MeetupPastTimeException();
|
||||
}
|
||||
String confirmationId = componentService.generateComponentId();
|
||||
String cancelId = componentService.generateComponentId();
|
||||
MeetupChangeTimeConfirmationModel model = MeetupChangeTimeConfirmationModel
|
||||
.builder()
|
||||
.meetupTime(newMeetupTime)
|
||||
.topic(meetup.getTopic())
|
||||
.description(meetup.getDescription())
|
||||
.userId(commandContext.getAuthor().getIdLong())
|
||||
.guildId(commandContext.getGuild().getIdLong())
|
||||
.meetupId(meetupId)
|
||||
.confirmationId(confirmationId)
|
||||
.cancelId(cancelId)
|
||||
.build();
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(CHANGE_MEETUP_TIME_CONFIRMATION, model, commandContext.getGuild().getIdLong());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||
.thenAccept(unused -> meetupServiceBean.storeMeetupChangeTimeConfirmation(model))
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
Integer time = slashCommandParameterService.getCommandOption(MEETUP_NEW_TIMESTAMP_PARAMETER, event, Long.class, Integer.class);
|
||||
Instant meetupTime = Instant.ofEpochSecond(time);
|
||||
if(meetupTime.isBefore(Instant.now())) {
|
||||
throw new MeetupPastTimeException();
|
||||
}
|
||||
String confirmationId = componentService.generateComponentId();
|
||||
String cancelId = componentService.generateComponentId();
|
||||
MeetupChangeTimeConfirmationModel model = MeetupChangeTimeConfirmationModel
|
||||
.builder()
|
||||
.meetupTime(meetupTime)
|
||||
.topic(meetup.getTopic())
|
||||
.description(meetup.getDescription())
|
||||
.userId(event.getMember().getIdLong())
|
||||
.guildId(event.getGuild().getIdLong())
|
||||
.meetupId(meetupId)
|
||||
.confirmationId(confirmationId)
|
||||
.cancelId(cancelId)
|
||||
.build();
|
||||
return interactionService.replyEmbed(CHANGE_MEETUP_TIME_CONFIRMATION, model, event)
|
||||
.thenAccept(interactionHook -> meetupServiceBean.storeMeetupChangeTimeConfirmation(model))
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter meetupIdParameter = Parameter
|
||||
.builder()
|
||||
.templated(true)
|
||||
.name(MEETUP_ID_PARAMETER)
|
||||
.type(Long.class)
|
||||
.build();
|
||||
|
||||
Parameter newTimeStampParameter = Parameter
|
||||
.builder()
|
||||
.templated(true)
|
||||
.name(MEETUP_NEW_TIMESTAMP_PARAMETER)
|
||||
.type(Long.class)
|
||||
.build();
|
||||
|
||||
List<Parameter> parameters = Arrays.asList(meetupIdParameter, newTimeStampParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(MeetupSlashCommandNames.MEETUP)
|
||||
.commandName("changeTime")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(CHANGE_MEETUP_TIME_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;
|
||||
}
|
||||
}
|
||||
@@ -5,17 +5,17 @@ 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.config.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.slash.parameter.SlashCommandParameterService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.ComponentService;
|
||||
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.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.ComponentService;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
@@ -71,7 +71,9 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
||||
private static final String MEETUP_TIME_PARAMETER = "meetupTime";
|
||||
private static final String TOPIC_PARAMETER = "topic";
|
||||
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 DEFAULT_LOCATION_STRING = "\"\"";
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
@@ -86,7 +88,7 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
||||
}
|
||||
AUserInAServer organizer = userInServerManagementService.loadOrCreateUser(commandContext.getAuthor());
|
||||
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 cancelId = componentService.generateComponentId();
|
||||
MeetupConfirmationModel model = MeetupConfirmationModel
|
||||
@@ -95,6 +97,7 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
||||
.guildId(commandContext.getGuild().getIdLong())
|
||||
.description(description)
|
||||
.topic(meetupTopic)
|
||||
.location(meetup.getLocation())
|
||||
.confirmationId(confirmationId)
|
||||
.cancelId(cancelId)
|
||||
.meetupId(meetup.getId().getId())
|
||||
@@ -117,10 +120,17 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
||||
} else {
|
||||
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);
|
||||
AUserInAServer organizer = userInServerManagementService.loadOrCreateUser(event.getMember());
|
||||
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 cancelId = componentService.generateComponentId();
|
||||
MeetupConfirmationModel model = MeetupConfirmationModel
|
||||
@@ -129,6 +139,7 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
||||
.guildId(event.getGuild().getIdLong())
|
||||
.description(description)
|
||||
.topic(topic)
|
||||
.location(meetup.getLocation())
|
||||
.confirmationId(confirmationId)
|
||||
.cancelId(cancelId)
|
||||
.meetupId(meetup.getId().getId())
|
||||
@@ -166,7 +177,17 @@ public class CreateMeetup extends AbstractConditionableCommand {
|
||||
.type(String.class)
|
||||
.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
|
||||
.builder()
|
||||
.templated(true)
|
||||
|
||||
@@ -5,11 +5,11 @@ 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.config.SlashCommandConfig;
|
||||
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.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
@@ -49,19 +49,19 @@ public class ListMeetups extends AbstractConditionableCommand {
|
||||
|
||||
@Override
|
||||
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()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
|
||||
private MessageToSend getMessageToSend(Long serverId) {
|
||||
List<Meetup> meetups = meetupManagementServiceBean.getFutureMeetups();
|
||||
private MessageToSend getMessageToSend(Long serverId, Long channelId) {
|
||||
List<Meetup> meetups = meetupManagementServiceBean.getIncomingMeetups(serverId, channelId);
|
||||
List<MeetupListItemModel> listItems = meetups
|
||||
.stream()
|
||||
.map(MeetupListItemModel::fromMeetup)
|
||||
@@ -86,7 +86,7 @@ public class ListMeetups extends AbstractConditionableCommand {
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(MeetupSlashCommandNames.MEETUP)
|
||||
.rootCommandName(MeetupSlashCommandNames.MEETUP_PUBLIC)
|
||||
.commandName("list")
|
||||
.build();
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
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.model.database.MeetupDecision;
|
||||
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 NotifyMeetupParticipants extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private MeetupManagementServiceBean meetupManagementServiceBean;
|
||||
|
||||
@Autowired
|
||||
private MeetupServiceBean meetupServiceBean;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
private static final String MEETUP_ID_PARAMETER = "meetupId";
|
||||
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_RESPONSE = "notifyMeetupParticipants_response";
|
||||
|
||||
@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 notificationMessage = (String) parameters.get(1);
|
||||
return meetupServiceBean.notifyMeetupParticipants(meetup, notificationMessage, null)
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
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);
|
||||
return meetupServiceBean.notifyMeetupParticipants(meetup, notificationMessage, toNotify)
|
||||
.thenCompose(unused -> interactionService.replyEmbed(NOTIFY_MEETUP_PARTICIPANTS_RESPONSE, event))
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter meetupIdParameter = Parameter
|
||||
.builder()
|
||||
.templated(true)
|
||||
.name(MEETUP_ID_PARAMETER)
|
||||
.type(Long.class)
|
||||
.build();
|
||||
|
||||
Parameter notificationMessage = Parameter
|
||||
.builder()
|
||||
.templated(true)
|
||||
.name(NOTIFICATION_MESSAGE_PARAMETER)
|
||||
.type(String.class)
|
||||
.remainder(true)
|
||||
.build();
|
||||
|
||||
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
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(MeetupSlashCommandNames.MEETUP)
|
||||
.commandName("notify")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(NOTIFY_MEETUP_PARTICIPANTS_COMMAND)
|
||||
.module(UtilityModuleDefinition.UTILITY)
|
||||
.templated(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return MeetupFeatureDefinition.MEETUP;
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,14 @@ package dev.sheldan.sissi.module.meetup.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
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
|
||||
public class MeetupFeatureConfig implements FeatureConfig {
|
||||
@Override
|
||||
@@ -11,4 +17,8 @@ public class MeetupFeatureConfig implements FeatureConfig {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,5 @@ package dev.sheldan.sissi.module.meetup.config;
|
||||
|
||||
public class MeetupSlashCommandNames {
|
||||
public static final String MEETUP = "meetup";
|
||||
public static final String MEETUP_PUBLIC = "meetupPublic";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.sissi.module.meetup.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
|
||||
|
||||
public class NotMeetupOrganizerException extends AbstractoTemplatableException {
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "meetup_not_organizer_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package dev.sheldan.sissi.module.meetup.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.interaction.ComponentPayloadManagementService;
|
||||
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.sissi.module.meetup.config.MeetupFeatureDefinition;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
||||
import dev.sheldan.sissi.module.meetup.model.payload.MeetupChangeTimeConfirmationPayload;
|
||||
import dev.sheldan.sissi.module.meetup.service.MeetupServiceBean;
|
||||
import dev.sheldan.sissi.module.meetup.service.management.MeetupManagementServiceBean;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MeetupChangeTimeConfirmationListener implements ButtonClickedListener {
|
||||
|
||||
@Autowired
|
||||
private MeetupManagementServiceBean meetupManagementServiceBean;
|
||||
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
|
||||
@Autowired
|
||||
private ComponentPayloadManagementService componentPayloadManagementService;
|
||||
|
||||
@Autowired
|
||||
private MeetupServiceBean meetupServiceBean;
|
||||
|
||||
@Override
|
||||
public ButtonClickedListenerResult execute(ButtonClickedListenerModel model) {
|
||||
MeetupChangeTimeConfirmationPayload payload = (MeetupChangeTimeConfirmationPayload) model.getDeserializedPayload();
|
||||
if(model.getEvent().getUser().getIdLong() != payload.getOrganizerUserId()) {
|
||||
return ButtonClickedListenerResult.IGNORED;
|
||||
}
|
||||
if(model.getEvent().getComponentId().equals(payload.getConfirmationId())) {
|
||||
Meetup meetup = meetupManagementServiceBean.getMeetup(payload.getMeetupId(), payload.getGuildId());
|
||||
meetupServiceBean.changeMeetupTimeAndNotifyParticipants(meetup, Instant.ofEpochSecond(payload.getNewTime()));
|
||||
messageService.deleteMessage(model.getEvent().getMessage());
|
||||
cleanupConfirmationMessagePayloads(payload);
|
||||
} else if(model.getEvent().getComponentId().equals(payload.getCancelId())) {
|
||||
messageService.deleteMessage(model.getEvent().getMessage());
|
||||
cleanupConfirmationMessagePayloads(payload);
|
||||
return ButtonClickedListenerResult.ACKNOWLEDGED;
|
||||
} else {
|
||||
return ButtonClickedListenerResult.IGNORED;
|
||||
}
|
||||
return ButtonClickedListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
private void cleanupConfirmationMessagePayloads(MeetupChangeTimeConfirmationPayload payload) {
|
||||
componentPayloadManagementService.deletePayload(payload.getCancelId());
|
||||
componentPayloadManagementService.deletePayload(payload.getConfirmationId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean handlesEvent(ButtonClickedListenerModel model) {
|
||||
return model.getOrigin().equals(MeetupServiceBean.MEETUP_CHANGE_TIME_CONFIRMATION_BUTTON) &&
|
||||
model.getEvent().isFromGuild();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return MeetupFeatureDefinition.MEETUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPriority() {
|
||||
return ListenerPriority.LOWEST;
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,21 @@ package dev.sheldan.sissi.module.meetup.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.listener.ButtonClickedListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.ButtonClickedListener;
|
||||
import dev.sheldan.abstracto.core.interaction.ComponentPayloadManagementService;
|
||||
import dev.sheldan.abstracto.core.interaction.ComponentPayloadService;
|
||||
import dev.sheldan.abstracto.core.interaction.ComponentService;
|
||||
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.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.listener.ButtonClickedListenerModel;
|
||||
import dev.sheldan.abstracto.core.models.database.ComponentPayload;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.ComponentPayloadService;
|
||||
import dev.sheldan.abstracto.core.service.ComponentService;
|
||||
import dev.sheldan.abstracto.core.service.MessageService;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.ComponentPayloadManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
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.sissi.module.meetup.config.MeetupFeatureDefinition;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
||||
@@ -24,6 +26,7 @@ import dev.sheldan.sissi.module.meetup.model.payload.MeetupDecisionPayload;
|
||||
import dev.sheldan.sissi.module.meetup.model.payload.MeetupConfirmationPayload;
|
||||
import dev.sheldan.sissi.module.meetup.model.template.MeetupMessageModel;
|
||||
import dev.sheldan.sissi.module.meetup.service.MeetupServiceBean;
|
||||
import dev.sheldan.sissi.module.meetup.service.management.MeetupComponentManagementServiceBean;
|
||||
import dev.sheldan.sissi.module.meetup.service.management.MeetupManagementServiceBean;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
@@ -71,6 +74,12 @@ public class MeetupConfirmationListener implements ButtonClickedListener {
|
||||
@Autowired
|
||||
private ComponentPayloadManagementService componentPayloadManagementService;
|
||||
|
||||
@Autowired
|
||||
private MeetupComponentManagementServiceBean meetupComponentManagementServiceBean;
|
||||
|
||||
@Autowired
|
||||
private FileService fileService;
|
||||
|
||||
@Override
|
||||
public ButtonClickedListenerResult execute(ButtonClickedListenerModel model) {
|
||||
MeetupConfirmationPayload payload = (MeetupConfirmationPayload) model.getDeserializedPayload();
|
||||
@@ -83,22 +92,26 @@ public class MeetupConfirmationListener implements ButtonClickedListener {
|
||||
} else if(model.getEvent().getComponentId().equals(payload.getCancelId())){
|
||||
meetup.setState(MeetupState.CANCELLED);
|
||||
messageService.deleteMessage(model.getEvent().getMessage());
|
||||
cleanupConfirmationMessage(payload);
|
||||
cleanupConfirmationMessagePayloads(payload);
|
||||
meetupManagementServiceBean.deleteMeetup(meetup);
|
||||
return ButtonClickedListenerResult.ACKNOWLEDGED;
|
||||
} else {
|
||||
return ButtonClickedListenerResult.IGNORED;
|
||||
}
|
||||
cleanupConfirmationMessage(payload);
|
||||
cleanupConfirmationMessagePayloads(payload);
|
||||
String yesButtonId = componentService.generateComponentId();
|
||||
String noButtonId = componentService.generateComponentId();
|
||||
String maybeButtonId = componentService.generateComponentId();
|
||||
String cancelButtonId = componentService.generateComponentId();
|
||||
String noTimeButtonId = componentService.generateComponentId();
|
||||
MeetupMessageModel messageModel = meetupServiceBean.getMeetupMessageModel(meetup);
|
||||
messageModel.setYesId(yesButtonId);
|
||||
messageModel.setNoId(noButtonId);
|
||||
messageModel.setMaybeId(maybeButtonId);
|
||||
messageModel.setCancelId(cancelButtonId);
|
||||
messageModel.setNoTimeId(noTimeButtonId);
|
||||
meetup.setYesButtonId(yesButtonId);
|
||||
meetup.setMaybeButtonId(maybeButtonId);
|
||||
meetup.setNoTimeButtonId(noTimeButtonId);
|
||||
meetup.setNotInterestedButtonId(noButtonId);
|
||||
messageModel.setCancelled(false);
|
||||
Long meetupId = payload.getMeetupId();
|
||||
Long serverId = payload.getGuildId();
|
||||
@@ -106,9 +119,12 @@ public class MeetupConfirmationListener implements ButtonClickedListener {
|
||||
List<CompletableFuture<Message>> messageFutures = channelService.sendMessageToSendToChannel(messageToSend, model.getEvent().getMessageChannel());
|
||||
FutureUtils.toSingleFutureGeneric(messageFutures).thenAccept(unused -> {
|
||||
messageService.deleteMessage(model.getEvent().getMessage());
|
||||
messageToSend.getAttachedFiles().forEach(attachedFile -> {
|
||||
fileService.safeDeleteIgnoreException(attachedFile.getFile());
|
||||
});
|
||||
Message meetupMessage = messageFutures.get(0).join();
|
||||
messageService.pinMessage(meetupMessage);
|
||||
self.persistPayloads(meetupId, serverId, yesButtonId, noButtonId, maybeButtonId, cancelButtonId, meetupMessage);
|
||||
self.persistPayloads(meetupId, serverId, yesButtonId, noButtonId, maybeButtonId, noTimeButtonId, meetupMessage);
|
||||
}).exceptionally(throwable -> {
|
||||
log.error("Failed to send meetup message for meetup {}.", meetupId, throwable);
|
||||
return null;
|
||||
@@ -116,30 +132,36 @@ public class MeetupConfirmationListener implements ButtonClickedListener {
|
||||
return ButtonClickedListenerResult.ACKNOWLEDGED;
|
||||
}
|
||||
|
||||
private void cleanupConfirmationMessage(MeetupConfirmationPayload payload) {
|
||||
private void cleanupConfirmationMessagePayloads(MeetupConfirmationPayload payload) {
|
||||
componentPayloadManagementService.deletePayload(payload.getCancelId());
|
||||
componentPayloadManagementService.deletePayload(payload.getConfirmationId());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void persistPayloads(Long meetupId, Long serverId, String yesButtonId, String noButtonId, String maybeButtonId, String cancelButtonId, Message meetupMessage) {
|
||||
public void persistPayloads(Long meetupId, Long serverId, String yesButtonId, String noButtonId, String maybeButtonId, String noTimeButtonId, Message meetupMessage) {
|
||||
MeetupDecisionPayload decisionPayload = MeetupDecisionPayload
|
||||
.builder()
|
||||
.meetupId(meetupId)
|
||||
.guildId(serverId)
|
||||
.componentPayloads(Arrays.asList(yesButtonId, noButtonId, maybeButtonId))
|
||||
.componentPayloads(Arrays.asList(yesButtonId, noButtonId, maybeButtonId, noTimeButtonId))
|
||||
.build();
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
|
||||
decisionPayload.setMeetupDecision(MeetupDecision.YES);
|
||||
componentPayloadService.createButtonPayload(yesButtonId, decisionPayload, MEETUP_DECISION_BUTTON, server);
|
||||
ComponentPayload yesPayload = componentPayloadService.createButtonPayload(yesButtonId, decisionPayload, MEETUP_DECISION_BUTTON, server);
|
||||
decisionPayload.setMeetupDecision(MeetupDecision.NO);
|
||||
componentPayloadService.createButtonPayload(noButtonId, decisionPayload, MEETUP_DECISION_BUTTON, server);
|
||||
ComponentPayload noPayload = componentPayloadService.createButtonPayload(noButtonId, decisionPayload, MEETUP_DECISION_BUTTON, server);
|
||||
decisionPayload.setMeetupDecision(MeetupDecision.MAYBE);
|
||||
componentPayloadService.createButtonPayload(maybeButtonId, decisionPayload, MEETUP_DECISION_BUTTON, server);
|
||||
decisionPayload.setMeetupDecision(MeetupDecision.CANCEL);
|
||||
componentPayloadService.createButtonPayload(cancelButtonId, decisionPayload, MEETUP_DECISION_BUTTON, server);
|
||||
ComponentPayload maybePayload = componentPayloadService.createButtonPayload(maybeButtonId, decisionPayload, MEETUP_DECISION_BUTTON, server);
|
||||
decisionPayload.setMeetupDecision(MeetupDecision.NO_TIME);
|
||||
ComponentPayload noTimePayload = componentPayloadService.createButtonPayload(noTimeButtonId, decisionPayload, MEETUP_DECISION_BUTTON, server);
|
||||
Meetup meetup = meetupManagementServiceBean.getMeetup(meetupId, serverId);
|
||||
// storing the button IDs, so we can remove them independently
|
||||
meetupComponentManagementServiceBean.createComponent(meetup, yesButtonId, yesPayload);
|
||||
meetupComponentManagementServiceBean.createComponent(meetup, noButtonId, noPayload);
|
||||
meetupComponentManagementServiceBean.createComponent(meetup, maybeButtonId, maybePayload);
|
||||
meetupComponentManagementServiceBean.createComponent(meetup, noTimeButtonId, noTimePayload);
|
||||
|
||||
meetupServiceBean.scheduleReminders(meetup);
|
||||
meetup.setMessageId(meetupMessage.getIdLong());
|
||||
AChannel channel = channelManagementService.loadChannel(meetupMessage.getChannel());
|
||||
|
||||
@@ -2,10 +2,10 @@ package dev.sheldan.sissi.module.meetup.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.listener.ButtonClickedListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.ButtonClickedListener;
|
||||
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.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.listener.ButtonClickedListenerModel;
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
@@ -13,7 +13,7 @@ import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
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.MeetupDecision;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupParticipator;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupParticipant;
|
||||
import dev.sheldan.sissi.module.meetup.model.payload.MeetupDecisionPayload;
|
||||
import dev.sheldan.sissi.module.meetup.model.template.MeetupMessageModel;
|
||||
import dev.sheldan.sissi.module.meetup.service.MeetupServiceBean;
|
||||
@@ -49,13 +49,9 @@ public class MeetupDecisionListener implements ButtonClickedListener {
|
||||
public ButtonClickedListenerResult execute(ButtonClickedListenerModel model) {
|
||||
MeetupDecisionPayload payload = (MeetupDecisionPayload) model.getDeserializedPayload();
|
||||
Meetup meetup = meetupManagementServiceBean.getMeetup(payload.getMeetupId(), payload.getGuildId());
|
||||
if(payload.getMeetupDecision().equals(MeetupDecision.CANCEL) && model.getEvent().getUser().getIdLong() == meetup.getOrganizer().getUserReference().getId()) {
|
||||
meetupServiceBean.cancelMeetup(meetup, payload.getComponentPayloads());
|
||||
return ButtonClickedListenerResult.ACKNOWLEDGED;
|
||||
}
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadOrCreateUser(model.getEvent().getMember());
|
||||
|
||||
Optional<MeetupParticipator> participationOptional = meetupParticipatorManagementServiceBean.getParticipation(meetup, userInAServer);
|
||||
Optional<MeetupParticipant> participationOptional = meetupParticipatorManagementServiceBean.getParticipation(meetup, userInAServer);
|
||||
if(participationOptional.isPresent()) {
|
||||
participationOptional.get().setDecision(payload.getMeetupDecision());
|
||||
} else {
|
||||
@@ -64,12 +60,12 @@ public class MeetupDecisionListener implements ButtonClickedListener {
|
||||
MeetupMessageModel meetupMessageModel = meetupServiceBean.getMeetupMessageModel(meetup);
|
||||
addParticipationToModel(meetupMessageModel, userInAServer, payload.getMeetupDecision());
|
||||
MessageToSend messageToSend = meetupServiceBean.getMeetupMessage(meetupMessageModel);
|
||||
channelService.editEmbedMessageInAChannel(messageToSend.getEmbeds().get(0), model.getEvent().getChannel(), meetup.getMessageId()).thenAccept(message -> {
|
||||
log.info("Updated message of meetup {} in channel {} in server {}.", meetup.getId().getId(), meetup.getMeetupChannel().getId(), meetup.getServer().getId());
|
||||
}).exceptionally(throwable -> {
|
||||
log.info("Failed to update message of meetup {} in channel {} in server {}.", meetup.getId().getId(), meetup.getMeetupChannel().getId(), meetup.getServer().getId(), throwable);
|
||||
return null;
|
||||
});
|
||||
channelService.editEmbedMessageInAChannel(messageToSend.getEmbeds().get(0), model.getEvent().getChannel(), meetup.getMessageId())
|
||||
.thenAccept(message -> log.info("Updated message of meetup {} in channel {} in server {}.", meetup.getId().getId(), meetup.getMeetupChannel().getId(), meetup.getServer().getId()))
|
||||
.exceptionally(throwable -> {
|
||||
log.info("Failed to update message of meetup {} in channel {} in server {}.", meetup.getId().getId(), meetup.getMeetupChannel().getId(), meetup.getServer().getId(), throwable);
|
||||
return null;
|
||||
});
|
||||
return ButtonClickedListenerResult.ACKNOWLEDGED;
|
||||
}
|
||||
|
||||
@@ -80,7 +76,8 @@ public class MeetupDecisionListener implements ButtonClickedListener {
|
||||
addIfMissing(model.getParticipants(), aUserInAServer);
|
||||
} else if(decision.equals(MeetupDecision.MAYBE)) {
|
||||
addIfMissing(model.getMaybeParticipants(), aUserInAServer);
|
||||
}
|
||||
} else if(decision.equals(MeetupDecision.NO_TIME))
|
||||
addIfMissing(model.getNoTimeParticipants(), aUserInAServer);
|
||||
}
|
||||
|
||||
private void addIfMissing(List<MemberDisplay> list, AUserInAServer aUserInAServer) {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.sheldan.sissi.module.meetup.model.command;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class MeetupChangeTimeConfirmationModel {
|
||||
private Instant meetupTime;
|
||||
private String topic;
|
||||
private Long userId;
|
||||
private String description;
|
||||
private Long meetupId;
|
||||
private Long guildId;
|
||||
private String confirmationId;
|
||||
private String cancelId;
|
||||
}
|
||||
@@ -14,6 +14,7 @@ public class MeetupConfirmationModel {
|
||||
private MemberDisplay organizer;
|
||||
private Instant meetupTime;
|
||||
private Long meetupId;
|
||||
private String location;
|
||||
private String topic;
|
||||
private String description;
|
||||
private Long guildId;
|
||||
|
||||
@@ -6,7 +6,7 @@ import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import jakarta.persistence.*;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -43,13 +43,41 @@ public class Meetup {
|
||||
@Column(name = "message_id")
|
||||
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(
|
||||
fetch = FetchType.LAZY,
|
||||
orphanRemoval = true,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
mappedBy = "meetup")
|
||||
@Builder.Default
|
||||
private List<MeetupParticipator> participants = new ArrayList<>();
|
||||
private List<MeetupParticipant> participants = new ArrayList<>();
|
||||
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
orphanRemoval = true,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
mappedBy = "meetup")
|
||||
@Builder.Default
|
||||
private List<MeetupComponent> meetupComponents = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
@Enumerated(EnumType.STRING)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package dev.sheldan.sissi.module.meetup.model.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.ComponentPayload;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.embed.MeetupComponentId;
|
||||
import lombok.*;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.time.Instant;
|
||||
|
||||
@Builder
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "meetup_component")
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class MeetupComponent {
|
||||
|
||||
@EmbeddedId
|
||||
@Getter
|
||||
private MeetupComponentId id;
|
||||
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
|
||||
@MapsId("componentId")
|
||||
@JoinColumn(name = "component_id", nullable = false)
|
||||
private ComponentPayload payload;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumns(
|
||||
{
|
||||
@JoinColumn(updatable = false, insertable = false, name = "meetup_id", referencedColumnName = "id"),
|
||||
@JoinColumn(updatable = false, insertable = false, name = "server_id", referencedColumnName = "server_id")
|
||||
})
|
||||
private Meetup meetup;
|
||||
|
||||
@Column(name = "created")
|
||||
private Instant created;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package dev.sheldan.sissi.module.meetup.model.database;
|
||||
|
||||
public enum MeetupDecision {
|
||||
YES, NO, MAYBE, CANCEL
|
||||
YES, NO, MAYBE, NO_TIME
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.embed.MeetupParticipationId;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import jakarta.persistence.*;
|
||||
import java.time.Instant;
|
||||
|
||||
@Builder
|
||||
@@ -15,14 +15,14 @@ import java.time.Instant;
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class MeetupParticipator {
|
||||
public class MeetupParticipant {
|
||||
|
||||
@EmbeddedId
|
||||
@Getter
|
||||
private MeetupParticipationId id;
|
||||
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
|
||||
@MapsId("voterId")
|
||||
@MapsId("participatorId")
|
||||
@JoinColumn(name = "meetup_participator_user_in_server_id", nullable = false)
|
||||
private AUserInAServer participator;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package dev.sheldan.sissi.module.meetup.model.database.embed;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Embeddable
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@EqualsAndHashCode
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MeetupComponentId implements Serializable {
|
||||
@Column(name = "component_id")
|
||||
private String componentId;
|
||||
|
||||
@Column(name = "meetup_id")
|
||||
private Long meetupId;
|
||||
|
||||
@Column(name = "server_id")
|
||||
private Long serverId;
|
||||
}
|
||||
@@ -2,8 +2,8 @@ package dev.sheldan.sissi.module.meetup.model.database.embed;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Embeddable
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.sheldan.sissi.module.meetup.model.payload;
|
||||
|
||||
import dev.sheldan.abstracto.core.interaction.button.ButtonPayload;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
@Setter
|
||||
public class MeetupChangeTimeConfirmationPayload implements ButtonPayload {
|
||||
private Long organizerUserId;
|
||||
private Long meetupId;
|
||||
private Long newTime;
|
||||
private Long guildId;
|
||||
private String confirmationId;
|
||||
private String cancelId;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.sissi.module.meetup.model.payload;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.button.ButtonPayload;
|
||||
import dev.sheldan.abstracto.core.interaction.button.ButtonPayload;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.sissi.module.meetup.model.payload;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.button.ButtonPayload;
|
||||
import dev.sheldan.abstracto.core.interaction.button.ButtonPayload;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupDecision;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -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,13 +15,18 @@ public class MeetupMessageModel {
|
||||
private String topic;
|
||||
private String description;
|
||||
private Instant meetupTime;
|
||||
private String location;
|
||||
private String decodedLocation;
|
||||
private MemberDisplay organizer;
|
||||
private Long meetupId;
|
||||
private String yesId;
|
||||
private String noId;
|
||||
private String maybeId;
|
||||
private String cancelId;
|
||||
private String noTimeId;
|
||||
private Boolean cancelled;
|
||||
private List<MemberDisplay> participants;
|
||||
private List<MemberDisplay> maybeParticipants;
|
||||
private List<MemberDisplay> noTimeParticipants;
|
||||
private List<MemberDisplay> declinedParticipants;
|
||||
private MeetupIcsModel meetupIcsModel;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.sheldan.sissi.module.meetup.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class MeetupNotificationModel {
|
||||
private List<MemberDisplay> participants;
|
||||
private String notificationMessage;
|
||||
private Long meetupMessageId;
|
||||
private String meetupTopic;
|
||||
private Long meetupId;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.sheldan.sissi.module.meetup.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerChannelMessage;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class MeetupTimeChangedNotificationModel {
|
||||
private String meetupTopic;
|
||||
private String meetupDescription;
|
||||
private Instant oldDate;
|
||||
private Instant newDate;
|
||||
private ServerChannelMessage meetupMessage;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.sheldan.sissi.module.meetup.repository;
|
||||
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupComponent;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.embed.MeetupComponentId;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface MeetupComponentRepository extends JpaRepository<MeetupComponent, MeetupComponentId> {
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package dev.sheldan.sissi.module.meetup.repository;
|
||||
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupParticipator;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupParticipant;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.embed.MeetupParticipationId;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface MeetupParticipatorRepository extends JpaRepository<MeetupParticipator, MeetupParticipationId> {
|
||||
public interface MeetupParticipatorRepository extends JpaRepository<MeetupParticipant, MeetupParticipationId> {
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.sheldan.sissi.module.meetup.repository;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupState;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -11,5 +12,6 @@ import java.util.List;
|
||||
@Repository
|
||||
public interface MeetupRepository extends JpaRepository<Meetup, ServerSpecificId> {
|
||||
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> findByState(MeetupState state);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,52 @@
|
||||
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.ComponentPayloadService;
|
||||
import dev.sheldan.abstracto.core.models.ServerChannelMessage;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import dev.sheldan.abstracto.core.service.*;
|
||||
import dev.sheldan.abstracto.core.service.management.ComponentPayloadManagementService;
|
||||
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.FileService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.scheduling.model.JobParameters;
|
||||
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.MeetupConfirmationModel;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupDecision;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupParticipator;
|
||||
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.payload.MeetupChangeTimeConfirmationPayload;
|
||||
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.MeetupNotificationModel;
|
||||
import dev.sheldan.sissi.module.meetup.model.template.MeetupTimeChangedNotificationModel;
|
||||
import dev.sheldan.sissi.module.meetup.service.management.MeetupComponentManagementServiceBean;
|
||||
import dev.sheldan.sissi.module.meetup.service.management.MeetupManagementServiceBean;
|
||||
import dev.sheldan.sissi.module.meetup.service.management.MeetupParticipatorManagementServiceBean;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
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.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -36,9 +55,11 @@ import java.util.stream.Collectors;
|
||||
public class MeetupServiceBean {
|
||||
|
||||
public static final String MEETUP_CONFIRMATION_BUTTON = "MEETUP_CONFIRMATION_BUTTON";
|
||||
public static final String MEETUP_CHANGE_TIME_CONFIRMATION_BUTTON = "MEETUP_CHANGE_TIME_CONFIRMATION_BUTTON";
|
||||
public static final String MEETUP_DECISION_BUTTON = "MEETUP_DECISION_BUTTON";
|
||||
private static final String MEETUP_DISPLAY_TEMPLATE = "meetup_display";
|
||||
private static final String MEETUP_CANCELLATION_TEMPLATE = "meetup_cancel_notification";
|
||||
private static final String MEETUP_CHANGE_TIME_NOTIFICATION_TEMPLATE = "changeMeetupTime_notification";
|
||||
private static final String MEETUP_REMINDER_TEMPLATE = "meetup_reminder_notification";
|
||||
private static final String MEETUP_LATE_REMINDER_CONFIG_KEY = "meetupLateReminderSeconds";
|
||||
private static final String MEETUP_EARLY_REMINDER_CONFIG_KEY = "meetupEarlyReminderSeconds";
|
||||
@@ -65,6 +86,9 @@ public class MeetupServiceBean {
|
||||
@Autowired
|
||||
private MeetupServiceBean self;
|
||||
|
||||
@Autowired
|
||||
private FileService fileService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@@ -77,6 +101,17 @@ public class MeetupServiceBean {
|
||||
@Autowired
|
||||
private SchedulerService schedulerService;
|
||||
|
||||
@Autowired
|
||||
private FeatureModeService featureModeService;
|
||||
|
||||
@Autowired
|
||||
private MeetupParticipatorManagementServiceBean meetupParticipatorManagementServiceBean;
|
||||
|
||||
@Autowired
|
||||
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) {
|
||||
AServer server = serverManagementService.loadServer(model.getGuildId());
|
||||
MeetupConfirmationPayload confirmationPayload = MeetupConfirmationPayload
|
||||
@@ -91,35 +126,80 @@ public class MeetupServiceBean {
|
||||
componentPayloadService.createButtonPayload(model.getCancelId(), confirmationPayload, MEETUP_CONFIRMATION_BUTTON, server);
|
||||
}
|
||||
|
||||
public void storeMeetupChangeTimeConfirmation(MeetupChangeTimeConfirmationModel model) {
|
||||
AServer server = serverManagementService.loadServer(model.getGuildId());
|
||||
MeetupChangeTimeConfirmationPayload confirmationPayload = MeetupChangeTimeConfirmationPayload
|
||||
.builder()
|
||||
.newTime(model.getMeetupTime().getEpochSecond())
|
||||
.confirmationId(model.getConfirmationId())
|
||||
.meetupId(model.getMeetupId())
|
||||
.organizerUserId(model.getUserId())
|
||||
.cancelId(model.getCancelId())
|
||||
.guildId(model.getGuildId())
|
||||
.build();
|
||||
componentPayloadService.createButtonPayload(model.getConfirmationId(), 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) {
|
||||
List<MeetupParticipator> allParticipants = meetup.getParticipants();
|
||||
List<MeetupParticipator> participating = allParticipants
|
||||
List<MeetupParticipant> allParticipants = meetup.getParticipants();
|
||||
List<MeetupParticipant> participating = allParticipants
|
||||
.stream()
|
||||
.filter(meetupParticipator -> meetupParticipator.getDecision().equals(MeetupDecision.YES))
|
||||
.collect(Collectors.toList());
|
||||
List<MeetupParticipator> maybe = allParticipants
|
||||
List<MeetupParticipant> maybe = allParticipants
|
||||
.stream()
|
||||
.filter(meetupParticipator -> meetupParticipator.getDecision().equals(MeetupDecision.MAYBE))
|
||||
.collect(Collectors.toList());
|
||||
List<MeetupParticipator> notParticipating = allParticipants
|
||||
List<MeetupParticipant> notParticipating = allParticipants
|
||||
.stream()
|
||||
.filter(meetupParticipator -> meetupParticipator.getDecision().equals(MeetupDecision.NO))
|
||||
.collect(Collectors.toList());
|
||||
List<MeetupParticipant> notTimeParticipating = allParticipants
|
||||
.stream()
|
||||
.filter(meetupParticipator -> meetupParticipator.getDecision().equals(MeetupDecision.NO_TIME))
|
||||
.collect(Collectors.toList());
|
||||
String rawLocation = java.net.URLDecoder.decode(meetup.getLocation(), StandardCharsets.UTF_8);
|
||||
return MeetupMessageModel
|
||||
.builder()
|
||||
.description(meetup.getDescription())
|
||||
.topic(meetup.getTopic())
|
||||
.location(meetup.getLocation())
|
||||
.decodedLocation(rawLocation)
|
||||
.noTimeId(meetup.getNoTimeButtonId())
|
||||
.yesId(meetup.getYesButtonId())
|
||||
.maybeId(meetup.getMaybeButtonId())
|
||||
.noId(meetup.getNotInterestedButtonId())
|
||||
.meetupTime(meetup.getMeetupTime())
|
||||
.meetupId(meetup.getId().getId())
|
||||
.participants(getMemberDisplays(participating))
|
||||
.declinedParticipants(getMemberDisplays(notParticipating))
|
||||
.noTimeParticipants(getMemberDisplays(notTimeParticipating))
|
||||
.maybeParticipants(getMemberDisplays(maybe))
|
||||
.cancelled(meetup.getState().equals(MeetupState.CANCELLED))
|
||||
.organizer(MemberDisplay.fromAUserInAServer(meetup.getOrganizer()))
|
||||
.meetupIcsModel(getMeetupICSModel(meetup))
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<MemberDisplay> getMemberDisplays(List<MeetupParticipator> participants) {
|
||||
private List<MemberDisplay> getMemberDisplays(List<MeetupParticipant> participants) {
|
||||
return participants
|
||||
.stream()
|
||||
.map(meetupParticipator -> MemberDisplay.fromAUserInAServer(meetupParticipator.getParticipator()))
|
||||
@@ -130,11 +210,16 @@ public class MeetupServiceBean {
|
||||
return templateService.renderEmbedTemplate(MEETUP_DISPLAY_TEMPLATE, model);
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> cancelMeetup(Meetup meetup, List<String> componentPayloads) {
|
||||
public CompletableFuture<Void> cancelMeetup(Meetup meetup) {
|
||||
Long serverId = meetup.getServer().getId();
|
||||
Long meetupId = meetup.getId().getId();
|
||||
GuildMessageChannel channel = channelService.getMessageChannelFromServer(serverId, meetup.getMeetupChannel().getId());
|
||||
MeetupMessageModel model = getMeetupMessageModel(meetup);
|
||||
List<String> componentPayloads = meetup
|
||||
.getMeetupComponents()
|
||||
.stream()
|
||||
.map(meetupComponent -> meetupComponent.getId().getComponentId())
|
||||
.collect(Collectors.toList());
|
||||
model.setCancelled(true);
|
||||
MessageToSend meetupMessage = getMeetupMessage(model);
|
||||
return messageService.editMessageInChannel(channel, meetupMessage, meetup.getMessageId())
|
||||
@@ -147,18 +232,29 @@ public class MeetupServiceBean {
|
||||
Meetup meetup = meetupManagementServiceBean.getMeetup(meetupId, serverId);
|
||||
MeetupMessageModel model = getMeetupMessageModel(meetup);
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(MEETUP_CANCELLATION_TEMPLATE, model);
|
||||
meetup.getParticipants().forEach(meetupParticipator -> {
|
||||
Long userId = meetupParticipator.getParticipator().getUserReference().getId();
|
||||
userService.retrieveUserForId(userId)
|
||||
.thenCompose(user -> messageService.sendMessageToSendToUser(user, messageToSend))
|
||||
.thenAccept(message -> log.info("Notified user {} about cancellation of meetup {} in server {}.", userId, meetupId, serverId));
|
||||
});
|
||||
meetup
|
||||
.getParticipants()
|
||||
.stream()
|
||||
.filter(meetupParticipator ->
|
||||
meetupParticipator.getDecision().equals(MeetupDecision.MAYBE) ||
|
||||
meetupParticipator.getDecision().equals(MeetupDecision.YES))
|
||||
.forEach(meetupParticipator -> {
|
||||
Long userId = meetupParticipator.getParticipator().getUserReference().getId();
|
||||
userService.retrieveUserForId(userId)
|
||||
.thenCompose(user -> messageService.sendMessageToSendToUser(user, messageToSend))
|
||||
.thenAccept(message -> log.info("Notified user {} about cancellation of meetup {} in server {}.", userId, meetupId, serverId))
|
||||
.exceptionally(throwable -> {
|
||||
log.warn("Failed to notify user {} about cancellation of meetup {} in server {}.", userId, meetupId, serverId);
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void cleanupMeetup(Long meetupId, Long serverId, List<String> componentPayloads) {
|
||||
Meetup meetup = meetupManagementServiceBean.getMeetup(meetupId, serverId);
|
||||
meetup.setState(MeetupState.CANCELLED);
|
||||
meetupComponentManagementServiceBean.deleteAllComponents(meetup);
|
||||
log.info("Cleanup meetup {} in server {}.", meetup, serverId);
|
||||
if(meetup.getEarlyReminderJobTriggerKey() != null) {
|
||||
schedulerService.stopTrigger(meetup.getEarlyReminderJobTriggerKey());
|
||||
@@ -197,6 +293,28 @@ public class MeetupServiceBean {
|
||||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> notifyMeetupParticipants(Meetup meetup, String message, MeetupDecision toNotify) {
|
||||
List<MeetupDecision> decisionsToBeNotified = toNotify == null ? Arrays.asList(MeetupDecision.MAYBE, MeetupDecision.YES) : Arrays.asList(toNotify);
|
||||
List<MemberDisplay> participants = meetup
|
||||
.getParticipants()
|
||||
.stream()
|
||||
.filter(meetupParticipator -> decisionsToBeNotified.contains(meetupParticipator.getDecision()))
|
||||
.map(meetupParticipator -> MemberDisplay.fromAUserInAServer(meetupParticipator.getParticipator()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
MeetupNotificationModel model = MeetupNotificationModel
|
||||
.builder()
|
||||
.notificationMessage(message)
|
||||
.meetupId(meetup.getId().getId())
|
||||
.meetupMessageId(meetup.getMessageId())
|
||||
.meetupTopic(meetup.getTopic())
|
||||
.participants(participants)
|
||||
.build();
|
||||
MessageChannel channel = channelService.getMessageChannelFromServer(meetup.getServer().getId(), meetup.getMeetupChannel().getId());
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("notifyMeetupParticipants_notification_message", model, meetup.getServer().getId());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, channel));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void remindParticipants(Long meetupId, Long serverId) {
|
||||
Meetup meetup = meetupManagementServiceBean.getMeetup(meetupId, serverId);
|
||||
@@ -209,21 +327,144 @@ public class MeetupServiceBean {
|
||||
meetupParticipator.getDecision().equals(MeetupDecision.MAYBE) ||
|
||||
meetupParticipator.getDecision().equals(MeetupDecision.YES))
|
||||
.forEach(meetupParticipator -> {
|
||||
Long userId = meetupParticipator.getParticipator().getUserReference().getId();
|
||||
userService.retrieveUserForId(userId)
|
||||
.thenCompose(user -> messageService.sendMessageToSendToUser(user, messageToSend))
|
||||
.thenAccept(message -> log.info("Notified user {} about incoming meetup {} in server {}.", userId, meetupId, serverId));
|
||||
});
|
||||
Long userId = meetupParticipator.getParticipator().getUserReference().getId();
|
||||
userService.retrieveUserForId(userId)
|
||||
.thenCompose(user -> messageService.sendMessageToSendToUser(user, messageToSend))
|
||||
.thenAccept(message -> log.info("Notified user {} about incoming meetup {} in server {}.", userId, meetupId, serverId));
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void cleanupMeetups() {
|
||||
Instant time = Instant.now().minus(1, ChronoUnit.DAYS);
|
||||
List<Meetup> oldMeetups = meetupManagementServiceBean.getMeetupsOlderThan(time)
|
||||
.stream()
|
||||
.filter(meetup -> meetup.getMessageId() != null)
|
||||
.collect(Collectors.toList());
|
||||
oldMeetups.forEach(meetup -> messageService.deleteMessageInChannelInServer(meetup.getServer().getId(), meetup.getMeetupChannel().getId(), meetup.getMessageId()));
|
||||
List<Meetup> oldMeetups = meetupManagementServiceBean.getMeetupsOlderThan(time);
|
||||
log.info("Deleting {} old meetups.", oldMeetups.size());
|
||||
deleteMeetups(oldMeetups);
|
||||
List<Meetup> cancelledMeetups = meetupManagementServiceBean.findCancelledMeetups();
|
||||
log.info("Deleting {} cancelled meetups.", cancelledMeetups.size());
|
||||
deleteMeetups(cancelledMeetups);
|
||||
}
|
||||
|
||||
private void deleteMeetups(List<Meetup> oldMeetups) {
|
||||
oldMeetups.forEach(meetup -> {
|
||||
if(meetup.getMessageId() != null) {
|
||||
Long messageId = meetup.getMessageId();
|
||||
Long meetupId = meetup.getId().getId();
|
||||
Long serverId = meetup.getServer().getId();
|
||||
messageService.deleteMessageInChannelInServer(meetup.getServer().getId(), meetup.getMeetupChannel().getId(), meetup.getMessageId())
|
||||
.exceptionally(throwable -> {
|
||||
log.error("Failed to delete message {} for meetup {} in server {}.", messageId, meetupId, serverId);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
meetupComponentManagementServiceBean.deleteAllComponents(meetup);
|
||||
});
|
||||
meetupManagementServiceBean.deleteMeetups(oldMeetups);
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> changeMeetupTimeAndNotifyParticipants(Meetup meetup, Instant newTime) {
|
||||
List<MeetupDecision> decisions = Arrays.asList(MeetupDecision.MAYBE, MeetupDecision.NO_TIME, MeetupDecision.YES);
|
||||
List<MeetupParticipant> participants = meetup
|
||||
.getParticipants()
|
||||
.stream()
|
||||
.filter(meetupParticipator -> decisions.contains(meetupParticipator.getDecision()))
|
||||
.collect(Collectors.toList());
|
||||
List<Long> userIdsToNotify = participants
|
||||
.stream()
|
||||
.map(meetupParticipator -> meetupParticipator.getParticipator().getUserReference().getId())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Long serverId = meetup.getServer().getId();
|
||||
|
||||
ServerChannelMessage meetupMessage = ServerChannelMessage
|
||||
.builder()
|
||||
.serverId(serverId)
|
||||
.channelId(meetup.getMeetupChannel().getId())
|
||||
.messageId(meetup.getMessageId())
|
||||
.build();
|
||||
MeetupTimeChangedNotificationModel notificationModel = MeetupTimeChangedNotificationModel
|
||||
.builder()
|
||||
.meetupDescription(meetup.getDescription())
|
||||
.meetupTopic(meetup.getTopic())
|
||||
.meetupMessage(meetupMessage)
|
||||
.newDate(newTime)
|
||||
.oldDate(meetup.getMeetupTime())
|
||||
.build();
|
||||
|
||||
if(meetup.getEarlyReminderJobTriggerKey() != null) {
|
||||
schedulerService.stopTrigger(meetup.getEarlyReminderJobTriggerKey());
|
||||
}
|
||||
if(meetup.getLateReminderJobTriggerKey() != null) {
|
||||
schedulerService.stopTrigger(meetup.getLateReminderJobTriggerKey());
|
||||
}
|
||||
// set the new time here, so that we can use it in schedule
|
||||
meetup.setMeetupTime(newTime);
|
||||
scheduleReminders(meetup);
|
||||
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(MEETUP_CHANGE_TIME_NOTIFICATION_TEMPLATE, notificationModel, serverId);
|
||||
Long meetupId = meetup.getId().getId();
|
||||
userIdsToNotify.forEach(userId -> {
|
||||
userService.retrieveUserForId(userId).thenCompose(user -> messageService.sendMessageToSendToUser(user, messageToSend)
|
||||
.exceptionally(throwable -> {
|
||||
log.warn("Failed to notify user {} about changed time of meetup {} in server {}.", userId, meetupId, serverId);
|
||||
return null;
|
||||
}));
|
||||
});
|
||||
|
||||
meetupParticipatorManagementServiceBean.deleteParticipants(participants);
|
||||
List<Long> userInServerIds = participants
|
||||
.stream()
|
||||
.map(meetupParticipant -> meetupParticipant.getParticipator().getUserInServerId())
|
||||
.collect(Collectors.toList());
|
||||
meetup
|
||||
.getParticipants().removeIf(meetupParticipant -> userInServerIds.contains(meetupParticipant.getParticipator().getUserInServerId()));
|
||||
MeetupMessageModel meetupMessageModel = getMeetupMessageModel(meetup);
|
||||
meetupMessageModel.setParticipants(new ArrayList<>());
|
||||
meetupMessageModel.setMaybeParticipants(new ArrayList<>());
|
||||
meetupMessageModel.setNoTimeParticipants(new ArrayList<>());
|
||||
|
||||
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 -> {
|
||||
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 -> {
|
||||
log.info("Failed to update message of meetup {} in channel {} in server {}.", meetupId, meetup.getMeetupChannel().getId(), serverId, throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package dev.sheldan.sissi.module.meetup.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.ComponentPayload;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupComponent;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.embed.MeetupComponentId;
|
||||
import dev.sheldan.sissi.module.meetup.repository.MeetupComponentRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MeetupComponentManagementServiceBean {
|
||||
|
||||
@Autowired
|
||||
private MeetupComponentRepository meetupComponentRepository;
|
||||
|
||||
public MeetupComponent createComponent(Meetup meetup, String componentId, ComponentPayload payload) {
|
||||
MeetupComponentId id = MeetupComponentId
|
||||
.builder()
|
||||
.meetupId(meetup.getId().getId())
|
||||
.serverId(meetup.getServer().getId())
|
||||
.componentId(componentId)
|
||||
.build();
|
||||
MeetupComponent component = MeetupComponent
|
||||
.builder()
|
||||
.id(id)
|
||||
.payload(payload)
|
||||
.meetup(meetup)
|
||||
.build();
|
||||
return meetupComponentRepository.save(component);
|
||||
}
|
||||
|
||||
public void deleteComponent(MeetupComponent meetupComponent) {
|
||||
meetupComponentRepository.delete(meetupComponent);
|
||||
}
|
||||
|
||||
public void deleteAllComponents(Meetup meetup) {
|
||||
meetupComponentRepository.deleteAll(meetup.getMeetupComponents());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
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.database.AChannel;
|
||||
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.stereotype.Component;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,22 +30,28 @@ public class MeetupManagementServiceBean {
|
||||
|
||||
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())) {
|
||||
throw new MeetupPastTimeException();
|
||||
}
|
||||
Long meetupId = counterService.getNextCounterValue(organizer.getServerReference(), MEETUP_COUNTER_KEY);
|
||||
Meetup meetup = Meetup
|
||||
.builder()
|
||||
.meetupTime(timeStamp)
|
||||
.description(description)
|
||||
.topic(topic)
|
||||
.organizer(organizer)
|
||||
.server(organizer.getServerReference())
|
||||
.meetupChannel(meetupChannel)
|
||||
.state(MeetupState.NEW)
|
||||
.id(new ServerSpecificId(organizer.getServerReference().getId(), meetupId))
|
||||
.build();
|
||||
Meetup meetup = null;
|
||||
try {
|
||||
meetup = Meetup
|
||||
.builder()
|
||||
.meetupTime(timeStamp)
|
||||
.description(description)
|
||||
.topic(topic)
|
||||
.location(URLEncoder.encode(location, StandardCharsets.UTF_8.toString()))
|
||||
.organizer(organizer)
|
||||
.server(organizer.getServerReference())
|
||||
.meetupChannel(meetupChannel)
|
||||
.state(MeetupState.NEW)
|
||||
.id(new ServerSpecificId(organizer.getServerReference().getId(), meetupId))
|
||||
.build();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new AbstractoRunTimeException(e);
|
||||
}
|
||||
return meetupRepository.save(meetup);
|
||||
}
|
||||
|
||||
@@ -58,8 +68,12 @@ public class MeetupManagementServiceBean {
|
||||
return meetupRepository.findAll();
|
||||
}
|
||||
|
||||
public List<Meetup> getFutureMeetups() {
|
||||
return meetupRepository.findByMeetupTimeGreaterThan(Instant.now());
|
||||
public List<Meetup> findCancelledMeetups() {
|
||||
return meetupRepository.findByState(MeetupState.CANCELLED);
|
||||
}
|
||||
|
||||
public List<Meetup> getIncomingMeetups(Long serverId, Long channelId) {
|
||||
return meetupRepository.findByMeetupTimeGreaterThanAndStateAndServer_IdAndMeetupChannel_Id(Instant.now(), MeetupState.CONFIRMED, serverId, channelId);
|
||||
}
|
||||
|
||||
public void deleteMeetups(List<Meetup> meetups) {
|
||||
|
||||
@@ -3,21 +3,24 @@ package dev.sheldan.sissi.module.meetup.service.management;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.Meetup;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupDecision;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupParticipator;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.MeetupParticipant;
|
||||
import dev.sheldan.sissi.module.meetup.model.database.embed.MeetupParticipationId;
|
||||
import dev.sheldan.sissi.module.meetup.repository.MeetupParticipatorRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MeetupParticipatorManagementServiceBean {
|
||||
|
||||
@Autowired
|
||||
private MeetupParticipatorRepository repository;
|
||||
|
||||
public Optional<MeetupParticipator> getParticipation(Meetup meetup, AUserInAServer aUserInAServer) {
|
||||
public Optional<MeetupParticipant> getParticipation(Meetup meetup, AUserInAServer aUserInAServer) {
|
||||
MeetupParticipationId id = MeetupParticipationId
|
||||
.builder()
|
||||
.meetupId(meetup.getId().getId())
|
||||
@@ -27,14 +30,20 @@ public class MeetupParticipatorManagementServiceBean {
|
||||
return repository.findById(id);
|
||||
}
|
||||
|
||||
public MeetupParticipator createParticipation(Meetup meetup, AUserInAServer aUserInAServer, MeetupDecision meetupDecision) {
|
||||
public void deleteParticipants(List<MeetupParticipant> participants) {
|
||||
log.info("Deleting {} participants", participants.size());
|
||||
repository.deleteAll(participants);
|
||||
participants.forEach(meetupParticipant -> meetupParticipant.setMeetup(null));
|
||||
}
|
||||
|
||||
public MeetupParticipant createParticipation(Meetup meetup, AUserInAServer aUserInAServer, MeetupDecision meetupDecision) {
|
||||
MeetupParticipationId id = MeetupParticipationId
|
||||
.builder()
|
||||
.meetupId(meetup.getId().getId())
|
||||
.serverId(meetup.getServer().getId())
|
||||
.participatorId(aUserInAServer.getUserInServerId())
|
||||
.build();
|
||||
MeetupParticipator participator = MeetupParticipator
|
||||
MeetupParticipant participator = MeetupParticipant
|
||||
.builder()
|
||||
.id(id)
|
||||
.meetup(meetup)
|
||||
|
||||
@@ -5,4 +5,8 @@ abstracto.systemConfigs.meetupEarlyReminderSeconds.name=meetupEarlyReminderSecon
|
||||
abstracto.systemConfigs.meetupEarlyReminderSeconds.longValue=604800
|
||||
|
||||
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="seedData/data.xml" relativeToChangelogFile="true"/>
|
||||
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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-commands">
|
||||
<insert tableName="command">
|
||||
<column name="name" value="cancelMeetup"/>
|
||||
<column name="module_id" valueComputed="${utilityModule}"/>
|
||||
<column name="feature_id" valueComputed="${meetupFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="changeMeetupTime"/>
|
||||
<column name="module_id" valueComputed="${utilityModule}"/>
|
||||
<column name="feature_id" valueComputed="${meetupFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="notifyMeetupParticipants"/>
|
||||
<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>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user