mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-06-17 07:36:11 +00:00
Compare commits
1 Commits
abstracto-
...
modelsplit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa8ff9ddb5 |
53
.github/workflows/build.yml
vendored
53
.github/workflows/build.yml
vendored
@@ -1,53 +0,0 @@
|
||||
# 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
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- feature/**
|
||||
- hotfix/**
|
||||
- bugfix/**
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- 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()
|
||||
env:
|
||||
JOB_STATUS: ${{ job.status }}
|
||||
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
|
||||
HOOK_OS_NAME: ${{ runner.os }}
|
||||
WORKFLOW_NAME: ${{ github.workflow }}
|
||||
run: |
|
||||
git clone https://github.com/DiscordHooks/github-actions-discord-webhook.git webhook
|
||||
bash webhook/send.sh $JOB_STATUS $WEBHOOK_URL
|
||||
shell: bash
|
||||
50
.github/workflows/release.yml
vendored
50
.github/workflows/release.yml
vendored
@@ -1,50 +0,0 @@
|
||||
name: Publish package to GitHub Packages and deploy documentation to GitHub pages
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Set up Java for publishing to GitHub Packages
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- name: Load current version
|
||||
id: version
|
||||
run: echo "version=$(mvn --file abstracto-application/pom.xml -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_ENV
|
||||
- name: Publish to GitHub Packages
|
||||
run: mvn --file abstracto-application/pom.xml -B deploy -P documentation,javadoc -Dmaven.wagon.http.pool=false -DskipTests=true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Deploy documentation to GitHub pages
|
||||
uses: JamesIves/github-pages-deploy-action@4.1.0
|
||||
with:
|
||||
repository-name: Sheldan/abstracto-docs
|
||||
target-folder: docs/${{ env.version }}
|
||||
branch: master
|
||||
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
|
||||
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
|
||||
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
|
||||
run: docker-compose build && docker-compose push
|
||||
env:
|
||||
REGISTRY_PREFIX: docker.pkg.github.com/sheldan/abstracto/
|
||||
VERSION: ${{ env.version }}
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -23,6 +23,3 @@ target/
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
|
||||
venv/
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Sheldan
|
||||
Copyright (c) 2019 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
|
||||
|
||||
38
README.md
38
README.md
@@ -1,38 +0,0 @@
|
||||
# Abstracto
|
||||
|
||||

|
||||
[](https://sonarcloud.io/dashboard?id=abstracto-core)
|
||||
[](https://sonarcloud.io/dashboard?id=abstracto-core)
|
||||
[](https://github.com/Sheldan/abstracto/blob/master/LICENSE)
|
||||
|
||||
|
||||
Abstracto represents a framework to be used as a basis for a Discord bot. It uses [JDA](https://github.com/DV8FromTheWorld/JDA/) as an API wrapper underneath
|
||||
and provides an extensive tool set to create new commands and a wide range of commands out of the box.
|
||||
|
||||
This repository does not provide the full functionality in order to start a discord bot, because it requires a Main class.
|
||||
An example implementation of this bot can be seen [here](https://github.com/Sheldan/Crimson). This repository contains the required configuration in order to run a bot and example customizations.
|
||||
|
||||
|
||||
## Technologies
|
||||
* [JDA](https://github.com/DV8FromTheWorld/JDA/) The Discord API Wrapper in the version 4.2.1_262
|
||||
* [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.
|
||||
* [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.
|
||||
|
||||
## License
|
||||
This project is licensed under the MIT license.
|
||||
@@ -1,49 +0,0 @@
|
||||
<?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>assignable-roles</artifactId>
|
||||
<version>1.2.10</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>assignable-roles-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>assignable-roles-int</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>metrics-int</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,18 +0,0 @@
|
||||
<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>
|
||||
@@ -1,61 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command used to activate an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
@Component
|
||||
public class ActivateAssignableRolePlace extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
service.activateAssignableRolePlace(server, name);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("activateAssignableRolePlace")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignableRoleAlreadyDefinedException;
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignableRoleNotUsableException;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.models.FullRole;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.RoleService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Command used to add an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole assignableRole}
|
||||
* to an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
@Component
|
||||
public class AddRoleToAssignableRolePost extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
FullEmote emote = (FullEmote) parameters.get(1);
|
||||
String description = (String) parameters.get(2);
|
||||
FullRole role = (FullRole) parameters.get(3);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
if(service.hasAssignableRolePlaceEmote(server, name, emote.getFakeEmote())) {
|
||||
throw new AssignableRoleAlreadyDefinedException(emote, name);
|
||||
}
|
||||
if(!roleService.canBotInteractWithRole(role.getRole())) {
|
||||
throw new AssignableRoleNotUsableException(role, commandContext.getGuild());
|
||||
}
|
||||
return service.addRoleToAssignableRolePlace(server, name, role.getRole(), emote, description)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
Parameter emote = Parameter.builder().name("emote").type(FullEmote.class).templated(true).build();
|
||||
Parameter description = Parameter.builder().name("description").type(String.class).templated(true).build();
|
||||
Parameter role = Parameter.builder().name("role").type(FullRole.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName, emote, description, role);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("addRoleToAssignableRolePlace")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleDefinition;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AssignableRoleModuleDefinition implements ModuleDefinition {
|
||||
public static final String ASSIGNABLE_ROLES = "assignableRole";
|
||||
|
||||
@Override
|
||||
public ModuleInfo getInfo() {
|
||||
return ModuleInfo.builder().name(ASSIGNABLE_ROLES).templated(true).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentModule() {
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRolePlaceParameterKey;
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Command used to change one attribute of an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ChangeAssignableRolePlaceConfig extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
AssignableRolePlaceParameterKey configKey = (AssignableRolePlaceParameterKey) parameters.get(1);
|
||||
Object parameterValue = parameters.get(2);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
return service.changeConfiguration(server, name, configKey, parameterValue)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter assignableRolePlaceName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
Parameter parameterKey = Parameter.builder().name("key").type(AssignableRolePlaceParameterKey.class).templated(true).build();
|
||||
Parameter parameterValue = Parameter.builder().name("value").type(Object.class).templated(true).build();
|
||||
|
||||
List<Parameter> parameters = Arrays.asList(assignableRolePlaceName, parameterKey, parameterValue);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("changeAssignableRolePlaceConfig")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.ParameterValidator;
|
||||
import dev.sheldan.abstracto.core.command.config.validator.MaxStringLengthValidator;
|
||||
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.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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CreateAssignableRolePost extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ChannelManagementService channelManagementService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
TextChannel channel = (TextChannel) parameters.get(1);
|
||||
String text = (String) parameters.get(2);
|
||||
AChannel chosenChannel = channelManagementService.loadChannel(channel.getIdLong());
|
||||
service.createAssignableRolePlace(name, chosenChannel, text);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<ParameterValidator> rolePlaceNameValidator = Arrays.asList(MaxStringLengthValidator.max(AssignableRolePlace.ASSIGNABLE_PLACE_NAME_LIMIT));
|
||||
Parameter rolePostName = Parameter.builder().name("name").validators(rolePlaceNameValidator).type(String.class).templated(true).build();
|
||||
Parameter channel = Parameter.builder().name("channel").type(TextChannel.class).templated(true).build();
|
||||
List<ParameterValidator> rolePlaceDescriptionValidator = Arrays.asList(MaxStringLengthValidator.max(AssignableRolePlace.ASSIGNABLE_PLACE_NAME_LIMIT));
|
||||
Parameter text = Parameter.builder().name("text").validators(rolePlaceDescriptionValidator).type(String.class).remainder(true).optional(true).templated(true).build();
|
||||
List<String> aliases = Arrays.asList("crRPl", "crAssRoPl");
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName, channel, text);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("createAssignableRolePlace")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.aliases(aliases)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command used to deactive an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
@Component
|
||||
public class DeactivateAssignableRolePlace extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
service.deactivateAssignableRolePlace(server, name);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("deactivateAssignableRolePlace")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Command used to delete an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
@Component
|
||||
public class DeleteAssignableRolePlace extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
return service.deleteAssignableRolePlace(server, name)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("deleteAssignableRolePlace")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.ParameterValidator;
|
||||
import dev.sheldan.abstracto.core.command.config.validator.MaxStringLengthValidator;
|
||||
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.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Command used to change the text of an {@link AssignableRolePlace place}
|
||||
*/
|
||||
@Component
|
||||
public class EditAssignableRolePlaceText extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
String newText = (String) parameters.get(1);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
return service.changeTextAsync(server, name, newText)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<ParameterValidator> rolePlaceNameValidator = Arrays.asList(MaxStringLengthValidator.max(AssignableRolePlace.ASSIGNABLE_PLACE_NAME_LIMIT));
|
||||
Parameter rolePostName = Parameter.builder().name("name").validators(rolePlaceNameValidator).type(String.class).templated(true).build();
|
||||
Parameter newText = Parameter.builder().name("newText").type(String.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName, newText);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("editAssignableRolePlaceText")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.service.management.ServerManagementService;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command used to move an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
* to another {@link dev.sheldan.abstracto.core.models.database.AChannel channel}
|
||||
*/
|
||||
@Component
|
||||
public class MoveAssignableRolePlace extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService placeManagementService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
TextChannel newChannel = (TextChannel) parameters.get(1);
|
||||
placeManagementService.moveAssignableRolePlace(name, newChannel);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@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();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName, channel);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("moveAssignableRolePlace")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Command used to remove a {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole role}
|
||||
* from an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
@Component
|
||||
public class RemoveRoleFromAssignableRolePlace extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
FullEmote emote = (FullEmote) parameters.get(1);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
return service.removeRoleFromAssignableRolePlace(server, name, emote)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
Parameter emote = Parameter.builder().name("emote").type(FullEmote.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName, emote);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("removeRoleFromAssignableRolePlace")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command used to set the position of one individual {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole assignableRole}
|
||||
* within an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
@Component
|
||||
public class SetAssignableRolePosition extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
FullEmote emote = (FullEmote) parameters.get(1);
|
||||
Integer newPosition = (Integer) parameters.get(2);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
service.setEmoteToPosition(server, name, emote, newPosition);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
Parameter emote = Parameter.builder().name("emote").type(FullEmote.class).templated(true).build();
|
||||
Parameter newPosition = Parameter.builder().name("newPosition").type(Integer.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName, emote, newPosition);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("setAssignableRolePosition")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Command used to render the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
* and create the {@link net.dv8tion.jda.api.entities.Message messages} used to add {@link net.dv8tion.jda.api.entities.MessageReaction reactions} to
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SetupAssignableRolePlace extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
return service.setupAssignableRolePlace(server, name)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("setupAssignableRolePlace")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Command used to show the configuration of an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
@Component
|
||||
public class ShowAssignableRolePlaceConfig extends AbstractConditionableCommand {
|
||||
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
// TODO refactor to return something to be posted in this command here instead of relying it to be posted somewhere else
|
||||
return service.showAssignablePlaceConfig(server, name, commandContext.getChannel())
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("showAssignableRolePlaceConfig")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.causesReaction(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Command used to show all {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace places}
|
||||
* within the current {@link AServer server}
|
||||
*/
|
||||
@Component
|
||||
public class ShowAssignableRolePlaces extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
return service.showAllAssignableRolePlaces(server, commandContext.getChannel())
|
||||
.thenApply(aVoid -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("showAssignableRolePlaces")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.exception.EmoteNotInAssignableRolePlaceException;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command used to swap the positions of two {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole roles}
|
||||
* within one {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
@Component
|
||||
public class SwapAssignableRolePosition extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private EmoteService emoteService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
FullEmote firstEmote = (FullEmote) parameters.get(1);
|
||||
FullEmote secondEmote = (FullEmote) parameters.get(2);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
if(emoteService.compareAEmote(firstEmote.getFakeEmote(), secondEmote.getFakeEmote())) {
|
||||
return CommandResult.fromError("You cannot swap the same emote");
|
||||
}
|
||||
if(!service.hasAssignableRolePlaceEmote(server, name, firstEmote.getFakeEmote())) {
|
||||
throw new EmoteNotInAssignableRolePlaceException(firstEmote, name);
|
||||
}
|
||||
if(!service.hasAssignableRolePlaceEmote(server, name, firstEmote.getFakeEmote())) {
|
||||
throw new EmoteNotInAssignableRolePlaceException(secondEmote, name);
|
||||
}
|
||||
service.swapPositions(server, name, firstEmote, secondEmote);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
Parameter firstEmote = Parameter.builder().name("firstEmote").type(FullEmote.class).templated(true).build();
|
||||
Parameter secondEmote = Parameter.builder().name("secondEmote").type(FullEmote.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName, firstEmote, secondEmote);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("swapAssignableRolePosition")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.command;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
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.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Command used to show how an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
* would look like in the current {@link net.dv8tion.jda.api.entities.TextChannel channel}
|
||||
*/
|
||||
@Component
|
||||
public class TestAssignableRolePlace extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService service;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
String name = (String) parameters.get(0);
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
return service.testAssignableRolePlace(server, name, commandContext.getChannel())
|
||||
.thenApply(aVoid -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter rolePostName = Parameter.builder().name("name").type(String.class).templated(true).build();
|
||||
List<Parameter> parameters = Arrays.asList(rolePostName);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("testAssignableRolePlace")
|
||||
.module(AssignableRoleModuleDefinition.ASSIGNABLE_ROLES)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:assignableRoles-config.properties")
|
||||
public class AssignableRolesConfig {
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.listener;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost;
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.AssignableRolePlacePostManagementService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncMessageDeletedListener;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.models.listener.MessageDeletedModel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AssignablePostDeletedListener implements AsyncMessageDeletedListener {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlacePostManagementService service;
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method deletes one individual {@link AssignableRolePlacePost post}, because its message has been deleted
|
||||
* @param model The {@link MessageDeletedModel message} containing the {@link CachedMessage cachedMessage} which was deleted
|
||||
*/
|
||||
@Override
|
||||
public DefaultListenerResult execute(MessageDeletedModel model) {
|
||||
Optional<AssignableRolePlacePost> messageOptional = service.findByMessageIdOptional(model.getCachedMessage().getMessageId());
|
||||
messageOptional.ifPresent(post -> {
|
||||
AssignableRolePlace assignablePlace = post.getAssignablePlace();
|
||||
log.info("Post {} has been deleted in server {} in channel {}, we are removing a post from place {}.",
|
||||
post.getId(), model.getServerId(), model.getCachedMessage().getChannelId(), assignablePlace.getKey());
|
||||
post.getAssignableRoles().forEach(assignableRole -> assignableRole.setAssignableRolePlacePost(null));
|
||||
assignablePlace.getMessagePosts().remove(post);
|
||||
});
|
||||
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
}
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.listener;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRole;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRolePlaceService;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRoleServiceBean;
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.AssignableRoleManagementService;
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.AssignableRolePlaceManagementService;
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.AssignableRolePlacePostManagementService;
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.AssignedRoleUserManagementService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncReactionAddedListener;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedReaction;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.listener.ReactionAddedModel;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.ReactionService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.MessageReaction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AssignablePostReactionAdded implements AsyncReactionAddedListener {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlacePostManagementService service;
|
||||
|
||||
@Autowired
|
||||
private AssignableRoleServiceBean assignableRoleServiceBean;
|
||||
|
||||
@Autowired
|
||||
private EmoteService emoteService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceService assignableRolePlaceService;
|
||||
|
||||
@Autowired
|
||||
private AssignedRoleUserManagementService assignedRoleUserManagementService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceManagementService assignableRolePlaceManagementService;
|
||||
|
||||
@Autowired
|
||||
private AssignablePostReactionAdded self;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRoleManagementService assignableRoleManagementService;
|
||||
|
||||
@Autowired
|
||||
private ReactionService reactionService;
|
||||
|
||||
@Autowired
|
||||
private MemberService memberService;
|
||||
|
||||
/**
|
||||
* Iterates over all {@link AssignableRole assignableRoles} of the post and checks which {@link AssignableRole assignableRole}
|
||||
* is identified by the added {@link MessageReaction reaction}. If there is no valid reaction, the {@link net.dv8tion.jda.api.entities.MessageReaction reaction}
|
||||
* will be removed again. In case the {@link AssignableRolePlace place} is configured to have unique roles, this will remove the existing
|
||||
* {@link net.dv8tion.jda.api.entities.MessageReaction reaction} and the assigned {@link net.dv8tion.jda.api.entities.Role role}.
|
||||
* Afterwards the appropriate {@link net.dv8tion.jda.api.entities.Role role} will be added and the update
|
||||
* will be stored in the database.
|
||||
* @param assignablePlacePost The {@link AssignableRolePlacePost post} onto which the {@link MessageReaction reaction} was added to
|
||||
* @param model The {@link ReactionAddedModel model} containing information about who added which reaction where
|
||||
*/
|
||||
private void addAppropriateRoles(AssignableRolePlacePost assignablePlacePost, ReactionAddedModel model) {
|
||||
boolean validReaction = false;
|
||||
AssignableRolePlace assignableRolePlace = assignablePlacePost.getAssignablePlace();
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
for (AssignableRole assignableRole : assignablePlacePost.getAssignableRoles()) {
|
||||
log.debug("Checking emote {} if it was reaction for assignable role place.", assignableRole.getEmote().getId());
|
||||
if (emoteService.isReactionEmoteAEmote(model.getReaction().getReactionEmote(), assignableRole.getEmote())) {
|
||||
if(assignableRolePlace.getUniqueRoles()) {
|
||||
log.debug("Assignable role place {} has unique roles configured. Removing existing reactions and roles.", assignableRolePlace.getId());
|
||||
Optional<AssignedRoleUser> byUserInServer = assignedRoleUserManagementService.findByUserInServerOptional(model.getUserReacting());
|
||||
byUserInServer.ifPresent(user -> futures.add(assignableRolePlaceService.removeExistingReactionsAndRoles(assignableRolePlace, user)));
|
||||
}
|
||||
|
||||
Long assignableRoleId = assignableRole.getId();
|
||||
log.info("User added {} reaction {} and gets assignable role {} in server {}.", model.getUserReacting().getUserId(), assignableRole.getEmote().getId(), assignableRoleId, model.getServerId());
|
||||
CompletableFuture<Void> roleAdditionFuture = assignableRoleServiceBean.assignAssignableRoleToUser(assignableRoleId, model.getUserReacting());
|
||||
|
||||
futures.add(CompletableFuture.allOf(roleAdditionFuture));
|
||||
validReaction = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!validReaction) {
|
||||
log.debug("Reaction was not found in the configuration of assignable role place {}, removing reaction.", assignableRolePlace.getId());
|
||||
futures.add(reactionService.removeReactionFromMessage(model.getReaction(), model.getMessage(), model.getMemberReacting().getUser()));
|
||||
}
|
||||
Long assignableRolePlaceId = assignableRolePlace.getId();
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(aVoid ->
|
||||
self.updateStoredAssignableRoles(assignableRolePlaceId, model.getUserReacting(), model.getReaction())
|
||||
).exceptionally(throwable -> {
|
||||
log.error("Failed to add role or remove emote for assignable role place {}.", assignableRolePlaceId, throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists the {@link AssignableRole role} changes for the user who added a reaction in the database
|
||||
* @param assignableRolePlaceId The ID of the {@link AssignableRolePlace place}
|
||||
* @param serverUser The {@link ServerUser serverUser} who added the {@link net.dv8tion.jda.api.entities.MessageReaction reaction}
|
||||
* @param reaction The {@link CachedReaction reaction} wich was added
|
||||
*/
|
||||
@Transactional
|
||||
public void updateStoredAssignableRoles(Long assignableRolePlaceId, ServerUser serverUser, MessageReaction reaction) {
|
||||
AssignableRolePlace place = assignableRolePlaceManagementService.findByPlaceId(assignableRolePlaceId);
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadOrCreateUser(serverUser);
|
||||
if(place.getUniqueRoles()) {
|
||||
log.debug("Assignable role place {} has unique roles. Deleting all existing references.", assignableRolePlaceId);
|
||||
assignableRoleServiceBean.clearAllRolesOfUserInPlace(place, userInAServer);
|
||||
}
|
||||
AssignableRole role = assignableRoleManagementService.getRoleForReactionEmote(reaction.getReactionEmote(), place);
|
||||
log.info("Adding role to assignable role {} to user {} in server {}.", role.getId(), userInAServer.getUserReference().getId(), userInAServer.getServerReference().getId());
|
||||
assignableRoleServiceBean.addRoleToUser(role.getId(), userInAServer);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the {@link net.dv8tion.jda.api.entities.Message message} a reaction was added to, belongs to a
|
||||
* {@link AssignableRolePlacePost post}.
|
||||
* If the {@link AssignableRolePlacePost post} belong to an inactive {@link AssignableRolePlace place} this method
|
||||
* will automatically remove the reaction, self reactions are ignored. Otherwise the logic according to the configuration
|
||||
* of the {@link AssignableRolePlace place} will be executed.
|
||||
* @param model The {@link ReactionAddedModel message} which contains information about the added reaction
|
||||
*/
|
||||
@Override
|
||||
public DefaultListenerResult execute(ReactionAddedModel model) {
|
||||
MessageReaction reaction = model.getReaction();
|
||||
Optional<AssignableRolePlacePost> messageOptional = service.findByMessageIdOptional(model.getMessage().getMessageId());
|
||||
if(messageOptional.isPresent()) {
|
||||
AssignableRolePlacePost assignablePlacePost = messageOptional.get();
|
||||
if(reaction.isSelf()) {
|
||||
log.info("Ignoring self reaction on assignable role post in server {}.", model.getServerId());
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
Long assignableRolePlacePostId = assignablePlacePost.getId();
|
||||
if(assignablePlacePost.getAssignablePlace().getActive()) {
|
||||
log.info("User {} added reaction to assignable role place {} in server {}. Handling added event.", model.getUserReacting().getUserId(), assignablePlacePost.getId(), model.getServerId());
|
||||
addAppropriateRoles(assignablePlacePost, model);
|
||||
} else {
|
||||
reactionService.removeReactionFromMessage(model.getReaction(), model.getMessage()).exceptionally(throwable -> {
|
||||
log.error("Failed to remove reaction on place post {} because place is inactive.", assignableRolePlacePostId, throwable);
|
||||
return null;
|
||||
});
|
||||
log.debug("Reaction for assignable place {} in sever {} was added, but place is inactive.", assignablePlacePost.getAssignablePlace().getKey(), model.getServerId());
|
||||
}
|
||||
}
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.listener;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRoleFeatureDefinition;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost;
|
||||
import dev.sheldan.abstracto.assignableroles.service.AssignableRoleService;
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.AssignableRolePlacePostManagementService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncReactionRemovedListener;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.models.listener.ReactionRemovedModel;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import dev.sheldan.abstracto.core.service.RoleService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AssignablePostReactionRemoved implements AsyncReactionRemovedListener {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlacePostManagementService service;
|
||||
|
||||
@Autowired
|
||||
private EmoteService emoteService;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRoleService assignableRoleService;
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the {@link net.dv8tion.jda.api.entities.Message message} a reaction was removed from, belongs to a
|
||||
* {@link AssignableRolePlacePost post}.
|
||||
* If the {@link AssignableRolePlacePost post} belong to an inactive {@link AssignableRolePlace place} this method ignores the removal.
|
||||
* Otherwise the logic according to the configuration
|
||||
* of the {@link AssignableRolePlace place} will be executed.
|
||||
* @param model The {@link ReactionRemovedModel model} containing the information which reaction was placed where
|
||||
*/
|
||||
@Override
|
||||
public DefaultListenerResult execute(ReactionRemovedModel model) {
|
||||
CachedMessage message = model.getMessage();
|
||||
|
||||
Optional<AssignableRolePlacePost> messageOptional = service.findByMessageIdOptional(message.getMessageId());
|
||||
if(messageOptional.isPresent()) {
|
||||
AssignableRolePlacePost assignablePlacePost = messageOptional.get();
|
||||
if(assignablePlacePost.getAssignablePlace().getActive()) {
|
||||
assignablePlacePost.getAssignableRoles().forEach(assignableRole -> {
|
||||
if(emoteService.isReactionEmoteAEmote(model.getReaction().getReactionEmote(), assignableRole.getEmote())) {
|
||||
Long assignableRoleId = assignableRole.getId();
|
||||
log.info("Removing assignable role {} for user {} in server {} from assignable role place {}.", assignableRoleId,
|
||||
model.getUserRemoving().getUserId(), model.getServerId(), assignablePlacePost.getAssignablePlace().getId());
|
||||
assignableRoleService.fullyRemoveAssignableRoleFromUser(assignableRole, model.getUserRemoving()).exceptionally(throwable -> {
|
||||
log.error("Failed to remove assignable role {} from user {} in server {}.", assignableRoleId, model.getUserRemoving().getUserId(), model.getServerId(), throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
});
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
} else {
|
||||
log.debug("Reaction for assignable place {} in sever {} was added, but place is inactive.", assignablePlacePost.getAssignablePlace().getKey(), model.getServerId());
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
}
|
||||
} else {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.repository;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Repository to manage the access to the table managed by {@link AssignableRolePlacePost posts}
|
||||
*/
|
||||
@Repository
|
||||
public interface AssignableRolePlacePostRepository extends JpaRepository<AssignableRolePlacePost, Long> {
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.repository;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Repository to manage the access to the table managed by {@link AssignableRolePlace place}
|
||||
*/
|
||||
@Repository
|
||||
public interface AssignableRolePlaceRepository extends JpaRepository<AssignableRolePlace, Long> {
|
||||
|
||||
/**
|
||||
* Whether or not an {@link AssignableRolePlace place} exists in a {@link AServer server} with the given key
|
||||
* @param server The {@link AServer server} to search in
|
||||
* @param key The key to search for
|
||||
* @return Whether or not a {@link AssignableRolePlace place} exists in the {@link AServer server} with the key
|
||||
*/
|
||||
boolean existsByServerAndKey(AServer server, String key);
|
||||
|
||||
/**
|
||||
* Finds an {@link AssignableRolePlace place} in a {@link AServer server} with the given key,
|
||||
* returns an empty {@link Optional optional} otherwise
|
||||
* @param server The {@link AServer server} to search in
|
||||
* @param key The key to search for
|
||||
* @return An {@link Optional optional} containing the {@link AssignableRolePlace place} if it exists, empty otherwise.
|
||||
*/
|
||||
Optional<AssignableRolePlace> findByServerAndKey(AServer server, String key);
|
||||
|
||||
/**
|
||||
* Finds all {@link AssignableRolePlace places} in the given {@link AServer server}
|
||||
* @param server The {@link AServer server} to retrieve {@link AssignableRolePlace places} for
|
||||
* @return A list of {@link AssignableRolePlace places} which were found in the given {@link AServer server}
|
||||
*/
|
||||
List<AssignableRolePlace> findByServer(AServer server);
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.repository;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRole;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Repository to manage the access to the table managed by {@link AssignableRole assignableRole}
|
||||
*/
|
||||
@Repository
|
||||
public interface AssignableRoleRepository extends JpaRepository<AssignableRole, Long> {
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.repository;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Repository to manage the access to the table managed by {@link AssignedRoleUser assignedRoleUser}
|
||||
*/
|
||||
@Repository
|
||||
public interface AssignedRoleUserRepository extends JpaRepository<AssignedRoleUser, Long> {
|
||||
}
|
||||
@@ -1,956 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRolePlaceParameterKey;
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlaceAlreadyExistsException;
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlaceChannelDoesNotExistException;
|
||||
import dev.sheldan.abstracto.assignableroles.exception.EmoteNotInAssignableRolePlaceException;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRole;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser;
|
||||
import dev.sheldan.abstracto.assignableroles.model.template.*;
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.*;
|
||||
import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException;
|
||||
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.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.*;
|
||||
import dev.sheldan.abstracto.core.service.management.*;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
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 org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AssignableRolePlaceServiceBean implements AssignableRolePlaceService {
|
||||
|
||||
public static final String ASSIGNABLE_ROLES_CONFIG_POST_TEMPLATE_KEY = "assignable_roles_config_post";
|
||||
public static final String ASSIGNABLE_ROLES_POST_TEMPLATE_KEY = "assignable_roles_post";
|
||||
public static final String ASSIGNABLE_ROLE_PLACES_OVERVIEW_TEMPLATE_KEY = "assignable_role_places_overview";
|
||||
@Autowired
|
||||
private AssignableRolePlaceManagementService rolePlaceManagementService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRoleManagementService assignableRoleManagementServiceBean;
|
||||
|
||||
@Autowired
|
||||
private ReactionService reactionService;
|
||||
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Autowired
|
||||
private GuildService guildService;
|
||||
|
||||
@Autowired
|
||||
private EmoteService emoteService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceServiceBean self;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private EmoteManagementService emoteManagementService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlacePostManagementService postManagementService;
|
||||
|
||||
@Autowired
|
||||
private ChannelManagementService channelManagementService;
|
||||
|
||||
@Autowired
|
||||
private RoleManagementService roleManagementService;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlacePostManagementServiceBean assignableRolePlacePostManagementServiceBean;
|
||||
|
||||
@Override
|
||||
public void createAssignableRolePlace(String name, AChannel channel, String text) {
|
||||
if(rolePlaceManagementService.doesPlaceExist(channel.getServer(), name)) {
|
||||
throw new AssignableRolePlaceAlreadyExistsException(name);
|
||||
}
|
||||
rolePlaceManagementService.createPlace(name, channel, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAssignableRolePlaceEmote(AServer server, String placeName, AEmote emote) {
|
||||
AssignableRolePlace assignableRolePlace = rolePlaceManagementService.findByServerAndKey(server, placeName);
|
||||
return hasAssignableRolePlaceEmote(assignableRolePlace, emote);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPositionUsed(AServer server, String placeName, Integer position) {
|
||||
AssignableRolePlace assignableRolePlace = rolePlaceManagementService.findByServerAndKey(server, placeName);
|
||||
return assignableRolePlace.getAssignableRoles().stream().anyMatch(role -> role.getPosition().equals(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEmoteToPosition(AServer server, String placeName, FullEmote emote, Integer position) {
|
||||
if(isPositionUsed(server, placeName, position)) {
|
||||
throw new AbstractoTemplatedException("Position is already used", "assignable_role_place_position_exists_exception");
|
||||
}
|
||||
if(!hasAssignableRolePlaceEmote(server, placeName, emote.getFakeEmote())) {
|
||||
throw new AbstractoTemplatedException("Place does not have emote assigned.", "assignable_role_place_position_exists_exception");
|
||||
}
|
||||
AssignableRolePlace assignableRolePlace = rolePlaceManagementService.findByServerAndKey(server, placeName);
|
||||
log.info("Setting emote to position {} in assignable role place {} in server {}.",
|
||||
position, assignableRolePlace.getId(), assignableRolePlace.getServer().getId());
|
||||
Optional<AssignableRole> emoteOptional = assignableRolePlace.getAssignableRoles().stream().filter(role -> emoteService.compareAEmote(emote.getFakeEmote(), role.getEmote())).findFirst();
|
||||
if(emoteOptional.isPresent()) {
|
||||
AssignableRole toChange = emoteOptional.get();
|
||||
toChange.setPosition(position);
|
||||
} else {
|
||||
throw new EmoteNotInAssignableRolePlaceException(emote, placeName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAssignableRolePlaceEmote(AssignableRolePlace place, AEmote emote) {
|
||||
for (AssignableRole assignableRole : place.getAssignableRoles()) {
|
||||
if(emoteService.compareAEmote(assignableRole.getEmote(), emote)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> addRoleToAssignableRolePlace(AServer server, String placeName, ARole role, FullEmote fakeEmote, String description) {
|
||||
AssignableRolePlace assignableRolePlace = rolePlaceManagementService.findByServerAndKey(server, placeName);
|
||||
Long placeId = assignableRolePlace.getId();
|
||||
Long roleId = role.getId();
|
||||
Long serverId = server.getId();
|
||||
boolean emoteUsable = true;
|
||||
if(fakeEmote.getEmote() != null) {
|
||||
// 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(), roleId, placeId, serverId);
|
||||
emoteUsable = emoteService.isEmoteUsableByBot(fakeEmote.getEmote()) && fakeEmote.getEmote().isAvailable();
|
||||
}
|
||||
if(emoteUsable) {
|
||||
List<AssignableRolePlacePost> existingMessagePosts = assignableRolePlace.getMessagePosts();
|
||||
existingMessagePosts.sort(Comparator.comparingLong(AssignableRolePlacePost::getId));
|
||||
|
||||
if(!assignableRolePlace.getMessagePosts().isEmpty()){
|
||||
log.debug("There are already message posts on for the assignable role place {}.", assignableRolePlace.getId());
|
||||
AssignableRolePlacePost latestPost = existingMessagePosts.get(assignableRolePlace.getMessagePosts().size() - 1);
|
||||
AssignablePostMessage model = prepareAssignablePostMessageModel(assignableRolePlace);
|
||||
boolean forceNewMessage = latestPost.getAssignableRoles().size() >= 20;
|
||||
log.info("We need to add a new message post {} for assignable role place {} in server {} in channel {}.",
|
||||
forceNewMessage, placeId, serverId, assignableRolePlace.getChannel().getId());
|
||||
AssignablePostRole newAssignableRole = AssignablePostRole
|
||||
.builder()
|
||||
.description(description)
|
||||
.emote(fakeEmote)
|
||||
.forceNewMessage(forceNewMessage)
|
||||
.build();
|
||||
model.getRoles().add(newAssignableRole);
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(ASSIGNABLE_ROLES_POST_TEMPLATE_KEY, model, server.getId());
|
||||
// add it to the last currently existing post
|
||||
Optional<TextChannel> channelOptional = channelService.getTextChannelFromServerOptional(server.getId(), latestPost.getUsedChannel().getId());
|
||||
if(channelOptional.isPresent()) {
|
||||
TextChannel textChannel = channelOptional.get();
|
||||
if(latestPost.getAssignableRoles().size() < 20) {
|
||||
log.debug("Adding reaction to existing post {} in channel {} in server {} for assignable role place {}.",
|
||||
latestPost.getId(), assignableRolePlace.getChannel().getId(), serverId, placeId);
|
||||
return addReactionToExistingAssignableRolePlacePost(fakeEmote, description, roleId, latestPost, messageToSend, textChannel);
|
||||
} else {
|
||||
log.debug("Adding new post to assignable role place {} in channel {} in server {}.",
|
||||
placeId, assignableRolePlace.getChannel().getId(), server.getId());
|
||||
return addNewMessageToAssignableRolePlace(placeId, fakeEmote, description, roleId, messageToSend, textChannel);
|
||||
}
|
||||
} else {
|
||||
throw new ChannelNotInGuildException(latestPost.getUsedChannel().getId());
|
||||
}
|
||||
} else {
|
||||
log.debug("Added emote to assignable place {} in server {}, but no message post yet.", placeId, serverId);
|
||||
self.addAssignableRoleInstanceWithoutPost(placeId, roleId, fakeEmote, description, serverId);
|
||||
}
|
||||
} else {
|
||||
throw new EmoteNotUsableException(fakeEmote.getEmote());
|
||||
}
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the reaction from {@link FullEmote} to the last {@link AssignableRolePlacePost post} of its {@link AssignableRolePlace place}.
|
||||
* It will also update the message representing the last {@link AssignableRolePlacePost post} with the given {@link MessageToSend messageToSend}
|
||||
* in the given {@link TextChannel channel}. Afterwards the added {@link AssignableRole assignableRole} will be persisted in the database
|
||||
* @param fakeEmote The *fake* {@link FullEmote emote} which represents the reaction which should be added and identifies the {@link AssignableRole role}
|
||||
* @param description The description the {@link AssignableRole role} should have
|
||||
* @param roleId The ID of the {@link ARole role} which should be given when a reaction is added by a {@link Member member}
|
||||
* @param latestPost The last {@link AssignableRolePlacePost post} in the list of posts
|
||||
* @param messageToSend The {@link MessageToSend messageToSend} which should be used to update the latest {@link AssignableRolePlacePost post} with. This
|
||||
* will be done in place.
|
||||
* @param textChannel The {@link TextChannel channel} in which the {@link AssignableRolePlacePost post} is
|
||||
* @return A {@link CompletableFuture future} which will complete when the reaction was added, the message was edited and the database has been updated
|
||||
*/
|
||||
private CompletableFuture<Void> addReactionToExistingAssignableRolePlacePost(FullEmote fakeEmote, String description, Long roleId, AssignableRolePlacePost latestPost, MessageToSend messageToSend, TextChannel textChannel) {
|
||||
// TODO maybe refactor to use the same message object, so we dont need to retrieve it twice and do in parallel
|
||||
Long serverId = latestPost.getAssignablePlace().getServer().getId();
|
||||
Long placeId = latestPost.getAssignablePlace().getId();
|
||||
Long latestPostId = latestPost.getId();
|
||||
int messagePostSize = latestPost.getAssignablePlace().getMessagePosts().size();
|
||||
return channelService.retrieveMessageInChannel(textChannel, latestPostId)
|
||||
.thenCompose(message -> {
|
||||
log.debug("Adding reaction to message {} in server {} for assignable role place {}.", message.getId(), serverId, placeId);
|
||||
return reactionService.addReactionToMessageAsync(fakeEmote.getFakeEmote(), serverId, message);
|
||||
}).thenCompose(aVoid -> {
|
||||
log.debug("Editing embed for assignable role place post {} in assignable role place {} in server {}.", latestPostId, placeId, serverId);
|
||||
MessageEmbed embedToUse = messageToSend.getEmbeds().get(messagePostSize - 1);
|
||||
return channelService.editEmbedMessageInAChannel(embedToUse, textChannel, latestPostId);
|
||||
}).thenAccept(message ->
|
||||
self.addAssignableRoleInstanceWithPost(message.getIdLong(), placeId, roleId, description, fakeEmote, serverId)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a new {@link Message message}, defined by the given {@link MessageToSend messageToSend}, to the channel the {@link AssignableRolePlace place}
|
||||
* is configured for, adds a reaction and stores the update in the database.
|
||||
* @param placeId The ID of the {@link AssignableRolePlace place} to add a post to
|
||||
* @param fakeEmote The *fake* {@link FullEmote emote} which represents the reaction which should be added and identifies the {@link AssignableRole role}
|
||||
* @param description The description the {@link AssignableRole role} should have
|
||||
* @param roleId The ID of the {@link ARole role} which should be given when a reaction is added by a {@link Member member}
|
||||
* @param messageToSend The {@link MessageToSend messageToSend} which should be used to create the new {@link AssignableRolePlacePost post}
|
||||
* @param textChannel The The {@link TextChannel channel} in which the {@link AssignableRolePlacePost post} should be in
|
||||
* @return A {@link CompletableFuture future} which competes when the {@link MessageToSend messageToSend} has been sent, a {@link MessageReaction reaction}
|
||||
* has been added and the changes have been persisted in the database.
|
||||
*/
|
||||
private CompletableFuture<Void> addNewMessageToAssignableRolePlace(Long placeId, FullEmote fakeEmote, String description, Long roleId, MessageToSend messageToSend, TextChannel textChannel) {
|
||||
MessageEmbed embedToUse = messageToSend.getEmbeds().get(messageToSend.getEmbeds().size() - 1);
|
||||
Long serverId = textChannel.getGuild().getIdLong();
|
||||
return channelService.sendEmbedToChannel(embedToUse, textChannel)
|
||||
.thenCompose(message -> {
|
||||
log.debug("Adding reaction for role {} to newly created message {} for assignable role place {} in server {}.", roleId, message.getId(), placeId, serverId);
|
||||
return reactionService.addReactionToMessageAsync(fakeEmote.getFakeEmote(), serverId, message)
|
||||
.thenAccept(aVoid ->
|
||||
self.addNewlyCreatedAssignablePlacePost(placeId, description, roleId, message, fakeEmote)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Persisted the newly created {@link AssignableRolePlacePost post} and adds a {@link AssignableRole assignableRolePlace} to this
|
||||
* @param placeId The ID of the {@link AssignableRolePlace place} to add a post to
|
||||
* @param description The description the {@link AssignableRole role} should have
|
||||
* @param roleId The ID of the {@link ARole role} which should be given when a reaction is added by a {@link Member member}
|
||||
* @param message The {@link Message message} which was created when sending the {@link MessageToSend messageToSend} representing this
|
||||
* {@link AssignableRolePlacePost post}
|
||||
* @param fakeEmote The *fake* {@link FullEmote emote} which is used to identify the {@link AssignableRole role}
|
||||
*/
|
||||
@Transactional
|
||||
public void addNewlyCreatedAssignablePlacePost(Long placeId, String description, Long roleId, Message message, FullEmote fakeEmote) {
|
||||
Long serverId = message.getGuild().getIdLong();
|
||||
log.info("Storing newly created assignable role place post {} for place {} in server {}.", message.getId(), placeId, serverId);
|
||||
ARole role = roleManagementService.findRole(roleId);
|
||||
AssignableRolePlace loadedPlace = rolePlaceManagementService.findByPlaceId(placeId);
|
||||
AEmote emote = emoteManagementService.createEmote(null, fakeEmote.getFakeEmote(), serverId, false);
|
||||
emote.setChangeable(false);
|
||||
log.debug("Setting emote {} to not changeable, because it is part of an assignable role place {} in server {}.", emote.getId(), placeId, serverId);
|
||||
|
||||
AssignableRolePlacePost newPost = assignableRolePlacePostManagementServiceBean.createAssignableRolePlacePost(loadedPlace, message.getIdLong());
|
||||
assignableRoleManagementServiceBean.addRoleToPlace(loadedPlace, emote, role, description, newPost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually creates the {@link AEmote emote} defined by the given {@link FullEmote emote} and adds a new instance
|
||||
* of an {@link AssignableRole assignableRole} to the {@link AssignableRolePlace place}. This is used in case
|
||||
* there already exists an {@link AssignableRolePlacePost post}
|
||||
* @param messageId The ID of the {@link Message message} which identifies the {@link AssignableRolePlacePost post}
|
||||
* at which this {@link AssignableRole role} is available via a {@link MessageReaction reaction}
|
||||
* @param placeId The ID of the {@link AssignableRolePlace place} to add the {@link AssignableRole assignableRole} to
|
||||
* @param roleId The ID of the {@link ARole role} which should be given when a reaction is added by a {@link Member member}
|
||||
* @param description The description the {@link AssignableRole role} should have
|
||||
* @param fakeEmote The *fake* {@link FullEmote emote} which is used to identify the {@link AssignableRole role}
|
||||
* @param serverId The ID of the {@link AServer server} this should be persisted for
|
||||
*/
|
||||
@Transactional
|
||||
public void addAssignableRoleInstanceWithPost(Long messageId, Long placeId, Long roleId, String description, FullEmote fakeEmote, Long serverId) {
|
||||
log.info("Storing newly created assignable role {} to post {} to assignable role place {} in server {}.", roleId, messageId, placeId, serverId);
|
||||
AEmote emote = emoteManagementService.createEmote(null, fakeEmote.getFakeEmote(), serverId, false);
|
||||
emote.setChangeable(false);
|
||||
log.debug("Setting emote {} to not changeable, because it is part of an assignable role place {} in server {}.", emote.getId(), placeId, serverId);
|
||||
assignableRoleManagementServiceBean.addRoleToPlace(placeId, emote.getId(), roleId, description, messageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually creates the {@link AEmote emote} defined by the given {@link FullEmote emote} and adds a new instance
|
||||
* of an {@link AssignableRole assignableRole} to the {@link AssignableRolePlace place}. This is used in case
|
||||
* there doesnt exists an {@link AssignableRolePlacePost post}
|
||||
* @param placeId The ID of the {@link AssignableRolePlace place} to add the {@link AssignableRole assignableRole} to
|
||||
* @param roleId The ID of the {@link ARole role} which should be given when a reaction is added by a {@link Member member}
|
||||
* @param description The description the {@link AssignableRole role} should have
|
||||
* @param fakeEmote The *fake* {@link FullEmote emote} which is used to identify the {@link AssignableRole role}
|
||||
* @param serverId The ID of the {@link AServer server} this should be persisted for
|
||||
*/
|
||||
@Transactional
|
||||
public void addAssignableRoleInstanceWithoutPost(Long placeId, Long roleId, FullEmote fakeEmote, String description, Long serverId) {
|
||||
log.info("Storing newly created assignable role {} without post to assignable role place {} in server {}.", roleId, placeId, serverId);
|
||||
AEmote emote = emoteManagementService.createEmote(null, fakeEmote.getFakeEmote(), serverId, false);
|
||||
emote.setChangeable(false);
|
||||
log.debug("Setting emote {} to not changeable, because it is part of an assignable role place {} in server {}.", emote.getId(), placeId, serverId);
|
||||
assignableRoleManagementServiceBean.addRoleToPlace(placeId, emote.getId(), roleId, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeRoleFromAssignableRolePlace(AServer server, String placeName, FullEmote emote) {
|
||||
AssignableRolePlace assignableRolePlace = rolePlaceManagementService.findByServerAndKey(server, placeName);
|
||||
Long assignableRolePlaceId = assignableRolePlace.getId();
|
||||
for (AssignableRole assignableRole : assignableRolePlace.getAssignableRoles()) {
|
||||
if(emoteService.compareAEmote(assignableRole.getEmote(), emote.getFakeEmote())) {
|
||||
log.info("Removing assignable role {} identified by emote {} from assignable role place {} in server {}.",
|
||||
assignableRole.getId(), assignableRole.getEmote().getId(), assignableRolePlace.getId(), assignableRolePlace.getServer().getId());
|
||||
return removeRoleFromAssignablePlace(assignableRole, assignableRolePlace).thenAccept(aVoid ->
|
||||
self.deleteAssignableRoleFromPlace(assignableRolePlaceId, assignableRole.getId())
|
||||
);
|
||||
}
|
||||
}
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method deletes the {@link AssignableRole assignableRole} from the given {@link AssignableRolePlace place}
|
||||
* in the database
|
||||
* @param placeId The ID of the {@link AssignableRolePlace place} to remove the {@link AssignableRole assignableRole} from
|
||||
* @param assignableRoleId The ID of the {@link AssignableRole assignableRole} to remove from the {@link AssignableRolePlace place}
|
||||
*/
|
||||
@Transactional
|
||||
public void deleteAssignableRoleFromPlace(Long placeId, Long assignableRoleId) {
|
||||
AssignableRolePlace assignableRolePlace = rolePlaceManagementService.findByPlaceId(placeId);
|
||||
log.info("Deleting the entry for assignable role {} in assignable role place {}.", assignableRoleId, placeId);
|
||||
Optional<AssignableRole> roleToRemoveOptional = assignableRolePlace.getAssignableRoles().stream().filter(role -> role.getId().equals(assignableRoleId)).findAny();
|
||||
roleToRemoveOptional.ifPresent(assignableRole -> {
|
||||
assignableRolePlace.getAssignableRoles().remove(assignableRole);
|
||||
assignableRole.getAssignedUsers().forEach(assignedRoleUser -> assignedRoleUser.getRoles().remove(assignableRole));
|
||||
assignableRole.getAssignedUsers().clear();
|
||||
assignableRole.setAssignablePlace(null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The removes the {@link AssignableRole assignableRole} from the given {@link AssignableRolePlace place}. If
|
||||
* there already is a {@link AssignableRolePlacePost post}, this removes the field from the post
|
||||
* and also clears all {@link MessageReaction reactions}
|
||||
* @param assignableRole The {@link AssignableRole role} to remove
|
||||
* @param assignableRolePlace The {@link AssignableRolePlace place} to remove the role from
|
||||
* @return A {@link CompletableFuture future} which completes when the message was updated and the reaction was removed, if
|
||||
* no post was present it completes immediately.
|
||||
*/
|
||||
private CompletableFuture<Void> removeRoleFromAssignablePlace(AssignableRole assignableRole, AssignableRolePlace assignableRolePlace) {
|
||||
AssignableRolePlacePost post = assignableRole.getAssignableRolePlacePost();
|
||||
if(post != null) {
|
||||
AServer server = assignableRolePlace.getServer();
|
||||
TextChannel textChannel = channelService.getTextChannelFromServer(server.getId(), post.getUsedChannel().getId());
|
||||
List<AssignableRole> assignableRoles = assignableRolePlace.getAssignableRoles();
|
||||
assignableRoles.sort(Comparator.comparing(AssignableRole::getPosition));
|
||||
Long messageId = post.getId();
|
||||
log.debug("Removing field describing assignable role {} in assignable role place {} from post {}.", assignableRole.getId(), assignableRolePlace.getId(), messageId);
|
||||
CompletableFuture<Message> fieldEditing = channelService.removeFieldFromMessage(textChannel, messageId, assignableRoles.indexOf(assignableRole));
|
||||
log.debug("Clearing reaction for emote {} on assignable role post {} in assignable role place {}.", assignableRole.getEmote().getId(), messageId, assignableRolePlace.getId());
|
||||
CompletableFuture<Void> reactionRemoval = reactionService.clearReactionFromMessageWithFuture(assignableRole.getEmote(), assignableRolePlace.getServer().getId(), assignableRole.getAssignableRolePlacePost().getUsedChannel().getId(), assignableRole.getAssignableRolePlacePost().getId());
|
||||
return CompletableFuture.allOf(fieldEditing, reactionRemoval);
|
||||
} else {
|
||||
// this case comes from the situation in which, the emote was deleted and he initial post setup failed
|
||||
log.warn("Reaction {} to remove does not have a post attached. The post needs to be setup again, it is most likely not functioning currently anyway.", assignableRole.getEmote().getEmoteId());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> setupAssignableRolePlace(AServer server, String name) {
|
||||
AssignableRolePlace assignableRolePlace = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
log.info("Setting up assignable role place {} in server {} towards channel {}.", assignableRolePlace.getId(), server.getId(), assignableRolePlace.getChannel().getId());
|
||||
List<CompletableFuture<Void>> oldPostDeletionFutures = deleteExistingMessagePostsForPlace(assignableRolePlace);
|
||||
assignableRolePlace.getMessagePosts().forEach(assignableRolePlacePost -> assignableRolePlacePost.setAssignablePlace(null));
|
||||
assignableRolePlace.getMessagePosts().clear();
|
||||
assignableRolePlace.getAssignableRoles().forEach(assignableRole ->
|
||||
assignableRole.setAssignableRolePlacePost(null)
|
||||
);
|
||||
Long serverId = server.getId();
|
||||
Long assignablePlaceId = assignableRolePlace.getId();
|
||||
CompletableFuture<Void> messageFuture = FutureUtils.toSingleFutureGeneric(oldPostDeletionFutures);
|
||||
return messageFuture.whenComplete((unused, throwable) -> {
|
||||
if(throwable != null) {
|
||||
log.warn("Not able to delete old messages of assignable role place {} in server {}.", assignablePlaceId, serverId);
|
||||
}
|
||||
self.createAssignableRolePlacePosts(serverId, assignablePlaceId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> refreshAssignablePlacePosts(AServer server, String name) {
|
||||
AssignableRolePlace assignableRolePlace = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
return refreshAssignablePlacePosts(assignableRolePlace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> refreshAssignablePlacePosts(AssignableRolePlace place) {
|
||||
if(place.getMessagePosts().isEmpty()) {
|
||||
log.info("Trying to refresh an assignable place {} in server {} without any posts.", place.getId(), place.getServer().getId());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
log.info("Refreshing assignable role place posts for assignable role place {} in server {}.", place.getId(), place.getServer().getId());
|
||||
MessageToSend messageToSend = renderAssignablePlacePosts(place);
|
||||
List<AssignableRolePlacePost> existingMessagePosts = place.getMessagePosts();
|
||||
existingMessagePosts.sort(Comparator.comparingLong(AssignableRolePlacePost::getId));
|
||||
AssignableRolePlacePost latestPost = existingMessagePosts.get(place.getMessagePosts().size() - 1);
|
||||
List<CompletableFuture<Message>> futures = new ArrayList<>();
|
||||
Optional<TextChannel> channelOptional = channelService.getTextChannelFromServerOptional(place.getServer().getId(), latestPost.getUsedChannel().getId());
|
||||
if(channelOptional.isPresent()) {
|
||||
TextChannel textChannel = channelOptional.get();
|
||||
Iterator<MessageEmbed> iterator = messageToSend.getEmbeds().iterator();
|
||||
place.getMessagePosts().forEach(post -> {
|
||||
log.debug("Refreshing the posts for message post {} in channel {} in assignable role place {} in server {}.", post.getId(), textChannel.getId(), place.getId(), place.getServer().getId());
|
||||
CompletableFuture<Message> messageCompletableFuture = channelService.editEmbedMessageInAChannel(iterator.next(), textChannel, post.getId());
|
||||
futures.add(messageCompletableFuture);
|
||||
});
|
||||
} else {
|
||||
throw new ChannelNotInGuildException(latestPost.getUsedChannel().getId());
|
||||
}
|
||||
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> refreshTextFromPlace(AssignableRolePlace place) {
|
||||
List<AssignableRolePlacePost> existingMessagePosts = place.getMessagePosts();
|
||||
if(!existingMessagePosts.isEmpty()) {
|
||||
MessageToSend renderedMessage = renderAssignablePlacePosts(place);
|
||||
log.debug("There are {} current posts known for the assignable role place {}.", existingMessagePosts.size(), place.getId());
|
||||
existingMessagePosts.sort(Comparator.comparingLong(AssignableRolePlacePost::getId));
|
||||
AssignableRolePlacePost firstPost = existingMessagePosts.get(0);
|
||||
Long channelId = firstPost.getUsedChannel().getId();
|
||||
Optional<TextChannel> channelOptional = channelService.getTextChannelFromServerOptional(place.getServer().getId(), channelId);
|
||||
if(channelOptional.isPresent()) {
|
||||
log.info("Refreshing text for assignable role place {} in channel {} in post {}.", place.getId(), channelId, firstPost.getId());
|
||||
return channelService.editEmbedMessageInAChannel(renderedMessage.getEmbeds().get(0), channelOptional.get(), firstPost.getId()).thenCompose(message -> CompletableFuture.completedFuture(null));
|
||||
} else {
|
||||
throw new ChannelNotInGuildException(channelId);
|
||||
}
|
||||
}
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAssignablePlaceActiveTo(AServer server, String name, Boolean newValue) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
if(newValue) {
|
||||
this.activateAssignableRolePlace(place);
|
||||
} else {
|
||||
this.deactivateAssignableRolePlace(place);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all {@link Message messages} which are stored as {@link AssignableRolePlacePost posts} from the given
|
||||
* {@link AssignableRolePlace place}
|
||||
* @param assignableRolePlace The {@link AssignableRolePlace place} to delete the posts of
|
||||
* @return A list of {@link CompletableFuture futures} each representing one deleted {@link Message message}
|
||||
*/
|
||||
private List<CompletableFuture<Void>> deleteExistingMessagePostsForPlace(AssignableRolePlace assignableRolePlace) {
|
||||
List<CompletableFuture<Void>> oldPostDeletionFutures = new ArrayList<>();
|
||||
assignableRolePlace.getMessagePosts().forEach(assignableRolePlacePost -> {
|
||||
log.info("Deleting existing message post with id {} in channel{} for assignable role place {} in server {}.",
|
||||
assignableRolePlacePost.getId(), assignableRolePlacePost.getUsedChannel().getId(), assignableRolePlace.getId(), assignableRolePlace.getServer().getId());
|
||||
oldPostDeletionFutures.add(messageService.deleteMessageInChannelInServer(assignableRolePlace.getServer().getId(), assignableRolePlacePost.getUsedChannel().getId(), assignableRolePlacePost.getId()));
|
||||
});
|
||||
return oldPostDeletionFutures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateAssignableRolePlace(AServer server, String name) {
|
||||
setAssignablePlaceActiveTo(server, name, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateAssignableRolePlace(AssignableRolePlace place) {
|
||||
place.setActive(false);
|
||||
log.info("Deactivating assignable role place {} in server {}", place.getId(), place.getServer().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAssignableRolePlace(AServer server, String name) {
|
||||
setAssignablePlaceActiveTo(server, name, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAssignableRolePlace(AssignableRolePlace place) {
|
||||
place.setActive(true);
|
||||
log.info("Activating assignable role place {} in server {}", place.getId(), place.getServer().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> setAssignablePlaceInlineTo(AServer server, String name, Boolean newValue) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
if(newValue) {
|
||||
return this.inlineAssignableRolePlace(place);
|
||||
} else {
|
||||
return this.spreadAssignableRolePlace(place);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> inlineAssignableRolePlace(AServer server, String name) {
|
||||
return setAssignablePlaceInlineTo(server, name, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> inlineAssignableRolePlace(AssignableRolePlace place) {
|
||||
log.info("Setting assignable role place inline {} in server {} to {}", place.getId(), place.getServer().getId(), true);
|
||||
place.setInline(true);
|
||||
return refreshAssignablePlacePosts(place);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> spreadAssignableRolePlace(AServer server, String name) {
|
||||
return setAssignablePlaceInlineTo(server, name, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> spreadAssignableRolePlace(AssignableRolePlace place) {
|
||||
log.info("Setting assignable role place inline {} in server {} to {}", place.getId(), place.getServer().getId(), false);
|
||||
place.setInline(false);
|
||||
return refreshAssignablePlacePosts(place);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAssignablePlaceUniqueTo(AServer server, String name, Boolean newValue) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
if(newValue) {
|
||||
this.uniqueAssignableRolePlace(place);
|
||||
} else {
|
||||
this.multipleAssignableRolePlace(place);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uniqueAssignableRolePlace(AServer server, String name) {
|
||||
setAssignablePlaceInlineTo(server, name, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uniqueAssignableRolePlace(AssignableRolePlace place) {
|
||||
log.info("Setting assignable role place uniqueness {} in server {} to {}", place.getId(), place.getServer().getId(), true);
|
||||
place.setUniqueRoles(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void multipleAssignableRolePlace(AServer server, String name) {
|
||||
setAssignablePlaceInlineTo(server, name, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void multipleAssignableRolePlace(AssignableRolePlace place) {
|
||||
log.info("Setting assignable role place uniqueness {} in server {} to {}", place.getId(), place.getServer().getId(), false);
|
||||
place.setUniqueRoles(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAssignablePlaceAutoRemoveTo(AServer server, String name, Boolean newValue) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
if(newValue) {
|
||||
this.autoRemoveAssignableRolePlace(place);
|
||||
} else {
|
||||
this.keepReactionsAssignableRolePlace(place);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoRemoveAssignableRolePlace(AServer server, String name) {
|
||||
setAssignablePlaceAutoRemoveTo(server, name, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoRemoveAssignableRolePlace(AssignableRolePlace place) {
|
||||
log.info("Setting assignable role place auto remove {} in server {} to {}", place.getId(), place.getServer().getId(), true);
|
||||
place.setAutoRemove(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keepReactionsAssignableRolePlace(AServer server, String name) {
|
||||
setAssignablePlaceAutoRemoveTo(server, name, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keepReactionsAssignableRolePlace(AssignableRolePlace place) {
|
||||
log.info("Setting assignable role place auto remove {} in server {} to {}", place.getId(), place.getServer().getId(), false);
|
||||
place.setAutoRemove(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swapPositions(AServer server, String name, FullEmote firstEmote, FullEmote secondEmote) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
Optional<AssignableRole> firstEmoteOptional = place.getAssignableRoles().stream().filter(role -> emoteService.compareAEmote(role.getEmote(), firstEmote.getFakeEmote())).findFirst();
|
||||
Optional<AssignableRole> secondEmoteOptional = place.getAssignableRoles().stream().filter(role -> emoteService.compareAEmote(role.getEmote(), secondEmote.getFakeEmote())).findFirst();
|
||||
if(firstEmoteOptional.isPresent() && secondEmoteOptional.isPresent()) {
|
||||
AssignableRole firstRole = firstEmoteOptional.get();
|
||||
AssignableRole secondRole = secondEmoteOptional.get();
|
||||
log.info("Swapping positions of emotes {} and {} in assignable role place {} in server {}: first: {} -> {}, second: {} -> {}",
|
||||
firstRole.getEmote().getId(), secondRole.getEmote().getId(), place.getId(), server.getId(), firstRole.getPosition(), secondRole.getPosition(), secondRole.getPosition(), firstRole.getPosition());
|
||||
int firstPosition = firstRole.getPosition();
|
||||
firstRole.setPosition(secondRole.getPosition());
|
||||
secondRole.setPosition(firstPosition);
|
||||
} else {
|
||||
if(!firstEmoteOptional.isPresent()) {
|
||||
throw new EmoteNotInAssignableRolePlaceException(firstEmote, name);
|
||||
} else {
|
||||
throw new EmoteNotInAssignableRolePlaceException(secondEmote, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> testAssignableRolePlace(AServer server, String name, TextChannel channel) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
MessageToSend messageToSend = renderAssignablePlacePosts(place);
|
||||
log.info("Testing assignable role place {} in channel {} on server {}.", place.getId(), channel.getId(), server.getId());
|
||||
List<CompletableFuture<Message>> completableFutures = channelService.sendMessageToSendToChannel(messageToSend, channel);
|
||||
return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> showAssignablePlaceConfig(AServer server, String name, TextChannel channel) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
List<AssignableRolePlaceConfigRole> roles = new ArrayList<>();
|
||||
Guild guild = guildService.getGuildById(server.getId());
|
||||
log.info("Showing assignable role place config for place {} in channel {} on server {}.", place.getId(), channel.getId(), server.getId());
|
||||
List<AssignableRole> assignableRoles = place.getAssignableRoles().stream().sorted(Comparator.comparingInt(AssignableRole::getPosition)).collect(Collectors.toList());
|
||||
for (AssignableRole role : assignableRoles) {
|
||||
AEmote emoteForRole = role.getEmote();
|
||||
Emote jdaEmoteForRole = emoteService.getEmote(emoteForRole).orElse(null);
|
||||
Role jdaRole = guild.getRoleById(role.getRole().getId());
|
||||
AssignableRolePlaceConfigRole postRole = AssignableRolePlaceConfigRole
|
||||
.builder()
|
||||
.description(role.getDescription())
|
||||
.emote(FullEmote.builder().fakeEmote(emoteForRole).emote(jdaEmoteForRole).build())
|
||||
.position(role.getPosition())
|
||||
.awardedRole(jdaRole)
|
||||
.build();
|
||||
log.debug("Displaying config for role {} with emote {} in position {}.", role.getId(), emoteForRole.getId(), role.getPosition());
|
||||
roles.add(postRole);
|
||||
}
|
||||
AssignableRolePlaceConfig configModel = AssignableRolePlaceConfig
|
||||
.builder()
|
||||
.roles(roles)
|
||||
.place(place)
|
||||
.build();
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(ASSIGNABLE_ROLES_CONFIG_POST_TEMPLATE_KEY, configModel, channel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveAssignableRolePlace(String name, TextChannel newChannel) {
|
||||
AChannel channel = channelManagementService.loadChannel(newChannel.getIdLong());
|
||||
rolePlaceManagementService.moveAssignableRolePlace(name, channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeText(AServer server, String name, String newText) {
|
||||
rolePlaceManagementService.changeAssignableRolePlaceDescription(server, name, newText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> deleteAssignableRolePlace(AServer server, String name) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
|
||||
Long placeId = place.getId();
|
||||
List<CompletableFuture<Void>> deleteFutures = deleteExistingMessagePostsForPlace(place);
|
||||
return CompletableFuture.allOf(deleteFutures.toArray(new CompletableFuture[0]))
|
||||
.thenAccept(unused -> self.deleteAssignableRolePlaceInDatabase(placeId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the {@link AssignableRolePlace place} in the database and all the
|
||||
* {@link AEmote emotes} which were used to identify the {@link AssignableRole roles}
|
||||
* @param placeId The ID of the {@link AssignableRolePlace place} to delete
|
||||
*/
|
||||
@Transactional
|
||||
public void deleteAssignableRolePlaceInDatabase(Long placeId) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByPlaceId(placeId);
|
||||
rolePlaceManagementService.deleteAssignablePlace(place);
|
||||
deleteEmotesFromAssignableRolePlace(place);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> changeTextAsync(AServer server, String name, String newText) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByServerAndKey(server, name);
|
||||
log.info("Changing text of assignable role place {} in server {}.", place.getId(), server.getId());
|
||||
place.setText(newText);
|
||||
return refreshTextFromPlace(place);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeExistingReactionsAndRoles(AssignableRolePlace place, AssignedRoleUser user) {
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
log.info("Removing all existing reactions and roles by user {} on assignable role place {} in server {}.", user.getId(), place.getId(), user.getUser().getServerReference().getId());
|
||||
user.getRoles().forEach(assignableRole -> {
|
||||
futures.add(roleService.removeAssignableRoleFromUser(assignableRole, user.getUser()));
|
||||
log.debug("Removing role {} from user {} in server {} because of assignable role clearing.", assignableRole.getRole().getId(), user.getUser().getUserReference().getId(), place.getServer().getId());
|
||||
AEmote emoteToUseObject = emoteManagementService.loadEmote(assignableRole.getEmote().getId());
|
||||
AssignableRolePlacePost assignablePlacePost = assignableRole.getAssignableRolePlacePost();
|
||||
log.debug("Removing reaction with emote {} from user {} in server {} because of assignable role clearing.", emoteToUseObject.getId(), user.getUser().getUserReference().getId(), place.getServer().getId());
|
||||
futures.add(reactionService.removeReactionOfUserFromMessageWithFuture(emoteToUseObject, place.getServer().getId(),
|
||||
assignablePlacePost.getUsedChannel().getId(), assignablePlacePost.getId(), user.getUser().getUserReference().getId()));
|
||||
});
|
||||
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> changeConfiguration(AServer server, String name, AssignableRolePlaceParameterKey keyToChange, Object newValue) {
|
||||
Boolean booleanValue = BooleanUtils.toBooleanObject(newValue.toString());
|
||||
if(booleanValue == null) {
|
||||
throw new CommandParameterKeyValueWrongTypeException(Arrays.asList("yes", "no", "true", "false", "on", "off"));
|
||||
}
|
||||
switch (keyToChange) {
|
||||
case INLINE:
|
||||
return setAssignablePlaceInlineTo(server, name, booleanValue);
|
||||
case AUTOREMOVE:
|
||||
setAssignablePlaceAutoRemoveTo(server, name, booleanValue);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
case UNIQUE:
|
||||
setAssignablePlaceUniqueTo(server, name, booleanValue);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
case ACTIVE:
|
||||
setAssignablePlaceActiveTo(server, name, booleanValue);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
default:
|
||||
throw new AbstractoTemplatedException("Illegal configuration key was passed", "assignable_role_place_illegal_configuration_key_exception");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> showAllAssignableRolePlaces(AServer server, TextChannel channel) {
|
||||
List<AssignableRolePlace> assignableRolePlaces = rolePlaceManagementService.findAllByServer(server);
|
||||
AssignablePlaceOverview overViewModel = AssignablePlaceOverview.builder().places(assignableRolePlaces).build();
|
||||
log.info("Showing overview over all assignable role places for server {} in channel {}.", server.getId(), channel.getId());
|
||||
List<CompletableFuture<Message>> promises = channelService.sendEmbedTemplateInTextChannelList(ASSIGNABLE_ROLE_PLACES_OVERVIEW_TEMPLATE_KEY, overViewModel, channel);
|
||||
return CompletableFuture.allOf(promises.toArray(new CompletableFuture[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the {@link AEmote emotes} for each {@link AssignableRole assignableRole} from a {@link AssignableRolePlace place}
|
||||
* @param place The {@link AssignableRolePlace place} to delete the {@link AEmote emotes} of
|
||||
*/
|
||||
private void deleteEmotesFromAssignableRolePlace(AssignableRolePlace place) {
|
||||
log.info("Deleting all emotes associated with assignable role place {} in server {}.", place.getId(), place.getServer().getId());
|
||||
place.getAssignableRoles().forEach(role ->
|
||||
emoteManagementService.deleteEmote(role.getEmote())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the {@link AssignableRolePlace place} to a {@link MessageToSend messageToSend}, and
|
||||
* sends it in the given {@link TextChannel channel}
|
||||
* @param place The {@link AssignableRolePlace place} to render
|
||||
* @param channel The {@link TextChannel channel} in which the {@link MessageToSend messageToSend} should be sent to
|
||||
* @return A list of {@link CompletableFuture futures} which represent each message which was sent
|
||||
*/
|
||||
private List<CompletableFuture<Message>> sendAssignablePostMessages(AssignableRolePlace place, TextChannel channel) {
|
||||
MessageToSend messageToSend = renderAssignablePlacePosts(place);
|
||||
return channelService.sendMessageToSendToChannel(messageToSend, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the {@link AssignableRolePlace place} with the appropriate template and returns a {@link MessageToSend messageToSend}
|
||||
* @param place The {@link AssignableRolePlace place} to render
|
||||
* @return A {@link MessageToSend messageToSend} which can be sent, containing the individual posts
|
||||
*/
|
||||
private MessageToSend renderAssignablePlacePosts(AssignableRolePlace place) {
|
||||
AssignablePostMessage model = prepareAssignablePostMessageModel(place);
|
||||
return templateService.renderEmbedTemplate(ASSIGNABLE_ROLES_POST_TEMPLATE_KEY, model, place.getServer().getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts individual parts of the given {@link AssignableRolePlace place} into a model which is usable
|
||||
* in the template responsible to render the {@link AssignableRolePlace place}. This requires to load
|
||||
* the {@link Emote emotes} and ordering according to their position
|
||||
* @param place The {@link AssignableRolePlace place} which should be made available for rendering
|
||||
* @return The {@link AssignablePostMessage model} which holds the necessary values to render the template
|
||||
*/
|
||||
private AssignablePostMessage prepareAssignablePostMessageModel(AssignableRolePlace place) {
|
||||
List<AssignablePostRole> roles = new ArrayList<>();
|
||||
List<AssignableRole> rolesToAdd = place.getAssignableRoles().stream().sorted(Comparator.comparingInt(AssignableRole::getPosition)).collect(Collectors.toList());
|
||||
int maxPosition = 0;
|
||||
if(!rolesToAdd.isEmpty()) {
|
||||
maxPosition = rolesToAdd.get(rolesToAdd.size() - 1).getPosition();
|
||||
Iterator<AssignableRole> rolesToAddIterator = rolesToAdd.iterator();
|
||||
AssignableRole current = rolesToAddIterator.next();
|
||||
AssignablePostRole lastAddedRole = null;
|
||||
for (int position = 0; position < maxPosition + 1; position++) {
|
||||
boolean legitEntry = current.getPosition().equals(position);
|
||||
// TODO is this still required?
|
||||
boolean startOfNewMessage = position > 0 && (position % 21) == 0;
|
||||
if(legitEntry) {
|
||||
AEmote emoteForRole = current.getEmote();
|
||||
Emote jdaEmoteForRole = emoteService.getEmote(emoteForRole).orElse(null);
|
||||
FullEmote fullEmote = FullEmote.builder().emote(jdaEmoteForRole).fakeEmote(emoteForRole).build();
|
||||
AssignablePostRole postRole = AssignablePostRole
|
||||
.builder()
|
||||
.description(current.getDescription())
|
||||
.emote(fullEmote)
|
||||
.position(position)
|
||||
.forceNewMessage(startOfNewMessage)
|
||||
.build();
|
||||
roles.add(postRole);
|
||||
lastAddedRole = postRole;
|
||||
if(rolesToAddIterator.hasNext()) {
|
||||
current = rolesToAddIterator.next();
|
||||
}
|
||||
} else if(startOfNewMessage && lastAddedRole != null) {
|
||||
log.debug("Forcing new message for post of assignable role place {}.", place.getId());
|
||||
lastAddedRole.setForceNewMessage(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return AssignablePostMessage
|
||||
.builder()
|
||||
.roles(roles)
|
||||
.place(place)
|
||||
.maxPosition(maxPosition)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the {@link Message messages} for the posts required for the {@link AssignableRolePlace place} and
|
||||
* adds the reactions afterwards.
|
||||
* @param serverId The ID of the {@link AServer server} in which the {@link AssignableRolePlace place} posts should
|
||||
* be created in
|
||||
* @param assignablePlaceId The ID of the {@link AssignableRolePlace place} which should have its {@link Message messages} posted
|
||||
* @return A {@link CompletableFuture future} which completes when the {@link Message messages} were posted and the {@link MessageReaction reactions}
|
||||
* added
|
||||
*/
|
||||
@Transactional
|
||||
public CompletableFuture<Void> createAssignableRolePlacePosts(Long serverId, Long assignablePlaceId) {
|
||||
AssignableRolePlace assignableRolePlace = rolePlaceManagementService.findByPlaceId(assignablePlaceId);
|
||||
Optional<TextChannel> channelOptional = channelService.getTextChannelFromServerOptional(serverId, assignableRolePlace.getChannel().getId());
|
||||
if(channelOptional.isPresent()) {
|
||||
TextChannel channel = channelOptional.get();
|
||||
log.info("Sending assignable role place posts for place {} in channel {} in server {}.", assignableRolePlace.getId(), channel.getId(), serverId);
|
||||
List<CompletableFuture<Message>> messageFutures = sendAssignablePostMessages(assignableRolePlace, channel);
|
||||
return CompletableFuture.allOf(messageFutures.toArray(new CompletableFuture[0]))
|
||||
.thenCompose(aVoid -> self.addEmotes(messageFutures, assignablePlaceId));
|
||||
} else {
|
||||
log.warn("Channel to create assignable role post in does not exist.");
|
||||
throw new AssignableRolePlaceChannelDoesNotExistException(assignableRolePlace.getChannel().getId(), assignableRolePlace.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the appropriate {@link MessageReaction reactions} defined by the {@link AssignableRole assignableRoles} of the
|
||||
* {@link AssignableRolePlace place} to the {@link Message messages} which are provided via the {@link CompletableFuture futures}.
|
||||
* The mapping of reaction to assignable role is done via the index of the fields. Depending on the amount of fields
|
||||
* which were created in the {@link Message messages}. Afterwards it will store the created
|
||||
* {@link AssignableRolePlacePost posts}
|
||||
* @param assignablePlacePostsMessageFutures A list of {@link CompletableFuture futures} which represent the individual
|
||||
* {@link Message messages} which were posted when setting up
|
||||
* the {@link AssignableRolePlace place}
|
||||
* @param assignablePlaceId The ID of the {@link AssignableRolePlace place} which was setup
|
||||
* @return A {@link CompletableFuture future} which completes when all reactions were added and the database
|
||||
* was updated.
|
||||
*/
|
||||
@Transactional
|
||||
public CompletableFuture<Void> addEmotes(List<CompletableFuture<Message>> assignablePlacePostsMessageFutures, Long assignablePlaceId) {
|
||||
AssignableRolePlace innerRolePlace = rolePlaceManagementService.findByPlaceId(assignablePlaceId);
|
||||
log.info("Adding emotes to assignable role place {}.", innerRolePlace);
|
||||
log.debug("We have {} posts and {} roles.", assignablePlacePostsMessageFutures.size(), innerRolePlace.getAssignableRoles().size());
|
||||
|
||||
List<AssignableRole> roleStream = innerRolePlace.getAssignableRoles().stream().sorted(Comparator.comparingInt(AssignableRole::getPosition)).collect(Collectors.toList());
|
||||
List<CompletableFuture<Void>> reactionFutures = new ArrayList<>();
|
||||
int usedEmotes = 0;
|
||||
for (CompletableFuture<Message> messageCompletableFuture : assignablePlacePostsMessageFutures) {
|
||||
Message sentMessage = messageCompletableFuture.join();
|
||||
// this uses the actual embed count as a limit, so this relies on fields to be used for description, if this changes, this needs to be changed
|
||||
MessageEmbed embed = sentMessage.getEmbeds().get(0);
|
||||
List<AssignableRole> firstRoles = roleStream.subList(usedEmotes, usedEmotes + embed.getFields().size());
|
||||
usedEmotes += embed.getFields().size();
|
||||
log.debug("Adding {} emotes to message {} for place {}. In total {} were added.", embed.getFields().size(), sentMessage.getId(), innerRolePlace.getId(), usedEmotes);
|
||||
List<Integer> usedEmoteIds = firstRoles.stream().map(assignableRole -> assignableRole.getEmote().getId()).collect(Collectors.toList());
|
||||
CompletableFuture<Void> firstMessageFuture = addingReactionsToAssignableRolePlacePost(sentMessage, usedEmoteIds);
|
||||
reactionFutures.add(firstMessageFuture);
|
||||
}
|
||||
return CompletableFuture.allOf(reactionFutures.toArray(new CompletableFuture[0])).thenCompose(aVoid -> {
|
||||
try {
|
||||
self.storeCreatedAssignableRolePlacePosts(assignablePlaceId, assignablePlacePostsMessageFutures);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to persist assignable role place posts. ", e);
|
||||
}
|
||||
return CompletableFuture.completedFuture(null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the {@link AssignableRolePlacePost posts} for the created {@link Message messages} and stores them in the
|
||||
* database. This also uses the fields in the {@link MessageEmbed embed} in order to determine which
|
||||
* {@link AssignableRole role} is in which {@link AssignableRolePlacePost post}
|
||||
* @param assignablePlaceId The ID of the {@link AssignableRolePlace place} to which the {@link AssignableRolePlacePost posts}
|
||||
* should be added to
|
||||
* @param futures A list of {@link CompletableFuture futures} which holds the {@link Message messages} which were created
|
||||
* when setting up the {@link AssignableRolePlace place}
|
||||
*/
|
||||
@Transactional
|
||||
public void storeCreatedAssignableRolePlacePosts(Long assignablePlaceId, List<CompletableFuture<Message>> futures) {
|
||||
AssignableRolePlace updatedPlace = rolePlaceManagementService.findByPlaceId(assignablePlaceId);
|
||||
log.info("Storing {} messages for assignable role place {} in server {}.", futures.size(), assignablePlaceId, updatedPlace.getServer().getId());
|
||||
List<AssignableRole> rolesToAdd = updatedPlace.getAssignableRoles().stream().sorted(Comparator.comparingInt(AssignableRole::getPosition)).collect(Collectors.toList());
|
||||
int usedEmotes = 0;
|
||||
for (int i = 0; i < futures.size(); i++) {
|
||||
CompletableFuture<Message> messageCompletableFuture = futures.get(i);
|
||||
Message message = messageCompletableFuture.join();
|
||||
// this uses the actual embed count as a limit, so this relies on fields to be used for description, if this changes, this needs to be changed
|
||||
MessageEmbed embed = message.getEmbeds().get(0);
|
||||
log.debug("Storing post {} with {} fields.", message.getId(), embed.getFields().size());
|
||||
List<AssignableRole> firstRoles = rolesToAdd.subList(usedEmotes, usedEmotes + embed.getFields().size());
|
||||
usedEmotes += embed.getFields().size();
|
||||
AssignableRolePlacePost post = assignableRolePlacePostManagementServiceBean.createAssignableRolePlacePost(updatedPlace, message.getIdLong());
|
||||
firstRoles.forEach(assignableRole ->
|
||||
assignableRole.setAssignableRolePlacePost(post)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given {@link AEmote emotes} identified by the ID to the given Message
|
||||
* @param message The {@link Message message} on which the {@link MessageReaction reactions} should be added on
|
||||
* @param emotesToAdd A list of {@link Integer integers} which contains the ID of the {@link AEmote emotes} which should be added
|
||||
* @return A {@link CompletableFuture future} which complets when all reactions have been added
|
||||
*/
|
||||
@Transactional
|
||||
public CompletableFuture<Void> addingReactionsToAssignableRolePlacePost(Message message, List<Integer> emotesToAdd) {
|
||||
// TODO might need to guarantee the order
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
Long serverId = message.getGuild().getIdLong();
|
||||
log.info("Adding {} emotes to assignable role place post {} in server {}.", emotesToAdd.size(), message.getId(), serverId);
|
||||
emotesToAdd.forEach(emotesToUse -> {
|
||||
AEmote emoteToUseObject = emoteManagementService.loadEmote(emotesToUse);
|
||||
futures.add(reactionService.addReactionToMessageAsync(emoteToUseObject, serverId, message));
|
||||
});
|
||||
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRole;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser;
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.AssignableRoleManagementServiceBean;
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.AssignedRoleUserManagementService;
|
||||
import dev.sheldan.abstracto.assignableroles.service.management.AssignedRoleUserManagementServiceBean;
|
||||
import dev.sheldan.abstracto.core.metric.service.CounterMetric;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricService;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricTag;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.RoleService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AssignableRoleServiceBean implements AssignableRoleService {
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private AssignedRoleUserManagementService assignedRoleUserManagementService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRoleManagementServiceBean assignableRoleManagementServiceBean;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private AssignedRoleUserManagementServiceBean assignedRoleUserManagementServiceBean;
|
||||
|
||||
@Autowired
|
||||
private AssignableRoleServiceBean self;
|
||||
|
||||
@Autowired
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private MetricService metricService;
|
||||
|
||||
public static final String ASSIGNABLE_ROLES_METRIC = "assignable.roles";
|
||||
public static final String ACTION = "action";
|
||||
private static final CounterMetric ASSIGNABLE_ROLES_ASSIGNED =
|
||||
CounterMetric
|
||||
.builder()
|
||||
.name(ASSIGNABLE_ROLES_METRIC)
|
||||
.tagList(Arrays.asList(MetricTag.getTag(ACTION, "assigned")))
|
||||
.build();
|
||||
|
||||
private static final CounterMetric ASSIGNABLE_ROLES_REMOVED =
|
||||
CounterMetric
|
||||
.builder()
|
||||
.name(ASSIGNABLE_ROLES_METRIC)
|
||||
.tagList(Arrays.asList(MetricTag.getTag(ACTION, "removed")))
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, Member member) {
|
||||
metricService.incrementCounter(ASSIGNABLE_ROLES_ASSIGNED);
|
||||
AssignableRole role = assignableRoleManagementServiceBean.getByAssignableRoleId(assignableRoleId);
|
||||
log.info("Assigning role {} to member {} in server {}.", assignableRoleId, member.getId(), member.getGuild().getId());
|
||||
return roleService.addRoleToMemberFuture(member, role.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, ServerUser serverUser) {
|
||||
return memberService.retrieveMemberInServer(serverUser).thenCompose(member -> assignAssignableRoleToUser(assignableRoleId, member));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllRolesOfUserInPlace(AssignableRolePlace place, AUserInAServer userInAServer) {
|
||||
AssignedRoleUser user = assignedRoleUserManagementServiceBean.findByUserInServer(userInAServer);
|
||||
log.info("Clearing all {} assignable roles in place {} for user {} in server {}.",
|
||||
user.getRoles().size(), place.getId(), userInAServer.getUserReference().getId(), userInAServer.getServerReference().getId());
|
||||
user.getRoles().forEach(assignableRole -> {
|
||||
if(assignableRole.getAssignablePlace().equals(place)) {
|
||||
assignableRole.getAssignedUsers().remove(user);
|
||||
}
|
||||
});
|
||||
user.getRoles().removeIf(assignableRole -> assignableRole.getAssignablePlace().equals(place));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> fullyAssignAssignableRoleToUser(Long assignableRoleId, Member toAdd) {
|
||||
return this.assignAssignableRoleToUser(assignableRoleId, toAdd).thenAccept(aVoid ->
|
||||
self.addRoleToUser(assignableRoleId, toAdd)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, Member member) {
|
||||
log.info("Removing assignable role {} from user {} in server {}.", assignableRole.getId(), member.getId(), member.getGuild().getId());
|
||||
metricService.incrementCounter(ASSIGNABLE_ROLES_REMOVED);
|
||||
return roleService.removeRoleFromMemberAsync(member, assignableRole.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CompletableFuture<Void> removeAssignableRoleFromUser(Long assignableRoleId, Member member) {
|
||||
AssignableRole role = assignableRoleManagementServiceBean.getByAssignableRoleId(assignableRoleId);
|
||||
return self.removeAssignableRoleFromUser(role, member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, AUserInAServer aUserInAServer) {
|
||||
Long assignableRoleId = assignableRole.getId();
|
||||
return memberService.getMemberInServerAsync(aUserInAServer).thenCompose(member ->
|
||||
self.removeAssignableRoleFromUser(assignableRoleId, member)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> fullyRemoveAssignableRoleFromUser(AssignableRole assignableRole, ServerUser serverUser) {
|
||||
Long assignableRoleId = assignableRole.getId();
|
||||
return memberService.retrieveMemberInServer(serverUser).thenCompose(member ->
|
||||
this.removeAssignableRoleFromUser(assignableRole, member)
|
||||
.thenAccept(aVoid -> self.persistRoleRemovalFromUser(assignableRoleId, member))
|
||||
);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void addRoleToUser(Long assignableRoleId, AUserInAServer aUserInAServer) {
|
||||
AssignableRole role = assignableRoleManagementServiceBean.getByAssignableRoleId(assignableRoleId);
|
||||
addRoleToUser(role, aUserInAServer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRoleToUser(AssignableRole assignableRole, AUserInAServer aUserInAServer) {
|
||||
log.info("Persisting storing adding assignable role {} to user {} in server {}.",
|
||||
assignableRole.getId(), aUserInAServer.getUserReference().getId(), aUserInAServer.getServerReference().getId());
|
||||
assignedRoleUserManagementServiceBean.addAssignedRoleToUser(assignableRole, aUserInAServer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoleFromUser(AssignableRole assignableRole, AUserInAServer aUserInAServer) {
|
||||
log.info("Persisting storing removing assignable role {} to user {} in server {}.",
|
||||
assignableRole.getId(), aUserInAServer.getUserReference().getId(), aUserInAServer.getServerReference().getId());
|
||||
assignedRoleUserManagementServiceBean.removeAssignedRoleFromUser(assignableRole, aUserInAServer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given {@link AssignableRole assignableRole} identified by the ID to the given {@link Member member}
|
||||
* @param assignableRoleId The ID of the {@link AssignableRole} to be added to the {@link Member member}
|
||||
* @param member The {@link Member member} to add the {@link AssignableRole role} to
|
||||
*/
|
||||
@Transactional
|
||||
public void addRoleToUser(Long assignableRoleId, Member member) {
|
||||
AssignableRole role = assignableRoleManagementServiceBean.getByAssignableRoleId(assignableRoleId);
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
addRoleToUser(role, aUserInAServer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given {@link AssignableRole assignableRole} identified by the ID from the given {@link AUserInAServer user}
|
||||
* @param assignableRoleId The ID of the {@link AssignableRole} to be removed from the {@link Member member}
|
||||
* @param aUserInAServer The {@link AUserInAServer user} to remove the {@link AssignableRole role} from
|
||||
*/
|
||||
@Transactional
|
||||
public void removeRoleFromUser(Long assignableRoleId, AUserInAServer aUserInAServer) {
|
||||
AssignableRole role = assignableRoleManagementServiceBean.getByAssignableRoleId(assignableRoleId);
|
||||
removeRoleFromUser(role, aUserInAServer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the removal of an {@link AssignableRole assignableRole} from a {@link Member member} in the database
|
||||
* @param assignableRoleId The ID of the {@link AssignableRole} to be removed from the {@link Member member}
|
||||
* @param member The {@link Member member} which should get the {@link AssignableRole role} removed
|
||||
*/
|
||||
@Transactional
|
||||
public void persistRoleRemovalFromUser(Long assignableRoleId, Member member) {
|
||||
AssignableRole role = assignableRoleManagementServiceBean.getByAssignableRoleId(assignableRoleId);
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
removeRoleFromUser(role, aUserInAServer);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
metricService.registerCounter(ASSIGNABLE_ROLES_ASSIGNED, "Assignable roles assigned.");
|
||||
metricService.registerCounter(ASSIGNABLE_ROLES_REMOVED, "Assignable roles removed.");
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlaceNotFoundException;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRole;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost;
|
||||
import dev.sheldan.abstracto.assignableroles.repository.AssignableRoleRepository;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import dev.sheldan.abstracto.core.service.management.EmoteManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.MessageReaction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AssignableRoleManagementServiceBean implements AssignableRoleManagementService {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceManagementService rolePlaceManagementService;
|
||||
|
||||
@Autowired
|
||||
private EmoteManagementService emoteManagementService;
|
||||
|
||||
@Autowired
|
||||
private RoleManagementService roleManagementService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlacePostManagementService postManagementService;
|
||||
|
||||
@Autowired
|
||||
private AssignableRoleRepository repository;
|
||||
|
||||
@Autowired
|
||||
private EmoteService emoteService;
|
||||
|
||||
@Override
|
||||
public AssignableRole addRoleToPlace(AssignableRolePlace place, AEmote emote, ARole role, String description, AssignableRolePlacePost post) {
|
||||
Integer maxPosition = place.getAssignableRoles().stream().map(AssignableRole::getPosition).max(Integer::compareTo).orElse(0);
|
||||
if(!place.getAssignableRoles().isEmpty()) {
|
||||
maxPosition += 1;
|
||||
}
|
||||
AssignableRole roleToAdd = AssignableRole
|
||||
.builder()
|
||||
.assignablePlace(place)
|
||||
.emote(emote)
|
||||
.role(role)
|
||||
.requiredLevel(0)
|
||||
.server(place.getServer())
|
||||
.position(maxPosition)
|
||||
.description(description)
|
||||
.assignableRolePlacePost(post)
|
||||
.build();
|
||||
place.getAssignableRoles().add(roleToAdd);
|
||||
log.info("Adding role {} to assignable role place {}. There are now {} roles.", role.getId(), place.getId(), place.getAssignableRoles().size());
|
||||
return roleToAdd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignableRole addRoleToPlace(Long placeId, Integer emoteId, Long roleId, String description, Long messageId) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByPlaceIdOptional(placeId).orElseThrow(() -> new AssignableRolePlaceNotFoundException(placeId));
|
||||
AEmote emote = emoteManagementService.loadEmote(emoteId);
|
||||
ARole role = roleManagementService.findRole(roleId);
|
||||
AssignableRolePlacePost post = postManagementService.findByMessageId(messageId);
|
||||
AssignableRole assignableRole = addRoleToPlace(place, emote, role, description, post);
|
||||
post.getAssignableRoles().add(assignableRole);
|
||||
return assignableRole;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignableRole addRoleToPlace(Long placeId, Integer emoteId, Long roleId, String description) {
|
||||
AssignableRolePlace place = rolePlaceManagementService.findByPlaceIdOptional(placeId).orElseThrow(() -> new AssignableRolePlaceNotFoundException(placeId));
|
||||
AEmote emote = emoteManagementService.loadEmote(emoteId);
|
||||
ARole role = roleManagementService.findRole(roleId);
|
||||
return addRoleToPlace(place, emote, role, description, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignableRole getByAssignableRoleId(Long assignableRoleId) {
|
||||
return repository.findById(assignableRoleId).orElseThrow(() -> new AbstractoRunTimeException("Assignable role not found"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignableRole getRoleForReactionEmote(CachedEmote cachedEmote, AssignableRolePlace assignableRolePlace) {
|
||||
for (AssignableRolePlacePost post : assignableRolePlace.getMessagePosts()) {
|
||||
for (AssignableRole assignableRole : post.getAssignableRoles()) {
|
||||
if (emoteService.compareCachedEmoteWithAEmote(cachedEmote, assignableRole.getEmote())) {
|
||||
return assignableRole;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new AbstractoRunTimeException("Role for reaction was not found.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignableRole getRoleForReactionEmote(MessageReaction.ReactionEmote cachedEmote, AssignableRolePlace assignableRolePlace) {
|
||||
for (AssignableRolePlacePost post : assignableRolePlace.getMessagePosts()) {
|
||||
for (AssignableRole assignableRole : post.getAssignableRoles()) {
|
||||
if (emoteService.isReactionEmoteAEmote(cachedEmote, assignableRole.getEmote())) {
|
||||
return assignableRole;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new AbstractoRunTimeException("Role for reaction was not found.");
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlaceNotFoundException;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.repository.AssignableRolePlaceRepository;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AssignableRolePlaceManagementServiceBean implements AssignableRolePlaceManagementService {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlaceRepository repository;
|
||||
|
||||
@Override
|
||||
public AssignableRolePlace createPlace(String name, AChannel channel, String text) {
|
||||
AssignableRolePlace place = AssignableRolePlace
|
||||
.builder()
|
||||
.channel(channel)
|
||||
.server(channel.getServer())
|
||||
.text(text)
|
||||
.key(name)
|
||||
.build();
|
||||
log.info("Creating assignable role place in channel {} on server {}.", channel.getId(), channel.getServer().getId());
|
||||
return repository.save(place);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesPlaceExist(AServer server, String name) {
|
||||
return repository.existsByServerAndKey(server, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignableRolePlace findByServerAndKey(AServer server, String name) {
|
||||
// todo use other exception or adapt exception
|
||||
return repository.findByServerAndKey(server, name).orElseThrow(() -> new AssignableRolePlaceNotFoundException(0L));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<AssignableRolePlace> findByPlaceIdOptional(Long id) {
|
||||
return repository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignableRolePlace findByPlaceId(Long id) {
|
||||
return findByPlaceIdOptional(id).orElseThrow(() -> new AssignableRolePlaceNotFoundException(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveAssignableRolePlace(String name, AChannel newChannel) {
|
||||
AssignableRolePlace assignablePlaceToChange = findByServerAndKey(newChannel.getServer(), name);
|
||||
log.info("Moving assignable role place {} in server {} from channel {} to channel {}.",
|
||||
assignablePlaceToChange.getId(), newChannel.getServer().getId(), assignablePlaceToChange.getChannel().getId(), newChannel.getId());
|
||||
assignablePlaceToChange.setChannel(newChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeAssignableRolePlaceDescription(AServer server, String name, String newDescription) {
|
||||
AssignableRolePlace assignablePlaceToChange = findByServerAndKey(server, name);
|
||||
log.info("Changing description of assignable role place {} in server {}.", assignablePlaceToChange.getId(), server.getId());
|
||||
assignablePlaceToChange.setText(newDescription);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAssignablePlace(AssignableRolePlace toDelete) {
|
||||
log.info("Deleting assignable role place {} in server {} which was in server {}.", toDelete.getId(), toDelete.getChannel().getId(), toDelete.getServer().getId());
|
||||
repository.delete(toDelete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AssignableRolePlace> findAllByServer(AServer server) {
|
||||
return repository.findByServer(server);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlacePostNotFoundException;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost;
|
||||
import dev.sheldan.abstracto.assignableroles.repository.AssignableRolePlacePostRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class AssignableRolePlacePostManagementServiceBean implements AssignableRolePlacePostManagementService {
|
||||
|
||||
@Autowired
|
||||
private AssignableRolePlacePostRepository repository;
|
||||
|
||||
@Override
|
||||
public Optional<AssignableRolePlacePost> findByMessageIdOptional(Long messageId) {
|
||||
return repository.findById(messageId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignableRolePlacePost findByMessageId(Long messageId) {
|
||||
return findByMessageIdOptional(messageId).orElseThrow(() -> new AssignableRolePlacePostNotFoundException(messageId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignableRolePlacePost createAssignableRolePlacePost(AssignableRolePlace updatedPlace, Long messageId) {
|
||||
AssignableRolePlacePost post = AssignableRolePlacePost
|
||||
.builder()
|
||||
.id(messageId)
|
||||
.usedChannel(updatedPlace.getChannel())
|
||||
.server(updatedPlace.getServer())
|
||||
.assignablePlace(updatedPlace)
|
||||
.build();
|
||||
updatedPlace.getMessagePosts().add(post);
|
||||
return post;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignedUserNotFoundException;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRole;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser;
|
||||
import dev.sheldan.abstracto.assignableroles.repository.AssignedRoleUserRepository;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AssignedRoleUserManagementServiceBean implements AssignedRoleUserManagementService {
|
||||
|
||||
@Autowired
|
||||
private AssignedRoleUserRepository repository;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Override
|
||||
public void addAssignedRoleToUser(AssignableRole assignableRole, AUserInAServer aUserInAServer) {
|
||||
Optional<AssignedRoleUser> optional = findByUserInServerOptional(aUserInAServer);
|
||||
log.info("Adding assignable role {} to user {} in server {} because of assignable role place {}.",
|
||||
assignableRole.getId(), aUserInAServer.getUserReference().getId(), aUserInAServer.getServerReference().getId(),
|
||||
assignableRole.getAssignablePlace().getId());
|
||||
AssignedRoleUser user = optional.orElseGet(() -> createAssignedRoleUser(aUserInAServer));
|
||||
assignableRole.getAssignedUsers().add(user);
|
||||
user.getRoles().add(assignableRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAssignedRoleFromUser(AssignableRole assignableRole, AUserInAServer aUserInAServer) {
|
||||
log.info("Removing assignable role {} from user {} in server {} in assignable role place {}.",
|
||||
assignableRole.getId(), aUserInAServer.getUserReference().getId(), aUserInAServer.getServerReference().getId(),
|
||||
assignableRole.getAssignablePlace().getId());
|
||||
AssignedRoleUser user = findByUserInServer(aUserInAServer);
|
||||
removeAssignedRoleFromUser(assignableRole, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAssignedRoleFromUser(AssignableRole assignableRole, AssignedRoleUser user) {
|
||||
assignableRole.getAssignedUsers().remove(user);
|
||||
user.getRoles().remove(assignableRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignedRoleUser createAssignedRoleUser(AUserInAServer aUserInAServer) {
|
||||
log.info("Creating assigned role user for user {} in server {}.", aUserInAServer.getUserReference().getId(), aUserInAServer.getServerReference().getId());
|
||||
AssignedRoleUser newUser = AssignedRoleUser.builder().user(aUserInAServer).id(aUserInAServer.getUserInServerId()).build();
|
||||
return repository.save(newUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<AssignedRoleUser> findByUserInServerOptional(AUserInAServer aUserInAServer) {
|
||||
return repository.findById(aUserInAServer.getUserInServerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<AssignedRoleUser> findByUserInServerOptional(ServerUser serverUser) {
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(serverUser);
|
||||
return findByUserInServerOptional(aUserInAServer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignedRoleUser findByUserInServer(AUserInAServer aUserInAServer) {
|
||||
return findByUserInServerOptional(aUserInAServer).orElseThrow(() -> new AssignedUserNotFoundException(aUserInAServer));
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
abstracto.featureFlags.emoteTracking.featureName=emoteTracking
|
||||
abstracto.featureFlags.emoteTracking.enabled=false
|
||||
@@ -1,89 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<property name="experienceModule" value="(SELECT id FROM module WHERE name = 'assignableRoles')"/>
|
||||
<property name="experienceFeature" value="(SELECT id FROM feature WHERE key = 'assignableRole')"/>
|
||||
<changeSet author="Sheldan" id="assignable_roles-commands">
|
||||
<insert tableName="command">
|
||||
<column name="name" value="addRoleToAssignableRolePlace"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="setupAssignableRolePlace"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="activateAssignableRolePlace"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="deactivateAssignableRolePlace"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="removeRoleFromAssignableRolePlace"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="changeAssignableRolePlaceConfig"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="setAssignableRolePosition"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="swapAssignableRolePosition"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="testAssignableRolePlace"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="deleteAssignableRolePlace"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="createAssignableRolePlace"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="showAssignableRolePlaceConfig"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="editAssignableRolePlaceText"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="moveAssignableRolePlace"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="showAssignableRolePlaces"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<include file="feature.xml" relativeToChangelogFile="true"/>
|
||||
<include file="module.xml" relativeToChangelogFile="true"/>
|
||||
<include file="command.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<changeSet author="Sheldan" id="assignable_role-feature-insertion">
|
||||
<insert tableName="feature">
|
||||
<column name="key" value="assignableRole"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<changeSet author="Sheldan" id="assignable_role-module-insertion">
|
||||
<insert tableName="module">
|
||||
<column name="name" value="assignableRoles"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -1,54 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<changeSet author="Sheldan" id="assignable_role-table">
|
||||
<createTable tableName="assignable_role">
|
||||
<column autoIncrement="true" name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="assignable_role_pkey"/>
|
||||
</column>
|
||||
<column name="emote_id" type="INTEGER">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="role_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="assignable_place_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="server_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="place_post_id" type="BIGINT">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="description" type="VARCHAR(255)"/>
|
||||
<column name="required_level" type="INTEGER"/>
|
||||
<column name="position" type="INTEGER">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseColumnNames="emote_id" baseTableName="assignable_role" constraintName="fk_assignable_role_emote" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="emote" validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="role_id" baseTableName="assignable_role" constraintName="fk_assignable_role_role" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="role" validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="assignable_place_id" baseTableName="assignable_role" constraintName="fk_assignable_role_place" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="assignable_role_place" validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="place_post_id" baseTableName="assignable_role" constraintName="fk_assignable_role_post" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="assignable_role_place_post" validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="server_id" baseTableName="assignable_role" constraintName="fk_assignable_role_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS assignable_role_update_trigger ON assignable_role;
|
||||
CREATE TRIGGER assignable_role_update_trigger BEFORE UPDATE ON assignable_role FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS assignable_role_insert_trigger ON assignable_role;
|
||||
CREATE TRIGGER assignable_role_insert_trigger BEFORE INSERT ON assignable_role FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -1,57 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<changeSet author="Sheldan" id="assignable_role_place-table">
|
||||
<createTable tableName="assignable_role_place">
|
||||
<column autoIncrement="true" name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="assignable_role_place_pkey"/>
|
||||
</column>
|
||||
<column name="channel_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="server_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="key" type="VARCHAR(255)">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="text" type="VARCHAR(255)"/>
|
||||
<column name="active" type="BOOLEAN">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="inline" type="BOOLEAN">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="unique_roles" type="BOOLEAN">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="auto_remove" type="BOOLEAN">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<createIndex indexName="idx_assignable_role_place" tableName="assignable_role_place">
|
||||
<column name="server_id"/>
|
||||
<column name="key"/>
|
||||
</createIndex>
|
||||
<addForeignKeyConstraint baseColumnNames="channel_id" baseTableName="assignable_role_place" constraintName="fk_assignable_role_place_channel" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="channel" validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="server_id" baseTableName="assignable_role_place" constraintName="fk_assignable_role_place_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS assignable_role_place_update_trigger ON assignable_role_place;
|
||||
CREATE TRIGGER assignable_role_place_update_trigger BEFORE UPDATE ON assignable_role_place FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS assignable_role_place_insert_trigger ON assignable_role_place;
|
||||
CREATE TRIGGER assignable_role_place_insert_trigger BEFORE INSERT ON assignable_role_place FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -1,41 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<changeSet author="Sheldan" id="assignable_role_place_post-table">
|
||||
<createTable tableName="assignable_role_place_post">
|
||||
<column autoIncrement="true" name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="assignable_role_place_post_pkey"/>
|
||||
</column>
|
||||
<column name="assignable_place_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="channel_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="server_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseColumnNames="assignable_place_id" baseTableName="assignable_role_place_post" constraintName="fk_assignable_role_place_post_place_id" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="assignable_role_place" validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="server_id" baseTableName="assignable_role_place_post" constraintName="fk_assignable_role_place_post_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="channel_id" baseTableName="assignable_role_place_post" constraintName="fk_assignable_role_place_post_channel" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="channel" validate="true"/>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS assignable_role_place_post_update_trigger ON assignable_role_place_post;
|
||||
CREATE TRIGGER assignable_role_place_post_update_trigger BEFORE UPDATE ON assignable_role_place_post FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS assignable_role_place_post_insert_trigger ON assignable_role_place_post;
|
||||
CREATE TRIGGER assignable_role_place_post_insert_trigger BEFORE INSERT ON assignable_role_place_post FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -1,42 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<changeSet author="Sheldan" id="assigned_role_user-table">
|
||||
<createTable tableName="assigned_role_user">
|
||||
<column name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="assigned_role_user_pkey"/>
|
||||
</column>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseColumnNames="id" baseTableName="assigned_role_user" constraintName="fk_assigned_role_user_user" 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 assigned_role_user_update_trigger ON assigned_role_user;
|
||||
CREATE TRIGGER assigned_role_user_update_trigger BEFORE UPDATE ON assigned_role_user FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS assigned_role_user_insert_trigger ON assigned_role_user;
|
||||
CREATE TRIGGER assigned_role_user_insert_trigger BEFORE INSERT ON assigned_role_user FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
<changeSet author="Sheldan" id="assigned_role_in_user-table">
|
||||
<createTable tableName="assigned_role_in_user">
|
||||
<column name="assigned_role_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="user_in_server_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseColumnNames="assigned_role_id" baseTableName="assigned_role_in_user" constraintName="fk_assigned_role_in_user_assignable_role" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="assignable_role" validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="user_in_server_id" baseTableName="assigned_role_in_user" constraintName="fk_assigned_role_in_user_assigned_user" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="assigned_role_user" validate="true"/>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -1,13 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<include file="assignable_role_place.xml" relativeToChangelogFile="true"/>
|
||||
<include file="assignable_role_place_post.xml" relativeToChangelogFile="true"/>
|
||||
<include file="assignable_role.xml" relativeToChangelogFile="true"/>
|
||||
<include file="assigned_role_user.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../dbchangelog-3.8.xsd" >
|
||||
<include file="assignableRoles-tables/tables.xml" relativeToChangelogFile="true"/>
|
||||
<include file="assignableRoles-seedData/data.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -1,10 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog-3.8.xsd" >
|
||||
<include file="1.0-assignableRoles/collection.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,12 +0,0 @@
|
||||
<?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>assignable-roles</artifactId>
|
||||
<version>1.2.10</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>assignable-roles-int</artifactId>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -1,13 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AssignableFeatureConfig implements FeatureConfig {
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return AssignableRoleFeatureDefinition.ASSIGNABLE_ROLES;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum AssignableRoleFeatureDefinition implements FeatureDefinition {
|
||||
ASSIGNABLE_ROLES("assignableRole");
|
||||
|
||||
private String key;
|
||||
|
||||
AssignableRoleFeatureDefinition(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandParameterKey;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* This enum is used to define the different key for which there exist properties on an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace}.
|
||||
* And is used for the command parameter when changing the value of an attribute on this place.
|
||||
*/
|
||||
@Getter
|
||||
public enum AssignableRolePlaceParameterKey implements CommandParameterKey {
|
||||
INLINE, UNIQUE, AUTOREMOVE, ACTIVE
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.exception;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.exception.AssignableRoleAlreadyDefinedExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public class AssignableRoleAlreadyDefinedException extends AbstractoRunTimeException implements Templatable {
|
||||
private final AssignableRoleAlreadyDefinedExceptionModel model;
|
||||
|
||||
public AssignableRoleAlreadyDefinedException(FullEmote emote, String placeName) {
|
||||
super("Assignable role already assigned");
|
||||
this.model = AssignableRoleAlreadyDefinedExceptionModel.builder().emote(emote).placeName(placeName).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "assignable_role_place_emote_already_defined_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.exception;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.exception.AssignableRoleNotUsableExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.FullRole;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
|
||||
/**
|
||||
* Exception thrown in case the defined {@link net.dv8tion.jda.api.entities.Role role} cannot be interacted with by the bot,
|
||||
* because of permissions, this can happen if the role is the same or higher than the bot, therefore cannot be given to
|
||||
* {@link net.dv8tion.jda.api.entities.Member members}
|
||||
*/
|
||||
public class AssignableRoleNotUsableException extends AbstractoRunTimeException implements Templatable {
|
||||
private final AssignableRoleNotUsableExceptionModel model;
|
||||
|
||||
public AssignableRoleNotUsableException(FullRole role, Guild guild) {
|
||||
super("Role is not usable as assignable role");
|
||||
this.model = AssignableRoleNotUsableExceptionModel.builder().role(role).guild(guild).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "assignable_role_place_role_not_usable_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.exception;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.exception.AssignableRolePlaceAlreadyExistsExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
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}
|
||||
*/
|
||||
public class AssignableRolePlaceAlreadyExistsException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final AssignableRolePlaceAlreadyExistsExceptionModel model;
|
||||
|
||||
public AssignableRolePlaceAlreadyExistsException(String name) {
|
||||
super("Assignable role place already exists");
|
||||
this.model = AssignableRolePlaceAlreadyExistsExceptionModel.builder().name(name).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "assignable_role_place_exists_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.exception;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.exception.AssignableRolePlaceChannelDoesNotExistExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
|
||||
/**
|
||||
* Exception thrown in case the {@link dev.sheldan.abstracto.core.models.database.AChannel channel} in which a
|
||||
* {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place} is defined, does not exist
|
||||
*/
|
||||
public class AssignableRolePlaceChannelDoesNotExistException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final AssignableRolePlaceChannelDoesNotExistExceptionModel model;
|
||||
|
||||
public AssignableRolePlaceChannelDoesNotExistException(Long channelId, String placeName) {
|
||||
super("Assignable role place channel does not exist");
|
||||
this.model = AssignableRolePlaceChannelDoesNotExistExceptionModel.builder().channelId(channelId).placeName(placeName).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "assignable_role_place_channel_does_not_exist_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return this.model;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.exception;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.exception.AssignableRolePlaceNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
|
||||
/**
|
||||
* Exception which is thrown in case a {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
* defined by a {@link String key} does not exist
|
||||
*/
|
||||
public class AssignableRolePlaceNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final AssignableRolePlaceNotFoundExceptionModel model;
|
||||
|
||||
public AssignableRolePlaceNotFoundException(Long placeId) {
|
||||
super("Assignable role place not found");
|
||||
this.model = AssignableRolePlaceNotFoundExceptionModel.builder().placeId(placeId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "assignable_role_place_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.exception;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.exception.AssignableRolePlacePostNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
|
||||
/**
|
||||
* Exception which is thrown, in case the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost post}
|
||||
* was not found via its message ID
|
||||
*/
|
||||
public class AssignableRolePlacePostNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final AssignableRolePlacePostNotFoundExceptionModel model;
|
||||
|
||||
public AssignableRolePlacePostNotFoundException(Long messageId) {
|
||||
super("Assignable place post not found.");
|
||||
this.model = AssignableRolePlacePostNotFoundExceptionModel.builder().messageId(messageId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "assignable_role_place_post_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.exception;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.exception.AssignedUserNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
|
||||
/**
|
||||
* Exception which is thrown in case an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser user}
|
||||
* was not found.
|
||||
*/
|
||||
public class AssignedUserNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final AssignedUserNotFoundExceptionModel model;
|
||||
|
||||
public AssignedUserNotFoundException(AUserInAServer userInAServer) {
|
||||
super("Assigned user was not found");
|
||||
this.model = AssignedUserNotFoundExceptionModel.builder().aUserInAServer(userInAServer).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "assignable_role_place_assigned_user_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.exception;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.exception.EmoteNotInAssignableRolePlaceExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
|
||||
/**
|
||||
* Exception which is thrown in case a given {@link dev.sheldan.abstracto.core.models.database.AEmote} was not found
|
||||
* in the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace}, when it was tried to switch
|
||||
* or move the emotes around.
|
||||
*/
|
||||
public class EmoteNotInAssignableRolePlaceException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final EmoteNotInAssignableRolePlaceExceptionModel model;
|
||||
|
||||
public EmoteNotInAssignableRolePlaceException(FullEmote emote, String placeName) {
|
||||
super("Emote not found in assignable role place");
|
||||
this.model = EmoteNotInAssignableRolePlaceExceptionModel.builder().emote(emote).placeName(placeName).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "emote_not_in_assignable_role_place_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A {@link ARole role} which can be mapped to an {@link AssignableRolePlace ṕlace}. This is uniquely defined by an emote on the
|
||||
* respective assignable role place, but the same role can be given via different {@link AEmote emote}
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "assignable_role")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class AssignableRole implements Serializable {
|
||||
|
||||
/**
|
||||
* The unique ID of this {@link AssignableRole assignableRole}
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* The {@link AEmote emote} this role is associated with
|
||||
*/
|
||||
@OneToOne(fetch = FetchType.LAZY, orphanRemoval = true)
|
||||
@JoinColumn(name = "emote_id")
|
||||
private AEmote emote;
|
||||
|
||||
/**
|
||||
* The {@link ARole} which given via this {@link AssignableRole assignableRole}
|
||||
*/
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "role_id", nullable = false)
|
||||
private ARole role;
|
||||
|
||||
/**
|
||||
* The {@link AServer server} in which this {@link AssignableRole assignableRole} is used
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "server_id", nullable = false)
|
||||
private AServer server;
|
||||
|
||||
/**
|
||||
* The {@link AssignableRolePlace} this assignable role is in
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@JoinColumn(name = "assignable_place_id", nullable = false)
|
||||
private AssignableRolePlace assignablePlace;
|
||||
|
||||
/**
|
||||
* The {@link AssignableRolePlacePost} this assignable role is currently available as a reaction.
|
||||
* This is necessary, to easier find the reaction which are valid, in case a reaction is added to a post
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@JoinColumn(name = "place_post_id")
|
||||
private AssignableRolePlacePost assignableRolePlacePost;
|
||||
|
||||
/**
|
||||
* The {@link AssignedRoleUser users} which currently have this role assigned via this mechanism.
|
||||
* This is necessary to enforce the unique property of {@link AssignableRolePlace}, in which you only may chose one
|
||||
* role.
|
||||
*/
|
||||
@ManyToMany(mappedBy = "roles")
|
||||
@Builder.Default
|
||||
private List<AssignedRoleUser> assignedUsers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The description which is shown in the embeds of the posts of the {@link AssignableRolePlace}
|
||||
*/
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* The level in experience which is required in order to receive this {@link AssignableRole}
|
||||
*/
|
||||
@Column(name = "required_level")
|
||||
private Integer requiredLevel;
|
||||
|
||||
/**
|
||||
* The position of this assignable role within the {@link AssignableRole}. This is required in order to show them
|
||||
* the same order as the descriptions in the fields and also to move them around and switch positions
|
||||
*/
|
||||
@Column(name = "position")
|
||||
private Integer position;
|
||||
|
||||
/**
|
||||
* The {@link Instant} this entity was created
|
||||
*/
|
||||
@Column(name = "created")
|
||||
private Instant created;
|
||||
|
||||
/**
|
||||
* The {@link Instant} this entity was updated
|
||||
*/
|
||||
@Column(name = "updated")
|
||||
private Instant updated;
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The place entity holding the {@link AssignableRole roles} and {@link AssignableRolePlacePost posts} together.
|
||||
* This is also the entity holding all the configuration for the place and is identified by a key as a String, which is unique
|
||||
* for each server. This place holds the {@link AChannel} in which the
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "assignable_role_place")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class AssignableRolePlace implements Serializable {
|
||||
|
||||
public static final Long ASSIGNABLE_PLACE_NAME_LIMIT = 255L;
|
||||
public static final Long ASSIGNABLE_PLACE_DESCRIPTION_LIMIT = 255L;
|
||||
|
||||
/**
|
||||
* A unique ID created
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* The channel in which the {@link AssignableRolePlacePost posts} for this place should be created
|
||||
*/
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name="channel_id")
|
||||
private AChannel channel;
|
||||
|
||||
/**
|
||||
* The {@link AServer server} for which this place is configured for. Unique in combination with the key
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "server_id", nullable = false)
|
||||
private AServer server;
|
||||
|
||||
/**
|
||||
* The key this place is associated with via commands. Unique per server.
|
||||
*/
|
||||
@Column(name = "key")
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* The {@link AssignableRolePlacePost posts} which were created when this place was setup. Is empty in the beginning
|
||||
* and actively maintained in case a post is deleted.
|
||||
*/
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
orphanRemoval = true,
|
||||
mappedBy = "assignablePlace"
|
||||
)
|
||||
@Builder.Default
|
||||
private List<AssignableRolePlacePost> messagePosts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A List containing the {@link AssignableRole} which are associated with this place
|
||||
*/
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
orphanRemoval = true,
|
||||
mappedBy = "assignablePlace"
|
||||
)
|
||||
@Builder.Default
|
||||
private List<AssignableRole> assignableRoles = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The text which is displayed in the first description area of the created {@link AssignableRolePlacePost}
|
||||
*/
|
||||
@Column(name = "text")
|
||||
private String text;
|
||||
|
||||
/**
|
||||
* Whether or not the reactions placed onto the posts should be acted upon
|
||||
*/
|
||||
@Builder.Default
|
||||
@Column(name = "active")
|
||||
private Boolean active = true;
|
||||
|
||||
/**
|
||||
* Whether or not the fields containing the descriptions should be inline
|
||||
*/
|
||||
@Builder.Default
|
||||
@Column(name = "inline")
|
||||
private Boolean inline = false;
|
||||
|
||||
/**
|
||||
* Whether or not it should be restricted, that a {@link AssignedRoleUser} should only have one role of this place
|
||||
*/
|
||||
@Builder.Default
|
||||
@Column(name = "unique_roles")
|
||||
private Boolean uniqueRoles = false;
|
||||
|
||||
/**
|
||||
* Whether or not the added reactions should be removed automatically
|
||||
*/
|
||||
@Builder.Default
|
||||
@Column(name = "auto_remove")
|
||||
private Boolean autoRemove = false;
|
||||
|
||||
/**
|
||||
* The {@link Instant} this entity was created
|
||||
*/
|
||||
@Column(name = "created")
|
||||
private Instant created;
|
||||
|
||||
/**
|
||||
* The {@link Instant} this entity was updated
|
||||
*/
|
||||
@Column(name = "updated")
|
||||
private Instant updated;
|
||||
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* One individual {@link net.dv8tion.jda.api.entities.Message message} which was sent when setting up an {@link AssignableRolePlace place}
|
||||
* and contains the embeds and the reactions were placed onto it.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "assignable_role_place_post")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class AssignableRolePlacePost implements Serializable {
|
||||
|
||||
/**
|
||||
* The ID of the {@link net.dv8tion.jda.api.entities.Message message} which represents this post with the reactions.
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* The actual {@link AChannel channel} in which the post ended up in
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "channel_id")
|
||||
private AChannel usedChannel;
|
||||
|
||||
/**
|
||||
* The {@link AServer server} in which this place post is posted
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "server_id", nullable = false)
|
||||
private AServer server;
|
||||
|
||||
/**
|
||||
* The {@link AssignableRolePlace place} this post is associated with
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@JoinColumn(name = "assignable_place_id", nullable = false)
|
||||
private AssignableRolePlace assignablePlace;
|
||||
|
||||
/**
|
||||
* The actual {@link AssignableRole assignableRoles} which are associated with this post, and whose respective {@link dev.sheldan.abstracto.core.models.database.AEmote}
|
||||
* have been placed as reactions
|
||||
*/
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
mappedBy = "assignableRolePlacePost")
|
||||
@Builder.Default
|
||||
private List<AssignableRole> assignableRoles = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The {@link Instant} this entity was created
|
||||
*/
|
||||
@Column(name = "created")
|
||||
private Instant created;
|
||||
|
||||
/**
|
||||
* The {@link Instant} this entity was updated
|
||||
*/
|
||||
@Column(name = "updated")
|
||||
private Instant updated;
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A {@link AUserInAServer userInAServer} which added a reaction to an {@link AssignableRolePlace place}.
|
||||
* This is required in order to guarantee the uniqueness (if desired) of {@link AssignableRole} per place.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "assigned_role_user")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class AssignedRoleUser implements Serializable {
|
||||
|
||||
/**
|
||||
* The ID of the associated {@link AUserInAServer userInAServer}
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@PrimaryKeyJoinColumn
|
||||
private AUserInAServer user;
|
||||
|
||||
/**
|
||||
* The {@link AssignableRole assignableRoles} this user has in the server
|
||||
*/
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "assigned_role_in_user",
|
||||
joinColumns = @JoinColumn(name = "user_in_server_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "assigned_role_id"))
|
||||
@Builder.Default
|
||||
private List<AssignableRole> roles = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The {@link Instant} this entity was created
|
||||
*/
|
||||
@Column(name = "created")
|
||||
private Instant created;
|
||||
|
||||
/**
|
||||
* The {@link Instant} this entity was updated
|
||||
*/
|
||||
@Column(name = "updated")
|
||||
private Instant updated;
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.FullEmote;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exception.AssignableRoleAlreadyDefinedException}
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class AssignableRoleAlreadyDefinedExceptionModel implements Serializable {
|
||||
/**
|
||||
* The {@link FullEmote emote} which was tried to be added to a {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
private final FullEmote emote;
|
||||
/**
|
||||
* The key of the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace} for which it was tried to add a
|
||||
* {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole role}
|
||||
*/
|
||||
private final String placeName;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.FullRole;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlaceNotFoundException}
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class AssignableRoleNotUsableExceptionModel implements Serializable {
|
||||
/**
|
||||
* The {@link FullRole role} which is not usable as an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole role}
|
||||
*/
|
||||
private final FullRole role;
|
||||
/**
|
||||
* The {@link Guild server} in which it was not possible to use the {@link net.dv8tion.jda.api.entities.Role role}
|
||||
*/
|
||||
private final transient Guild guild;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.exception;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlaceAlreadyExistsException}
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class AssignableRolePlaceAlreadyExistsExceptionModel implements Serializable {
|
||||
/**
|
||||
* The key which collides with an existing {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace}
|
||||
*/
|
||||
private final String name;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.exception;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlaceChannelDoesNotExistException;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Contains the model for {@link AssignableRolePlaceChannelDoesNotExistException}
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class AssignableRolePlaceChannelDoesNotExistExceptionModel implements Serializable {
|
||||
/**
|
||||
* The ID of the {@link dev.sheldan.abstracto.core.models.database.AChannel channel} which does not exist in the {@link net.dv8tion.jda.api.entities.Guild}
|
||||
*/
|
||||
private final Long channelId;
|
||||
/**
|
||||
* The key of the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place} for which
|
||||
* the channel does not exist anymore in the {@link net.dv8tion.jda.api.entities.Guild}
|
||||
*/
|
||||
private final String placeName;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.exception;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlaceNotFoundException}
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class AssignableRolePlaceNotFoundExceptionModel implements Serializable {
|
||||
/**
|
||||
* The ID of the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place} which was not found
|
||||
*/
|
||||
private final Long placeId;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.exception;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlacePostNotFoundException}
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class AssignableRolePlacePostNotFoundExceptionModel implements Serializable {
|
||||
/**
|
||||
* The ID of the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost post} which was not found in the database
|
||||
*/
|
||||
private final Long messageId;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exception.AssignedUserNotFoundException}
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class AssignedUserNotFoundExceptionModel implements Serializable {
|
||||
/**
|
||||
* The instance of the {@link AUserInAServer userInAServer} for which the assigned user was not found
|
||||
*/
|
||||
private final AUserInAServer aUserInAServer;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.FullEmote;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exception.EmoteNotInAssignableRolePlaceException}
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class EmoteNotInAssignableRolePlaceExceptionModel implements Serializable {
|
||||
/**
|
||||
* The {@link FullEmote emote} which was not found in the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
private final FullEmote emote;
|
||||
/**
|
||||
* The key of the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place} for which the emote was not found in
|
||||
*/
|
||||
private final String placeName;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Model used to render the overview over all {@link AssignableRolePlace places}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class AssignablePlaceOverview {
|
||||
/**
|
||||
* The {@link AssignableRolePlace places} in the server to display
|
||||
*/
|
||||
@Builder.Default
|
||||
private List<AssignableRolePlace> places = new ArrayList<>();
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Model used to render the {@link AssignableRolePlace place}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class AssignablePostMessage {
|
||||
/**
|
||||
* The {@link AssignableRolePlace place} to render
|
||||
*/
|
||||
private AssignableRolePlace place;
|
||||
/**
|
||||
* The awarded {@link AssignablePostRole roles} for this {@link AssignableRolePlace place}
|
||||
*/
|
||||
private List<AssignablePostRole> roles;
|
||||
/**
|
||||
* The highest number of the position within the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole} of the
|
||||
* {@link AssignableRolePlace place}
|
||||
*/
|
||||
private Integer maxPosition;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.template;
|
||||
|
||||
|
||||
import dev.sheldan.abstracto.core.models.FullEmote;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* The model which is used to render the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost post}
|
||||
* to a {@link dev.sheldan.abstracto.core.templating.model.MessageToSend messageToSend} for one individual {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole role}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class AssignablePostRole {
|
||||
/**
|
||||
* The {@link FullEmote emote} to be used in the field
|
||||
*/
|
||||
private FullEmote emote;
|
||||
/**
|
||||
* The description to be used in the field
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* The relative position within the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place} of this
|
||||
* {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole role}
|
||||
*/
|
||||
private Integer position;
|
||||
/**
|
||||
* Whether or not this field should be at the beginning of a new {@link net.dv8tion.jda.api.entities.Message message}
|
||||
* to be send
|
||||
*/
|
||||
@Builder.Default
|
||||
private Boolean forceNewMessage = false;
|
||||
/**
|
||||
* Whether or not the field should be displayed inline
|
||||
*/
|
||||
private Boolean inline;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This model is used as a container to display the configuration of an {@link AssignableRolePlace place}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class AssignableRolePlaceConfig {
|
||||
/**
|
||||
* The {@link AssignableRolePlace place} to show the config of
|
||||
*/
|
||||
private AssignableRolePlace place;
|
||||
/**
|
||||
* The {@link AssignableRolePlaceConfig roles} which are contained in this {@link AssignableRolePlace}
|
||||
*/
|
||||
private List<AssignableRolePlaceConfigRole> roles;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.model.template;
|
||||
|
||||
|
||||
import dev.sheldan.abstracto.core.models.FullEmote;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
|
||||
/**
|
||||
* Model used to display the configuration of an individual {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole}
|
||||
* within an {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace place}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class AssignableRolePlaceConfigRole {
|
||||
/**
|
||||
* The description used for the field for this {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole role}
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* The position of this {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole role}
|
||||
*/
|
||||
private Integer position;
|
||||
/**
|
||||
* Whether or not the field is displayed inline
|
||||
*/
|
||||
private Boolean inline;
|
||||
/**
|
||||
* The {@link FullEmote emote} which is associated with this {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRole role}
|
||||
*/
|
||||
private FullEmote emote;
|
||||
/**
|
||||
* The {@link dev.sheldan.abstracto.core.models.database.ARole} which is given/removed upon reacting with the emote
|
||||
*/
|
||||
private Role awardedRole;
|
||||
}
|
||||
@@ -1,431 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.config.AssignableRolePlaceParameterKey;
|
||||
import dev.sheldan.abstracto.assignableroles.exception.EmoteNotInAssignableRolePlaceException;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRole;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser;
|
||||
import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException;
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotInGuildException;
|
||||
import dev.sheldan.abstracto.core.models.FullEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageReaction;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Service responsible to manage actions on an {@link AssignableRolePlace assignableRolePlace}
|
||||
*/
|
||||
public interface AssignableRolePlaceService {
|
||||
/**
|
||||
* Creates a {@link AssignableRolePlace place} with the given parameters
|
||||
* @param name The key of the {@link AssignableRolePlace} to be used
|
||||
* @param channel The {@link AChannel channel} in which the posts of this {@link AssignableRolePlace place} should be posted, also determines
|
||||
* the {@link AServer server} in which the place should reside in. This {@link AServer server} needs to be unique in combination with the
|
||||
* key
|
||||
* @param text The description of the {@link AssignableRolePlace place} which is displayed in the first post of the place
|
||||
* @throws dev.sheldan.abstracto.assignableroles.exception.AssignableRoleAlreadyDefinedException if the combination of {@link AServer server}
|
||||
* and {@link AssignableRolePlace#key} already exists
|
||||
*/
|
||||
void createAssignableRolePlace(String name, AChannel channel, String text);
|
||||
|
||||
/**
|
||||
* Whether or not the {@link AssignableRolePlace place} already has the given {@link AEmote emote} as an {@link AssignableRole role}
|
||||
* with the given {@link AEmote emote}
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} should be in
|
||||
* @param placeName The key of an {@link AssignableRolePlace place} to check
|
||||
* @param emote The {@link AEmote emote} which is sought after
|
||||
* @return Whether or not the {@link AssignableRolePlace place} already has an {@link AssignableRole role}
|
||||
* with the associated {@link AEmote emote}
|
||||
*/
|
||||
boolean hasAssignableRolePlaceEmote(AServer server, String placeName, AEmote emote);
|
||||
|
||||
/**
|
||||
* Whether or not the {@link AssignableRolePlace place} (identified by {@link AServer server} and placeName) already has
|
||||
* the given {@link AEmote emote} as an {@link AssignableRole role}
|
||||
* with the given {@link AEmote emote}
|
||||
* @param place The {@link AssignableRolePlace place} in which the {@link AEmote emote} should be sought in
|
||||
* @param emote The {@link AEmote emote} which is sought after
|
||||
* @return Whether or not the {@link AssignableRolePlace place} already has an {@link AssignableRole role}
|
||||
* with the associated {@link AEmote emote}
|
||||
*/
|
||||
boolean hasAssignableRolePlaceEmote(AssignableRolePlace place, AEmote emote);
|
||||
|
||||
/**
|
||||
* Whether or not the {@link AssignableRolePlace place} has the position used. Each of the {@link AssignableRole roles}
|
||||
* in the {@link AssignableRolePlace place} has a position in which it is posted. This is used to order the roles when posting them. This position is an {@link Integer integer}
|
||||
* and it is not guaranteed every position up until the amount of {@link AssignableRole roles} is used.
|
||||
* There can be spots, it is only used as an ordering and to swap/move {@link AssignableRole roles}
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} should be in
|
||||
* @param placeName The key of the {@link AssignableRolePlace place}
|
||||
* @param position The position of an {@link AssignableRole role} within the place
|
||||
* @return Whether or not there exists an {@link AssignableRole role} within the
|
||||
* {@link AssignableRolePlace place} identified by the {@link AServer server} and key
|
||||
*/
|
||||
boolean isPositionUsed(AServer server, String placeName, Integer position);
|
||||
|
||||
/**
|
||||
* Sets the {@link AssignableRole role} identified by the
|
||||
* {@link FullEmote emote} to the given {@link Integer position} in the {@link AssignableRolePlace place} identified by the
|
||||
* {@link AServer server} and key.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} should be
|
||||
* @param placeName The key of the {@link AssignableRolePlace place}
|
||||
* @param emote The {@link FullEmote emote} which identifies the {@link AssignableRole role}
|
||||
* which position should be changed
|
||||
* @param position The new position of the {@link AssignableRole role}
|
||||
* within the place
|
||||
* @throws AbstractoTemplatedException if the position is already used or the {@link FullEmote emote} has not associated {@link AssignableRole role}
|
||||
* within the place
|
||||
*/
|
||||
void setEmoteToPosition(AServer server, String placeName, FullEmote emote, Integer position);
|
||||
|
||||
/**
|
||||
* Adds the given {@link ARole role} to the {@link AssignableRolePlace place} identified by the {@link AServer server} and key
|
||||
* in the form as a {@link AssignableRole role}. This role is identified
|
||||
* by the given {@link FullEmote emote} and has the description. If the {@link AssignableRolePlace place} is already setup, this will
|
||||
* try to update the message: adding the field and the reaction. This might not always work e.g. the reaction limit was reached.
|
||||
* If the update is successful, it will also store the updates in the database.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is present
|
||||
* @param placeName The key of the {@link AssignableRolePlace place}
|
||||
* @param role The {@link ARole role} which should be awarded when reacting with the given {@link FullEmote emote}
|
||||
* @param emote The {@link FullEmote emote} which should be placed on the {@link Message message}
|
||||
* to react to and identify the {@link AssignableRole}
|
||||
* for this place
|
||||
* @param description The description which will be displayed in the {@link Message message}
|
||||
* which has the reactions
|
||||
* @throws dev.sheldan.abstracto.core.exception.EmoteNotUsableException in case the {@link net.dv8tion.jda.api.entities.Emote emote}
|
||||
* cannot be used by the current user. This might be an issue, if its from an external {@link net.dv8tion.jda.api.entities.Guild}
|
||||
* the user is not a part of.
|
||||
* @return A {@link CompletableFuture future} when the {@link Message message} has been updated
|
||||
* and the {@link MessageReaction reaction} has been added. Only tries to execute this, in case there
|
||||
* {@link AssignableRolePlacePost posts} known.
|
||||
*/
|
||||
CompletableFuture<Void> addRoleToAssignableRolePlace(AServer server, String placeName, ARole role, FullEmote emote, String description);
|
||||
|
||||
/**
|
||||
* Removes the given {@link AssignableRole role} from the {@link AssignableRolePlace place}
|
||||
* identified by the {@link AServer server} and the key. The {@link AssignableRole role} is identified
|
||||
* by the {@link FullEmote emote} which is associated to it. If there are already {@link AssignableRolePlacePost posts}
|
||||
* for this {@link AssignableRolePlace place} this will remove the {@link MessageReaction reaction} and
|
||||
* edit the {@link Message message}. If not, the method returns immediately. If the update
|
||||
* was successful or was not necessary, the data will be updated in the database as well.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param placeName The key of the {@link AssignableRolePlace place} to remove an {@link AssignableRole role}
|
||||
* from
|
||||
* @param emote The {@link FullEmote fullEmote} which has an {@link AEmote emote} to identify the {@link AssignableRole role}
|
||||
* to remove
|
||||
* @return A {@link CompletableFuture future} which completes when the {@link MessageReaction reaction}
|
||||
* was removed and the {@link Message message} updated and the database updated, or, if no post is present, only if the database was updated
|
||||
*/
|
||||
CompletableFuture<Void> removeRoleFromAssignableRolePlace(AServer server, String placeName, FullEmote emote);
|
||||
|
||||
/**
|
||||
* This method is used to setup the {@link AssignableRolePlacePost} for an
|
||||
* {@link AssignableRolePlace place}. If there are previous {@link AssignableRolePlacePost posts},
|
||||
* this method will delete them first. This method does not do the rendering, but is only the entry point for the process.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key which identifies the {@link AssignableRolePlace place} within the {@link AServer server}
|
||||
* @return A {@link CompletableFuture future} which completes if the complete setup is finished successfully.
|
||||
*/
|
||||
CompletableFuture<Void> setupAssignableRolePlace(AServer server, String name);
|
||||
|
||||
/**
|
||||
* This method is used to update the {@link AssignableRolePlacePost posts}
|
||||
* of the {@link AssignableRolePlace place} identified by the {@link AServer server} and the key. This
|
||||
* effectively re-renders the template for an {@link AssignableRolePlace place} and updates the existing
|
||||
* {@link AssignableRolePlacePost posts} accordingly. In case there are no posts, this method returns immediately.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @throws ChannelNotInGuildException if the channel which contained the posts does not exist anymore
|
||||
* @return A {@link CompletableFuture future} which completes successfully if *every* update was successful.
|
||||
*/
|
||||
CompletableFuture<Void> refreshAssignablePlacePosts(AServer server, String name);
|
||||
|
||||
/**
|
||||
* This method is used to update the {@link AssignableRolePlacePost posts}
|
||||
* of the {@link AssignableRolePlace place}. This effectively re-renders the template for an
|
||||
* {@link AssignableRolePlace place} and updates the existing {@link AssignableRolePlacePost posts} accordingly.
|
||||
* In case there are no posts, this method returns immediately.
|
||||
* @param place The {@link AssignableRolePlace place} which should have their {@link Message messages} were updated
|
||||
* @throws ChannelNotInGuildException if the channel which contained the posts does not exist anymore
|
||||
* @return A {@link CompletableFuture future} which completes successfully if *every* update was successful.
|
||||
*/
|
||||
CompletableFuture<Void> refreshAssignablePlacePosts(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* This method updates the first {@link AssignableRolePlacePost posts} which contains the description of the
|
||||
* {@link AssignableRolePlace place}. If there are no posts, this method will return immediately
|
||||
* @param place The {@link AssignableRolePlace place} to update the
|
||||
* @throws ChannelNotInGuildException if the channel which contained the post does not exist anymore
|
||||
* @return A {@link CompletableFuture future} which completes when the update of the {@link Message message}
|
||||
* was completed
|
||||
*/
|
||||
CompletableFuture<Void> refreshTextFromPlace(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* Sets the active attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param newValue The new vale of the active attribute
|
||||
*/
|
||||
void setAssignablePlaceActiveTo(AServer server, String name, Boolean newValue);
|
||||
|
||||
/**
|
||||
* Activates the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place} to activate
|
||||
*/
|
||||
void activateAssignableRolePlace(AServer server, String name);
|
||||
|
||||
/**
|
||||
* Activates the {@link AssignableRolePlace place}, which means that the activate attribute will be set to true
|
||||
* @param place The {@link AssignableRolePlace place} to activate
|
||||
*/
|
||||
void activateAssignableRolePlace(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* De-activates the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place} to de-activate
|
||||
*/
|
||||
void deactivateAssignableRolePlace(AServer server, String name);
|
||||
|
||||
/**
|
||||
* De-activates the {@link AssignableRolePlace place}, which means that the activate attribute will be set to false
|
||||
* @param place The {@link AssignableRolePlace place} to de-activate
|
||||
*/
|
||||
void deactivateAssignableRolePlace(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* Sets the inline attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key. This method will update any existing {@link AssignableRolePlacePost posts} of the place, if there
|
||||
* are any.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param newValue The new vale of the inline attribute
|
||||
* @return A {@link CompletableFuture future} which completes when the config has been updated, or when the message was edited (if the posts already exist)
|
||||
*/
|
||||
CompletableFuture<Void> setAssignablePlaceInlineTo(AServer server, String name, Boolean newValue);
|
||||
|
||||
/**
|
||||
* Sets the inline attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key to true. This method will update any existing {@link AssignableRolePlacePost posts} of the place, if there
|
||||
* are any.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place} to inline
|
||||
* @return A {@link CompletableFuture future} which completes when the config has been updated, or when the message was edited (if the posts already exist)
|
||||
*/
|
||||
CompletableFuture<Void> inlineAssignableRolePlace(AServer server, String name);
|
||||
|
||||
/**
|
||||
* Sets the inline attribute of the {@link AssignableRolePlace place} to true. This method will update any existing
|
||||
* {@link AssignableRolePlacePost posts} of the place, if there are any.
|
||||
* @param place The {@link AssignableRolePlace place} to inline
|
||||
* @return A {@link CompletableFuture future} which completes when the config has been updated, or when the message was edited (if the posts already exist)
|
||||
*/
|
||||
CompletableFuture<Void> inlineAssignableRolePlace(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* Sets the inline attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key to false. This method will update any existing {@link AssignableRolePlacePost posts} of the place, if there
|
||||
* are any.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place} to spread
|
||||
* @return A {@link CompletableFuture future} which completes when the config has been updated, or when the message was edited (if the posts already exist)
|
||||
*/
|
||||
CompletableFuture<Void> spreadAssignableRolePlace(AServer server, String name);
|
||||
|
||||
/**
|
||||
* Sets the inline attribute of the {@link AssignableRolePlace place} to false. This method will update any existing
|
||||
* {@link AssignableRolePlacePost posts} of the place, if there are any.
|
||||
* @param place The {@link AssignableRolePlace place} to spread
|
||||
* @return A {@link CompletableFuture future} which completes when the config has been updated, or when the message was edited (if the posts already exist)
|
||||
*/
|
||||
CompletableFuture<Void> spreadAssignableRolePlace(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* Sets the unique attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param newValue The new vale of the unique attribute
|
||||
*/
|
||||
void setAssignablePlaceUniqueTo(AServer server, String name, Boolean newValue);
|
||||
|
||||
/**
|
||||
* Sets the unique attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key to true.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place} to activate unique role handling
|
||||
*/
|
||||
void uniqueAssignableRolePlace(AServer server, String name);
|
||||
|
||||
/**
|
||||
* Sets the unique attribute of the {@link AssignableRolePlace place} to true.
|
||||
* @param place The {@link AssignableRolePlace place} to activate unique role handling
|
||||
*/
|
||||
void uniqueAssignableRolePlace(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* Sets the unique attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key to false.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place} to disable unique role handling
|
||||
*/
|
||||
void multipleAssignableRolePlace(AServer server, String name);
|
||||
|
||||
/**
|
||||
* Sets the unique attribute of the {@link AssignableRolePlace place} to false.
|
||||
* @param place The {@link AssignableRolePlace place} to disable unique role handling
|
||||
*/
|
||||
void multipleAssignableRolePlace(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* Sets the auto-remove attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param newValue The new vale of the auto-remove attribute
|
||||
*/
|
||||
void setAssignablePlaceAutoRemoveTo(AServer server, String name, Boolean newValue);
|
||||
|
||||
/**
|
||||
* Sets the auto-remove attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key to true.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place} to activate the automatic removal of reactions
|
||||
*/
|
||||
void autoRemoveAssignableRolePlace(AServer server, String name);
|
||||
|
||||
/**
|
||||
* Sets the auto-remove attribute of the {@link AssignableRolePlace place} to true.
|
||||
* @param place The {@link AssignableRolePlace place} to activate the automatic removal of reactions
|
||||
*/
|
||||
void autoRemoveAssignableRolePlace(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* Sets the auto-remove attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and the key to false.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place} to keep reactions
|
||||
*/
|
||||
void keepReactionsAssignableRolePlace(AServer server, String name);
|
||||
|
||||
/**
|
||||
* Sets the auto-remove attribute of the {@link AssignableRolePlace place} to false.
|
||||
* @param place The {@link AssignableRolePlace place} to keep reactions
|
||||
*/
|
||||
void keepReactionsAssignableRolePlace(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* Swaps the positions of the two {@link AssignableRole roles} identified by the respective
|
||||
* {@link FullEmote emote}. This will only update the it in the database, and require a new setup. The
|
||||
* two {@link FullEmote emotes} are assumed to be different
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param firstEmote The {@link FullEmote emote} which identifies the first {@link AssignableRole role} to swap
|
||||
* @param secondEmote The {@link FullEmote emote} which identifies the second {@link AssignableRole role} to swap
|
||||
* @throws EmoteNotInAssignableRolePlaceException if either one of them is not part of the {@link AssignableRolePlace place}
|
||||
*
|
||||
*/
|
||||
void swapPositions(AServer server, String name, FullEmote firstEmote, FullEmote secondEmote);
|
||||
|
||||
/**
|
||||
* This method renders the {@link AssignableRolePlace place} and post the created {@link MessageToSend messageToSend}
|
||||
* in the current channel.
|
||||
* @param server The {@link AServer server} of the {@link AssignableRolePlace place} to test
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param channel The {@link TextChannel channel} in which the resulting {@link MessageToSend messageToSend}
|
||||
* should be posted in
|
||||
* @return A {@link CompletableFuture future} which completes when all {@link MessageToSend messageToSend}
|
||||
* have been sent
|
||||
*/
|
||||
CompletableFuture<Void> testAssignableRolePlace(AServer server, String name, TextChannel channel);
|
||||
|
||||
/**
|
||||
* This method renders the configuration of the {@link AssignableRolePlace place} identified by {@link AServer server}
|
||||
* and key into an {@link MessageToSend messageToSend} and sends a message to the given {@link TextChannel channel}.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param channel The {@link TextChannel channel} in which the resulting {@link MessageToSend messageToSend} should be posted in
|
||||
* @return A {@link CompletableFuture future} which completes when the {@link MessageToSend} has been sent
|
||||
*/
|
||||
CompletableFuture<Void> showAssignablePlaceConfig(AServer server, String name, TextChannel channel);
|
||||
|
||||
/**
|
||||
* Changes the {@link AChannel channel} of the {@link AssignableRole place} identified by {@link AServer server}
|
||||
* and key to the given {@link TextChannel channel}. This only changes the configuration and does not impact
|
||||
* any currently posted {@link AssignableRolePlacePost posts}
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param newChannel The {@link TextChannel channel} where the {@link AssignableRolePlace place} should be posted to.
|
||||
*/
|
||||
void moveAssignableRolePlace(String name, TextChannel newChannel);
|
||||
|
||||
/**
|
||||
* Deletes the {@link AssignableRolePlace place} identified by {@link AServer server} and key. This method will first
|
||||
* delete all the {@link AssignableRolePlacePost posts} and then remove the references from the database.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @return A {@link CompletableFuture future} which completes after all posts have been deleted
|
||||
*/
|
||||
CompletableFuture<Void> deleteAssignableRolePlace(AServer server, String name);
|
||||
|
||||
/**
|
||||
* Changes the text of an {@link AssignableRolePlace place} in the database only.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param newText The new value for the text attribute displayed in the first {@link AssignableRolePlacePost post}
|
||||
*/
|
||||
void changeText(AServer server, String name, String newText);
|
||||
|
||||
/**
|
||||
* Changes the text of an {@link AssignableRolePlace place} in the database, and updates the first
|
||||
* {@link AssignableRolePlacePost post}. The update of the post happens after the change in the database.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param newText The new value for the text attribute displayed in the first {@link AssignableRolePlacePost post}
|
||||
* @return A {@link CompletableFuture future} which completes when the config has been updated, or when the message was edited (if the posts already exist)
|
||||
*/
|
||||
CompletableFuture<Void> changeTextAsync(AServer server, String name, String newText);
|
||||
|
||||
/**
|
||||
* Removes the reactions and the roles from the user from the place, this does not touch the stored data
|
||||
* @param place The {@link AssignableRolePlace place} to which remove the existing reactions and roles from
|
||||
* @param user The {@link AssignedRoleUser user} to the remove *all* reactions and assigned roles from
|
||||
* @return A {@link CompletableFuture future} which completes when both of these actions have been done for all {@link AssignableRole assignableRoles}
|
||||
*/
|
||||
CompletableFuture<Void> removeExistingReactionsAndRoles(AssignableRolePlace place, AssignedRoleUser user);
|
||||
|
||||
/**
|
||||
* Changes the configuration of the given {@link AssignableRolePlaceParameterKey key} to the given value of the
|
||||
* {@link AssignableRolePlace place} identified by {@link AServer server} and key. If it can be updated immediately,
|
||||
* this will update the {@link AssignableRolePlacePost posts} and the return {@link CompletableFuture future}
|
||||
* will return afterwards. This is the case for {@link AssignableRolePlaceParameterKey#INLINE}. The rest of the
|
||||
* keys will only update the configuration in the database, and the place needs a refresh at a later point.
|
||||
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
|
||||
* @param name The key of the {@link AssignableRolePlace place}
|
||||
* @param keyToChange The {@link AssignableRolePlaceParameterKey key} to change
|
||||
* @param newValue The new value of the attribute, but be able to convert to a boolean via {@link org.apache.commons.lang3.BooleanUtils#toBooleanObject(String)}
|
||||
* @return A {@link CompletableFuture future} which completes when the configuration has been completed
|
||||
*/
|
||||
CompletableFuture<Void> changeConfiguration(AServer server, String name, AssignableRolePlaceParameterKey keyToChange, Object newValue);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link AssignableRolePlace places}, renders them into {@link MessageToSend messageToSend} and sends
|
||||
* this message to the given {@link TextChannel channel}.
|
||||
* @param server The {@link AServer server} for which the {@link AssignableRolePlace places} should be shown for
|
||||
* @param channel The {@link TextChannel channel} to send the {@link MessageToSend messageToSend} in
|
||||
* @return A {@link CompletableFuture future} which completes when the message has been sent
|
||||
*/
|
||||
CompletableFuture<Void> showAllAssignableRolePlaces(AServer server, TextChannel channel);
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRole;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Service responsible to manage actions on an {@link AssignableRole assignableRole}
|
||||
*/
|
||||
public interface AssignableRoleService {
|
||||
|
||||
/**
|
||||
* Adds the given {@link AssignableRole assignableRole} to the given {@link Member member}
|
||||
* @param assignableRoleId The ID of the {@link AssignableRole} to add
|
||||
* @param member The {@link Member member} who should receive the {@link AssignableRole role}
|
||||
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role} was added to the {@link Member member}
|
||||
*/
|
||||
|
||||
CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, Member member);
|
||||
/**
|
||||
* Adds the given {@link AssignableRole assignableRole} to the given {@link ServerUser serverUser}
|
||||
* @param assignableRoleId The ID of the {@link AssignableRole} to add
|
||||
* @param serverUser The {@link ServerUser serverUser} who should receive the {@link AssignableRole role}
|
||||
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role} was added to the {@link ServerUser serverUser}
|
||||
*/
|
||||
CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, ServerUser serverUser);
|
||||
|
||||
/**
|
||||
* Clears all {@link AssignableRole assignableRoles} which are currently given to the {@link AUserInAServer user} of a certain
|
||||
* {@link AssignableRolePlace place}
|
||||
* @param place The {@link AssignableRolePlace place} from which all {@link AssignableRole roles} from an {@link AUserInAServer user} should be removed of
|
||||
* @param user The {@link AUserInAServer user} to remove the {@link AssignableRole assignableRoles} of
|
||||
*/
|
||||
void clearAllRolesOfUserInPlace(AssignableRolePlace place, AUserInAServer user);
|
||||
|
||||
/**
|
||||
* Assigns the given {@link AssignableRole role} to the {@link Member member} and stores the assignment as a
|
||||
* {@link dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser}
|
||||
* @param assignableRoleId The ID of an {@link AssignableRole assignableRole} to be added to the {@link Member member}
|
||||
* @param toAdd The {@link Member member} to add the role to
|
||||
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role} has
|
||||
* been added and the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser user} has been persisted
|
||||
*/
|
||||
CompletableFuture<Void> fullyAssignAssignableRoleToUser(Long assignableRoleId, Member toAdd);
|
||||
|
||||
/**
|
||||
* Removes the {@link AssignableRole role} from the given {@link Member member}
|
||||
* @param assignableRole The {@link AssignableRole role} to remove
|
||||
* @param member The {@link Member member} to remove the {@link AssignableRole role} from
|
||||
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role}
|
||||
* has been removed from the {@link Member member}
|
||||
*/
|
||||
CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, Member member);
|
||||
|
||||
/**
|
||||
* Removes the {@link AssignableRole role} from the given {@link Member member}
|
||||
* @param assignableRoleId The ID of an {@link AssignableRole role} to remove
|
||||
* @param member The {@link Member member} to remove the {@link AssignableRole role} from
|
||||
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role}
|
||||
* has been removed from the {@link Member member}
|
||||
*/
|
||||
CompletableFuture<Void> removeAssignableRoleFromUser(Long assignableRoleId, Member member);
|
||||
|
||||
/**
|
||||
* Removes the {@link AssignableRole role} from the given {@link AUserInAServer aUserInAServer}
|
||||
* @param assignableRole The {@link AssignableRole role} to remove
|
||||
* @param aUserInAServer The {@link AUserInAServer aUserInAServer} to remove the {@link AssignableRole role} from
|
||||
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role}
|
||||
* has been removed from the {@link AUserInAServer aUserInAServer}
|
||||
*/
|
||||
CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, AUserInAServer aUserInAServer);
|
||||
|
||||
/**
|
||||
* Removes the given {@link AssignableRole role} from the {@link ServerUser serverUser} and stores the assignment as a
|
||||
* {@link dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser}
|
||||
* @param assignableRole The {@link AssignableRole assignableRole} to be removed from the {@link ServerUser serverUser}
|
||||
* @param serverUser The {@link ServerUser serverUser} to remove the role from
|
||||
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role} has
|
||||
* been removed and the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser user} has been persisted
|
||||
*/
|
||||
CompletableFuture<Void> fullyRemoveAssignableRoleFromUser(AssignableRole assignableRole, ServerUser serverUser);
|
||||
|
||||
/**
|
||||
* Adds the {@link AssignableRole assignableRole} to the given {@link AUserInAServer userInAServer} in the database
|
||||
* @param assignableRoleId The ID of the {@link AssignableRole role} to be added
|
||||
* @param aUserInAServer The {@link AUserInAServer user} to get the {@link AssignableRole role}
|
||||
*/
|
||||
void addRoleToUser(Long assignableRoleId, AUserInAServer aUserInAServer);
|
||||
|
||||
/**
|
||||
* Adds the {@link AssignableRole assignableRole} to the given {@link AUserInAServer userInAServer} in the database
|
||||
* @param assignableRole The {@link AssignableRole role} to be added
|
||||
* @param aUserInAServer The {@link AUserInAServer user} to get the {@link AssignableRole role}
|
||||
*/
|
||||
void addRoleToUser(AssignableRole assignableRole, AUserInAServer aUserInAServer);
|
||||
|
||||
/**
|
||||
* Removes the {@link AssignableRole assignableRole} from the given {@link AUserInAServer userInAServer} in the database
|
||||
* @param assignableRole The {@link AssignableRole role} to be removed
|
||||
* @param aUserInAServer The {@link AUserInAServer user} to get the {@link AssignableRole role} removed
|
||||
*/
|
||||
void removeRoleFromUser(AssignableRole assignableRole, AUserInAServer aUserInAServer);
|
||||
|
||||
/**
|
||||
* Removes the {@link AssignableRole assignableRole} from the given {@link AUserInAServer userInAServer} in the database
|
||||
* @param assignableRoleId The ID of the {@link AssignableRole role} to be removed
|
||||
* @param aUserInAServer The {@link AUserInAServer user} to get the {@link AssignableRole role} removed
|
||||
*/
|
||||
void removeRoleFromUser(Long assignableRoleId, AUserInAServer aUserInAServer);
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRole;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import net.dv8tion.jda.api.entities.MessageReaction;
|
||||
|
||||
/**
|
||||
* Management service for the table of {@link AssignableRole assignableRoles}
|
||||
*/
|
||||
public interface AssignableRoleManagementService {
|
||||
/**
|
||||
* Adds the given {@link ARole role} to the {@link AssignableRolePlace place} to be identified with the given {@link AEmote emote}
|
||||
* and displayed with the given description. An optional {@link AssignableRolePlacePost post} can be provided, if the
|
||||
* place has already been setup.
|
||||
* @param place The {@link AssignableRolePlace place} to add the the {@link ARole role} to
|
||||
* @param emote The {@link AEmote emote} which is used as an reaction on the {@link AssignableRolePlacePost post}
|
||||
* @param role The {@link ARole role} which should be given to the {@link dev.sheldan.abstracto.core.models.database.AUserInAServer user} placing a reaction
|
||||
* @param description The description which should be displayed in the field for the given {@link ARole role}
|
||||
* @param post If a {@link AssignableRolePlacePost post} already exists, it can be provided to link the newly created {@link AssignableRole directly}
|
||||
* @return The created instance of the {@link AssignableRole assignableRole} according to the given parameters
|
||||
*/
|
||||
AssignableRole addRoleToPlace(AssignableRolePlace place, AEmote emote, ARole role, String description, AssignableRolePlacePost post);
|
||||
|
||||
/**
|
||||
* Adds the {@link ARole role} (identified by its ID) to the {@link AssignableRolePlace place} (identified by its ID),
|
||||
* which in turn is identified by the given {@link AEmote emote} (identified by its ID) and displayed with the given description.
|
||||
* An optional {@link AssignableRolePlacePost post} can be provided (identified by the ID of the {@link net.dv8tion.jda.api.entities.Message}), if
|
||||
* it already exists
|
||||
* @param placeId The ID of the {@link AssignableRolePlace} to add an {@link AssignableRole assignableRole} to
|
||||
* @param emoteId The ID of the {@link AEmote emote} which should be used as an reaction on the {@link AssignableRolePlacePost post}
|
||||
* @param roleId The ID of the {@link ARole role} which should be given to the {@link dev.sheldan.abstracto.core.models.database.AUserInAServer user} placing a reaction
|
||||
* @param description The description which should be displayed in the field for the given {@link ARole role}
|
||||
* @param messageId If provided, this message ID will be used to identify the {@link AssignableRolePlacePost post} which already exists
|
||||
* @return The created instance of the {@link AssignableRole assignableRole} according to the given parameters
|
||||
*/
|
||||
AssignableRole addRoleToPlace(Long placeId, Integer emoteId, Long roleId, String description, Long messageId);
|
||||
|
||||
/**
|
||||
* Adds the {@link ARole role} (identified by its ID) to the {@link AssignableRolePlace place} (identified by its ID),
|
||||
* which in turn is identified by the given {@link AEmote emote} (identified by its ID) and displayed with the given description.
|
||||
* @param placeId The ID of the {@link AssignableRolePlace} to add an {@link AssignableRole assignableRole} to
|
||||
* @param emoteId The ID of the {@link AEmote emote} which should be used as an reaction on the {@link AssignableRolePlacePost post}
|
||||
* @param roleId The ID of the {@link ARole role} which should be given to the {@link dev.sheldan.abstracto.core.models.database.AUserInAServer user} placing a reaction
|
||||
* @param description The description which should be displayed in the field for the given {@link ARole role}
|
||||
* @return The created instance of the {@link AssignableRole assignableRole} according to the given parameters
|
||||
*/
|
||||
AssignableRole addRoleToPlace(Long placeId, Integer emoteId, Long roleId, String description);
|
||||
|
||||
/**
|
||||
* Finds the {@link AssignableRole} given by the ID and returns it if found. Throws an exception otherwise.
|
||||
* @param assignableRoleId The ID Of the {@link AssignableRole assignableRole} to find
|
||||
* @return An instance of {@link AssignableRole assignableRole} if it exists for the given ID
|
||||
*/
|
||||
AssignableRole getByAssignableRoleId(Long assignableRoleId);
|
||||
|
||||
/**
|
||||
* Returns the respective {@link AssignableRole assignableRole} for the {@link CachedEmote emote} which is part of the
|
||||
* {@link AssignableRolePlace place}. It will throw an exception, if the {@link CachedEmote emote} is not used.
|
||||
* @param cachedEmote The {@link CachedEmote emote} which should be used to identify the {@link AssignableRole role}
|
||||
* @param assignableRolePlace The {@link AssignableRolePlace place} from which the {@link AssignableRole role} should be retrieved for
|
||||
* @return An instance of {@link AssignableRole role} which was in the place and identified by the emote
|
||||
*/
|
||||
AssignableRole getRoleForReactionEmote(CachedEmote cachedEmote, AssignableRolePlace assignableRolePlace);
|
||||
AssignableRole getRoleForReactionEmote(MessageReaction.ReactionEmote cachedEmote, AssignableRolePlace assignableRolePlace);
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Management service for {@link AssignableRolePlace place} table
|
||||
*/
|
||||
public interface AssignableRolePlaceManagementService {
|
||||
|
||||
/**
|
||||
* Creates an {@link AssignableRolePlace place} with the given attributes
|
||||
* @param name The key of the {@link AssignableRolePlace place} to identify it with
|
||||
* @param channel The {@link AChannel channel} in which the {@link dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost posts}
|
||||
* should be created in
|
||||
* @param text The text which should be shown in the description
|
||||
* @return The {@link AssignableRolePlace place} which was created
|
||||
*/
|
||||
AssignableRolePlace createPlace(String name, AChannel channel, String text);
|
||||
|
||||
/**
|
||||
* Whether or not a place with the key exists in the given {@link AServer server}
|
||||
* @param server The {@link AServer server} in which it should be searched
|
||||
* @param name The key of an {@link AssignableRolePlace place} which should be searched
|
||||
* @return Whether or not an {@link AssignableRolePlace place} with the key exists in the {@link AServer server}
|
||||
*/
|
||||
boolean doesPlaceExist(AServer server, String name);
|
||||
|
||||
/**
|
||||
* Retrieves an {@link AssignableRolePlace place} identified by the given key in the {@link AServer server}
|
||||
* @param server The {@link AServer server} to search in
|
||||
* @param name The key of the {@link AssignableRolePlace place} to search for
|
||||
* @throws dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlaceNotFoundException if not found
|
||||
* @return Returns an instance of {@link AssignableRolePlace place}, if it was found
|
||||
*/
|
||||
AssignableRolePlace findByServerAndKey(AServer server, String name);
|
||||
|
||||
/**
|
||||
* Retrieves an {@link AssignableRolePlace place} via its ID in an {@link Optional optional}
|
||||
* @param id The ID to search for
|
||||
* @return Returns an {@link Optional optional} with an instance of {@link AssignableRolePlace place}, if it was found
|
||||
* and empty otherwise
|
||||
*/
|
||||
Optional<AssignableRolePlace> findByPlaceIdOptional(Long id);
|
||||
|
||||
/**
|
||||
* Retrieves an {@link AssignableRolePlace place} via its ID
|
||||
* @param id The ID to search for
|
||||
* @throws dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlaceNotFoundException if not found
|
||||
* @return Returns an {@link AssignableRolePlace place} if one was found with this ID
|
||||
*/
|
||||
AssignableRolePlace findByPlaceId(Long id);
|
||||
|
||||
/**
|
||||
* Changes the {@link AChannel channel} in which a {@link AssignableRolePlace place} should be posted towards
|
||||
* when being setup.
|
||||
* @param name The key of the {@link AssignableRolePlace place} to move
|
||||
* @param newChannel The new {@link AChannel channel} where the place should be moved to, used to determine in which {@link AServer server}
|
||||
* the {@link AssignableRolePlace place} is
|
||||
*/
|
||||
void moveAssignableRolePlace(String name, AChannel newChannel);
|
||||
|
||||
/**
|
||||
* Changes the {@link AssignableRolePlace#text description} of an assignable role place
|
||||
* @param server The {@link AServer server} in which to look for the place
|
||||
* @param name The key of the {@link AssignableRolePlace place} to change the descripiont for
|
||||
* @param newDescription The description value which should be used from now on
|
||||
*/
|
||||
void changeAssignableRolePlaceDescription(AServer server, String name, String newDescription);
|
||||
|
||||
/**
|
||||
* Deletes the {@link AssignableRolePlace place}
|
||||
* @param place The {@link AssignableRolePlace place} to remove
|
||||
*/
|
||||
void deleteAssignablePlace(AssignableRolePlace place);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link AssignableRolePlace assignableRolePlaces} for the given {@link AServer server}
|
||||
* @param server The {@link AServer server} for whom the places should be retrieved for
|
||||
* @return All {@link AssignableRolePlace assignableRolePlaces} in the given {@link AServer server}
|
||||
*/
|
||||
List<AssignableRolePlace> findAllByServer(AServer server);
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignableRolePlacePostNotFoundException;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlace;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRolePlacePost;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Management service for {@link AssignableRolePlacePost post} table
|
||||
*/
|
||||
public interface AssignableRolePlacePostManagementService {
|
||||
/**
|
||||
* Finds a {@link AssignableRolePlacePost post} via the ID of the {@link net.dv8tion.jda.api.entities.Message} it was
|
||||
* posted
|
||||
* @param messageId The ID of the {@link net.dv8tion.jda.api.entities.Message} in which the
|
||||
* @return An {@link Optional optional} containing the {@link AssignableRolePlacePost post}, if one was found, empty otherwise
|
||||
*/
|
||||
Optional<AssignableRolePlacePost> findByMessageIdOptional(Long messageId);
|
||||
|
||||
/**
|
||||
* Finds a {@link AssignableRolePlacePost post} via the ID of the {@link net.dv8tion.jda.api.entities.Message} it was
|
||||
* posted
|
||||
* @param messageId The ID of the {@link net.dv8tion.jda.api.entities.Message} in which the
|
||||
* @throws AssignableRolePlacePostNotFoundException if it was not found
|
||||
* @return The {@link AssignableRolePlacePost post} if one existed with this ID
|
||||
*/
|
||||
AssignableRolePlacePost findByMessageId(Long messageId);
|
||||
|
||||
/**
|
||||
* Creates an {@link AssignableRolePlacePost post} for the given {@link AssignableRolePlace place} in the given message ID
|
||||
* @param updatedPlace The {@link AssignableRolePlace place} this post should be part of
|
||||
* @param messageId The ID of the message in which the post exists
|
||||
* @return The {@link AssignableRolePlacePost post} which is found in the given {@link AssignableRolePlace place} of the {@link net.dv8tion.jda.api.entities.Message message} ID
|
||||
*/
|
||||
AssignableRolePlacePost createAssignableRolePlacePost(AssignableRolePlace updatedPlace, Long messageId);
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package dev.sheldan.abstracto.assignableroles.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.assignableroles.exception.AssignedUserNotFoundException;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignableRole;
|
||||
import dev.sheldan.abstracto.assignableroles.model.database.AssignedRoleUser;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Management service for {@link AssignedRoleUser assignedRoleUser} table
|
||||
*/
|
||||
public interface AssignedRoleUserManagementService {
|
||||
/**
|
||||
* Adds the given {@link AssignableRole assignableRole} to the given {@link AUserInAServer user}.
|
||||
* @param assignableRole The {@link AssignableRole assignableRole} to add
|
||||
* @param aUserInAServer The {@link AUserInAServer user} who should get the {@link AssignableRole role}
|
||||
*/
|
||||
void addAssignedRoleToUser(AssignableRole assignableRole, AUserInAServer aUserInAServer);
|
||||
|
||||
/**
|
||||
* Removes the given {@link AssignableRole assignableFrom} from the given {@link AUserInAServer user}.
|
||||
* @param assignableRole The {@link AssignableRole assignableRole} to remove
|
||||
* @param aUserInAServer The {@link AUserInAServer user} from whom the {@link AssignableRole role} should be removed
|
||||
*/
|
||||
void removeAssignedRoleFromUser(AssignableRole assignableRole, AUserInAServer aUserInAServer);
|
||||
|
||||
/**
|
||||
* Removes the given {@link AssignableRole assignableFrom} from the given {@link AssignedRoleUser user}.
|
||||
* @param assignableRole The {@link AssignableRole assignableRole} to remove
|
||||
* @param user The {@link AssignedRoleUser user} from whom the {@link AssignableRole role} should be removed
|
||||
*/
|
||||
void removeAssignedRoleFromUser(AssignableRole assignableRole, AssignedRoleUser user);
|
||||
|
||||
/**
|
||||
* Creating an {@link AssignedRoleUser assignedRoleUser} from the given {@link AUserInAServer user}
|
||||
* @param aUserInAServer The {@link AUserInAServer user} to create it for
|
||||
* @return The created instance of {@link AssignedRoleUser assignedRoleUser}
|
||||
*/
|
||||
AssignedRoleUser createAssignedRoleUser(AUserInAServer aUserInAServer);
|
||||
|
||||
/**
|
||||
* Tries to retrieve a {@link AssignedRoleUser assignedRoleUser} from an {@link AUserInAServer userInAServer},
|
||||
* and returns it as an {@link Optional optional}, if it exists. Empty otherwise.
|
||||
* @param aUserInAServer The {@link AUserInAServer user} to search for
|
||||
* @return An {@link Optional optional} containing the {@link AssignedRoleUser user}
|
||||
*/
|
||||
Optional<AssignedRoleUser> findByUserInServerOptional(AUserInAServer aUserInAServer);
|
||||
|
||||
/**
|
||||
* Tries to retrieve a {@link AssignedRoleUser assignedRoleUser} from an {@link AUserInAServer userInAServer},
|
||||
* and returns it as an {@link Optional optional}, if it exists. Empty otherwise.
|
||||
* @param serverUser The {@link ServerUser user} to search for
|
||||
* @return An {@link Optional optional} containing the {@link AssignedRoleUser user}
|
||||
*/
|
||||
Optional<AssignedRoleUser> findByUserInServerOptional(ServerUser serverUser);
|
||||
|
||||
/**
|
||||
* Tries to retrieve a {@link AssignedRoleUser assignedRoleUser} from an {@link AUserInAServer userInAServer},
|
||||
* and returns it if it exists. Throws an exception otherwise.
|
||||
* @param aUserInAServer The {@link AUserInAServer user} to search for
|
||||
* @throws AssignedUserNotFoundException if it doesnt find any
|
||||
* @return The {@link AssignedRoleUser user} if it exists
|
||||
*/
|
||||
AssignedRoleUser findByUserInServer(AUserInAServer aUserInAServer);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?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>abstracto-modules</artifactId>
|
||||
<version>1.2.10</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>assignable-roles</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>assignable-roles-int</module>
|
||||
<module>assignable-roles-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>
|
||||
@@ -1,67 +0,0 @@
|
||||
<?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>entertainment</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.2.10</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>entertainment-impl</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<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>entertainment-int</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>metrics-int</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>core-int</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,18 +0,0 @@
|
||||
<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>
|
||||
@@ -1,65 +0,0 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
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.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
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.model.command.ChooseResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
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 Choose extends AbstractConditionableCommand {
|
||||
|
||||
public static final String CHOOSE_RESPONSE_TEMPLATE_KEY = "choose_response";
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@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);
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(CHOOSE_RESPONSE_TEMPLATE_KEY, responseModel, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@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();
|
||||
return CommandConfiguration.builder()
|
||||
.name("choose")
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ENTERTAINMENT;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
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.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
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.model.command.EightBallResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
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 EightBall extends AbstractConditionableCommand {
|
||||
|
||||
public static final String EIGHT_BALL_RESPONSE_TEMPLATE_KEY = "eight_ball_response";
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@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()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@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();
|
||||
return CommandConfiguration.builder()
|
||||
.name("8Ball")
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ENTERTAINMENT;
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
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.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
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.model.command.LoveCalcResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
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 LoveCalc extends AbstractConditionableCommand {
|
||||
|
||||
public static final String LOVE_CALC_RESPONSE_TEMPLATE_KEY = "loveCalc_response";
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@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()))
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@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();
|
||||
return CommandConfiguration.builder()
|
||||
.name("loveCalc")
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ENTERTAINMENT;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
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.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.command.handler.parameter.CombinedParameter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
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.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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static dev.sheldan.abstracto.core.command.config.Parameter.ADDITIONAL_TYPES_KEY;
|
||||
|
||||
@Component
|
||||
public class Mock extends AbstractConditionableCommand {
|
||||
|
||||
public static final String MOCK_RESPONSE_TEMPLATE_KEY = "mock_response";
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
Object givenParameter = commandContext.getParameters().getParameters().get(0);
|
||||
String messageText;
|
||||
Member mockedMember = null;
|
||||
if(givenParameter instanceof Message) {
|
||||
Message originalMessage = (Message) givenParameter;
|
||||
messageText = originalMessage.getContentRaw();
|
||||
mockedMember = originalMessage.getMember();
|
||||
} else {
|
||||
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);
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(MOCK_RESPONSE_TEMPLATE_KEY, model, commandContext.getChannel()))
|
||||
.thenApply(unused -> 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();
|
||||
return CommandConfiguration.builder()
|
||||
.name("mock")
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ENTERTAINMENT;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
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.service.ReactionService;
|
||||
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.exception.ReactTooManyReactionsException;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class React extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Autowired
|
||||
private ReactionService reactionService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Message message = (Message) parameters.get(0);
|
||||
String text = (String) parameters.get(1);
|
||||
|
||||
List<String> reactionChars = entertainmentService.convertTextToEmojis(text);
|
||||
int existingReactions = message.getReactions().size();
|
||||
if(reactionChars.size() + existingReactions > Message.MAX_REACTIONS) {
|
||||
log.error("Message has already {} reactions, {} would be added.", existingReactions, reactionChars.size());
|
||||
throw new ReactTooManyReactionsException();
|
||||
}
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
reactionChars.forEach(s -> futures.add(reactionService.addDefaultReactionToMessageAsync(s, message)));
|
||||
return FutureUtils.toSingleFutureGeneric(futures)
|
||||
.thenApply(unused -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
parameters.add(Parameter.builder().name("message").type(Message.class).templated(true).build());
|
||||
parameters.add(Parameter.builder().name("text").type(String.class).remainder(true).templated(true).build());
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("react")
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ENTERTAINMENT;
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
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.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
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.model.command.RollResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
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 Roll extends AbstractConditionableCommand {
|
||||
|
||||
public static final String ROLL_RESPONSE_TEMPLATE_KEY = "roll_response";
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Integer high = configService.getLongValueOrConfigDefault(EntertainmentFeatureConfig.ROLL_DEFAULT_HIGH_KEY, commandContext.getGuild().getIdLong()).intValue();
|
||||
Integer low = 1;
|
||||
if(parameters.size() > 1) {
|
||||
low = (Integer) parameters.get(1);
|
||||
}
|
||||
if(!parameters.isEmpty()) {
|
||||
high = (Integer) parameters.get(0);
|
||||
}
|
||||
|
||||
Integer rolled = entertainmentService.calculateRollResult(low, high);
|
||||
RollResponseModel model = (RollResponseModel) ContextConverter.slimFromCommandContext(commandContext, RollResponseModel.class);
|
||||
model.setRolled(rolled);
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(ROLL_RESPONSE_TEMPLATE_KEY, model, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@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();
|
||||
return CommandConfiguration.builder()
|
||||
.name("roll")
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ENTERTAINMENT;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package dev.sheldan.abstracto.entertainment.command;
|
||||
|
||||
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.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
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.model.command.RouletteResponseModel;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
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 Roulette extends AbstractConditionableCommand {
|
||||
|
||||
public static final String ROULETTE_RESPONSE_TEMPLATE_KEY = "roulette_response";
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private EntertainmentService entertainmentService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
boolean rouletteResult = entertainmentService.executeRoulette(commandContext.getAuthor());
|
||||
RouletteResponseModel responseModel = (RouletteResponseModel) ContextConverter.slimFromCommandContext(commandContext, RouletteResponseModel.class);
|
||||
responseModel.setResult(rouletteResult);
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList(ROULETTE_RESPONSE_TEMPLATE_KEY, responseModel, commandContext.getChannel()))
|
||||
.thenApply(unused -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("roulette")
|
||||
.async(true)
|
||||
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return EntertainmentFeatureDefinition.ENTERTAINMENT;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package dev.sheldan.abstracto.entertainment.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:entertainment-config.properties")
|
||||
public class EntertainmentConfig {
|
||||
}
|
||||
|
||||
@@ -1,195 +0,0 @@
|
||||
package dev.sheldan.abstracto.entertainment.service;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureConfig;
|
||||
import dev.sheldan.abstracto.entertainment.exception.ReactDuplicateCharacterException;
|
||||
import dev.sheldan.abstracto.entertainment.model.ReactMapping;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class EntertainmentServiceBean implements EntertainmentService {
|
||||
|
||||
public static final List<String> EIGHT_BALL_ANSWER_KEYS = Arrays.asList(
|
||||
"IS_CERTAIN", "IS_DECIDEDLY", "WITHOUT_DOUBT", "DEFINITELY_SO", "MAY_RELY", // certain
|
||||
"SEE_IT", "MOST_LIKELY", "OUTLOOK", "YES", "POINT_YES", // certain
|
||||
"HAZY", "ASK_AGAIN", "NOT_TELL", "CANNOT_PREDICT", "CONCENTRATE", // uncertain
|
||||
"DONT_COUNT", "REPLY_NO", "SOURCES_NO", "OUTLOOK_NOT_GOOD", "DOUBTFUL" // negative
|
||||
);
|
||||
|
||||
private ReactMapping reactMapping;
|
||||
|
||||
@Autowired
|
||||
private SecureRandom secureRandom;
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@Value("classpath:react_mappings.json")
|
||||
private Resource reactMappingSource;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
|
||||
@Override
|
||||
public String getEightBallValue(String text) {
|
||||
return EIGHT_BALL_ANSWER_KEYS.get(secureRandom.nextInt(EIGHT_BALL_ANSWER_KEYS.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getLoveCalcValue(String firstPart, String secondPart) {
|
||||
return secureRandom.nextInt(100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer calculateRollResult(Integer low, Integer high) {
|
||||
int actualLow = Math.min(low, high);
|
||||
int actualHigh = Math.max(low, high);
|
||||
return actualLow + secureRandom.nextInt(actualHigh - actualLow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeRoulette(Member memberExecuting) {
|
||||
Long possibilities = configService.getLongValueOrConfigDefault(EntertainmentFeatureConfig.ROULETTE_BULLETS_CONFIG_KEY, memberExecuting.getGuild().getIdLong());
|
||||
// 1/possibilities of chance, we don't have a state, each time its reset
|
||||
return secureRandom.nextInt(possibilities.intValue()) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String takeChoice(List<String> choices, Member memberExecuting) {
|
||||
return choices.get(secureRandom.nextInt(choices.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createMockText(String text, Member memberExecuting, Member mockedUser) {
|
||||
if(text == null) {
|
||||
return "";
|
||||
}
|
||||
char[] textChars = text.toLowerCase().toCharArray();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0, textCharsLength = textChars.length; i < textCharsLength; i++) {
|
||||
char character = textChars[i];
|
||||
if(i % 2 == 0) {
|
||||
sb.append(Character.toUpperCase(character));
|
||||
} else {
|
||||
sb.append(character);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> convertTextToEmojis(String text) {
|
||||
return convertTextToEmojis(text, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTextToEmojisAString(String text) {
|
||||
return String.join("", convertTextToEmojis(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> convertTextToEmojis(String text, boolean allowDuplicates) {
|
||||
if(text == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
text = text.toLowerCase();
|
||||
// we have to have a separate set to check for combo duplicates, because the checks are different:
|
||||
// first check is if we already used it as an replacement
|
||||
// the second check below is whether or not we used it as a replacement, that way we allow
|
||||
// unicode cars from users as well, this leads to things like sos[sos] not being allowed, because the
|
||||
// unicode chars get removed, and the first sos gets replaced with the unicode
|
||||
Set<String> replacedCombos = new HashSet<>();
|
||||
List<String> result = new ArrayList<>();
|
||||
// this is used to replace the replacements for more than one character
|
||||
for (String s : this.reactMapping.getCombinationKeys()) {
|
||||
if (text.contains(s)) {
|
||||
String replacement = this.reactMapping.getCombination().get(s);
|
||||
if(!replacedCombos.contains(replacement) || allowDuplicates) {
|
||||
if(allowDuplicates) {
|
||||
text = text.replaceAll(s, replacement);
|
||||
} else {
|
||||
text = text.replaceFirst(s, replacement);
|
||||
}
|
||||
replacedCombos.add(replacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug("Replaced {} combos.", replacedCombos.size());
|
||||
Set<String> usedReplacements = new HashSet<>();
|
||||
char[] split = text.toCharArray();
|
||||
|
||||
for (int i = 0, splitLength = split.length; i < splitLength; i++) {
|
||||
char normalCharacter = split[i];
|
||||
String charAsString = Character.toString(normalCharacter);
|
||||
// the split, also splits surrogate chars (naturally), therefore we need this additional checks
|
||||
// to ignore the first part, and connect the chars again in order to check them
|
||||
if(Character.isHighSurrogate(normalCharacter)) {
|
||||
continue;
|
||||
}
|
||||
// in this case we already have unicode, this can either come from the multiple char replacement
|
||||
// or because we already got unicode to begin with (multi char only), in that case, we also do a duplicate check
|
||||
// and add it directly
|
||||
if(Character.isLowSurrogate(normalCharacter)) {
|
||||
String usedUnicode = split[i - 1] + charAsString;
|
||||
if(!usedReplacements.contains(usedUnicode) || allowDuplicates) {
|
||||
usedReplacements.add(usedUnicode);
|
||||
result.add(usedUnicode);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// reject any other character, as the ones we can deal with
|
||||
if (!this.reactMapping.getSingle().containsKey(charAsString)) {
|
||||
log.info("Cannot find mapping. Not replacing with emote.");
|
||||
continue;
|
||||
}
|
||||
List<String> listToUse = this.reactMapping.getSingle().get(charAsString);
|
||||
boolean foundReplacement = false;
|
||||
for (String replacementChar : listToUse) {
|
||||
if (!usedReplacements.contains(replacementChar) || allowDuplicates) {
|
||||
result.add(replacementChar);
|
||||
usedReplacements.add(replacementChar);
|
||||
foundReplacement = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundReplacement) {
|
||||
throw new ReactDuplicateCharacterException();
|
||||
}
|
||||
}
|
||||
log.debug("We used {} replacements for a string of length {}.", usedReplacements.size(), text.length());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTextToEmojisAsString(String text, boolean allowDuplicates) {
|
||||
return String.join("", convertTextToEmojis(text, allowDuplicates));
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
try {
|
||||
JsonReader reader = new JsonReader(new InputStreamReader(reactMappingSource.getInputStream()));
|
||||
this.reactMapping = gson.fromJson(reader, ReactMapping.class);
|
||||
this.reactMapping.populateKeys();
|
||||
log.info("Loaded {} single replacement mappings.", this.reactMapping.getSingle().size());
|
||||
log.info("Loaded {} combo replacements.", this.reactMapping.getCombination().size());
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to load react bindings.", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
abstracto.systemConfigs.rouletteBullets.name=rouletteBullets
|
||||
abstracto.systemConfigs.rouletteBullets.longValue=6
|
||||
|
||||
abstracto.systemConfigs.rollDefaultHigh.name=rollDefaultHigh
|
||||
abstracto.systemConfigs.rollDefaultHigh.longValue=6
|
||||
|
||||
abstracto.featureFlags.entertainment.featureName=entertainment
|
||||
abstracto.featureFlags.entertainment.enabled=false
|
||||
@@ -1,10 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../dbchangelog-3.8.xsd" >
|
||||
<include file="entertainment-seedData/data.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -1,40 +0,0 @@
|
||||
<?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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<property name="entertainmentModule" value="(SELECT id FROM module WHERE name = 'entertainment')"/>
|
||||
<property name="entertainmentFeature" value="(SELECT id FROM feature WHERE key = 'entertainment')"/>
|
||||
|
||||
<changeSet author="Sheldan" id="entertainment-commands">
|
||||
<insert tableName="command">
|
||||
<column name="name" value="8Ball"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${entertainmentFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="loveCalc"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${entertainmentFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="roll"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${entertainmentFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="roulette"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<column name="feature_id" valueComputed="${entertainmentFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="choose"/>
|
||||
<column name="module_id" valueComputed="${entertainmentModule}"/>
|
||||
<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