mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-07 18:03:50 +00:00
Compare commits
178 Commits
abstracto-
...
v1.5.9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74e5154e29 | ||
|
|
baad696a20 | ||
|
|
b7b5dc7b6a | ||
|
|
f27f59c0b3 | ||
|
|
ccd7ace8d9 | ||
|
|
73a73dc4f2 | ||
|
|
156725afa6 | ||
|
|
b369b56823 | ||
|
|
7482bf545d | ||
|
|
9804d165ca | ||
|
|
59ddb0b27d | ||
|
|
9aea9d2b4f | ||
|
|
b042e586a7 | ||
|
|
91e2bea2fc | ||
|
|
f03bee8b1e | ||
|
|
f3144eb094 | ||
|
|
2396bf300b | ||
|
|
06ebf4c882 | ||
|
|
ff534c03ac | ||
|
|
67c76487e2 | ||
|
|
9a2f47e244 | ||
|
|
2f33d19171 | ||
|
|
f6fc02e758 | ||
|
|
007929cfa5 | ||
|
|
77e2eec3d1 | ||
|
|
74c8cf7b6b | ||
|
|
c8739b90ec | ||
|
|
d39a303207 | ||
|
|
3e326fe47e | ||
|
|
a1d460973c | ||
|
|
d2475179e6 | ||
|
|
5adc304e77 | ||
|
|
4940577383 | ||
|
|
bba0a2ace6 | ||
|
|
b7c427026d | ||
|
|
cee10de915 | ||
|
|
1786231e11 | ||
|
|
2231fdf289 | ||
|
|
a46e22b5b2 | ||
|
|
1c9b9af833 | ||
|
|
3cafc95ceb | ||
|
|
6409bbaa1d | ||
|
|
346e462185 | ||
|
|
46baa79d3e | ||
|
|
650d062808 | ||
|
|
bac9832819 | ||
|
|
efbcb5c84b | ||
|
|
fd70e6ac90 | ||
|
|
29bde70796 | ||
|
|
ecd4feabb2 | ||
|
|
abf60409f1 | ||
|
|
080733957f | ||
|
|
8a41f366ae | ||
|
|
dbf478c44c | ||
|
|
3df688571f | ||
|
|
ca530949c6 | ||
|
|
724930e5a4 | ||
|
|
2875da117a | ||
|
|
f95ba6c28f | ||
|
|
1b2e7654f9 | ||
|
|
54976ed1d4 | ||
|
|
735816f5dd | ||
|
|
a984bdb84e | ||
|
|
21add6585d | ||
|
|
99e72245f3 | ||
|
|
9d184ff560 | ||
|
|
97895f5c56 | ||
|
|
f091559c49 | ||
|
|
fa7730975e | ||
|
|
03d7b9e2e2 | ||
|
|
a0bff12263 | ||
|
|
70e708601e | ||
|
|
f01418d0de | ||
|
|
ad539adb2a | ||
|
|
3c9fec989f | ||
|
|
21db3e3ee5 | ||
|
|
5b1ad2e075 | ||
|
|
63b3f68bdb | ||
|
|
7c1537c4a7 | ||
|
|
9836998087 | ||
|
|
8a1bb4cad8 | ||
|
|
a9dadec8ef | ||
|
|
3eaffaef87 | ||
|
|
b3a943e155 | ||
|
|
06dd4af131 | ||
|
|
0d51469975 | ||
|
|
aa10c88588 | ||
|
|
db27f64832 | ||
|
|
3903039aac | ||
|
|
41f42ee110 | ||
|
|
74f54e1257 | ||
|
|
a72e48f690 | ||
|
|
a813af8b1f | ||
|
|
abee7b2732 | ||
|
|
4c71ffbb7e | ||
|
|
18050e2a8a | ||
|
|
a0d83763d4 | ||
|
|
0461c8e4ec | ||
|
|
072f32975a | ||
|
|
6810d28c50 | ||
|
|
650a9099c4 | ||
|
|
1217e03725 | ||
|
|
2e837d8738 | ||
|
|
9ddd386c6f | ||
|
|
4e1db26df7 | ||
|
|
de335a1e2a | ||
|
|
9ba0ed711e | ||
|
|
b7376bf522 | ||
|
|
0d6182c5d5 | ||
|
|
96c38763b1 | ||
|
|
97b3099156 | ||
|
|
a0b2fc9c31 | ||
|
|
2db36ef96b | ||
|
|
08b3913b04 | ||
|
|
7a7ec5654f | ||
|
|
74679c2ccc | ||
|
|
063581ba1a | ||
|
|
5c7b018b2a | ||
|
|
d315113395 | ||
|
|
ea2f62b721 | ||
|
|
1a91275a2d | ||
|
|
e76b22ca59 | ||
|
|
5a21f9642c | ||
|
|
e3dd89b0ef | ||
|
|
4fe81c0ea2 | ||
|
|
ab55f5ee07 | ||
|
|
92cec30898 | ||
|
|
3a40ccccda | ||
|
|
e6802a0851 | ||
|
|
ce90370b9c | ||
|
|
b21afce1ad | ||
|
|
58fd11a561 | ||
|
|
3e38085a25 | ||
|
|
48f62f8bdf | ||
|
|
ad92ccd181 | ||
|
|
8ab0eaedda | ||
|
|
e2a7d3b9e8 | ||
|
|
8c101793a3 | ||
|
|
4e1f9e0018 | ||
|
|
102209aaca | ||
|
|
9a64da480b | ||
|
|
11c36691ce | ||
|
|
337ef87e47 | ||
|
|
056a7fe297 | ||
|
|
82383449c0 | ||
|
|
30655dbfef | ||
|
|
a43725df39 | ||
|
|
9a0bff154b | ||
|
|
4d54b11400 | ||
|
|
9c621954c8 | ||
|
|
f24552fdf2 | ||
|
|
e643080516 | ||
|
|
b747516881 | ||
|
|
0a4238c9f5 | ||
|
|
99fe84914b | ||
|
|
f9b85feeaf | ||
|
|
51edb50eee | ||
|
|
43a78a4989 | ||
|
|
e3e0ad98ba | ||
|
|
9c02be7299 | ||
|
|
9954515db0 | ||
|
|
68cae74819 | ||
|
|
1a1fde0800 | ||
|
|
74cee39f1a | ||
|
|
5ad3e30cc1 | ||
|
|
c02bf4aa8e | ||
|
|
c84a76b6a3 | ||
|
|
120df02dd0 | ||
|
|
61f43f6bc9 | ||
|
|
982cbb82d7 | ||
|
|
b4627d1ab0 | ||
|
|
1d6de3f1e8 | ||
|
|
1913bc930d | ||
|
|
09450429dd | ||
|
|
17470f9718 | ||
|
|
91a23f870c | ||
|
|
b047d3eb49 | ||
|
|
db5b420f0a |
42
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
42
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
name: Bug Report
|
||||
description: Found a bug that needs fixing?
|
||||
body:
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: General Troubleshooting
|
||||
description: You confirm to have made the following checks first.
|
||||
options:
|
||||
- label: I have checked for similar issues on the Issue-tracker.
|
||||
required: true
|
||||
- label: I have updated to the latest version
|
||||
required: true
|
||||
- label: I have checked the branches or the maintainers' PRs for upcoming bug fixes.
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Description"
|
||||
description: "General information about the bug"
|
||||
placeholder: "..."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Steps to reproduce"
|
||||
description: "What happened when the bug occurred?"
|
||||
placeholder: "1. ..."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Expected behaviour"
|
||||
description: "What should happen?"
|
||||
placeholder: "It should..."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Actual behaviour"
|
||||
description: "What did happen instead?"
|
||||
placeholder: "It actually ..."
|
||||
validations:
|
||||
required: true
|
||||
36
.github/ISSUE_TEMPLATE/feature.yml
vendored
Normal file
36
.github/ISSUE_TEMPLATE/feature.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: Feature request
|
||||
description: Want some functionality added?
|
||||
body:
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: General Information
|
||||
description: You confirm to have made the following checks first.
|
||||
options:
|
||||
- label: I have checked for similar issues on the Issue-tracker.
|
||||
required: true
|
||||
- label: I have updated to the latest version
|
||||
required: true
|
||||
- label: I have checked the branches or the maintainers' PRs for upcoming features fixes.
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Description"
|
||||
description: "General description of the feature"
|
||||
placeholder: "..."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Feature worth and general use"
|
||||
description: "Why should this be in abstracto?"
|
||||
placeholder: "..."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Suggestions for implementation"
|
||||
description: "Any ideas about what the feature should behave/look like? Commands?"
|
||||
placeholder: "It should..."
|
||||
validations:
|
||||
required: false
|
||||
|
||||
24
.github/workflows/build.yml
vendored
24
.github/workflows/build.yml
vendored
@@ -1,7 +1,7 @@
|
||||
# This workflow will build a Java project with Maven
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
name: Execute build and Sonar
|
||||
name: Execute Build
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -19,26 +19,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
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: 1.8
|
||||
distribution: 'corretto'
|
||||
java-version: 17
|
||||
- name: Build with Maven
|
||||
run: mvn -B install --file abstracto-application/pom.xml
|
||||
- name: Setup sonarqube
|
||||
uses: warchant/setup-sonar-scanner@v3
|
||||
- name: Run sonarqube
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: sonar-scanner
|
||||
-Dsonar.login=${{ secrets.SONAR_TOKEN }}
|
||||
-Dsonar.organization=sheldan
|
||||
-Dsonar.host.url=https://sonarcloud.io/
|
||||
-Dsonar.projectKey=abstracto-core
|
||||
-Dsonar.java.binaries=**/target/classes
|
||||
-Dsonar.coverage.jacoco.xmlReportPaths=abstracto-application/coverage/target/site/jacoco-aggregate/jacoco.xml
|
||||
-Dsonar.coverage.exclusions=**/*Test.java
|
||||
- uses: actions/setup-ruby@v1
|
||||
- name: Send Webhook Notification
|
||||
if: always()
|
||||
|
||||
34
.github/workflows/release.yml
vendored
34
.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 --file abstracto-application/pom.xml -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_ENV
|
||||
@@ -21,7 +22,7 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Deploy documentation to GitHub pages
|
||||
uses: JamesIves/github-pages-deploy-action@4.1.0
|
||||
uses: JamesIves/github-pages-deploy-action@v4
|
||||
with:
|
||||
repository-name: Sheldan/abstracto-docs
|
||||
target-folder: docs/${{ env.version }}
|
||||
@@ -29,22 +30,27 @@ jobs:
|
||||
ssh-key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||
folder: abstracto-application/documentation/target/generated-docs
|
||||
- name: Deploy documentation to GitHub pages latest
|
||||
uses: JamesIves/github-pages-deploy-action@4.1.0
|
||||
uses: JamesIves/github-pages-deploy-action@v4
|
||||
with:
|
||||
repository-name: Sheldan/abstracto-docs
|
||||
target-folder: docs/current
|
||||
branch: master
|
||||
ssh-key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||
folder: abstracto-application/documentation/target/generated-docs
|
||||
- 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
|
||||
working-directory: ./abstracto-application/installer/src/main/docker/deployment
|
||||
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/installer/.env
|
||||
- name: Push container
|
||||
run: docker-compose build && docker-compose push
|
||||
working-directory: ./deployment/installer/
|
||||
env:
|
||||
REGISTRY_PREFIX: docker.pkg.github.com/sheldan/abstracto/
|
||||
VERSION: ${{ env.version }}
|
||||
REGISTRY_PREFIX: ${{ steps.dotenv.outputs.registry_prefix }}
|
||||
VERSION: ${{ steps.dotenv.outputs.version }}
|
||||
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
|
||||
|
||||
14
README.md
14
README.md
@@ -1,8 +1,6 @@
|
||||
# Abstracto
|
||||
|
||||

|
||||
[](https://sonarcloud.io/dashboard?id=abstracto-core)
|
||||
[](https://sonarcloud.io/dashboard?id=abstracto-core)
|
||||

|
||||
[](https://github.com/Sheldan/abstracto/blob/master/LICENSE)
|
||||
|
||||
|
||||
@@ -14,22 +12,20 @@ An example implementation of this bot can be seen [here](https://github.com/Shel
|
||||
|
||||
|
||||
## Technologies
|
||||
* [JDA](https://github.com/DV8FromTheWorld/JDA/) The Discord API Wrapper in the version 4.3.0_315
|
||||
* [Spring boot](https://github.com/spring-projects/spring-boot) is used as a framework to create standalone application in Java with Java EE methods. (including Dependency injection and more)
|
||||
* [JDA](https://github.com/DV8FromTheWorld/JDA/) The Discord API Wrapper in the version 5.0.0-beta.5
|
||||
* [Spring boot](https://github.com/spring-projects/spring-boot) is used as a framework to create standalone application in Java with Java EE methods. (including dependency injection and more)
|
||||
* [Hibernate](https://github.com/hibernate/hibernate-orm) is used as a reference implementation of JPA.
|
||||
* [Freemarker](https://github.com/apache/freemarker) is used as a templating engine. This is used to provide internationalization for user facing text and enable dynamic embed configuration.
|
||||
* [Ehcache](https://github.com/ehcache/ehcache3) is used as a caching implementation.
|
||||
* [Lombok](https://github.com/rzwitserloot/lombok) is used as a framework in order to speed up creation of container classes and builders.
|
||||
* [Quartz](https://github.com/quartz-scheduler/quartz) is used as a scheduling framework in order to provide functionalities which either require a delayed or cronjob behaviour.
|
||||
* [Docker](https://github.com/docker) is used to package the application into a container and [Docker Compose](https://github.com/docker/compose) is used to connect the required containers together.
|
||||
* [Quartz](https://github.com/quartz-scheduler/quartz) is used as a scheduling framework in order to provide functionalities which either require a scheduled or cronjob behaviour.
|
||||
* [Docker](https://github.com/docker) is used to package the application into an image and [Docker Compose](https://github.com/docker/compose) is used to build the images
|
||||
* [Liquibase](https://github.com/liquibase/liquibase) is used to manage changes to the database
|
||||
|
||||
## Documentation
|
||||
A detailed documentation of the pure form of Abstracto including the terminology and commands in HTML form is available [here](https://sheldan.github.io/abstracto-docs/current). The PDF is available [here](https://sheldan.github.io/abstracto-docs/current/documentation.pdf)
|
||||
If you want to view the documentation to an earlier released version you need to append the desired version to the URL. The current version will be available aforementioned URL, but it is not right now, because Abstracto has not been released yet.
|
||||
|
||||
## Customization documentation
|
||||
TBD when Abstracto is released, as the current version is still being adapted, because of findings from the example customization in Crimson.
|
||||
|
||||
## Issues
|
||||
If you find any issue, feel free to create a GitHub issue.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>anti-raid</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.3.12</version>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncMessageReceivedListener;
|
||||
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -5,10 +5,7 @@ import dev.sheldan.abstracto.antiraid.model.MassPingNotificationModel;
|
||||
import dev.sheldan.abstracto.core.models.ConditionContextInstance;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import dev.sheldan.abstracto.core.service.ConditionService;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.service.SystemCondition;
|
||||
import dev.sheldan.abstracto.core.service.*;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
@@ -61,19 +58,22 @@ public class MassPingServiceBean implements MassPingService {
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private MemberService memberService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> processMessage(Message message) {
|
||||
if(message.getMentionedMembers().size() > maxAllowedMentions) {
|
||||
if(message.getMentions().getUsers().size() > maxAllowedMentions) {
|
||||
Integer level = configService.getLongValueOrConfigDefault(MassPingService.MAX_AFFECTED_LEVEL_KEY, message.getGuild().getIdLong()).intValue();
|
||||
boolean allowed = allowedToMassMention(message, level);
|
||||
if(!allowed) {
|
||||
return muteService.muteMemberWithoutContext(message.getMember())
|
||||
return memberService.timeoutUserMaxDuration(message.getMember())
|
||||
.thenAccept(unused -> self.sendMassPingMuteNotification(message))
|
||||
.thenAccept(unused -> log.info("Muted member {} in server {} because of too many member mentions. (> {}).",
|
||||
message.getMember().getIdLong(), message.getGuild().getIdLong(), maxAllowedMentions));
|
||||
message.getAuthor().getIdLong(), message.getGuild().getIdLong(), maxAllowedMentions));
|
||||
} else {
|
||||
log.info("User {} in server {} is allowed to mass mention, because of level (or lack of level configuration).",
|
||||
message.getMember().getIdLong(), message.getGuild().getIdLong());
|
||||
message.getAuthor().getIdLong(), message.getGuild().getIdLong());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
} else {
|
||||
@@ -103,7 +103,7 @@ public class MassPingServiceBean implements MassPingService {
|
||||
MassPingNotificationModel model = MassPingNotificationModel
|
||||
.builder()
|
||||
.messageLink(message.getJumpUrl())
|
||||
.mentionCount(message.getMentionedMembers().size())
|
||||
.mentionCount(message.getMentions().getUsers().size())
|
||||
.messageContent(message.getContentRaw())
|
||||
.memberDisplay(MemberDisplay.fromMember(member))
|
||||
.build();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>anti-raid</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.3.12</version>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.3.12</version>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>assignable-roles</artifactId>
|
||||
<version>1.3.12</version>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import dev.sheldan.abstracto.core.exception.EntityGuildMismatchException;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.exception.EntityGuildMismatchException;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -48,8 +48,18 @@ public class MoveAssignableRolePlace extends AbstractConditionableCommand {
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
Parameter channel = Parameter.builder().name("channel").type(TextChannel.class).templated(true).build();
|
||||
Parameter rolePostName = Parameter
|
||||
.builder()
|
||||
.name("name")
|
||||
.type(String.class)
|
||||
.templated(true)
|
||||
.build();
|
||||
Parameter channel = Parameter
|
||||
.builder()
|
||||
.name("channel")
|
||||
.type(TextChannel.class)
|
||||
.templated(true)
|
||||
.build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName, channel);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
|
||||
@@ -19,10 +19,10 @@ import dev.sheldan.abstracto.assignableroles.service.management.AssignedRoleUser
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.listener.ButtonClickedListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.ButtonClickedListener;
|
||||
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListenerResult;
|
||||
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListener;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.listener.ButtonClickedListenerModel;
|
||||
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListenerModel;
|
||||
import dev.sheldan.abstracto.core.service.RoleService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
|
||||
@@ -31,8 +31,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
|
||||
import net.dv8tion.jda.api.interactions.components.ButtonInteraction;
|
||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.ButtonInteraction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -74,7 +74,7 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
|
||||
|
||||
@Override
|
||||
public ButtonClickedListenerResult execute(ButtonClickedListenerModel model) {
|
||||
ButtonClickEvent event = model.getEvent();
|
||||
ButtonInteractionEvent event = model.getEvent();
|
||||
Member member = event.getMember();
|
||||
if(event.getGuild() != null && member != null) {
|
||||
AssignableRolePlacePayload payload = (AssignableRolePlacePayload) model.getDeserializedPayload();
|
||||
@@ -219,7 +219,7 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
|
||||
|
||||
@Override
|
||||
public Boolean handlesEvent(ButtonClickedListenerModel model) {
|
||||
return AssignableRolePlaceServiceBean.ASSIGNABLE_ROLE_COMPONENT_ORIGIN.equals(model.getOrigin());
|
||||
return AssignableRolePlaceServiceBean.ASSIGNABLE_ROLE_COMPONENT_ORIGIN.equals(model.getOrigin()) && model.getEvent().isFromGuild();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model;
|
||||
|
||||
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;
|
||||
|
||||
@@ -11,6 +11,9 @@ import dev.sheldan.abstracto.assignableroles.service.management.*;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandParameterKeyValueWrongTypeException;
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotInGuildException;
|
||||
import dev.sheldan.abstracto.core.exception.EmoteNotUsableException;
|
||||
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.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
@@ -24,7 +27,9 @@ import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -114,13 +119,13 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
// it only may be unusable if its a custom emote
|
||||
log.debug("Using custom emote {} to create assignable role {} for assignable role place {} in server {}.",
|
||||
fakeEmote.getEmote().getId(), role.getId(), placeId, serverId);
|
||||
if (!emoteService.isEmoteUsableByBot(fakeEmote.getEmote()) && fakeEmote.getEmote().isAvailable()) {
|
||||
if (!emoteService.isEmoteUsableByBot(fakeEmote.getEmote())) {
|
||||
throw new EmoteNotUsableException(fakeEmote.getEmote());
|
||||
}
|
||||
}
|
||||
Optional<TextChannel> channelOptional = channelService.getTextChannelFromServerOptional(server.getId(), assignableRolePlace.getChannel().getId());
|
||||
Optional<GuildMessageChannel> channelOptional = channelService.getMessageChannelFromServerOptional(server.getId(), assignableRolePlace.getChannel().getId());
|
||||
if (channelOptional.isPresent()) {
|
||||
TextChannel textChannel = channelOptional.get();
|
||||
GuildMessageChannel textChannel = channelOptional.get();
|
||||
String buttonId = componentService.generateComponentId();
|
||||
String emoteMarkdown = fakeEmote != null ? fakeEmote.getEmoteRepr() : null;
|
||||
if (assignableRolePlace.getMessageId() != null) {
|
||||
@@ -223,7 +228,7 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
AssignablePostMessage model = prepareAssignablePostMessageModel(place);
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(ASSIGNABLE_ROLES_POST_TEMPLATE_KEY, model, place.getServer().getId());
|
||||
Long channelId = place.getChannel().getId();
|
||||
Optional<TextChannel> channelOptional = channelService.getTextChannelFromServerOptional(place.getServer().getId(), channelId);
|
||||
Optional<GuildMessageChannel> channelOptional = channelService.getMessageChannelFromServerOptional(place.getServer().getId(), channelId);
|
||||
if (channelOptional.isPresent()) {
|
||||
log.info("Refreshing text for assignable role place {} in channel {} in post {}.", place.getId(), channelId, place.getMessageId());
|
||||
return channelService.editEmbedMessageInAChannel(messageToSend.getEmbeds().get(0), channelOptional.get(), place.getMessageId()).thenCompose(message -> CompletableFuture.completedFuture(null));
|
||||
@@ -435,7 +440,7 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
.build();
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> sendAssignablePostMessage(AssignableRolePlace place, TextChannel channel) {
|
||||
private CompletableFuture<Void> sendAssignablePostMessage(AssignableRolePlace place, GuildMessageChannel channel) {
|
||||
AssignablePostMessage model = prepareAssignablePostMessageModel(place);
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(ASSIGNABLE_ROLES_POST_TEMPLATE_KEY, model, place.getServer().getId());
|
||||
log.info("Sending message for assignable role place {}.", place.getId());
|
||||
@@ -501,9 +506,9 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
@Transactional
|
||||
public CompletableFuture<Void> createAssignableRolePlacePost(Long serverId, Long assignablePlaceId) {
|
||||
AssignableRolePlace assignableRolePlace = rolePlaceManagementService.findByPlaceId(assignablePlaceId);
|
||||
Optional<TextChannel> channelOptional = channelService.getTextChannelFromServerOptional(serverId, assignableRolePlace.getChannel().getId());
|
||||
Optional<GuildMessageChannel> channelOptional = channelService.getMessageChannelFromServerOptional(serverId, assignableRolePlace.getChannel().getId());
|
||||
if (channelOptional.isPresent()) {
|
||||
TextChannel channel = channelOptional.get();
|
||||
GuildMessageChannel channel = channelOptional.get();
|
||||
log.info("Sending assignable role place posts for place {} in channel {} in server {}.", assignableRolePlace.getId(), channel.getId(), serverId);
|
||||
return sendAssignablePostMessage(assignableRolePlace, channel);
|
||||
} else {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>assignable-roles</artifactId>
|
||||
<version>1.3.12</version>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>assignable-roles-int</artifactId>
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.dv8tion.jda.api.entities.Role;
|
||||
/**
|
||||
* Exception thrown in case the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole} has already been
|
||||
* defined for an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace}. This is identified
|
||||
* via the {@link net.dv8tion.jda.api.entities.Emote} which is used to react.
|
||||
* via the emote which is used to react.
|
||||
*/
|
||||
public class AssignableRoleAlreadyDefinedException extends AbstractoRunTimeException implements Templatable {
|
||||
private final AssignableRoleAlreadyDefinedExceptionModel model;
|
||||
|
||||
@@ -6,7 +6,7 @@ import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
|
||||
/**
|
||||
* Exception thrown in case the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
* identified by {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace#key}
|
||||
* identified by {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace} key
|
||||
*/
|
||||
public class AssignableRolePlaceAlreadyExistsException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.ComponentPayload;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.assignableroles.model.database;
|
||||
import dev.sheldan.abstracto.assignableroles.model.condition.AssignableRoleConditionType;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "assignable_role_condition")
|
||||
|
||||
@@ -4,7 +4,7 @@ import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.assignableroles.model.database;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -11,7 +11,7 @@ import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.3.12</version>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -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.abstracto.modules</groupId>
|
||||
<artifactId>custom-command</artifactId>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>custom-command-impl</artifactId>
|
||||
|
||||
<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>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>custom-command-int</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</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,99 @@
|
||||
package dev.sheldan.abstracto.customcommand.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureDefinition;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandSlashCommandNames;
|
||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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
|
||||
@Slf4j
|
||||
public class CreateCustomCommand extends AbstractConditionableCommand {
|
||||
|
||||
private static final String CREATE_CUSTOM_COMMAND_COMMAND = "createCustomCommand";
|
||||
private static final String CUSTOM_COMMAND_NAME_PARAMETER = "commandName";
|
||||
private static final String CUSTOM_COMMAND_CONTENT_PARAMETER = "response";
|
||||
private static final String CREATE_CUSTOM_COMMAND_RESPONSE_TEMPLATE_KEY = "createCustomCommand_response";
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private CustomCommandService customCommandService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
String name = slashCommandParameterService.getCommandOption(CUSTOM_COMMAND_NAME_PARAMETER, event, String.class);
|
||||
String content = slashCommandParameterService.getCommandOption(CUSTOM_COMMAND_CONTENT_PARAMETER, event, String.class);
|
||||
|
||||
customCommandService.createCustomCommand(name, content, event.getMember());
|
||||
return interactionService.replyEmbed(CREATE_CUSTOM_COMMAND_RESPONSE_TEMPLATE_KEY, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CustomCommandFeatureDefinition.CUSTOM_COMMAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter commandNameParameter = Parameter
|
||||
.builder()
|
||||
.name(CUSTOM_COMMAND_NAME_PARAMETER)
|
||||
.templated(true)
|
||||
.type(String.class)
|
||||
.build();
|
||||
|
||||
Parameter commandContentParameter = Parameter
|
||||
.builder()
|
||||
.name(CUSTOM_COMMAND_CONTENT_PARAMETER)
|
||||
.templated(true)
|
||||
.type(String.class)
|
||||
.build();
|
||||
|
||||
List<Parameter> parameters = Arrays.asList(commandNameParameter, commandContentParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND)
|
||||
.commandName("create")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(CREATE_CUSTOM_COMMAND_COMMAND)
|
||||
.module(UtilityModuleDefinition.UTILITY)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.causesReaction(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package dev.sheldan.abstracto.customcommand.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.CommandAlternative;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandRegistry;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureConfig;
|
||||
import dev.sheldan.abstracto.customcommand.model.command.CustomCommandResponseModel;
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandManagementService;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class CustomCommandAlternative implements CommandAlternative {
|
||||
|
||||
private static final String CUSTOM_COMMAND_RESPONSE = "custom_command_response";
|
||||
|
||||
@Autowired
|
||||
private CommandRegistry commandRegistry;
|
||||
|
||||
@Autowired
|
||||
private CustomCommandManagementService customCommandManagementService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Autowired
|
||||
private CustomCommandFeatureConfig customCommandFeatureConfig;
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute(UnParsedCommandParameter parameter, Guild guild) {
|
||||
return featureFlagService.isFeatureEnabled(customCommandFeatureConfig, guild.getIdLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(UnParsedCommandParameter parameter, Message message) {
|
||||
String contentStripped = message.getContentRaw();
|
||||
List<String> parameters = Arrays.asList(contentStripped.split(" "));
|
||||
String commandName = commandRegistry.getCommandName(parameters.get(0), message.getGuild().getIdLong());
|
||||
Optional<CustomCommand> customCommandOptional = customCommandManagementService.getCustomCommandByName(commandName, message.getGuild().getIdLong());
|
||||
customCommandOptional.ifPresent(customCommand -> {
|
||||
CustomCommandResponseModel model = CustomCommandResponseModel
|
||||
.builder()
|
||||
.additionalText(customCommand.getAdditionalMessage())
|
||||
.build();
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(CUSTOM_COMMAND_RESPONSE, model, message.getGuild().getIdLong());
|
||||
channelService.sendMessageToSendToChannel(messageToSend, message.getChannel());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer getPriority() {
|
||||
return ListenerPriority.MEDIUM;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package dev.sheldan.abstracto.customcommand.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureDefinition;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandSlashCommandNames;
|
||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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
|
||||
@Slf4j
|
||||
public class DeleteCustomCommand extends AbstractConditionableCommand {
|
||||
|
||||
private static final String DELETE_CUSTOM_COMMAND_COMMAND = "deleteCustomCommand";
|
||||
private static final String DELETE_CUSTOM_COMMAND_RESPONSE_TEMPLATE_KEY = "deleteCustomCommand_response";
|
||||
private static final String CUSTOM_COMMAND_NAME_PARAMETER = "commandName";
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private CustomCommandService customCommandService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
String name = slashCommandParameterService.getCommandOption(CUSTOM_COMMAND_NAME_PARAMETER, event, String.class);
|
||||
|
||||
customCommandService.deleteCustomCommand(name, event.getGuild());
|
||||
return interactionService.replyEmbed(DELETE_CUSTOM_COMMAND_RESPONSE_TEMPLATE_KEY, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CustomCommandFeatureDefinition.CUSTOM_COMMAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter commandNameParameter = Parameter
|
||||
.builder()
|
||||
.name(CUSTOM_COMMAND_NAME_PARAMETER)
|
||||
.templated(true)
|
||||
.type(String.class)
|
||||
.build();
|
||||
|
||||
List<Parameter> parameters = Arrays.asList(commandNameParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND)
|
||||
.commandName("delete")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(DELETE_CUSTOM_COMMAND_COMMAND)
|
||||
.module(UtilityModuleDefinition.UTILITY)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.causesReaction(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package dev.sheldan.abstracto.customcommand.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandAutoCompleteService;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureDefinition;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandSlashCommandNames;
|
||||
import dev.sheldan.abstracto.customcommand.model.command.CustomCommandResponseModel;
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandService;
|
||||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class GetCustomCommand extends AbstractConditionableCommand {
|
||||
|
||||
private static final String GET_CUSTOM_COMMAND_COMMAND = "getCustomCommand";
|
||||
private static final String CUSTOM_COMMAND_NAME_PARAMETER = "commandName";
|
||||
private static final String GET_CUSTOM_COMMAND_RESPONSE_TEMPLATE_KEY = "getCustomCommand_response";
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private CustomCommandService customCommandService;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandAutoCompleteService slashCommandAutoCompleteService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
String name = slashCommandParameterService.getCommandOption(CUSTOM_COMMAND_NAME_PARAMETER, event, String.class);
|
||||
CustomCommand customCommand = customCommandService.getCustomCommand(name, event.getGuild());
|
||||
CustomCommandResponseModel model = CustomCommandResponseModel
|
||||
.builder()
|
||||
.additionalText(customCommand.getAdditionalMessage())
|
||||
.build();
|
||||
return interactionService.replyEmbed(GET_CUSTOM_COMMAND_RESPONSE_TEMPLATE_KEY, model, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> performAutoComplete(CommandAutoCompleteInteractionEvent event) {
|
||||
if(slashCommandAutoCompleteService.matchesParameter(event.getFocusedOption(), CUSTOM_COMMAND_NAME_PARAMETER)) {
|
||||
String input = event.getFocusedOption().getValue();
|
||||
return customCommandService.getCustomCommandsStartingWith(input, event.getGuild())
|
||||
.stream()
|
||||
.map(CustomCommand::getName)
|
||||
.toList();
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CustomCommandFeatureDefinition.CUSTOM_COMMAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter commandNameParameter = Parameter
|
||||
.builder()
|
||||
.name(CUSTOM_COMMAND_NAME_PARAMETER)
|
||||
.templated(true)
|
||||
.supportsAutoComplete(true)
|
||||
.type(String.class)
|
||||
.build();
|
||||
|
||||
List<Parameter> parameters = Arrays.asList(commandNameParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND_PUBLIC)
|
||||
.commandName("get")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(GET_CUSTOM_COMMAND_COMMAND)
|
||||
.module(UtilityModuleDefinition.UTILITY)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.causesReaction(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package dev.sheldan.abstracto.customcommand.command;
|
||||
|
||||
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.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.PaginatorService;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureDefinition;
|
||||
import dev.sheldan.abstracto.customcommand.config.CustomCommandSlashCommandNames;
|
||||
import dev.sheldan.abstracto.customcommand.model.command.ListCustomCommandsResponseModel;
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ListCustomCommands extends AbstractConditionableCommand {
|
||||
|
||||
private static final String CREATE_CUSTOM_COMMAND_COMMAND = "listCustomCommands";
|
||||
private static final String LIST_CUSTOM_COMMANDS_TEMPLATE_KEY = "listCustomCommands_response";
|
||||
private static final String NO_CUSTOM_COMMANDS_TEMPLATE_KEY = "listCustomCommands_no_commands_response";
|
||||
|
||||
@Autowired
|
||||
private CustomCommandService customCommandService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private PaginatorService paginatorService;
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
List<CustomCommand> customCommands = customCommandService.getCustomCommands(event.getGuild());
|
||||
if(customCommands.isEmpty()) {
|
||||
return interactionService.replyEmbed(NO_CUSTOM_COMMANDS_TEMPLATE_KEY, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
ListCustomCommandsResponseModel model = ListCustomCommandsResponseModel.fromCommands(customCommands);
|
||||
return paginatorService.createPaginatorFromTemplate(LIST_CUSTOM_COMMANDS_TEMPLATE_KEY, model, event)
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CustomCommandFeatureDefinition.CUSTOM_COMMAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND_PUBLIC)
|
||||
.commandName("list")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(CREATE_CUSTOM_COMMAND_COMMAND)
|
||||
.module(UtilityModuleDefinition.UTILITY)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.causesReaction(true)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.sheldan.abstracto.customcommand.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:custom-command-config.properties")
|
||||
public class CustomCommandConfig {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.sheldan.abstracto.customcommand.repository;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface CustomCommandRepository extends JpaRepository<CustomCommand, Long> {
|
||||
Optional<CustomCommand> getByNameIgnoreCaseAndServer(String name, AServer server);
|
||||
void deleteByNameAndServer(String name, AServer server);
|
||||
List<CustomCommand> findByServer(AServer server);
|
||||
List<CustomCommand> findByNameStartsWithIgnoreCaseAndServer(String prefix, AServer server);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package dev.sheldan.abstracto.customcommand.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.customcommand.exception.CustomCommandExistsException;
|
||||
import dev.sheldan.abstracto.customcommand.exception.CustomCommandNotFoundException;
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandManagementService;
|
||||
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandService;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CustomCommandServiceBean implements CustomCommandService {
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private CustomCommandManagementService customCommandManagementService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CustomCommand createCustomCommand(String name, String content, Member creator) {
|
||||
if(customCommandManagementService.getCustomCommandByName(name, creator.getGuild().getIdLong()).isPresent()) {
|
||||
throw new CustomCommandExistsException();
|
||||
}
|
||||
AUserInAServer creatorUser = userInServerManagementService.loadOrCreateUser(creator);
|
||||
return customCommandManagementService.createCustomCommand(name, content, creatorUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCustomCommand(String name, Guild guild) {
|
||||
if(customCommandManagementService.getCustomCommandByName(name, guild.getIdLong()).isEmpty()) {
|
||||
throw new CustomCommandNotFoundException();
|
||||
}
|
||||
AServer server = serverManagementService.loadServer(guild);
|
||||
customCommandManagementService.deleteCustomCommand(name, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CustomCommand> getCustomCommands(Guild guild) {
|
||||
AServer server = serverManagementService.loadServer(guild);
|
||||
return customCommandManagementService.getCustomCommands(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomCommand getCustomCommand(String name, Guild guild) {
|
||||
return customCommandManagementService.getCustomCommandByName(name, guild.getIdLong())
|
||||
.orElseThrow(CustomCommandNotFoundException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CustomCommand> getCustomCommandsStartingWith(String prefix, Guild guild) {
|
||||
AServer server = serverManagementService.loadServer(guild);
|
||||
return customCommandManagementService.getCustomCommandsStartingWith(prefix, server);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package dev.sheldan.abstracto.customcommand.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
import dev.sheldan.abstracto.customcommand.repository.CustomCommandRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class CustomCommandManagementServiceBean implements CustomCommandManagementService {
|
||||
|
||||
@Autowired
|
||||
private CustomCommandRepository repository;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public Optional<CustomCommand> getCustomCommandByName(String name, Long serverId) {
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
return repository.getByNameIgnoreCaseAndServer(name, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomCommand createCustomCommand(String name, String content, AUserInAServer creator) {
|
||||
CustomCommand customCommand = CustomCommand
|
||||
.builder()
|
||||
.name(name)
|
||||
.additionalMessage(content)
|
||||
.server(creator.getServerReference())
|
||||
.creator(creator)
|
||||
.build();
|
||||
return repository.save(customCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCustomCommand(String name, AServer server) {
|
||||
repository.deleteByNameAndServer(name, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CustomCommand> getCustomCommands(AServer server) {
|
||||
return repository.findByServer(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CustomCommand> getCustomCommandsStartingWith(String prefix, AServer server) {
|
||||
return repository.findByNameStartsWithIgnoreCaseAndServer(prefix, server);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
abstracto.featureFlags.customCommand.featureName=customCommand
|
||||
abstracto.featureFlags.customCommand.enabled=false
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
|
||||
<include file="seedData/data.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,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="feature.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="custom_command-feature-insertion">
|
||||
<insert tableName="feature">
|
||||
<column name="key" value="customCommand"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?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="custom_command-table">
|
||||
<createTable tableName="custom_command">
|
||||
<column name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="custom_command_pkey"/>
|
||||
</column>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="creator_user_in_server_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="additional_message" type="VARCHAR(2048)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="NAME" type="VARCHAR(64)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="server_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<addUniqueConstraint columnNames="name"
|
||||
constraintName="uc_custom_command_name"
|
||||
disabled="false"
|
||||
tableName="custom_command"/>
|
||||
<addForeignKeyConstraint baseColumnNames="server_id" baseTableName="custom_command"
|
||||
constraintName="fk_custom_command_server" deferrable="false" initiallyDeferred="false"
|
||||
onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="creator_user_in_server_id" baseTableName="custom_command"
|
||||
constraintName="fk_custom_command_creator" deferrable="false" initiallyDeferred="false"
|
||||
onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="user_in_server_id" referencedTableName="user_in_server" validate="true"/>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS custom_command_update_trigger ON custom_command;
|
||||
CREATE TRIGGER custom_command_update_trigger BEFORE UPDATE ON custom_command FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS custom_command_insert_trigger ON custom_command;
|
||||
CREATE TRIGGER custom_command_insert_trigger BEFORE INSERT ON custom_command FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<include file="custom_command.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="seedData/data.xml" relativeToChangelogFile="true"/>
|
||||
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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="customCommandFeature" value="(SELECT id FROM feature WHERE key = 'customCommand')"/>
|
||||
|
||||
<changeSet author="Sheldan" id="customCommand-commands">
|
||||
<insert tableName="command">
|
||||
<column name="name" value="createCustomCommand"/>
|
||||
<column name="module_id" valueComputed="${utilityModule}"/>
|
||||
<column name="feature_id" valueComputed="${customCommandFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="deleteCustomCommand"/>
|
||||
<column name="module_id" valueComputed="${utilityModule}"/>
|
||||
<column name="feature_id" valueComputed="${customCommandFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="getCustomCommand"/>
|
||||
<column name="module_id" valueComputed="${utilityModule}"/>
|
||||
<column name="feature_id" valueComputed="${customCommandFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="listCustomCommands"/>
|
||||
<column name="module_id" valueComputed="${utilityModule}"/>
|
||||
<column name="feature_id" valueComputed="${customCommandFeature}"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<include file="command.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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="custom_command-add_auto_increment">
|
||||
<sql>
|
||||
create sequence custom_command_id_seq;
|
||||
alter table custom_command alter id set default nextval('custom_command_id_seq');
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<include file="custom_command.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="1.4.0/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.5.8/collection.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,12 @@
|
||||
<?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.abstracto</groupId>
|
||||
<artifactId>abstracto-application</artifactId>
|
||||
<version>1.3.12</version>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>custom-command</artifactId>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>installer</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<artifactId>custom-command-int</artifactId>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.customcommand.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CustomCommandFeatureConfig implements FeatureConfig {
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CustomCommandFeatureDefinition.CUSTOM_COMMAND;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.customcommand.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum CustomCommandFeatureDefinition implements FeatureDefinition {
|
||||
CUSTOM_COMMAND("customCommand");
|
||||
|
||||
private String key;
|
||||
|
||||
CustomCommandFeatureDefinition(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package dev.sheldan.abstracto.customcommand.config;
|
||||
|
||||
public class CustomCommandSlashCommandNames {
|
||||
public static final String CUSTOM_COMMAND = "cc";
|
||||
public static final String CUSTOM_COMMAND_PUBLIC = "customCommands";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.customcommand.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
|
||||
|
||||
public class CustomCommandExistsException extends AbstractoTemplatableException {
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "custom_command_exists_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.customcommand.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
|
||||
|
||||
public class CustomCommandNotFoundException extends AbstractoTemplatableException {
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "custom_command_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.sheldan.abstracto.customcommand.model.command;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class CustomCommandResponseModel {
|
||||
private String additionalText;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package dev.sheldan.abstracto.customcommand.model.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class ListCustomCommandModel {
|
||||
private String name;
|
||||
private String content;
|
||||
private MemberDisplay creator;
|
||||
|
||||
public static ListCustomCommandModel fromCustomCommand(CustomCommand customCommand) {
|
||||
return ListCustomCommandModel
|
||||
.builder()
|
||||
.name(customCommand.getName())
|
||||
.content(customCommand.getAdditionalMessage())
|
||||
.creator(MemberDisplay.fromAUserInAServer(customCommand.getCreator()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package dev.sheldan.abstracto.customcommand.model.command;
|
||||
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class ListCustomCommandsResponseModel {
|
||||
private List<ListCustomCommandModel> customCommands;
|
||||
|
||||
public static ListCustomCommandsResponseModel fromCommands(List<CustomCommand> customCommands) {
|
||||
return ListCustomCommandsResponseModel
|
||||
.builder()
|
||||
.customCommands(customCommands
|
||||
.stream()
|
||||
.map(ListCustomCommandModel::fromCustomCommand)
|
||||
.collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package dev.sheldan.abstracto.customcommand.model.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.*;
|
||||
import lombok.*;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
|
||||
@Entity
|
||||
@Table(name = "custom_command")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class CustomCommand implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "id", nullable = false)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "additional_message")
|
||||
private String additionalMessage;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "server_id", nullable = false)
|
||||
private AServer server;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "creator_user_in_server_id", nullable = false)
|
||||
private AUserInAServer creator;
|
||||
|
||||
@Column(name = "created", nullable = false, insertable = false, updatable = false)
|
||||
private Instant created;
|
||||
|
||||
@Column(name = "updated", insertable = false, updatable = false)
|
||||
private Instant updated;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.customcommand.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CustomCommandManagementService {
|
||||
Optional<CustomCommand> getCustomCommandByName(String name, Long serverId);
|
||||
CustomCommand createCustomCommand(String name, String content, AUserInAServer creator);
|
||||
void deleteCustomCommand(String name, AServer server);
|
||||
List<CustomCommand> getCustomCommands(AServer server);
|
||||
List<CustomCommand> getCustomCommandsStartingWith(String prefix, AServer server);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.customcommand.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CustomCommandService {
|
||||
CustomCommand createCustomCommand(String name, String content, Member creator);
|
||||
void deleteCustomCommand(String name, Guild guild);
|
||||
List<CustomCommand> getCustomCommands(Guild guild);
|
||||
CustomCommand getCustomCommand(String name, Guild guild);
|
||||
List<CustomCommand> getCustomCommandsStartingWith(String prefix, Guild guild);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>custom-command</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>custom-command-int</module>
|
||||
<module>custom-command-impl</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>core-int</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>dynamic-activity</artifactId>
|
||||
<version>1.3.12</version>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>dynamic-activity</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.3.12</version>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.activity.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import jakarta.persistence.*;
|
||||
import java.time.Instant;
|
||||
|
||||
@Builder
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.3.12</version>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>entertainment</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.3.12</version>
|
||||
<version>1.5.9</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -4,16 +4,20 @@ 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.interaction.slash.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.ChooseResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -25,30 +29,81 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class Choose extends AbstractConditionableCommand {
|
||||
|
||||
public static final String CHOOSE_RESPONSE_TEMPLATE_KEY = "choose_response";
|
||||
private static final String CHOOSE_COMMAND = "choose";
|
||||
private static final String TEXT_PARAMETER = "text";
|
||||
private static final int CHOICES_SIZE = 5;
|
||||
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<String> choices = (List) commandContext.getParameters().getParameters().get(0);
|
||||
String choice = entertainmentService.takeChoice(choices, commandContext.getAuthor());
|
||||
ChooseResponseModel responseModel = (ChooseResponseModel) ContextConverter.slimFromCommandContext(commandContext, ChooseResponseModel.class);
|
||||
responseModel.setChosenValue(choice);
|
||||
ChooseResponseModel responseModel = ChooseResponseModel
|
||||
.builder()
|
||||
.chosenValue(choice)
|
||||
.build();
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(CHOOSE_RESPONSE_TEMPLATE_KEY, responseModel, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
List<String> choices = new ArrayList<>();
|
||||
for (int i = 0; i < CHOICES_SIZE; i++) {
|
||||
if(slashCommandParameterService.hasCommandOption(TEXT_PARAMETER + "_" + i, event)) {
|
||||
String choice = slashCommandParameterService.getCommandOption(TEXT_PARAMETER + "_" + i, event, String.class);
|
||||
choices.add(choice);
|
||||
}
|
||||
}
|
||||
String choice = entertainmentService.takeChoice(choices, event.getMember());
|
||||
ChooseResponseModel responseModel = ChooseResponseModel
|
||||
.builder()
|
||||
.chosenValue(choice)
|
||||
.build();
|
||||
return interactionService.replyEmbed(CHOOSE_RESPONSE_TEMPLATE_KEY, responseModel, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
parameters.add(Parameter.builder().name("text").type(String.class).templated(true).remainder(true).isListParam(true).build());
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
Parameter textParameter = Parameter
|
||||
.builder()
|
||||
.name(TEXT_PARAMETER)
|
||||
.type(String.class)
|
||||
.templated(true)
|
||||
.remainder(true)
|
||||
.listSize(CHOICES_SIZE)
|
||||
.isListParam(true)
|
||||
.build();
|
||||
parameters.add(textParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.UTILITY)
|
||||
.commandName(CHOOSE_COMMAND)
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name("choose")
|
||||
.name(CHOOSE_COMMAND)
|
||||
.async(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
|
||||
@@ -4,17 +4,22 @@ 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.interaction.slash.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.EightBallResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -26,6 +31,8 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class EightBall extends AbstractConditionableCommand {
|
||||
|
||||
public static final String EIGHT_BALL_RESPONSE_TEMPLATE_KEY = "eight_ball_response";
|
||||
public static final String BALL_COMMAND = "8Ball";
|
||||
public static final String TEXT_PARAMETER = "text";
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@@ -35,24 +42,65 @@ public class EightBall extends AbstractConditionableCommand {
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
String text = (String) commandContext.getParameters().getParameters().get(0);
|
||||
String chosenKey = entertainmentService.getEightBallValue(text);
|
||||
EightBallResponseModel responseModel = (EightBallResponseModel) ContextConverter.slimFromCommandContext(commandContext, EightBallResponseModel.class);
|
||||
responseModel.setChosenKey(chosenKey);
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(EIGHT_BALL_RESPONSE_TEMPLATE_KEY, responseModel, commandContext.getChannel()))
|
||||
MessageToSend messageToSend = getMessageToSend(text, commandContext.getGuild().getIdLong());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
String text = slashCommandParameterService.getCommandOption(TEXT_PARAMETER, event, String.class);
|
||||
MessageToSend messageToSend = getMessageToSend(text, event.getGuild().getIdLong());
|
||||
return interactionService.replyMessageToSend(messageToSend, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
private MessageToSend getMessageToSend(String text, Long serverId) {
|
||||
String chosenKey = entertainmentService.getEightBallValue(text);
|
||||
EightBallResponseModel responseModel = EightBallResponseModel
|
||||
.builder()
|
||||
.chosenKey(chosenKey)
|
||||
.build();
|
||||
return templateService.renderEmbedTemplate(EIGHT_BALL_RESPONSE_TEMPLATE_KEY, responseModel, serverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
parameters.add(Parameter.builder().name("text").type(String.class).templated(true).remainder(true).build());
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
Parameter textParameter = Parameter
|
||||
.builder()
|
||||
.name(TEXT_PARAMETER)
|
||||
.type(String.class)
|
||||
.templated(true)
|
||||
.remainder(true)
|
||||
.build();
|
||||
parameters.add(textParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.UTILITY)
|
||||
.commandName(BALL_COMMAND)
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name("8Ball")
|
||||
.name(BALL_COMMAND)
|
||||
.async(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
|
||||
@@ -4,16 +4,22 @@ 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.interaction.slash.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
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.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.LoveCalcResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -25,6 +31,9 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class LoveCalc extends AbstractConditionableCommand {
|
||||
|
||||
public static final String LOVE_CALC_RESPONSE_TEMPLATE_KEY = "loveCalc_response";
|
||||
public static final String FIRST_SUBJECT_PARAMETER = "firstSubject";
|
||||
public static final String SECOND_SUBJECT_PARAMETER = "secondSubject";
|
||||
public static final String LOVE_CALC_COMMAND = "loveCalc";
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
@@ -32,28 +41,77 @@ public class LoveCalc extends AbstractConditionableCommand {
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String firstPart = (String) parameters.get(0);
|
||||
String secondPart = (String) parameters.get(1);
|
||||
Integer rolled = entertainmentService.getLoveCalcValue(firstPart, secondPart);
|
||||
LoveCalcResponseModel model = (LoveCalcResponseModel) ContextConverter.slimFromCommandContext(commandContext, LoveCalcResponseModel.class);
|
||||
model.setRolled(rolled);
|
||||
model.setFirstPart(firstPart);
|
||||
model.setSecondPart(secondPart);
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(LOVE_CALC_RESPONSE_TEMPLATE_KEY, model, commandContext.getChannel()))
|
||||
MessageToSend messageToSend = getMessageToSend(commandContext.getGuild().getIdLong(), firstPart, secondPart);
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
String firstPart = slashCommandParameterService.getCommandOption(FIRST_SUBJECT_PARAMETER, event, String.class);
|
||||
String secondPart = slashCommandParameterService.getCommandOption(SECOND_SUBJECT_PARAMETER, event, String.class);
|
||||
MessageToSend messageToSend = getMessageToSend(event.getGuild().getIdLong(), firstPart, secondPart);
|
||||
return interactionService.replyMessageToSend(messageToSend, event.getInteraction())
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
private MessageToSend getMessageToSend(Long serverId, String firstPart, String secondPart) {
|
||||
Integer rolled = entertainmentService.getLoveCalcValue(firstPart, secondPart);
|
||||
LoveCalcResponseModel model = LoveCalcResponseModel
|
||||
.builder()
|
||||
.rolled(rolled)
|
||||
.firstPart(firstPart)
|
||||
.secondPart(secondPart)
|
||||
.build();
|
||||
return templateService.renderEmbedTemplate(LOVE_CALC_RESPONSE_TEMPLATE_KEY, model, serverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
parameters.add(Parameter.builder().name("firstSubject").type(String.class).templated(true).build());
|
||||
parameters.add(Parameter.builder().name("secondSubject").type(String.class).templated(true).build());
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
Parameter firstSubjectParameter = Parameter
|
||||
.builder()
|
||||
.name(FIRST_SUBJECT_PARAMETER)
|
||||
.type(String.class)
|
||||
.templated(true)
|
||||
.build();
|
||||
parameters.add(firstSubjectParameter);
|
||||
Parameter secondSubjectParameter = Parameter
|
||||
.builder()
|
||||
.name(SECOND_SUBJECT_PARAMETER)
|
||||
.type(String.class)
|
||||
.templated(true)
|
||||
.build();
|
||||
parameters.add(secondSubjectParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.UTILITY)
|
||||
.commandName(LOVE_CALC_COMMAND)
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name("loveCalc")
|
||||
.name(LOVE_CALC_COMMAND)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
|
||||
@@ -6,17 +6,21 @@ 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.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.command.handler.parameter.CombinedParameter;
|
||||
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.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.MockResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -29,12 +33,20 @@ import static dev.sheldan.abstracto.core.command.config.Parameter.ADDITIONAL_TYP
|
||||
public class Mock extends AbstractConditionableCommand {
|
||||
|
||||
public static final String MOCK_RESPONSE_TEMPLATE_KEY = "mock_response";
|
||||
public static final String MOCK_COMMAND = "mock";
|
||||
public static final String MESSAGE_PARAMETER = "message";
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
Object givenParameter = commandContext.getParameters().getParameters().get(0);
|
||||
@@ -48,26 +60,63 @@ public class Mock extends AbstractConditionableCommand {
|
||||
messageText = givenParameter.toString();
|
||||
}
|
||||
String mockingText = entertainmentService.createMockText(messageText, commandContext.getAuthor(), mockedMember);
|
||||
MockResponseModel model = (MockResponseModel) ContextConverter.slimFromCommandContext(commandContext, MockResponseModel.class);
|
||||
model.setOriginalText(messageText);
|
||||
model.setMockingText(mockingText);
|
||||
MockResponseModel model = MockResponseModel
|
||||
.builder()
|
||||
.originalText(messageText)
|
||||
.mockingText(mockingText)
|
||||
.build();
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(MOCK_RESPONSE_TEMPLATE_KEY, model, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
String text = slashCommandParameterService.getCommandOption(MESSAGE_PARAMETER, event, String.class);
|
||||
String mockingText = entertainmentService.createMockText(text, event.getMember(), null);
|
||||
MockResponseModel model = MockResponseModel
|
||||
.builder()
|
||||
.originalText(text)
|
||||
.mockingText(mockingText)
|
||||
.build();
|
||||
return interactionService.replyEmbed(MOCK_RESPONSE_TEMPLATE_KEY, model, event.getInteraction())
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
Map<String, Object> parameterAlternatives = new HashMap<>();
|
||||
parameterAlternatives.put(ADDITIONAL_TYPES_KEY, Arrays.asList(Message.class, String.class));
|
||||
parameters.add(Parameter.builder().name("message").type(CombinedParameter.class).remainder(true)
|
||||
.additionalInfo(parameterAlternatives).templated(true).build());
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
|
||||
Parameter messageParameter = Parameter
|
||||
.builder()
|
||||
.name(MESSAGE_PARAMETER)
|
||||
.type(CombinedParameter.class)
|
||||
.remainder(true)
|
||||
.additionalInfo(parameterAlternatives)
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
parameters.add(messageParameter);
|
||||
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.ENTERTAINMENT)
|
||||
.commandName(MOCK_COMMAND)
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name("mock")
|
||||
.name(MOCK_COMMAND)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
|
||||
@@ -4,19 +4,23 @@ 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.interaction.slash.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.command.config.validator.MinIntegerValueValidator;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureConfig;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.RollResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -29,6 +33,9 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class Roll extends AbstractConditionableCommand {
|
||||
|
||||
public static final String ROLL_RESPONSE_TEMPLATE_KEY = "roll_response";
|
||||
private static final String ROLL_COMMAND = "roll";
|
||||
private static final String LOW_PARAMETER = "low";
|
||||
private static final String HIGH_PARAMETER = "high";
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
@@ -39,6 +46,12 @@ public class Roll extends AbstractConditionableCommand {
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
@@ -52,20 +65,73 @@ public class Roll extends AbstractConditionableCommand {
|
||||
}
|
||||
|
||||
Integer rolled = entertainmentService.calculateRollResult(low, high);
|
||||
RollResponseModel model = (RollResponseModel) ContextConverter.slimFromCommandContext(commandContext, RollResponseModel.class);
|
||||
model.setRolled(rolled);
|
||||
RollResponseModel model = RollResponseModel
|
||||
.builder()
|
||||
.rolled(rolled)
|
||||
.build();
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(ROLL_RESPONSE_TEMPLATE_KEY, model, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
Integer low;
|
||||
if(slashCommandParameterService.hasCommandOption(LOW_PARAMETER, event)) {
|
||||
low = slashCommandParameterService.getCommandOption(LOW_PARAMETER, event, Integer.class);
|
||||
} else {
|
||||
low = 1;
|
||||
}
|
||||
Integer high;
|
||||
if(slashCommandParameterService.hasCommandOption(HIGH_PARAMETER, event)) {
|
||||
high = slashCommandParameterService.getCommandOption(HIGH_PARAMETER, event, Integer.class);
|
||||
} else {
|
||||
high = configService.getLongValueOrConfigDefault(EntertainmentFeatureConfig.ROLL_DEFAULT_HIGH_KEY, event.getGuild().getIdLong()).intValue();
|
||||
}
|
||||
Integer rolled = entertainmentService.calculateRollResult(low, high);
|
||||
RollResponseModel model = RollResponseModel
|
||||
.builder()
|
||||
.rolled(rolled)
|
||||
.build();
|
||||
return interactionService.replyEmbed(ROLL_RESPONSE_TEMPLATE_KEY, model, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
parameters.add(Parameter.builder().name("high").type(Integer.class).templated(true).validators(Arrays.asList(MinIntegerValueValidator.min(2L))).optional(true).build());
|
||||
parameters.add(Parameter.builder().name("low").type(Integer.class).templated(true).validators(Arrays.asList(MinIntegerValueValidator.min(0L))).optional(true).build());
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
Parameter highParameter = Parameter
|
||||
.builder()
|
||||
.name(HIGH_PARAMETER)
|
||||
.type(Integer.class)
|
||||
.templated(true)
|
||||
.validators(Arrays.asList(MinIntegerValueValidator.min(2L)))
|
||||
.optional(true)
|
||||
.build();
|
||||
parameters.add(highParameter);
|
||||
Parameter lowParameter = Parameter
|
||||
.builder()
|
||||
.name(LOW_PARAMETER)
|
||||
.type(Integer.class)
|
||||
.templated(true)
|
||||
.validators(Arrays.asList(MinIntegerValueValidator.min(0L)))
|
||||
.optional(true)
|
||||
.build();
|
||||
parameters.add(lowParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.UTILITY)
|
||||
.commandName(ROLL_COMMAND)
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name("roll")
|
||||
.name(ROLL_COMMAND)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
|
||||
@@ -4,16 +4,19 @@ 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.interaction.slash.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.RouletteResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -25,28 +28,57 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class Roulette extends AbstractConditionableCommand {
|
||||
|
||||
public static final String ROULETTE_RESPONSE_TEMPLATE_KEY = "roulette_response";
|
||||
public static final String ROULETTE_COMMAND = "roulette";
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
boolean rouletteResult = entertainmentService.executeRoulette(commandContext.getAuthor());
|
||||
RouletteResponseModel responseModel = (RouletteResponseModel) ContextConverter.slimFromCommandContext(commandContext, RouletteResponseModel.class);
|
||||
responseModel.setResult(rouletteResult);
|
||||
RouletteResponseModel responseModel = RouletteResponseModel
|
||||
.builder()
|
||||
.result(rouletteResult)
|
||||
.build();
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(ROULETTE_RESPONSE_TEMPLATE_KEY, responseModel, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
boolean rouletteResult = entertainmentService.executeRoulette(event.getMember());
|
||||
RouletteResponseModel responseModel = RouletteResponseModel
|
||||
.builder()
|
||||
.result(rouletteResult)
|
||||
.build();
|
||||
return interactionService.replyEmbed(ROULETTE_RESPONSE_TEMPLATE_KEY, responseModel, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.UTILITY)
|
||||
.commandName(ROULETTE_COMMAND)
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name("roulette")
|
||||
.name(ROULETTE_COMMAND)
|
||||
.async(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package dev.sheldan.abstracto.entertainment.command.economy;
|
||||
|
||||
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.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.dto.CreditGambleResult;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.CreditGambleResultModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EconomyService;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class CreditGamble extends AbstractConditionableCommand {
|
||||
private static final String CREDIT_GAMBLE_COMMAND = "creditGamble";
|
||||
private static final String CREDIT_GAMBLE_RESPONSE = "creditGamble_response";
|
||||
|
||||
@Autowired
|
||||
private EconomyService economyService;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(commandContext.getAuthor());
|
||||
CreditGambleResult result = economyService.triggerCreditGamble(aUserInAServer);
|
||||
CreditGambleResultModel model = CreditGambleResultModel.fromCreditGambleResult(result);
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(CREDIT_GAMBLE_RESPONSE, model, commandContext.getGuild().getIdLong());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(event.getMember());
|
||||
CreditGambleResult result = economyService.triggerCreditGamble(aUserInAServer);
|
||||
CreditGambleResultModel model = CreditGambleResultModel.fromCreditGambleResult(result);
|
||||
return interactionService.replyEmbed(CREDIT_GAMBLE_RESPONSE, model, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.ECONOMY)
|
||||
.commandName("creditgamble")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(CREDIT_GAMBLE_COMMAND)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ECONOMY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package dev.sheldan.abstracto.entertainment.command.economy;
|
||||
|
||||
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.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.CreditsLeaderboardEntry;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.CreditsLeaderboardResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EconomyService;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class CreditLeaderboard extends AbstractConditionableCommand {
|
||||
|
||||
private static final String CREDIT_LEADERBOARD_COMMAND_NAME = "creditLeaderboard";
|
||||
private static final String CREDIT_LEADERBOARD_RESPONSE = "creditLeaderboard_response";
|
||||
private static final String PAGE_PARAMETER = "page";
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private EconomyService economyService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private MemberService memberService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
// parameter is optional, in case its not present, we default to the 0th page
|
||||
Integer page = !parameters.isEmpty() ? (Integer) parameters.get(0) : 1;
|
||||
List<CreditsLeaderboardEntry> creditLeaderboard = economyService.getCreditLeaderboard(server, page);
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(commandContext.getAuthor());
|
||||
CreditsLeaderboardEntry ownRank = economyService.getRankOfUser(aUserInAServer);
|
||||
CreditsLeaderboardResponseModel model = CreditsLeaderboardResponseModel
|
||||
.builder()
|
||||
.entries(creditLeaderboard)
|
||||
.ownRank(ownRank)
|
||||
.build();
|
||||
return enrichModelWithMembers(model, commandContext.getGuild().getIdLong())
|
||||
.thenCompose(model1 -> {
|
||||
MessageToSend message = templateService.renderEmbedTemplate(CREDIT_LEADERBOARD_RESPONSE, model1, commandContext.getGuild().getIdLong());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(message, commandContext.getChannel()));
|
||||
})
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
event.deferReply().queue();
|
||||
Integer page;
|
||||
if(slashCommandParameterService.hasCommandOption(PAGE_PARAMETER, event)) {
|
||||
page = slashCommandParameterService.getCommandOption(PAGE_PARAMETER, event, Integer.class);
|
||||
} else {
|
||||
page = 1;
|
||||
}
|
||||
AServer server = serverManagementService.loadServer(event.getGuild());
|
||||
List<CreditsLeaderboardEntry> creditLeaderboard = economyService.getCreditLeaderboard(server, page);
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(event.getMember());
|
||||
CreditsLeaderboardEntry ownRank = economyService.getRankOfUser(aUserInAServer);
|
||||
CreditsLeaderboardResponseModel model = CreditsLeaderboardResponseModel
|
||||
.builder()
|
||||
.entries(creditLeaderboard)
|
||||
.ownRank(ownRank)
|
||||
.build();
|
||||
return enrichModelWithMembers(model, event.getGuild().getIdLong())
|
||||
.thenCompose(model1 -> FutureUtils.toSingleFutureGeneric(interactionService.sendMessageToInteraction(CREDIT_LEADERBOARD_RESPONSE, model1, event.getHook())))
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
private CompletableFuture<CreditsLeaderboardResponseModel> enrichModelWithMembers(CreditsLeaderboardResponseModel model, Long serverId) {
|
||||
List<CompletableFuture<Member>> memberFutures = new ArrayList<>();
|
||||
model.getEntries().forEach(creditsLeaderboardEntry -> {
|
||||
memberFutures.add(memberService.getMemberInServerAsync(serverId, creditsLeaderboardEntry.getMemberDisplay().getUserId()));
|
||||
});
|
||||
memberFutures.add(memberService.getMemberInServerAsync(serverId, model.getOwnRank().getMemberDisplay().getUserId()));
|
||||
CompletableFuture<CreditsLeaderboardResponseModel> modelFuture = new CompletableFuture<>();
|
||||
CompletableFutureList<Member> futureList = new CompletableFutureList<>(memberFutures);
|
||||
futureList.getMainFuture().whenComplete((unused, throwable) -> {
|
||||
Map<Long, Member> memberMap = new HashMap<>();
|
||||
futureList.getObjects().forEach(member -> memberMap.put(member.getIdLong(), member));
|
||||
model.getEntries().forEach(creditsLeaderboardEntry -> {
|
||||
if(memberMap.containsKey(creditsLeaderboardEntry.getMemberDisplay().getUserId())) {
|
||||
creditsLeaderboardEntry.setMember(memberMap.get(creditsLeaderboardEntry.getMemberDisplay().getUserId()));
|
||||
}
|
||||
});
|
||||
if(memberMap.containsKey(model.getOwnRank().getMemberDisplay().getUserId())) {
|
||||
model.getOwnRank().setMember(memberMap.get(model.getOwnRank().getMemberDisplay().getUserId()));
|
||||
}
|
||||
modelFuture.complete(model);
|
||||
});
|
||||
return modelFuture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
Parameter pageParameter = Parameter
|
||||
.builder()
|
||||
.name(PAGE_PARAMETER)
|
||||
.optional(true)
|
||||
.templated(true)
|
||||
.type(Integer.class)
|
||||
.build();
|
||||
List<Parameter> parameters = Arrays.asList(pageParameter);
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.ECONOMY)
|
||||
.commandName("creditboard")
|
||||
.build();
|
||||
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(CREDIT_LEADERBOARD_COMMAND_NAME)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(false)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ECONOMY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package dev.sheldan.abstracto.entertainment.command.economy;
|
||||
|
||||
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.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.CreditsLeaderboardEntry;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.CreditsModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EconomyService;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class Credits extends AbstractConditionableCommand {
|
||||
|
||||
private static final String CREDITS_COMMAND = "credits";
|
||||
private static final String CREDITS_RESPONSE = "credits_response";
|
||||
|
||||
@Autowired
|
||||
private EconomyService economyService;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
AUserInAServer targetUser = userInServerManagementService.loadOrCreateUser(commandContext.getAuthor());
|
||||
CreditsLeaderboardEntry rankEntry = economyService.getRankOfUser(targetUser);
|
||||
rankEntry.setMember(commandContext.getAuthor());
|
||||
CreditsModel model = CreditsModel
|
||||
.builder()
|
||||
.entry(rankEntry)
|
||||
.build();
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(CREDITS_RESPONSE, model, commandContext.getGuild().getIdLong());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
AUserInAServer targetUser = userInServerManagementService.loadOrCreateUser(event.getMember());
|
||||
CreditsLeaderboardEntry rankEntry = economyService.getRankOfUser(targetUser);
|
||||
rankEntry.setMember(event.getMember());
|
||||
CreditsModel model = CreditsModel
|
||||
.builder()
|
||||
.entry(rankEntry)
|
||||
.build();
|
||||
return interactionService.replyEmbed(CREDITS_RESPONSE, model, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.ECONOMY)
|
||||
.commandName("credits")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(CREDITS_COMMAND)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ECONOMY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package dev.sheldan.abstracto.entertainment.command.economy;
|
||||
|
||||
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.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.dto.PayDayResult;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.PayDayResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyLeaderboardResult;
|
||||
import dev.sheldan.abstracto.entertainment.service.EconomyService;
|
||||
import dev.sheldan.abstracto.entertainment.service.management.EconomyUserManagementService;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class Payday extends AbstractConditionableCommand {
|
||||
|
||||
private static final String PAYDAY_COMMAND_NAME = "payday";
|
||||
|
||||
@Autowired
|
||||
private EconomyService economyService;
|
||||
|
||||
@Autowired
|
||||
private EconomyUserManagementService economyUserManagementService;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
private static final String PAYDAY_RESPONSE = "payday_response";
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
Member member = commandContext.getAuthor();
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
PayDayResult payDayResult = economyService.triggerPayDay(aUserInAServer);
|
||||
EconomyLeaderboardResult rank = economyUserManagementService.getRankOfUserInServer(aUserInAServer);
|
||||
PayDayResponseModel responseModel = PayDayResponseModel
|
||||
.builder()
|
||||
.currentCredits(payDayResult.getCurrentCredits())
|
||||
.gainedCredits(payDayResult.getGainedCredits())
|
||||
.leaderboardPosition(rank.getRank().longValue())
|
||||
.build();
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(PAYDAY_RESPONSE, responseModel, member.getGuild().getIdLong());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
Member member = event.getMember();
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
PayDayResult payDayResult = economyService.triggerPayDay(aUserInAServer);
|
||||
EconomyLeaderboardResult rank = economyUserManagementService.getRankOfUserInServer(aUserInAServer);
|
||||
PayDayResponseModel responseModel = PayDayResponseModel
|
||||
.builder()
|
||||
.currentCredits(payDayResult.getCurrentCredits())
|
||||
.gainedCredits(payDayResult.getGainedCredits())
|
||||
.leaderboardPosition(rank.getRank().longValue())
|
||||
.build();
|
||||
return interactionService.replyEmbed(PAYDAY_RESPONSE, responseModel, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.ECONOMY)
|
||||
.commandName("payday")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(PAYDAY_COMMAND_NAME)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ECONOMY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package dev.sheldan.abstracto.entertainment.command.economy;
|
||||
|
||||
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.validator.MinIntegerValueValidator;
|
||||
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.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.dto.SlotsResult;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.SlotsResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EconomyServiceBean;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class Slots extends AbstractConditionableCommand {
|
||||
|
||||
private static final String SLOTS_COMMAND_NAME = "slots";
|
||||
private static final String BID_PARAMETER = "bid";
|
||||
private static final String SLOTS_RESPONSE = "slots_response";
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private EconomyServiceBean economyUserServiceBean;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
Integer bid = (Integer) commandContext.getParameters().getParameters().get(0);
|
||||
Member member = commandContext.getAuthor();
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
SlotsResult slotsResult = economyUserServiceBean.triggerSlots(aUserInAServer, bid.longValue());
|
||||
SlotsResponseModel responseModel = SlotsResponseModel.fromSlotsResult(slotsResult);
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(SLOTS_RESPONSE, responseModel, member.getGuild().getIdLong());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
Long bid = slashCommandParameterService.getCommandOption(BID_PARAMETER, event, Integer.class).longValue();
|
||||
Member member = event.getMember();
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
SlotsResult slotsResult = economyUserServiceBean.triggerSlots(aUserInAServer, bid);
|
||||
SlotsResponseModel responseModel = SlotsResponseModel.fromSlotsResult(slotsResult);
|
||||
return interactionService.replyEmbed(SLOTS_RESPONSE, responseModel, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
Parameter bidParameter = Parameter
|
||||
.builder()
|
||||
.name(BID_PARAMETER)
|
||||
.type(Integer.class)
|
||||
.templated(true)
|
||||
.validators(Arrays.asList(MinIntegerValueValidator.min(0L)))
|
||||
.build();
|
||||
parameters.add(bidParameter);
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.ECONOMY)
|
||||
.commandName("slots")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(SLOTS_COMMAND_NAME)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ECONOMY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package dev.sheldan.abstracto.entertainment.command.economy;
|
||||
|
||||
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.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.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.TransferCreditsModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EconomyService;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
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 TransferCredits extends AbstractConditionableCommand {
|
||||
private static final String TRANSFER_CREDITS_COMMAND = "transferCredits";
|
||||
private static final String TRANSFER_CREDITS_RESPONSE = "transferCredits_response";
|
||||
private static final String MEMBER_PARAMETER = "targetMember";
|
||||
private static final String AMOUNT_PARAMETER = "amount";
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private EconomyService economyService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Member targetMember = (Member) parameters.get(0);
|
||||
Integer amount = (Integer) parameters.get(1);
|
||||
AUserInAServer targetUser = userInServerManagementService.loadOrCreateUser(targetMember);
|
||||
AUserInAServer sourceUser = userInServerManagementService.loadOrCreateUser(commandContext.getAuthor());
|
||||
economyService.transferCredits(sourceUser, targetUser, amount.longValue());
|
||||
TransferCreditsModel responseModel = TransferCreditsModel
|
||||
.builder()
|
||||
.sourceMember(MemberDisplay.fromMember(commandContext.getAuthor()))
|
||||
.targetMember(MemberDisplay.fromMember(targetMember))
|
||||
.credits(amount)
|
||||
.build();
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(TRANSFER_CREDITS_RESPONSE, responseModel, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
Member targetMember = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER, event, Member.class);
|
||||
Integer amount = slashCommandParameterService.getCommandOption(AMOUNT_PARAMETER, event, Integer.class);
|
||||
AUserInAServer targetUser = userInServerManagementService.loadOrCreateUser(targetMember);
|
||||
AUserInAServer sourceUser = userInServerManagementService.loadOrCreateUser(event.getMember());
|
||||
TransferCreditsModel responseModel = TransferCreditsModel
|
||||
.builder()
|
||||
.sourceMember(MemberDisplay.fromMember(event.getMember()))
|
||||
.targetMember(MemberDisplay.fromMember(targetMember))
|
||||
.credits(amount)
|
||||
.build();
|
||||
economyService.transferCredits(sourceUser, targetUser, amount.longValue());
|
||||
return interactionService.replyEmbed(TRANSFER_CREDITS_RESPONSE, responseModel, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
Parameter memberParameter = Parameter
|
||||
.builder()
|
||||
.name(MEMBER_PARAMETER)
|
||||
.templated(true)
|
||||
.type(Member.class)
|
||||
.optional(true)
|
||||
.build();
|
||||
|
||||
Parameter amountParameter = Parameter
|
||||
.builder()
|
||||
.name(AMOUNT_PARAMETER)
|
||||
.templated(true)
|
||||
.type(Integer.class)
|
||||
.optional(true)
|
||||
.build();
|
||||
|
||||
List<Parameter> parameters = Arrays.asList(memberParameter, amountParameter);
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.ECONOMY)
|
||||
.commandName("transfer")
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(TRANSFER_CREDITS_COMMAND)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.causesReaction(false)
|
||||
.async(true)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ECONOMY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
package dev.sheldan.abstracto.entertainment.command.games;
|
||||
|
||||
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.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentSlashCommandNames;
|
||||
import dev.sheldan.abstracto.entertainment.exception.NotEnoughCreditsException;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.games.MineBoard;
|
||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyUser;
|
||||
import dev.sheldan.abstracto.entertainment.service.GameService;
|
||||
import dev.sheldan.abstracto.entertainment.service.management.EconomyUserManagementService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class Mines extends AbstractConditionableCommand {
|
||||
|
||||
private static final String MINES_COMMAND_NAME = "mines";
|
||||
private static final String WIDTH_PARAMETER = "width";
|
||||
private static final String HEIGHT_PARAMETER = "height";
|
||||
private static final String MINES_PARAMETER = "mines";
|
||||
private static final String CREDITS_PARAMETER = "credits";
|
||||
public static final String MINE_BOARD_TEMPLATE_KEY = "mines_board_response";
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Autowired
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Autowired
|
||||
private GameService gameService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private EconomyUserManagementService economyUserManagementService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
Integer width = 5;
|
||||
if(slashCommandParameterService.hasCommandOption(WIDTH_PARAMETER, event)) {
|
||||
width = slashCommandParameterService.getCommandOption(WIDTH_PARAMETER, event, Integer.class);
|
||||
}
|
||||
Integer height = 5;
|
||||
if(slashCommandParameterService.hasCommandOption(HEIGHT_PARAMETER, event)) {
|
||||
height = slashCommandParameterService.getCommandOption(HEIGHT_PARAMETER, event, Integer.class);
|
||||
}
|
||||
Integer mines = 5;
|
||||
if(slashCommandParameterService.hasCommandOption(MINES_PARAMETER, event)) {
|
||||
mines = slashCommandParameterService.getCommandOption(MINES_PARAMETER, event, Integer.class);
|
||||
}
|
||||
Integer credit = null;
|
||||
long serverId = event.getGuild().getIdLong();
|
||||
boolean economyEnabled = featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, serverId);
|
||||
if(economyEnabled){
|
||||
credit = 50;
|
||||
if(slashCommandParameterService.hasCommandOption(CREDITS_PARAMETER, event)) {
|
||||
credit = slashCommandParameterService.getCommandOption(CREDITS_PARAMETER, event, Integer.class);
|
||||
}
|
||||
|
||||
Optional<EconomyUser> userOptional = economyUserManagementService.getUser(ServerUser.fromMember(event.getMember()));
|
||||
if(!userOptional.isPresent()) {
|
||||
throw new NotEnoughCreditsException();
|
||||
}
|
||||
EconomyUser user = userOptional.get();
|
||||
if(user.getCredits() < credit) {
|
||||
throw new NotEnoughCreditsException();
|
||||
}
|
||||
}
|
||||
MineBoard board = gameService.createBoard(width, height, mines, serverId);
|
||||
board.setCreditsEnabled(economyEnabled);
|
||||
board.setUserId(event.getMember().getIdLong());
|
||||
board.setServerId(serverId);
|
||||
board.setCredits(credit);
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(MINE_BOARD_TEMPLATE_KEY, board);
|
||||
return interactionService.replyMessageToSend(messageToSend, event)
|
||||
.thenCompose(interactionHook -> interactionHook.retrieveOriginal().submit())
|
||||
.thenApply(message -> {
|
||||
gameService.persistMineBoardMessage(board, message);
|
||||
return CommandResult.fromSuccess();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
Integer width = 5;
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
if(!parameters.isEmpty()) {
|
||||
width = (Integer) parameters.get(0);
|
||||
}
|
||||
Integer height = 5;
|
||||
if(parameters.size() >= 2) {
|
||||
height = (Integer) parameters.get(1);
|
||||
}
|
||||
Integer mines = 5;
|
||||
if(parameters.size() >= 3) {
|
||||
mines = (Integer) parameters.get(2);
|
||||
}
|
||||
Integer credit = null;
|
||||
long serverId = commandContext.getGuild().getIdLong();
|
||||
boolean economyEnabled = featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, serverId);
|
||||
if(economyEnabled){
|
||||
credit = 50;
|
||||
if(parameters.size() == 4) {
|
||||
credit = (Integer) parameters.get(3);
|
||||
}
|
||||
|
||||
Optional<EconomyUser> userOptional = economyUserManagementService.getUser(ServerUser.fromMember(commandContext.getAuthor()));
|
||||
if(!userOptional.isPresent()) {
|
||||
throw new NotEnoughCreditsException();
|
||||
}
|
||||
EconomyUser user = userOptional.get();
|
||||
if(user.getCredits() < credit) {
|
||||
throw new NotEnoughCreditsException();
|
||||
}
|
||||
}
|
||||
MineBoard board = gameService.createBoard(width, height, mines, serverId);
|
||||
board.setCreditsEnabled(economyEnabled);
|
||||
board.setUserId(commandContext.getAuthor().getIdLong());
|
||||
board.setServerId(serverId);
|
||||
board.setCredits(credit);
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(MINE_BOARD_TEMPLATE_KEY, board);
|
||||
List<CompletableFuture<Message>> futures = channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel());
|
||||
return FutureUtils.toSingleFutureGeneric(futures)
|
||||
.thenAccept(unused -> gameService.persistMineBoardMessage(board, futures.get(0).join()))
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
Parameter widthParameter = Parameter
|
||||
.builder()
|
||||
.name(WIDTH_PARAMETER)
|
||||
.type(Integer.class)
|
||||
.optional(true)
|
||||
.templated(true)
|
||||
.build();
|
||||
parameters.add(widthParameter);
|
||||
|
||||
Parameter heightParameter = Parameter
|
||||
.builder()
|
||||
.name(HEIGHT_PARAMETER)
|
||||
.type(Integer.class)
|
||||
.optional(true)
|
||||
.templated(true)
|
||||
.build();
|
||||
parameters.add(heightParameter);
|
||||
|
||||
Parameter minesParameter = Parameter
|
||||
.builder()
|
||||
.name(MINES_PARAMETER)
|
||||
.type(Integer.class)
|
||||
.optional(true)
|
||||
.templated(true)
|
||||
.build();
|
||||
parameters.add(minesParameter);
|
||||
|
||||
Parameter creditsParameter = Parameter
|
||||
.builder()
|
||||
.name(CREDITS_PARAMETER)
|
||||
.type(Integer.class)
|
||||
.optional(true)
|
||||
.templated(true)
|
||||
.dependentFeatures(Arrays.asList(EntertainmentFeatureDefinition.ECONOMY.getKey()))
|
||||
.build();
|
||||
parameters.add(creditsParameter);
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(EntertainmentSlashCommandNames.GAME)
|
||||
.commandName(MINES_COMMAND_NAME)
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(MINES_COMMAND_NAME)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.GAMES;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package dev.sheldan.abstracto.entertainment.listener.interaction;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListener;
|
||||
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListenerModel;
|
||||
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListenerResult;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.entertainment.command.games.Mines;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.games.MineBoard;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.games.MineBoardPayload;
|
||||
import dev.sheldan.abstracto.entertainment.service.GameService;
|
||||
import dev.sheldan.abstracto.entertainment.service.GameServiceBean;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MinesButtonClickedListener implements ButtonClickedListener {
|
||||
|
||||
@Autowired
|
||||
private GameService gameService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Override
|
||||
public ButtonClickedListenerResult execute(ButtonClickedListenerModel model) {
|
||||
MineBoardPayload payload = (MineBoardPayload) model.getDeserializedPayload();
|
||||
if(model.getEvent().getUser().getIdLong() != payload.getMineBoard().getUserId()) {
|
||||
return ButtonClickedListenerResult.IGNORED;
|
||||
}
|
||||
MineBoard mineBoard = payload.getMineBoard();
|
||||
if(!mineBoard.getState().equals(GameService.MineResult.CONTINUE)) {
|
||||
return ButtonClickedListenerResult.IGNORED;
|
||||
}
|
||||
GameService.MineResult mineResult = gameService.uncoverField(mineBoard, payload.getX(), payload.getY());
|
||||
mineBoard.setState(mineResult);
|
||||
if(mineBoard.getState() != GameService.MineResult.CONTINUE) {
|
||||
if(featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, model.getServerId())){
|
||||
gameService.evaluateCreditChanges(mineBoard);
|
||||
}
|
||||
gameService.uncoverBoard(mineBoard);
|
||||
}
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(Mines.MINE_BOARD_TEMPLATE_KEY, mineBoard);
|
||||
interactionService.editOriginal(messageToSend, model.getEvent().getHook()).thenAccept(message -> {
|
||||
gameService.updateMineBoard(mineBoard);
|
||||
log.info("Updated original mineboard for board {}.", mineBoard.getBoardId());
|
||||
});
|
||||
return ButtonClickedListenerResult.ACKNOWLEDGED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.GAMES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPriority() {
|
||||
return ListenerPriority.MEDIUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean handlesEvent(ButtonClickedListenerModel model) {
|
||||
return model.getOrigin().equals(GameServiceBean.MINES_BUTTON_ORIGIN);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package dev.sheldan.abstracto.entertainment.listener.interaction;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.interaction.MessageContextConfig;
|
||||
import dev.sheldan.abstracto.core.interaction.context.ContextCommandService;
|
||||
import dev.sheldan.abstracto.core.interaction.context.message.listener.MessageContextCommandListener;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.models.listener.interaction.MessageContextInteractionModel;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.MockResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static dev.sheldan.abstracto.entertainment.command.Mock.MOCK_RESPONSE_TEMPLATE_KEY;
|
||||
|
||||
|
||||
@Component
|
||||
public class MockMessageContextCommandListener implements MessageContextCommandListener {
|
||||
|
||||
@Autowired
|
||||
private ContextCommandService contextCommandService;
|
||||
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Override
|
||||
public DefaultListenerResult execute(MessageContextInteractionModel eventModel) {
|
||||
Message targetMessage = eventModel.getEvent().getTarget();
|
||||
String mockText = entertainmentService.createMockText(targetMessage.getContentRaw(), eventModel.getEvent().getMember(), targetMessage.getMember());
|
||||
MockResponseModel model = MockResponseModel
|
||||
.builder()
|
||||
.originalText(targetMessage.getContentRaw())
|
||||
.mockingText(mockText)
|
||||
.build();
|
||||
interactionService.replyEmbed(MOCK_RESPONSE_TEMPLATE_KEY, model, eventModel.getEvent());
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ENTERTAINMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageContextConfig getConfig() {
|
||||
return MessageContextConfig
|
||||
.builder()
|
||||
.isTemplated(true)
|
||||
.name("mock")
|
||||
.templateKey("mock_message_context_menu_label")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean handlesEvent(MessageContextInteractionModel model) {
|
||||
return contextCommandService.matchesGuildContextName(model, getConfig(), model.getServerId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package dev.sheldan.abstracto.entertainment.repository;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyLeaderboardResult;
|
||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyUser;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface EconomyUserRepository extends JpaRepository<EconomyUser, Long> {
|
||||
Optional<EconomyUser> findByUser(AUserInAServer aUserInAServer);
|
||||
Optional<EconomyUser> findByServer_IdAndUser_UserReference_Id(Long serverId, Long userId);
|
||||
|
||||
@Query(value = "WITH economy_user_ranked AS" +
|
||||
"( " +
|
||||
" SELECT eu.id, eu.credits, uis.user_id, ROW_NUMBER() OVER ( ORDER BY credits DESC ) " +
|
||||
" FROM economy_user eu INNER JOIN user_in_server uis ON eu.id = uis.user_in_server_id INNER JOIN server s ON s.id = uis.server_id WHERE s.id = :serverId" +
|
||||
") " +
|
||||
"SELECT rank.id as \"id\", rank.user_id as \"userid\", rank.credits as \"credits\", rank.row_number as \"rank\" " +
|
||||
"FROM economy_user_ranked rank " +
|
||||
"WHERE rank.id = :userInServerId", nativeQuery = true)
|
||||
EconomyLeaderboardResult getRankOfUserInServer(@Param("userInServerId") Long id, @Param("serverId") Long serverId);
|
||||
|
||||
@Query(value = "WITH economy_user_ranked AS" +
|
||||
"( " +
|
||||
" SELECT eu.id, eu.credits, uis.user_id, ROW_NUMBER() OVER ( ORDER BY credits DESC ) " +
|
||||
" FROM economy_user eu INNER JOIN user_in_server uis ON eu.id = uis.user_in_server_id INNER JOIN server s ON s.id = uis.server_id WHERE s.id = :serverId" +
|
||||
") " +
|
||||
"SELECT rank.id as \"id\", rank.user_id as \"userid\", rank.credits as \"credits\", rank.row_number as \"rank\" " +
|
||||
"FROM economy_user_ranked rank ", nativeQuery = true)
|
||||
List<EconomyLeaderboardResult> getRanksInServer(@Param("serverId") Long serverId);
|
||||
List<EconomyUser> findTop10ByServerOrderByCreditsDesc(AServer server, Pageable pageable);
|
||||
|
||||
List<EconomyUser> findByServerOrderByCredits(AServer server);
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
package dev.sheldan.abstracto.entertainment.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.entertainment.config.EconomyFeatureConfig;
|
||||
import dev.sheldan.abstracto.entertainment.dto.CreditGambleResult;
|
||||
import dev.sheldan.abstracto.entertainment.dto.PayDayResult;
|
||||
import dev.sheldan.abstracto.entertainment.dto.SlotsResult;
|
||||
import dev.sheldan.abstracto.entertainment.exception.NotEnoughCreditsException;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.CreditsLeaderboardEntry;
|
||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyLeaderboardResult;
|
||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyUser;
|
||||
import dev.sheldan.abstracto.entertainment.service.management.EconomyUserManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class EconomyServiceBean implements EconomyService {
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private EconomyUserManagementService economyUserManagementService;
|
||||
|
||||
@Autowired
|
||||
private SecureRandom secureRandom;
|
||||
|
||||
private static final String CREDIT_GAMBLE_STORAGE = "creditGambleJackpot";
|
||||
|
||||
private static final String SNOWFLAKE = "❄";
|
||||
private static final String CHERRY = "🍒";
|
||||
private static final String COOKIE = "🍪";
|
||||
private static final String TWO = "2️⃣";
|
||||
private static final String CLOVER = "🍀";
|
||||
private static final String MUSHROOM = "🍄";
|
||||
private static final String SUNFLOWER = "🌻";
|
||||
private static final String HEART = "❤";
|
||||
private static final String SIX = "6️⃣";
|
||||
private static final String CYCLONE = "🌀";
|
||||
private static final String OUTCOME_KEY_THREE_CHERRIES = "threecherries";
|
||||
private static final String OUTCOME_KEY_NOTHING = "nothing";
|
||||
private static final String OUTCOME_KEY_JACKPOT = "jackpot";
|
||||
private static final String OUTCOME_KEY_CLOVERS = "clovers";
|
||||
private static final String OUTCOME_KEY_TWO_CHERRIES = "twocherries";
|
||||
private static final String OUTCOME_KEY_TWOSIX = "twosix";
|
||||
private static final String OUTCOME_KEY_3SYMBOLS = "threesymbols";
|
||||
private static final String OUTCOME_KEY_2SYMBOLS = "twosymbols";
|
||||
private static final List<String> POSSIBLE_SLOTS = Arrays.asList(SNOWFLAKE, CHERRY, COOKIE, TWO, CLOVER, MUSHROOM, SUNFLOWER, HEART, SIX, CYCLONE);
|
||||
private static final List<SlotMapping> WINNING_PATTERNS = Arrays.asList(
|
||||
new SlotMapping(Arrays.asList(CHERRY, CHERRY, CHERRY), 20, OUTCOME_KEY_THREE_CHERRIES),
|
||||
new SlotMapping(Arrays.asList(CLOVER, CLOVER, CLOVER), 25, OUTCOME_KEY_CLOVERS),
|
||||
new SlotMapping(Arrays.asList(TWO, TWO, SIX), 50, OUTCOME_KEY_JACKPOT),
|
||||
new SlotMapping(Arrays.asList(TWO, SIX), 4, OUTCOME_KEY_TWOSIX),
|
||||
new SlotMapping(Arrays.asList(CHERRY, CHERRY), 3, OUTCOME_KEY_TWO_CHERRIES)
|
||||
);
|
||||
private static final Integer TRIPLE_FACTOR = 10;
|
||||
private static final Integer DOUBLE_FACTOR = 2;
|
||||
|
||||
@Override
|
||||
public EconomyUser addCredits(AUserInAServer aUserInAServer, Long credits) {
|
||||
Optional<EconomyUser> existingUserOptional = economyUserManagementService.getUser(aUserInAServer);
|
||||
if (existingUserOptional.isPresent()) {
|
||||
EconomyUser existingUser = existingUserOptional.get();
|
||||
addCredits(existingUser, credits);
|
||||
return existingUser;
|
||||
} else {
|
||||
EconomyUser user = economyUserManagementService.createUser(aUserInAServer);
|
||||
user.setCredits(credits);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCredits(EconomyUser economyUser, Long credits) {
|
||||
economyUser.setCredits(economyUser.getCredits() + credits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPayDayCredits(AUserInAServer aUserInAServer) {
|
||||
Long creditsToAdd = configService.getLongValueOrConfigDefault(EconomyFeatureConfig.PAYDAY_CREDITS_CONFIG_KEY,
|
||||
aUserInAServer.getServerReference().getId());
|
||||
addCredits(aUserInAServer, creditsToAdd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PayDayResult triggerPayDay(AUserInAServer aUserInAServer) {
|
||||
Long creditsToAdd = configService.getLongValueOrConfigDefault(EconomyFeatureConfig.PAYDAY_CREDITS_CONFIG_KEY,
|
||||
aUserInAServer.getServerReference().getId());
|
||||
EconomyUser economyUser = addCredits(aUserInAServer, creditsToAdd);
|
||||
return PayDayResult
|
||||
.builder()
|
||||
.currentCredits(economyUser.getCredits())
|
||||
.gainedCredits(creditsToAdd)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotsResult triggerSlots(AUserInAServer aUserInAServer, Long bid) {
|
||||
Optional<EconomyUser> userOptional = economyUserManagementService.getUser(aUserInAServer);
|
||||
if(!userOptional.isPresent()) {
|
||||
throw new NotEnoughCreditsException();
|
||||
}
|
||||
EconomyUser user = userOptional.get();
|
||||
Long oldCredits = user.getCredits();
|
||||
if(user.getCredits() < bid) {
|
||||
throw new NotEnoughCreditsException();
|
||||
}
|
||||
SlotGame slotGame = playSlots();
|
||||
Integer factor = slotGame.getResultFactor();
|
||||
Long creditChange = bid * factor;
|
||||
addCredits(user, -bid);
|
||||
addCredits(user, creditChange);
|
||||
|
||||
return SlotsResult
|
||||
.builder()
|
||||
.bid(bid)
|
||||
.factor(factor.longValue())
|
||||
.newCredits(user.getCredits())
|
||||
.outComeKey(slotGame.getOutcome())
|
||||
.oldCredits(oldCredits)
|
||||
.winnings(creditChange)
|
||||
.rows(slotGame.getRows())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotGame playSlots() {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
List<String> tempSlots = new ArrayList<>(POSSIBLE_SLOTS);
|
||||
Collections.rotate(tempSlots, secureRandom.nextInt(2000) - 1000);
|
||||
result.add(tempSlots.get(0));
|
||||
result.add(tempSlots.get(1));
|
||||
result.add(tempSlots.get(2));
|
||||
}
|
||||
List<List<String>> rows = new ArrayList<>();
|
||||
rows.add(Arrays.asList(result.get(0), result.get(3), result.get(6)));
|
||||
List<String> decidingRow = Arrays.asList(result.get(1), result.get(4), result.get(7));
|
||||
rows.add(decidingRow);
|
||||
rows.add(Arrays.asList(result.get(2), result.get(5), result.get(8)));
|
||||
String decidingRowAsString = String.join("", decidingRow);
|
||||
SlotMapping specialPattern = getSpecialPattern(decidingRowAsString);
|
||||
Integer factor = 0;
|
||||
String outcomeKey = OUTCOME_KEY_NOTHING;
|
||||
if(specialPattern != null){
|
||||
factor = specialPattern.factor;
|
||||
outcomeKey = specialPattern.outcome;
|
||||
} else {
|
||||
Set<String> uniqueChars = new HashSet<>(decidingRow);
|
||||
if(uniqueChars.size() == 1) {
|
||||
factor = TRIPLE_FACTOR;
|
||||
outcomeKey = OUTCOME_KEY_3SYMBOLS;
|
||||
} else if(decidingRow.get(0).equals(decidingRow.get(1)) || decidingRow.get(1).equals(decidingRow.get(2)) ) {
|
||||
factor = DOUBLE_FACTOR;
|
||||
outcomeKey = OUTCOME_KEY_2SYMBOLS;
|
||||
}
|
||||
}
|
||||
return SlotGame
|
||||
.builder()
|
||||
.rows(rows)
|
||||
.outcome(outcomeKey)
|
||||
.resultFactor(factor)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CreditsLeaderboardEntry> getCreditLeaderboard(AServer server, Integer page) {
|
||||
if(page <= 0) {
|
||||
throw new IllegalArgumentException("Page needs to be >= 1");
|
||||
}
|
||||
page--;
|
||||
int pageSize = 10;
|
||||
List<CreditsLeaderboardEntry> entries = new ArrayList<>();
|
||||
List<EconomyUser> ranks = economyUserManagementService.getRanksInServer(server, page, pageSize);
|
||||
int pageOffset = page * pageSize;
|
||||
for (int i = 0; i < ranks.size(); i++) {
|
||||
EconomyUser rank = ranks.get(i);
|
||||
CreditsLeaderboardEntry entry = CreditsLeaderboardEntry
|
||||
.builder()
|
||||
.credits(rank.getCredits())
|
||||
.memberDisplay(MemberDisplay.fromAUserInAServer(rank.getUser()))
|
||||
.rank(pageOffset + i + 1)
|
||||
.build();
|
||||
entries.add(entry);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreditsLeaderboardEntry getRankOfUser(AUserInAServer aUserInAServer) {
|
||||
EconomyLeaderboardResult rank = economyUserManagementService.getRankOfUserInServer(aUserInAServer);
|
||||
if(rank != null) {
|
||||
return CreditsLeaderboardEntry
|
||||
.builder()
|
||||
.credits(rank.getCredits())
|
||||
.memberDisplay(MemberDisplay.fromAUserInAServer(aUserInAServer))
|
||||
.rank(rank.getRank())
|
||||
.build();
|
||||
} else {
|
||||
return CreditsLeaderboardEntry
|
||||
.builder()
|
||||
.credits(0L)
|
||||
.memberDisplay(MemberDisplay.fromAUserInAServer(aUserInAServer))
|
||||
.rank(-1)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferCredits(AUserInAServer source, AUserInAServer target, Long amount) {
|
||||
Optional<EconomyUser> userOptional = economyUserManagementService.getUser(source);
|
||||
if(!userOptional.isPresent()) {
|
||||
throw new NotEnoughCreditsException();
|
||||
}
|
||||
EconomyUser user = userOptional.get();
|
||||
if(user.getCredits() < amount) {
|
||||
throw new NotEnoughCreditsException();
|
||||
}
|
||||
addCredits(target, amount);
|
||||
addCredits(user, -amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreditGambleResult triggerCreditGamble(AUserInAServer aUserInAServer) {
|
||||
// TODO move these constants to system configs
|
||||
Optional<EconomyUser> userOptional = economyUserManagementService.getUser(aUserInAServer);
|
||||
if(!userOptional.isPresent()) {
|
||||
throw new NotEnoughCreditsException();
|
||||
}
|
||||
EconomyUser user = userOptional.get();
|
||||
Long bid = 25L;
|
||||
if(user.getCredits() < bid) {
|
||||
throw new NotEnoughCreditsException();
|
||||
}
|
||||
Long serverId = aUserInAServer.getServerReference().getId();
|
||||
Long currentJackpot = configService.getLongValueOrConfigDefault(CREDIT_GAMBLE_STORAGE, serverId);
|
||||
List<Integer> diceRoles = new ArrayList<>();
|
||||
diceRoles.add(creditGambleDiceResult());
|
||||
diceRoles.add(creditGambleDiceResult());
|
||||
diceRoles.add(creditGambleDiceResult());
|
||||
diceRoles.add(creditGambleDiceResult());
|
||||
|
||||
Long toJackpot = 20L;
|
||||
Integer uniqueNumbers = new HashSet<>(diceRoles).size();
|
||||
Boolean won = uniqueNumbers == 1;
|
||||
CreditGambleResult result = CreditGambleResult
|
||||
.builder()
|
||||
.uniqueNumbers(uniqueNumbers)
|
||||
.won(won)
|
||||
.bid(bid)
|
||||
.toBank(bid - toJackpot)
|
||||
.toJackpot(toJackpot)
|
||||
.rolls(diceRoles)
|
||||
.currentJackpot(currentJackpot + toJackpot)
|
||||
.build();
|
||||
if(won) {
|
||||
addCredits(user, currentJackpot);
|
||||
currentJackpot = 1000L;
|
||||
} else {
|
||||
currentJackpot += toJackpot;
|
||||
addCredits(user, -bid);
|
||||
}
|
||||
configService.setOrCreateConfigValue(CREDIT_GAMBLE_STORAGE, serverId, currentJackpot.toString());
|
||||
return result;
|
||||
}
|
||||
|
||||
private Integer creditGambleDiceResult() {
|
||||
return secureRandom.nextInt(7) + 1;
|
||||
}
|
||||
|
||||
private SlotMapping getSpecialPattern(String row){
|
||||
return WINNING_PATTERNS
|
||||
.stream()
|
||||
.filter(slotMapping -> row.contains(slotMapping.processedMapping))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private static class SlotMapping {
|
||||
private Integer factor;
|
||||
private String processedMapping;
|
||||
private String outcome;
|
||||
|
||||
public SlotMapping(List<String> slots, Integer factor, String outcome) {
|
||||
this.factor = factor;
|
||||
this.processedMapping = String.join("", slots);
|
||||
this.outcome = outcome;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
package dev.sheldan.abstracto.entertainment.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.interaction.ComponentPayloadService;
|
||||
import dev.sheldan.abstracto.core.interaction.ComponentService;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.entertainment.exception.InvalidGameBoardException;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.games.MineBoard;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.games.MineBoardField;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.games.MineBoardPayload;
|
||||
import dev.sheldan.abstracto.entertainment.model.command.games.MineBoardRow;
|
||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyUser;
|
||||
import dev.sheldan.abstracto.entertainment.service.management.EconomyUserManagementService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static dev.sheldan.abstracto.entertainment.config.GamesFeatureConfig.MINES_CREDITS_FACTOR;
|
||||
import static dev.sheldan.abstracto.entertainment.config.GamesFeatureConfig.MINES_MINIMUM_MINES_RATIO;
|
||||
|
||||
@Component
|
||||
public class GameServiceBean implements GameService {
|
||||
|
||||
public static final String MINES_BUTTON_ORIGIN = "MINES_BUTTON";
|
||||
@Autowired
|
||||
private SecureRandom secureRandom;
|
||||
|
||||
@Autowired
|
||||
private ComponentService componentService;
|
||||
|
||||
@Autowired
|
||||
private ComponentPayloadService componentPayloadService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Autowired
|
||||
private EconomyService economyService;
|
||||
|
||||
@Autowired
|
||||
private EconomyUserManagementService economyUserManagementService;
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@Override
|
||||
public MineBoard createBoard(Integer width, Integer height, Integer mines, Long serverId) {
|
||||
double minMinesRatio = configService.getDoubleValueOrConfigDefault(MINES_MINIMUM_MINES_RATIO, serverId);
|
||||
if(mines >= width * height || width > 5 || height > 5 || mines <= 1 || height <= 1 || width <= 1) {
|
||||
throw new InvalidGameBoardException(minMinesRatio);
|
||||
}
|
||||
if((double) mines / (width * height) < minMinesRatio) {
|
||||
throw new InvalidGameBoardException(minMinesRatio);
|
||||
}
|
||||
MineBoard mineBoard = generateEmptyBoard(width, height);
|
||||
mineBoard.setMineCount(mines);
|
||||
fillWithMines(mineBoard);
|
||||
evaluateCounters(mineBoard);
|
||||
|
||||
return mineBoard;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void persistMineBoardMessage(MineBoard mineBoard, Message message) {
|
||||
mineBoard.setMessageId(message.getIdLong());
|
||||
mineBoard.setChannelId(message.getChannel().getIdLong());
|
||||
AServer server = serverManagementService.loadServer(message.getGuild());
|
||||
mineBoard.getFields().forEach(mineBoardField -> {
|
||||
MineBoardPayload payload = MineBoardPayload
|
||||
.builder()
|
||||
.x(mineBoardField.getX())
|
||||
.y(mineBoardField.getY())
|
||||
.mineBoard(mineBoard)
|
||||
.build();
|
||||
String componentId = mineBoard.getBoardId() + "_" + mineBoardField.getX() + "_" + mineBoardField.getY();
|
||||
componentPayloadService.createButtonPayload(componentId, payload, MINES_BUTTON_ORIGIN, server);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateMineBoard(MineBoard mineBoard) {
|
||||
mineBoard.getFields().forEach(mineBoardField -> {
|
||||
MineBoardPayload newPayload = MineBoardPayload
|
||||
.builder()
|
||||
.x(mineBoardField.getX())
|
||||
.y(mineBoardField.getY())
|
||||
.mineBoard(mineBoard)
|
||||
.build();
|
||||
String componentId = mineBoard.getBoardId() + "_" + mineBoardField.getX() + "_" + mineBoardField.getY();
|
||||
componentPayloadService.updateButtonPayload(componentId, newPayload);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncoverBoard(MineBoard mineBoard) {
|
||||
mineBoard.getFields().forEach(mineBoardField -> {
|
||||
if(mineBoardField.getType().equals(MineBoardField.MineBoardFieldType.COVERED)) {
|
||||
mineBoardField.setType(MineBoardField.MineBoardFieldType.UNCOVERED);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluateCreditChanges(MineBoard mineBoard) {
|
||||
Long credits = mineBoard.getCredits().longValue();
|
||||
Integer mineCount = mineBoard.getMineCount();
|
||||
List<MineBoardField> allFields = mineBoard.getFields();
|
||||
Integer leftFields = (int) allFields
|
||||
.stream()
|
||||
.filter(mineBoardField -> mineBoardField.getType().equals(MineBoardField.MineBoardFieldType.COVERED)
|
||||
|| mineBoardField.getType().equals(MineBoardField.MineBoardFieldType.MINE))
|
||||
.count();
|
||||
Integer fieldCount = allFields.size();
|
||||
Integer uncoveredFields = fieldCount - leftFields;
|
||||
Long creditChange = (long) (calculateCreditFactor(fieldCount, mineCount, uncoveredFields) * credits);
|
||||
if(mineBoard.getState().equals(MineResult.WON)) {
|
||||
Double factor = configService.getDoubleValueOrConfigDefault(MINES_CREDITS_FACTOR, mineBoard.getServerId());
|
||||
creditChange = (long) (creditChange * factor);
|
||||
}
|
||||
ServerUser serverUser = ServerUser
|
||||
.builder()
|
||||
.serverId(mineBoard.getServerId())
|
||||
.userId(mineBoard.getUserId())
|
||||
.build();
|
||||
Optional<EconomyUser> economyUserOptional = economyUserManagementService.getUser(serverUser);
|
||||
if(economyUserOptional.isPresent()) {
|
||||
economyService.addCredits(economyUserOptional.get(), -credits);
|
||||
economyService.addCredits(economyUserOptional.get(), creditChange);
|
||||
}
|
||||
mineBoard.setCreditChange(creditChange);
|
||||
}
|
||||
|
||||
private double calculateCreditFactor(int totalFields, int mines, int uncovered) {
|
||||
return ((double) uncovered / (totalFields - mines)) + totalFields / 25.0 - ((totalFields - mines) / 25.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MineResult uncoverField(MineBoard board, Integer x, Integer y) {
|
||||
return uncoverFieldOnBoard(board, x, y);
|
||||
}
|
||||
|
||||
public GameService.MineResult uncoverFieldOnBoard(MineBoard board, Integer x, Integer y) {
|
||||
MineBoardField field = board.getField(x, y);
|
||||
if(!MineBoardField.canInteract(field.getType())) {
|
||||
return GameService.MineResult.CONTINUE;
|
||||
}
|
||||
if(field.getType().equals(MineBoardField.MineBoardFieldType.MINE)) {
|
||||
field.setType(MineBoardField.MineBoardFieldType.EXPLODED);
|
||||
return GameService.MineResult.LOST;
|
||||
}
|
||||
if(field.getType().equals(MineBoardField.MineBoardFieldType.COVERED)) {
|
||||
if(field.getCounterValue() == 0) {
|
||||
Set<String> alreadyConsidered = new HashSet<>();
|
||||
Queue<MineBoardField> toUncover = new LinkedList<>();
|
||||
toUncover.add(field);
|
||||
while(!toUncover.isEmpty()) {
|
||||
MineBoardField fieldToHandle = toUncover.poll();
|
||||
fieldToHandle.setType(MineBoardField.MineBoardFieldType.UNCOVERED);
|
||||
alreadyConsidered.add(fieldToHandle.getX() + "_" + fieldToHandle.getY());
|
||||
// only when we actually got a free field, we should add its neighbors to the next one to uncover
|
||||
if(fieldToHandle.getCounterValue() == 0) {
|
||||
List<MineBoardField> neighbors = getNeighbors(board, fieldToHandle.getX(), fieldToHandle.getY(), false);
|
||||
List<MineBoardField> uncoverableNeighbors = neighbors
|
||||
.stream().filter(mineBoardField -> mineBoardField.getType().equals(MineBoardField.MineBoardFieldType.COVERED))
|
||||
.collect(Collectors.toList());
|
||||
uncoverableNeighbors.forEach(mineBoardField -> {
|
||||
if(!alreadyConsidered.contains(mineBoardField.getX() + "_" + mineBoardField.getY())) {
|
||||
mineBoardField.setType(MineBoardField.MineBoardFieldType.UNCOVERED);
|
||||
// only if t he newly found neighbor is a free field, we should discover its neighbors
|
||||
if(mineBoardField.getCounterValue() == 0) {
|
||||
toUncover.addAll(uncoverableNeighbors);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
field.setType(MineBoardField.MineBoardFieldType.UNCOVERED);
|
||||
}
|
||||
if(hasWon(board)) {
|
||||
return GameService.MineResult.WON;
|
||||
}
|
||||
return GameService.MineResult.CONTINUE;
|
||||
}
|
||||
throw new IllegalStateException("Did not find correct type of field.");
|
||||
}
|
||||
|
||||
private List<MineBoardField> getNeighbors(MineBoard mineBoard, int xPosition, int yPosition) {
|
||||
return getNeighbors(mineBoard, xPosition, yPosition, false);
|
||||
}
|
||||
|
||||
private List<MineBoardField> getNeighbors(MineBoard board, int xPosition, int yPosition, boolean directOnly) {
|
||||
List<MineBoardField> neighbors = new ArrayList<>();
|
||||
boolean isFirstRow = yPosition == 0;
|
||||
boolean isLastRow = yPosition == board.getRowCount() - 1;
|
||||
boolean isFirstColumn = xPosition == 0;
|
||||
boolean isLastColumn = xPosition == board.getColumnCount() - 1;
|
||||
if(!isFirstColumn) {
|
||||
if(!isFirstRow && !directOnly) {
|
||||
neighbors.add(board.getField(xPosition - 1, yPosition - 1));
|
||||
}
|
||||
neighbors.add(board.getField(xPosition - 1, yPosition));
|
||||
if(!isLastRow && !directOnly) {
|
||||
neighbors.add(board.getField(xPosition - 1, yPosition + 1));
|
||||
}
|
||||
}
|
||||
if(!isFirstRow && !directOnly) {
|
||||
neighbors.add(board.getField(xPosition, yPosition - 1));
|
||||
}
|
||||
if(!isLastRow && !directOnly) {
|
||||
neighbors.add(board.getField(xPosition, yPosition + 1));
|
||||
}
|
||||
if(!isLastColumn) {
|
||||
if(!isFirstRow && !directOnly) {
|
||||
neighbors.add(board.getField(xPosition + 1, yPosition - 1));
|
||||
}
|
||||
neighbors.add(board.getField(xPosition + 1, yPosition));
|
||||
if(!isLastRow && !directOnly) {
|
||||
neighbors.add(board.getField(xPosition + 1, yPosition + 1));
|
||||
}
|
||||
}
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
|
||||
public MineBoard generateEmptyBoard(Integer width, Integer height) {
|
||||
List<MineBoardRow> rows = new ArrayList<>();
|
||||
for (int y = 0; y < height; y++) {
|
||||
List<MineBoardField> fields = new ArrayList<>();
|
||||
for (int x = 0; x < width; x++) {
|
||||
MineBoardField field = MineBoardField
|
||||
.builder()
|
||||
.y(y)
|
||||
.x(x)
|
||||
.counterValue(0)
|
||||
.type(MineBoardField.MineBoardFieldType.COVERED)
|
||||
.build();
|
||||
fields.add(field);
|
||||
}
|
||||
MineBoardRow row = MineBoardRow
|
||||
.builder()
|
||||
.fields(fields)
|
||||
.build();
|
||||
rows.add(row);
|
||||
}
|
||||
return MineBoard
|
||||
.builder()
|
||||
.rows(rows)
|
||||
.state(MineResult.CONTINUE)
|
||||
.columnCount(width)
|
||||
.creditChange(0L)
|
||||
.rowCount(height)
|
||||
.boardId(UUID.randomUUID().toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
public void fillWithMines(MineBoard board) {
|
||||
Set<String> usedKeys = new HashSet<>();
|
||||
int maxIterations = 1_0000_000;
|
||||
int iterations = 0;
|
||||
List<Pair<Integer, Integer>> foundPositions = new ArrayList<>();
|
||||
do {
|
||||
int x = secureRandom.nextInt(board.getColumnCount());
|
||||
int y = secureRandom.nextInt(board.getRowCount());
|
||||
String positionKey = x + "_" + y;
|
||||
if(!usedKeys.contains(positionKey)) {
|
||||
foundPositions.add(Pair.of(x, y));
|
||||
usedKeys.add(positionKey);
|
||||
iterations = 0;
|
||||
}
|
||||
iterations++;
|
||||
} while(foundPositions.size() < board.getMineCount() && iterations < maxIterations);
|
||||
foundPositions.forEach(xYPair -> board.getRows().get(xYPair.getRight()).getFields().get(xYPair.getLeft()).setType(MineBoardField.MineBoardFieldType.MINE));
|
||||
}
|
||||
|
||||
public void evaluateCounters(MineBoard board) {
|
||||
board.getRows().forEach(mineBoardRow -> mineBoardRow.getFields().forEach(mineBoardField -> {
|
||||
if(!mineBoardField.getType().equals(MineBoardField.MineBoardFieldType.MINE)) {
|
||||
long mineCounts = getMineCounts(board, mineBoardField.getX(), mineBoardField.getY());
|
||||
mineBoardField.setCounterValue((int) mineCounts);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private long getMineCounts(MineBoard board, int xPosition, int yPosition) {
|
||||
List<MineBoardField> neighbors = getNeighbors(board, xPosition, yPosition);
|
||||
return neighbors
|
||||
.stream()
|
||||
.filter(mineBoardField -> mineBoardField.getType().equals(MineBoardField.MineBoardFieldType.MINE))
|
||||
.count();
|
||||
}
|
||||
|
||||
private boolean hasWon(MineBoard board) {
|
||||
return board
|
||||
.getFields()
|
||||
.stream()
|
||||
.noneMatch(mineBoardField ->
|
||||
mineBoardField.getType().equals(MineBoardField.MineBoardFieldType.COVERED)
|
||||
&& !mineBoardField.getType().equals(MineBoardField.MineBoardFieldType.MINE));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package dev.sheldan.abstracto.entertainment.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyLeaderboardResult;
|
||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyUser;
|
||||
import dev.sheldan.abstracto.entertainment.repository.EconomyUserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class EconomyUserManagementServiceBean implements EconomyUserManagementService {
|
||||
|
||||
@Autowired
|
||||
private EconomyUserRepository repository;
|
||||
|
||||
@Override
|
||||
public EconomyUser createUser(AUserInAServer aUserInAServer) {
|
||||
EconomyUser user = EconomyUser
|
||||
.builder()
|
||||
.id(aUserInAServer.getUserInServerId())
|
||||
.server(aUserInAServer.getServerReference())
|
||||
.credits(0L)
|
||||
.user(aUserInAServer)
|
||||
.build();
|
||||
return repository.save(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EconomyUser> getUser(AUserInAServer aUserInAServer) {
|
||||
return repository.findByUser(aUserInAServer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EconomyUser> getUser(ServerUser serverUser) {
|
||||
return repository.findByServer_IdAndUser_UserReference_Id(serverUser.getServerId(), serverUser.getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyLeaderboardResult getRankOfUserInServer(AUserInAServer aUserInAServer) {
|
||||
return repository.getRankOfUserInServer(aUserInAServer.getUserInServerId(), aUserInAServer.getServerReference().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EconomyUser> getRanksInServer(AServer server, Integer page, Integer pagesize) {
|
||||
return repository.findTop10ByServerOrderByCreditsDesc(server, PageRequest.of(page, pagesize));
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,22 @@ abstracto.systemConfigs.rollDefaultHigh.longValue=6
|
||||
|
||||
abstracto.featureFlags.entertainment.featureName=entertainment
|
||||
abstracto.featureFlags.entertainment.enabled=false
|
||||
|
||||
abstracto.systemConfigs.paydayCredits.name=paydayCredits
|
||||
abstracto.systemConfigs.paydayCredits.longValue=120
|
||||
|
||||
abstracto.featureFlags.economy.featureName=economy
|
||||
abstracto.featureFlags.economy.enabled=false
|
||||
|
||||
abstracto.featureFlags.games.featureName=games
|
||||
abstracto.featureFlags.games.enabled=false
|
||||
|
||||
abstracto.systemConfigs.minesCreditsFactor.name=minesCreditsFactor
|
||||
abstracto.systemConfigs.minesCreditsFactor.doubleValue=5
|
||||
|
||||
abstracto.systemConfigs.minesMinMineRatio.name=minesMinMineRatio
|
||||
abstracto.systemConfigs.minesMinMineRatio.doubleValue=0.2
|
||||
|
||||
# for now this is fine
|
||||
abstracto.systemConfigs.creditGambleJackpot.name=creditGambleJackpot
|
||||
abstracto.systemConfigs.creditGambleJackpot.longValue=1000
|
||||
@@ -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,45 @@
|
||||
<?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="entertainmentModule" value="(SELECT id FROM module WHERE name = 'entertainment')"/>
|
||||
<property name="economyFeature" value="(SELECT id FROM feature WHERE key = 'economy')"/>
|
||||
|
||||
<changeSet author="Sheldan" id="economy-command">
|
||||
<insert tableName="command">
|
||||
<column name="name" value="payday"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${economyFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="slots"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${economyFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="creditLeaderboard"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${economyFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="credits"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${economyFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="creditGamble"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${economyFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="transferCredits"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${economyFeature}"/>
|
||||
</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="economy_feature-insertion">
|
||||
<insert tableName="feature">
|
||||
<column name="key" value="economy"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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="economy_user-table">
|
||||
<createTable tableName="economy_user">
|
||||
<column name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="economy_user_pkey"/>
|
||||
</column>
|
||||
<column name="credits" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="last_pay_day" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="last_slots" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
<column name="server_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseColumnNames="server_id" baseTableName="economy_user" constraintName="fk_economy_user_server"
|
||||
deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
|
||||
referencedColumnNames="id" referencedTableName="server" validate="true"/>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS economy_user_update_trigger ON economy_user;
|
||||
CREATE TRIGGER economy_user_update_trigger BEFORE UPDATE ON economy_user FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS economy_user_insert_trigger ON economy_user;
|
||||
CREATE TRIGGER economy_user_insert_trigger BEFORE INSERT ON economy_user FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<include file="economy_user.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<include file="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="entertainmentModule" value="(SELECT id FROM module WHERE name = 'entertainment')"/>
|
||||
<property name="gamesFeature" value="(SELECT id FROM feature WHERE key = 'games')"/>
|
||||
|
||||
<changeSet author="Sheldan" id="mines-commands">
|
||||
<insert tableName="command">
|
||||
<column name="name" value="mines"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${gamesFeature}"/>
|
||||
</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="games_feature-insertion">
|
||||
<insert tableName="feature">
|
||||
<column name="key" value="games"/>
|
||||
</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,19 @@
|
||||
<?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="entertainmentFeature" value="(SELECT id FROM feature WHERE key = 'entertainment')"/>
|
||||
|
||||
<changeSet author="Sheldan" id="mock_context_command">
|
||||
<insert tableName="context_command">
|
||||
<column name="name" value="mock"/>
|
||||
<column name="type" value="MESSAGE"/>
|
||||
<column name="feature_id" valueComputed="${entertainmentFeature}"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user