Compare commits

...

35 Commits

Author SHA1 Message Date
release-bot
8fded5480d [maven-release-plugin] prepare release v1.6.2 2025-02-04 22:27:13 +00:00
Sheldan
b74a238090 [AB-xxx] update year 2025-02-04 23:25:00 +01:00
release-bot
149a85cde6 Commit from GitHub Actions (Publishes a new version of abstracto) 2025-02-04 22:20:54 +00:00
release-bot
6455d24711 [maven-release-plugin] prepare for next development iteration 2025-02-04 22:04:57 +00:00
release-bot
b862ed95f2 [maven-release-plugin] prepare release v1.6.1 2025-02-04 22:04:55 +00:00
Sheldan
5ba2f2a2f8 [AB-xxx] adding support to have a different template for user command descriptions
enabling user command for currency conversion command
2025-02-04 23:01:50 +01:00
release-bot
ce234f986e [maven-release-plugin] prepare for next development iteration 2025-02-03 22:28:23 +00:00
release-bot
6472c70229 [maven-release-plugin] prepare release v1.6.0 2025-02-03 22:28:22 +00:00
Sheldan
cdb6003976 [AB-xxx] preparing for release of minor version 2025-02-03 23:25:51 +01:00
release-bot
54cf1a8299 Commit from GitHub Actions (Publishes a new version of abstracto) 2025-02-03 22:17:10 +00:00
release-bot
1d6bb7af08 [maven-release-plugin] prepare for next development iteration 2025-02-03 22:08:05 +00:00
release-bot
629cafc902 [maven-release-plugin] prepare release v1.5.61 2025-02-03 22:08:04 +00:00
Sheldan
58632bcf9d [AB-xxx] preparing for minor release 2025-02-03 23:05:44 +01:00
Sheldan
592ac01bfa [AB-xxx] changes for newer JDA version 2025-02-03 23:01:52 +01:00
Sheldan
732535850b [AB-xxx] adding support for user installable apps to varying commands 2025-02-03 22:54:15 +01:00
release-bot
cd3378df32 Commit from GitHub Actions (Publishes a new version of abstracto) 2025-01-31 18:16:43 +00:00
release-bot
87d8338d51 [maven-release-plugin] prepare for next development iteration 2025-01-31 18:07:34 +00:00
release-bot
a371993c87 [maven-release-plugin] prepare release v1.5.60 2025-01-31 18:07:33 +00:00
Sheldan
77b97507b3 [AB-xxx] adding paginators to emote stats
adding handling for emotes which are only provided as ID to command inputs
removing message commands from emote statistic related commands
2025-01-31 19:03:38 +01:00
Sheldan
e952727849 [AB-xxx] fixing incorrect join for deleted emote stats 2025-01-27 23:19:26 +01:00
release-bot
909a08d3d2 Commit from GitHub Actions (Publishes a new version of abstracto) 2025-01-27 20:23:59 +00:00
release-bot
e02236145f [maven-release-plugin] prepare for next development iteration 2025-01-27 20:13:35 +00:00
release-bot
1d810bdc07 [maven-release-plugin] prepare release v1.5.59 2025-01-27 20:13:33 +00:00
Sheldan
f9334d5210 [AB-xxx] always showing all emotes in emote stats output 2025-01-27 21:09:46 +01:00
release-bot
0a7e30cace Commit from GitHub Actions (Publishes a new version of abstracto) 2025-01-27 00:44:12 +00:00
release-bot
d91091d149 [maven-release-plugin] prepare for next development iteration 2025-01-27 00:35:25 +00:00
release-bot
2690b1a5d9 [maven-release-plugin] prepare release v1.5.58 2025-01-27 00:35:24 +00:00
Sheldan
ed42940e29 [AB-xxx] adding ability to track emotes used in reactions
adding ability to have confirmations for slash commands
2025-01-27 01:31:56 +01:00
release-bot
2c3b16879e Commit from GitHub Actions (Publishes a new version of abstracto) 2025-01-15 21:25:59 +00:00
release-bot
bd7fc6aa65 [maven-release-plugin] prepare for next development iteration 2025-01-15 21:16:39 +00:00
release-bot
6dfcebb25b [maven-release-plugin] prepare release v1.5.57 2025-01-15 21:16:38 +00:00
Sheldan
0eaccb4b0f [AB-xxx] adding currency conversion command 2025-01-15 22:13:47 +01:00
Sheldan
4ae6a154c7 [AB-xxx] fixing not being able to delete a giveaway key for which there is no giveaway 2024-12-29 21:10:27 +01:00
release-bot
3ad8369ab3 Commit from GitHub Actions (Publishes a new version of abstracto) 2024-12-25 22:41:02 +00:00
release-bot
6be1b7df04 [maven-release-plugin] prepare for next development iteration 2024-12-25 22:30:39 +00:00
275 changed files with 3473 additions and 1769 deletions

2
.env
View File

@@ -1,2 +1,2 @@
REGISTRY_PREFIX=harbor.sheldan.dev/abstracto/
VERSION=1.5.55
VERSION=1.6.2

View File

@@ -30,7 +30,7 @@ jobs:
with:
title: Release of version ${{ env.version }}
- name: Release maven packages
uses: qcastel/github-actions-maven-release@v1.12.41
uses: qcastel/github-actions-maven-release@v1.12.43
env:
JAVA_HOME: /usr/lib/jvm/java-17-openjdk/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

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

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>anti-raid</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>anti-raid</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>abstracto-modules</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>assignable-roles</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>assignable-roles</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>assignable-roles-int</artifactId>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>abstracto-modules</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>custom-command</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -5,11 +5,13 @@ 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.UserCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureDefinition;
import dev.sheldan.abstracto.customcommand.config.CustomCommandSlashCommandNames;
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandService;
@@ -44,8 +46,11 @@ public class CreateCustomCommand extends AbstractConditionableCommand {
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
String name = slashCommandParameterService.getCommandOption(CUSTOM_COMMAND_NAME_PARAMETER, event, String.class);
String content = slashCommandParameterService.getCommandOption(CUSTOM_COMMAND_CONTENT_PARAMETER, event, String.class);
customCommandService.createCustomCommand(name, content, event.getMember());
if(ContextUtils.isUserCommand(event)) {
customCommandService.createUserCustomCommand(name, content, event.getUser());
} else {
customCommandService.createCustomCommand(name, content, event.getMember());
}
return interactionService.replyEmbed(CREATE_CUSTOM_COMMAND_RESPONSE_TEMPLATE_KEY, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@@ -80,6 +85,8 @@ public class CreateCustomCommand extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND)
.commandName("create")
.build();

View File

@@ -5,11 +5,13 @@ 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.UserCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureDefinition;
import dev.sheldan.abstracto.customcommand.config.CustomCommandSlashCommandNames;
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandService;
@@ -42,8 +44,11 @@ public class DeleteCustomCommand extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
String name = slashCommandParameterService.getCommandOption(CUSTOM_COMMAND_NAME_PARAMETER, event, String.class);
customCommandService.deleteCustomCommand(name, event.getGuild());
if(ContextUtils.isUserCommand(event)) {
customCommandService.deleteUserCustomCommand(name, event.getUser());
} else {
customCommandService.deleteCustomCommand(name, event.getGuild());
}
return interactionService.replyEmbed(DELETE_CUSTOM_COMMAND_RESPONSE_TEMPLATE_KEY, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@@ -66,6 +71,8 @@ public class DeleteCustomCommand extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND)
.commandName("delete")
.build();

View File

@@ -5,12 +5,14 @@ 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.UserCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandAutoCompleteService;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureDefinition;
import dev.sheldan.abstracto.customcommand.config.CustomCommandSlashCommandNames;
import dev.sheldan.abstracto.customcommand.model.command.CustomCommandResponseModel;
@@ -48,7 +50,12 @@ public class GetCustomCommand extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
String name = slashCommandParameterService.getCommandOption(CUSTOM_COMMAND_NAME_PARAMETER, event, String.class);
CustomCommand customCommand = customCommandService.getCustomCommand(name, event.getGuild());
CustomCommand customCommand;
if(ContextUtils.isUserCommand(event)) {
customCommand = customCommandService.getUserCustomCommand(name, event.getUser());
} else {
customCommand = customCommandService.getCustomCommand(name, event.getGuild());
}
CustomCommandResponseModel model = CustomCommandResponseModel
.builder()
.additionalText(customCommand.getAdditionalMessage())
@@ -61,11 +68,17 @@ public class GetCustomCommand extends AbstractConditionableCommand {
public List<String> performAutoComplete(CommandAutoCompleteInteractionEvent event) {
if(slashCommandAutoCompleteService.matchesParameter(event.getFocusedOption(), CUSTOM_COMMAND_NAME_PARAMETER)) {
String input = event.getFocusedOption().getValue();
return customCommandService.getCustomCommandsStartingWith(input, event.getGuild())
.stream()
.map(CustomCommand::getName)
.limit(25)
.toList();
if(ContextUtils.isNotUserCommand(event)) {
return customCommandService.getCustomCommandsStartingWith(input, event.getGuild())
.stream()
.map(CustomCommand::getName)
.toList();
} else {
return customCommandService.getUserCustomCommandsStartingWith(input, event.getUser())
.stream()
.map(CustomCommand::getName)
.toList();
}
} else {
return new ArrayList<>();
}
@@ -95,7 +108,10 @@ public class GetCustomCommand extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND_PUBLIC)
.userRootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND)
.commandName("get")
.build();

View File

@@ -4,11 +4,13 @@ import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.UserCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.service.PaginatorService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.customcommand.config.CustomCommandFeatureDefinition;
import dev.sheldan.abstracto.customcommand.config.CustomCommandSlashCommandNames;
import dev.sheldan.abstracto.customcommand.model.command.ListCustomCommandsResponseModel;
@@ -42,7 +44,12 @@ public class ListCustomCommands extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
List<CustomCommand> customCommands = customCommandService.getCustomCommands(event.getGuild());
List<CustomCommand> customCommands;
if(ContextUtils.isUserCommand(event)) {
customCommands = customCommandService.getUserCustomCommands(event.getUser());
} else {
customCommands = customCommandService.getCustomCommands(event.getGuild());
}
if(customCommands.isEmpty()) {
return interactionService.replyEmbed(NO_CUSTOM_COMMANDS_TEMPLATE_KEY, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
@@ -67,7 +74,10 @@ public class ListCustomCommands extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND_PUBLIC)
.userRootCommandName(CustomCommandSlashCommandNames.CUSTOM_COMMAND)
.commandName("list")
.build();

View File

@@ -1,6 +1,7 @@
package dev.sheldan.abstracto.customcommand.repository;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -11,7 +12,12 @@ import java.util.Optional;
@Repository
public interface CustomCommandRepository extends JpaRepository<CustomCommand, Long> {
Optional<CustomCommand> getByNameIgnoreCaseAndServer(String name, AServer server);
Optional<CustomCommand> getByNameIgnoreCaseAndCreatorUser(String name, AUser creator);
Optional<CustomCommand> getByNameIgnoreCaseAndCreatorUser_IdAndUserSpecific(String name, Long userId, Boolean userSpecific);
void deleteByNameAndServer(String name, AServer server);
void deleteByNameAndCreatorUserAndUserSpecific(String name, AUser aUser, Boolean userSpecific);
List<CustomCommand> findByServer(AServer server);
List<CustomCommand> findByCreatorUserAndUserSpecific(AUser user, Boolean userSpecific);
List<CustomCommand> findByNameStartsWithIgnoreCaseAndServer(String prefix, AServer server);
List<CustomCommand> findByNameStartsWithIgnoreCaseAndCreatorUserAndUserSpecific(String prefix, AUser aUser, Boolean userSpecific);
}

View File

@@ -1,9 +1,11 @@
package dev.sheldan.abstracto.customcommand.service;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.core.service.management.UserManagementService;
import dev.sheldan.abstracto.customcommand.exception.CustomCommandExistsException;
import dev.sheldan.abstracto.customcommand.exception.CustomCommandNotFoundException;
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
@@ -11,6 +13,7 @@ import dev.sheldan.abstracto.customcommand.service.management.CustomCommandManag
import dev.sheldan.abstracto.customcommand.service.management.CustomCommandService;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -28,6 +31,9 @@ public class CustomCommandServiceBean implements CustomCommandService {
@Autowired
private ServerManagementService serverManagementService;
@Autowired
private UserManagementService userManagementService;
@Override
public CustomCommand createCustomCommand(String name, String content, Member creator) {
if(customCommandManagementService.getCustomCommandByName(name, creator.getGuild().getIdLong()).isPresent()) {
@@ -37,6 +43,15 @@ public class CustomCommandServiceBean implements CustomCommandService {
return customCommandManagementService.createCustomCommand(name, content, creatorUser);
}
@Override
public CustomCommand createUserCustomCommand(String name, String content, User user) {
AUser aUser = userManagementService.loadOrCreateUser(user.getIdLong());
if(customCommandManagementService.getUserCustomCommandByName(name, aUser).isPresent()) {
throw new CustomCommandExistsException();
}
return customCommandManagementService.createUserCustomCommand(name, content, aUser);
}
@Override
public void deleteCustomCommand(String name, Guild guild) {
if(customCommandManagementService.getCustomCommandByName(name, guild.getIdLong()).isEmpty()) {
@@ -46,21 +61,48 @@ public class CustomCommandServiceBean implements CustomCommandService {
customCommandManagementService.deleteCustomCommand(name, server);
}
@Override
public void deleteUserCustomCommand(String name, User user) {
if(customCommandManagementService.getUserCustomCommandByName(name, user.getIdLong()).isEmpty()) {
throw new CustomCommandNotFoundException();
}
AUser aUser = userManagementService.loadOrCreateUser(user.getIdLong());
customCommandManagementService.deleteCustomCommand(name, aUser);
}
@Override
public List<CustomCommand> getCustomCommands(Guild guild) {
AServer server = serverManagementService.loadServer(guild);
return customCommandManagementService.getCustomCommands(server);
}
@Override
public List<CustomCommand> getUserCustomCommands(User user) {
AUser aUser = userManagementService.loadOrCreateUser(user.getIdLong());
return customCommandManagementService.getUserCustomCommands(aUser);
}
@Override
public CustomCommand getCustomCommand(String name, Guild guild) {
return customCommandManagementService.getCustomCommandByName(name, guild.getIdLong())
.orElseThrow(CustomCommandNotFoundException::new);
}
@Override
public CustomCommand getUserCustomCommand(String name, User user) {
return customCommandManagementService.getUserCustomCommandByName(name, user.getIdLong())
.orElseThrow(CustomCommandNotFoundException::new);
}
@Override
public List<CustomCommand> getCustomCommandsStartingWith(String prefix, Guild guild) {
AServer server = serverManagementService.loadServer(guild);
return customCommandManagementService.getCustomCommandsStartingWith(prefix, server);
}
@Override
public List<CustomCommand> getUserCustomCommandsStartingWith(String prefix, User user) {
AUser aUser = userManagementService.loadOrCreateUser(user.getIdLong());
return customCommandManagementService.getUserCustomCommandsStartingWith(prefix, aUser);
}
}

View File

@@ -1,6 +1,7 @@
package dev.sheldan.abstracto.customcommand.service.management;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
@@ -26,6 +27,16 @@ public class CustomCommandManagementServiceBean implements CustomCommandManageme
return repository.getByNameIgnoreCaseAndServer(name, server);
}
@Override
public Optional<CustomCommand> getUserCustomCommandByName(String name, AUser user) {
return repository.getByNameIgnoreCaseAndCreatorUser(name, user);
}
@Override
public Optional<CustomCommand> getUserCustomCommandByName(String name, Long userId) {
return repository.getByNameIgnoreCaseAndCreatorUser_IdAndUserSpecific(name, userId, true);
}
@Override
public CustomCommand createCustomCommand(String name, String content, AUserInAServer creator) {
CustomCommand customCommand = CustomCommand
@@ -34,6 +45,20 @@ public class CustomCommandManagementServiceBean implements CustomCommandManageme
.additionalMessage(content)
.server(creator.getServerReference())
.creator(creator)
.userSpecific(false)
.creatorUser(creator.getUserReference())
.build();
return repository.save(customCommand);
}
@Override
public CustomCommand createUserCustomCommand(String name, String content, AUser user) {
CustomCommand customCommand = CustomCommand
.builder()
.name(name)
.additionalMessage(content)
.creatorUser(user)
.userSpecific(true)
.build();
return repository.save(customCommand);
}
@@ -43,14 +68,29 @@ public class CustomCommandManagementServiceBean implements CustomCommandManageme
repository.deleteByNameAndServer(name, server);
}
@Override
public void deleteCustomCommand(String name, AUser user) {
repository.deleteByNameAndCreatorUserAndUserSpecific(name, user, true);
}
@Override
public List<CustomCommand> getCustomCommands(AServer server) {
return repository.findByServer(server);
}
@Override
public List<CustomCommand> getUserCustomCommands(AUser aUser) {
return repository.findByCreatorUserAndUserSpecific(aUser, true);
}
@Override
public List<CustomCommand> getCustomCommandsStartingWith(String prefix, AServer server) {
return repository.findByNameStartsWithIgnoreCaseAndServer(prefix, server);
}
@Override
public List<CustomCommand> getUserCustomCommandsStartingWith(String prefix, AUser aUser) {
return repository.findByNameStartsWithIgnoreCaseAndCreatorUserAndUserSpecific(prefix, aUser, true);
}
}

View File

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

View File

@@ -0,0 +1,26 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="custom_command-add_user_installable_support">
<addColumn tableName="custom_command">
<column name="creator_id" type="BIGINT">
<constraints nullable="true"/>
</column>
<column name="user_specific" type="BOOLEAN" value="false">
<constraints nullable="false"/>
</column>
</addColumn>
<sql>
update custom_command set creator_id = (select ua.user_id from user_in_server ua where ua.user_in_server_id = creator_user_in_server_id order by ua.server_id limit 1)
</sql>
<addNotNullConstraint columnName="creator_id"
tableName="custom_command"
validate="true"/>
<sql>
ALTER TABLE custom_command ALTER COLUMN server_id DROP NOT NULL;
ALTER TABLE custom_command ALTER COLUMN creator_user_in_server_id DROP NOT NULL;
</sql>
</changeSet>
</databaseChangeLog>

View File

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

View File

@@ -4,4 +4,5 @@
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<include file="1.4.0/collection.xml" relativeToChangelogFile="true"/>
<include file="1.5.8/collection.xml" relativeToChangelogFile="true"/>
<include file="1.5.37/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>custom-command</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -13,11 +13,18 @@ public class ListCustomCommandModel {
private MemberDisplay creator;
public static ListCustomCommandModel fromCustomCommand(CustomCommand customCommand) {
MemberDisplay creatorObj;
if(customCommand.getUserSpecific()) {
creatorObj = MemberDisplay.fromAUser(customCommand.getCreatorUser());
} else {
creatorObj = MemberDisplay.fromAUserInAServer(customCommand.getCreator());
}
return ListCustomCommandModel
.builder()
.name(customCommand.getName())
.content(customCommand.getAdditionalMessage())
.creator(MemberDisplay.fromAUserInAServer(customCommand.getCreator()))
.creator(creatorObj)
.build();
}
}

View File

@@ -29,13 +29,20 @@ public class CustomCommand implements Serializable {
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "server_id", nullable = false)
@JoinColumn(name = "server_id")
private AServer server;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "creator_user_in_server_id", nullable = false)
@JoinColumn(name = "creator_user_in_server_id")
private AUserInAServer creator;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "creator_id", nullable = false)
private AUser creatorUser;
@Column(name = "user_specific")
private Boolean userSpecific;
@Column(name = "created", nullable = false, insertable = false, updatable = false)
private Instant created;

View File

@@ -1,6 +1,7 @@
package dev.sheldan.abstracto.customcommand.service.management;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
@@ -9,8 +10,14 @@ import java.util.Optional;
public interface CustomCommandManagementService {
Optional<CustomCommand> getCustomCommandByName(String name, Long serverId);
Optional<CustomCommand> getUserCustomCommandByName(String name, AUser user);
Optional<CustomCommand> getUserCustomCommandByName(String name, Long userId);
CustomCommand createCustomCommand(String name, String content, AUserInAServer creator);
CustomCommand createUserCustomCommand(String name, String content, AUser user);
void deleteCustomCommand(String name, AServer server);
void deleteCustomCommand(String name, AUser user);
List<CustomCommand> getCustomCommands(AServer server);
List<CustomCommand> getUserCustomCommands(AUser aUser);
List<CustomCommand> getCustomCommandsStartingWith(String prefix, AServer server);
List<CustomCommand> getUserCustomCommandsStartingWith(String prefix, AUser aUser);
}

View File

@@ -3,13 +3,19 @@ package dev.sheldan.abstracto.customcommand.service.management;
import dev.sheldan.abstracto.customcommand.model.database.CustomCommand;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import java.util.List;
public interface CustomCommandService {
CustomCommand createCustomCommand(String name, String content, Member creator);
CustomCommand createUserCustomCommand(String name, String content, User user);
void deleteCustomCommand(String name, Guild guild);
void deleteUserCustomCommand(String name, User user);
List<CustomCommand> getCustomCommands(Guild guild);
List<CustomCommand> getUserCustomCommands(User user);
CustomCommand getCustomCommand(String name, Guild guild);
CustomCommand getUserCustomCommand(String name, User user);
List<CustomCommand> getCustomCommandsStartingWith(String prefix, Guild guild);
List<CustomCommand> getUserCustomCommandsStartingWith(String prefix, User user);
}

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>abstracto-modules</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>dynamic-activity</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>dynamic-activity</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>abstracto-modules</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>entertainment</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -4,6 +4,7 @@ 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.UserCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
@@ -96,6 +97,8 @@ public class Choose extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(EntertainmentSlashCommandNames.UTILITY)
.commandName(CHOOSE_COMMAND)
.build();

View File

@@ -4,6 +4,7 @@ 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.UserCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
@@ -12,6 +13,7 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
@@ -60,7 +62,7 @@ public class EightBall extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
String text = slashCommandParameterService.getCommandOption(TEXT_PARAMETER, event, String.class);
MessageToSend messageToSend = getMessageToSend(text, event.getGuild().getIdLong());
MessageToSend messageToSend = getMessageToSend(text, ContextUtils.serverIdOrNull(event));
return interactionService.replyMessageToSend(messageToSend, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@@ -93,6 +95,8 @@ public class EightBall extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(EntertainmentSlashCommandNames.UTILITY)
.commandName(BALL_COMMAND)
.build();

View File

@@ -4,6 +4,7 @@ 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.UserCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
@@ -13,6 +14,7 @@ import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
@@ -64,7 +66,7 @@ public class LoveCalc extends AbstractConditionableCommand {
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
String firstPart = slashCommandParameterService.getCommandOption(FIRST_SUBJECT_PARAMETER, event, String.class);
String secondPart = slashCommandParameterService.getCommandOption(SECOND_SUBJECT_PARAMETER, event, String.class);
MessageToSend messageToSend = getMessageToSend(event.getGuild().getIdLong(), firstPart, secondPart);
MessageToSend messageToSend = getMessageToSend(ContextUtils.serverIdOrNull(event), firstPart, secondPart);
return interactionService.replyMessageToSend(messageToSend, event.getInteraction())
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@@ -105,6 +107,8 @@ public class LoveCalc extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(EntertainmentSlashCommandNames.UTILITY)
.commandName(LOVE_CALC_COMMAND)
.build();

View File

@@ -1,10 +1,7 @@
package dev.sheldan.abstracto.entertainment.command;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CombinedParameterEntry;
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.*;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.handler.parameter.CombinedParameter;
@@ -108,6 +105,8 @@ public class Mock extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(EntertainmentSlashCommandNames.ENTERTAINMENT)
.commandName(MOCK_COMMAND)
.build();

View File

@@ -4,6 +4,7 @@ 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.UserCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.command.config.validator.MinIntegerValueValidator;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
@@ -125,6 +126,8 @@ public class Roll extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(EntertainmentSlashCommandNames.UTILITY)
.commandName(ROLL_COMMAND)
.build();

View File

@@ -4,6 +4,7 @@ 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.UserCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
@@ -71,6 +72,8 @@ public class Roulette extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(EntertainmentSlashCommandNames.UTILITY)
.commandName(ROULETTE_COMMAND)
.build();

View File

@@ -4,6 +4,7 @@ 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.UserCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
@@ -15,6 +16,7 @@ import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.FeatureFlagService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
@@ -81,33 +83,39 @@ public class Mines extends AbstractConditionableCommand {
mines = slashCommandParameterService.getCommandOption(MINES_PARAMETER, event, Integer.class);
}
Integer credit = null;
long serverId = event.getGuild().getIdLong();
boolean economyEnabled = featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, serverId);
if(economyEnabled){
credit = 50;
if(slashCommandParameterService.hasCommandOption(CREDITS_PARAMETER, event)) {
credit = slashCommandParameterService.getCommandOption(CREDITS_PARAMETER, event, Integer.class);
}
Long serverId;
boolean economyEnabled = false;
if(ContextUtils.isNotUserCommand(event)) {
serverId = event.getGuild().getIdLong();
economyEnabled = featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, serverId);
if(economyEnabled){
credit = 50;
if(slashCommandParameterService.hasCommandOption(CREDITS_PARAMETER, event)) {
credit = slashCommandParameterService.getCommandOption(CREDITS_PARAMETER, event, Integer.class);
}
Optional<EconomyUser> userOptional = economyUserManagementService.getUser(ServerUser.fromMember(event.getMember()));
if(!userOptional.isPresent()) {
throw new NotEnoughCreditsException();
}
EconomyUser user = userOptional.get();
if(user.getCredits() < credit) {
throw new NotEnoughCreditsException();
Optional<EconomyUser> userOptional = economyUserManagementService.getUser(ServerUser.fromMember(event.getMember()));
if(!userOptional.isPresent()) {
throw new NotEnoughCreditsException();
}
EconomyUser user = userOptional.get();
if(user.getCredits() < credit) {
throw new NotEnoughCreditsException();
}
}
} else {
serverId = null;
}
MineBoard board = gameService.createBoard(width, height, mines, serverId);
board.setCreditsEnabled(economyEnabled);
board.setUserId(event.getMember().getIdLong());
board.setUserId(event.getUser().getIdLong());
board.setServerId(serverId);
board.setCredits(credit);
MessageToSend messageToSend = templateService.renderEmbedTemplate(MINE_BOARD_TEMPLATE_KEY, board, serverId);
return interactionService.replyMessageToSend(messageToSend, event)
.thenCompose(interactionHook -> interactionHook.retrieveOriginal().submit())
.thenApply(message -> {
gameService.persistMineBoardMessage(board, message);
gameService.persistMineBoardMessage(board, message, serverId);
return CommandResult.fromSuccess();
});
}
@@ -129,7 +137,7 @@ public class Mines extends AbstractConditionableCommand {
mines = (Integer) parameters.get(2);
}
Integer credit = null;
long serverId = commandContext.getGuild().getIdLong();
Long serverId = commandContext.getGuild().getIdLong();
boolean economyEnabled = featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, serverId);
if(economyEnabled){
credit = 50;
@@ -154,7 +162,7 @@ public class Mines extends AbstractConditionableCommand {
MessageToSend messageToSend = templateService.renderEmbedTemplate(MINE_BOARD_TEMPLATE_KEY, board, serverId);
List<CompletableFuture<Message>> futures = channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel());
return FutureUtils.toSingleFutureGeneric(futures)
.thenAccept(unused -> gameService.persistMineBoardMessage(board, futures.get(0).join()))
.thenAccept(unused -> gameService.persistMineBoardMessage(board, futures.get(0).join(), serverId))
.thenApply(unused -> CommandResult.fromSuccess());
}
@@ -207,6 +215,8 @@ public class Mines extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(EntertainmentSlashCommandNames.GAME)
.commandName(MINES_COMMAND_NAME)
.build();

View File

@@ -9,6 +9,7 @@ import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListe
import dev.sheldan.abstracto.core.service.FeatureFlagService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.entertainment.command.games.Mines;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
import dev.sheldan.abstracto.entertainment.model.command.games.MineBoard;
@@ -49,13 +50,15 @@ public class MinesButtonClickedListener implements ButtonClickedListener {
GameService.MineResult mineResult = gameService.uncoverField(mineBoard, payload.getX(), payload.getY());
mineBoard.setState(mineResult);
if(mineBoard.getState() != GameService.MineResult.CONTINUE) {
if(featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, model.getServerId())){
gameService.evaluateCreditChanges(mineBoard);
if(ContextUtils.isNotUserCommand(model.getEvent())) {
if(featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, model.getServerId())){
gameService.evaluateCreditChanges(mineBoard);
}
}
gameService.uncoverBoard(mineBoard);
}
MessageToSend messageToSend = templateService.renderEmbedTemplate(Mines.MINE_BOARD_TEMPLATE_KEY, mineBoard, model.getServerId());
interactionService.editOriginal(messageToSend, model.getEvent().getHook()).thenAccept(message -> {
interactionService.replaceOriginal(messageToSend, model.getEvent().getHook()).thenAccept(message -> {
gameService.updateMineBoard(mineBoard);
log.info("Updated original mineboard for board {}.", mineBoard.getBoardId());
});

View File

@@ -70,10 +70,16 @@ public class GameServiceBean implements GameService {
@Override
@Transactional
public void persistMineBoardMessage(MineBoard mineBoard, Message message) {
public void persistMineBoardMessage(MineBoard mineBoard, Message message, Long serverId) {
mineBoard.setMessageId(message.getIdLong());
mineBoard.setChannelId(message.getChannel().getIdLong());
AServer server = serverManagementService.loadServer(message.getGuild());
AServer server;
if(serverId != null) {
server = serverManagementService.loadServer(serverId);
} else {
server = null;
}
mineBoard.getFields().forEach(mineBoardField -> {
MineBoardPayload payload = MineBoardPayload
.builder()

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>entertainment</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -5,7 +5,7 @@ import net.dv8tion.jda.api.entities.Message;
public interface GameService {
MineBoard createBoard(Integer width, Integer height, Integer mines, Long serverId);
void persistMineBoardMessage(MineBoard mineBoard, Message message);
void persistMineBoardMessage(MineBoard mineBoard, Message message, Long serverId);
void updateMineBoard(MineBoard mineBoard);
void uncoverBoard(MineBoard mineBoard);
void evaluateCreditChanges(MineBoard mineBoard);

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>abstracto-modules</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>experience-tracking</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>experience-tracking</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>abstracto-modules</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -4,7 +4,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>giveaway</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<artifactId>giveaway-impl</artifactId>

View File

@@ -58,7 +58,9 @@ public class GiveawayKeyManagementServiceBean implements GiveawayKeyManagementSe
@Override
public void deleteById(Long id, Long serverId) {
GiveawayKey key = giveawayKeyRepository.findById(new GiveawayKeyId(id, serverId)).orElseThrow(GiveawayKeyNotFoundException::new);
key.getGiveaway().setGiveawayKey(null);
if(key.getGiveaway() != null) {
key.getGiveaway().setGiveawayKey(null);
}
giveawayKeyRepository.delete(key);
}

View File

@@ -4,7 +4,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>giveaway</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<artifactId>giveaway-int</artifactId>

View File

@@ -4,7 +4,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>abstracto-modules</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<artifactId>giveaway</artifactId>

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>image-generation</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<artifactId>image-generation-impl</artifactId>

View File

@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.config.UserCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
@@ -109,6 +110,8 @@ public class AmongusText extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(ImageGenerationSlashCommandNames.IMAGE_GENERATION)
.groupName("memes")
.commandName("amongustext")

View File

@@ -2,10 +2,7 @@ package dev.sheldan.abstracto.imagegeneration.command;
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CombinedParameterEntry;
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.*;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.handler.parameter.CombinedParameter;
@@ -24,6 +21,7 @@ import dev.sheldan.abstracto.imagegeneration.config.ImageGenerationSlashCommandN
import dev.sheldan.abstracto.imagegeneration.service.ImageGenerationService;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -92,13 +90,25 @@ public class Bonk extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
event.deferReply().queue();
String avatarUrl;
Member targetMember;
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER_KEY, event)) {
targetMember = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER_KEY, event, Member.class);
} else {
targetMember = event.getMember();
}
File bonkGifFile = imageGenerationService.getBonkGif(targetMember.getEffectiveAvatar().getUrl(imageSize));
if(targetMember == null) {
User targetUser;
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER_KEY, event)) {
targetUser = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER_KEY, event, User.class);
} else {
targetUser = event.getUser();
}
avatarUrl = targetUser.getEffectiveAvatar().getUrl(imageSize);
} else {
avatarUrl = targetMember.getEffectiveAvatar().getUrl(imageSize);
}
File bonkGifFile = imageGenerationService.getBonkGif(avatarUrl);
MessageToSend messageToSend = templateService.renderEmbedTemplate(BONK_EMBED_TEMPLATE_KEY, new Object(), event.getGuild().getIdLong());
// template support does not support binary files
AttachedFile file = AttachedFile
@@ -116,13 +126,18 @@ public class Bonk extends AbstractConditionableCommand {
public CommandConfiguration getConfiguration() {
List<Parameter> parameters = new ArrayList<>();
Map<String, Object> parameterAlternatives = new HashMap<>();
parameterAlternatives.put(ADDITIONAL_TYPES_KEY, Arrays.asList(CombinedParameterEntry.messageParameter(Message.class), CombinedParameterEntry.parameter(Member.class)));
parameterAlternatives.put(ADDITIONAL_TYPES_KEY, List.of(
CombinedParameterEntry.messageParameter(Message.class),
CombinedParameterEntry.parameter(Member.class),
CombinedParameterEntry.parameter(User.class)
));
Parameter memberParameter = Parameter
.builder()
.name(MEMBER_PARAMETER_KEY)
.type(CombinedParameter.class)
.additionalInfo(parameterAlternatives)
.templated(true)
.useStrictParameters(true)
.optional(true)
.build();
parameters.add(memberParameter);
@@ -134,6 +149,8 @@ public class Bonk extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(ImageGenerationSlashCommandNames.IMAGE_GENERATION)
.groupName("memes")
.commandName("bonk")

View File

@@ -2,10 +2,7 @@ package dev.sheldan.abstracto.imagegeneration.command;
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CombinedParameterEntry;
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.*;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.handler.parameter.CombinedParameter;
@@ -24,6 +21,7 @@ import dev.sheldan.abstracto.imagegeneration.config.ImageGenerationSlashCommandN
import dev.sheldan.abstracto.imagegeneration.service.ImageGenerationService;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -92,13 +90,25 @@ public class Pat extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
event.deferReply().queue();
String avatarUrl;
Member targetMember;
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER_KEY, event)) {
targetMember = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER_KEY, event, Member.class);
} else {
targetMember = event.getMember();
}
File patGifFile = imageGenerationService.getPatGif(targetMember.getEffectiveAvatar().getUrl(imageSize));
if(targetMember == null) {
User targetUser;
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER_KEY, event)) {
targetUser = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER_KEY, event, User.class);
} else {
targetUser = event.getUser();
}
avatarUrl = targetUser.getEffectiveAvatar().getUrl(imageSize);
} else {
avatarUrl = targetMember.getEffectiveAvatar().getUrl(imageSize);
}
File patGifFile = imageGenerationService.getPatGif(avatarUrl);
MessageToSend messageToSend = templateService.renderEmbedTemplate(PAT_EMBED_TEMPLATE_KEY, new Object(), event.getGuild().getIdLong());
// template support does not support binary files
AttachedFile file = AttachedFile
@@ -116,13 +126,17 @@ public class Pat extends AbstractConditionableCommand {
public CommandConfiguration getConfiguration() {
List<Parameter> parameters = new ArrayList<>();
Map<String, Object> parameterAlternatives = new HashMap<>();
parameterAlternatives.put(ADDITIONAL_TYPES_KEY, Arrays.asList(CombinedParameterEntry.messageParameter(Message.class), CombinedParameterEntry.parameter(Member.class)));
parameterAlternatives.put(ADDITIONAL_TYPES_KEY, List.of(
CombinedParameterEntry.messageParameter(Message.class),
CombinedParameterEntry.parameter(Member.class),
CombinedParameterEntry.parameter(User.class)));
Parameter memberParameter = Parameter
.builder()
.name(MEMBER_PARAMETER_KEY)
.type(CombinedParameter.class)
.additionalInfo(parameterAlternatives)
.templated(true)
.useStrictParameters(true)
.optional(true)
.build();
parameters.add(memberParameter);
@@ -134,6 +148,8 @@ public class Pat extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(ImageGenerationSlashCommandNames.IMAGE_GENERATION)
.groupName("memes")
.commandName("pat")

View File

@@ -2,11 +2,10 @@ package dev.sheldan.abstracto.imagegeneration.command;
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.config.*;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.handler.parameter.CombinedParameter;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
@@ -21,6 +20,8 @@ import dev.sheldan.abstracto.imagegeneration.config.ImageGenerationFeatureDefini
import dev.sheldan.abstracto.imagegeneration.config.ImageGenerationSlashCommandNames;
import dev.sheldan.abstracto.imagegeneration.service.ImageGenerationService;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -28,9 +29,13 @@ import org.springframework.stereotype.Component;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import static dev.sheldan.abstracto.core.command.config.Parameter.ADDITIONAL_TYPES_KEY;
@Component
public class Triggered extends AbstractConditionableCommand {
@@ -84,13 +89,25 @@ public class Triggered extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
event.deferReply().queue();
String avatarUrl;
Member targetMember;
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER_KEY, event)) {
targetMember = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER_KEY, event, Member.class);
} else {
targetMember = event.getMember();
}
File triggeredGifFile = imageGenerationService.getTriggeredGif(targetMember.getEffectiveAvatar().getUrl(imageSize));
if(targetMember == null) {
User targetUser;
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER_KEY, event)) {
targetUser = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER_KEY, event, User.class);
} else {
targetUser = event.getUser();
}
avatarUrl = targetUser.getEffectiveAvatar().getUrl(imageSize);
} else {
avatarUrl = targetMember.getEffectiveAvatar().getUrl(imageSize);
}
File triggeredGifFile = imageGenerationService.getTriggeredGif(avatarUrl);
MessageToSend messageToSend = templateService.renderEmbedTemplate(TRIGGERED_EMBED_TEMPLATE_KEY, new Object(), event.getGuild().getIdLong());
// template support does not support binary files
AttachedFile file = AttachedFile
@@ -107,11 +124,19 @@ public class Triggered extends AbstractConditionableCommand {
@Override
public CommandConfiguration getConfiguration() {
List<Parameter> parameters = new ArrayList<>();
Map<String, Object> parameterAlternatives = new HashMap<>();
parameterAlternatives.put(ADDITIONAL_TYPES_KEY, List.of(
CombinedParameterEntry.messageParameter(Message.class),
CombinedParameterEntry.parameter(Member.class),
CombinedParameterEntry.parameter(User.class)
));
Parameter memberParameter = Parameter
.builder()
.name(MEMBER_PARAMETER_KEY)
.type(Member.class)
.type(CombinedParameter.class)
.additionalInfo(parameterAlternatives)
.templated(true)
.useStrictParameters(true)
.optional(true)
.build();
parameters.add(memberParameter);
@@ -123,6 +148,8 @@ public class Triggered extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(ImageGenerationSlashCommandNames.IMAGE_GENERATION)
.groupName("memes")
.commandName("triggered")

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>image-generation</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<artifactId>image-generation-int</artifactId>

View File

@@ -4,7 +4,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>abstracto-modules</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<artifactId>image-generation</artifactId>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>invite-filter</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>invite-filter</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -18,7 +18,7 @@
<dependency>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>moderation-int</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>abstracto-modules</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>link-embed</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>link-embed</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>abstracto-modules</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>logging</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>logging</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>abstracto-modules</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>moderation</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -4,7 +4,6 @@ import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
@@ -12,10 +11,8 @@ import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.moderation.config.ModerationModuleDefinition;
import dev.sheldan.abstracto.moderation.config.ModerationSlashCommandNames;
import dev.sheldan.abstracto.moderation.config.feature.ModerationFeatureDefinition;
import dev.sheldan.abstracto.moderation.service.WarnService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -45,14 +42,6 @@ public class DecayAllWarnings extends AbstractConditionableCommand {
.thenApply(aVoid -> CommandResult.fromSuccess());
}
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
AServer server = serverManagementService.loadServer(event.getGuild());
return warnService.decayAllWarningsForServer(server)
.thenCompose(unused -> interactionService.replyEmbed(DECAY_ALL_WARNINGS_RESPONSE, event))
.thenApply(aVoid -> CommandResult.fromSuccess());
}
@Override
public CommandConfiguration getConfiguration() {
List<Parameter> parameters = new ArrayList<>();
@@ -61,19 +50,11 @@ public class DecayAllWarnings extends AbstractConditionableCommand {
.templated(true)
.build();
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.rootCommandName(ModerationSlashCommandNames.WARN_DECAY)
.commandName(DECAY_ALL_WARNINGS_COMMAND)
.build();
return CommandConfiguration.builder()
.name(DECAY_ALL_WARNINGS_COMMAND)
.module(ModerationModuleDefinition.MODERATION)
.templated(true)
.async(true)
.slashCommandConfig(slashCommandConfig)
.requiresConfirmation(true)
.supportsEmbedException(true)
.causesReaction(true)

View File

@@ -4,18 +4,14 @@ import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.moderation.config.ModerationModuleDefinition;
import dev.sheldan.abstracto.moderation.config.ModerationSlashCommandNames;
import dev.sheldan.abstracto.moderation.config.feature.ModerationFeatureDefinition;
import dev.sheldan.abstracto.moderation.service.WarnService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -27,7 +23,6 @@ import java.util.concurrent.CompletableFuture;
public class DecayWarnings extends AbstractConditionableCommand {
private static final String DECAY_WARNINGS_COMMAND = "decayWarnings";
private static final String DECAY_WARNINGS_RESPONSE = "decayWarnings_response";
@Autowired
private WarnService warnService;
@@ -35,9 +30,6 @@ public class DecayWarnings extends AbstractConditionableCommand {
@Autowired
private ServerManagementService serverManagementService;
@Autowired
private InteractionService interactionService;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
AServer server = serverManagementService.loadServer(commandContext.getGuild());
@@ -45,14 +37,6 @@ public class DecayWarnings extends AbstractConditionableCommand {
.thenApply(aVoid -> CommandResult.fromSuccess());
}
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
AServer server = serverManagementService.loadServer(event.getGuild());
return warnService.decayWarningsForServer(server)
.thenCompose(unused -> interactionService.replyEmbed(DECAY_WARNINGS_RESPONSE, event))
.thenApply(aVoid -> CommandResult.fromSuccess());
}
@Override
public CommandConfiguration getConfiguration() {
List<Parameter> parameters = new ArrayList<>();
@@ -61,18 +45,10 @@ public class DecayWarnings extends AbstractConditionableCommand {
.templated(true)
.build();
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.rootCommandName(ModerationSlashCommandNames.WARN_DECAY)
.commandName(DECAY_WARNINGS_COMMAND)
.build();
return CommandConfiguration.builder()
.name(DECAY_WARNINGS_COMMAND)
.module(ModerationModuleDefinition.MODERATION)
.templated(true)
.slashCommandConfig(slashCommandConfig)
.requiresConfirmation(true)
.async(true)
.supportsEmbedException(true)

View File

@@ -217,7 +217,7 @@ public class PurgeServiceBean implements PurgeService {
}
log.debug("Setting status for {} out of {}", currentCount, totalCount);
MessageToSend finalUpdateMessage = getStatusMessageToSend(totalCount, channel.getGuild().getIdLong(), currentCount);
interactionService.editOriginal(finalUpdateMessage, interactionHook);
interactionService.replaceOriginal(finalUpdateMessage, interactionHook);
};
}
@@ -244,7 +244,7 @@ public class PurgeServiceBean implements PurgeService {
CompletableFuture<MessageHistory> historyFuture = channelService.getHistoryOfChannel(channel, startId, toDeleteInThisIteration);
MessageToSend statusMessageToSend = getStatusMessageToSend(totalCount, channel.getGuild().getIdLong(), 0);
CompletableFuture<Message> statusMessageFuture = interactionService.editOriginal(statusMessageToSend, interactionHook);
CompletableFuture<Message> statusMessageFuture = interactionService.replaceOriginal(statusMessageToSend, interactionHook);
CompletableFuture<Void> deletionFuture = new CompletableFuture<>();
CompletableFuture<Void> retrievalFuture = CompletableFuture.allOf(historyFuture, statusMessageFuture);

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>moderation</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>abstracto-modules</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>modmail</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.command.Command;
import dev.sheldan.abstracto.core.command.condition.ConditionResult;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.modmail.condition.ModMailContextCondition;
import dev.sheldan.abstracto.modmail.condition.detail.NotInModMailThreadConditionDetail;
import dev.sheldan.abstracto.modmail.model.database.ModMailThread;
@@ -45,6 +46,9 @@ public class RequiresModMailCondition implements ModMailContextCondition {
@Override
public ConditionResult shouldExecute(SlashCommandInteractionEvent slashCommandInteractionEvent, Command command) {
if(ContextUtils.isUserCommand(slashCommandInteractionEvent)) {
return ConditionResult.SUCCESS;
}
Optional<ModMailThread> threadOptional = modMailThreadManagementService.getByChannelOptional(channelManagementService.loadChannel(slashCommandInteractionEvent.getChannel()));
if(threadOptional.isPresent()) {
return ConditionResult

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>modmail</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>abstracto-modules</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto</groupId>
<artifactId>abstracto-application</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>abstracto-modules</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>profanity-filter</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>profanity-filter</artifactId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>abstracto-modules</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>remind</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.config.UserCommandConfig;
import dev.sheldan.abstracto.core.interaction.ComponentPayloadService;
import dev.sheldan.abstracto.core.interaction.ComponentService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
@@ -14,12 +15,17 @@ import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParame
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.models.ServerChannelMessage;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.models.template.display.MemberNameDisplay;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.core.service.management.UserManagementService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.core.utils.ParseUtils;
import dev.sheldan.abstracto.core.utils.SnowflakeUtils;
@@ -73,6 +79,12 @@ public class Remind extends AbstractConditionableCommand {
@Autowired
private ComponentPayloadService componentPayloadService;
@Autowired
private UserManagementService userManagementService;
@Autowired
private ServerManagementService serverManagementService;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
@@ -88,7 +100,7 @@ public class Remind extends AbstractConditionableCommand {
ReminderModel remindModel = ReminderModel
.builder()
.remindText(text)
.memberDisplay(MemberNameDisplay.fromMember(commandContext.getAuthor()))
.userDisplay(UserDisplay.fromUser(commandContext.getAuthor().getUser()))
.joinButtonId(joinButtonId)
.reminder(ReminderDisplay.fromReminder(createdReminder))
.message(ServerChannelMessage.fromMessage(commandContext.getMessage()))
@@ -118,29 +130,41 @@ public class Remind extends AbstractConditionableCommand {
if(slashCommandParameterService.hasCommandOption(REMIND_TEXT_PARAMETER, event)) {
reminderText = slashCommandParameterService.getCommandOption(REMIND_TEXT_PARAMETER, event, String.class, String.class);
}
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(event.getMember());
Long snowFlake = SnowflakeUtils.createSnowFlake();
String joinButtonId = componentService.generateComponentId();
Reminder createdReminder = remindService.createReminderInForUser(aUserInAServer, reminderText, duration, event.getChannel().getIdLong(), snowFlake);
String joinButtonId;
Reminder createdReminder;
if(ContextUtils.isUserCommand(event)) {
joinButtonId = null;
AUser aUser = userManagementService.loadOrCreateUser(event.getUser().getIdLong());
createdReminder = remindService.createReminderInForUser(aUser, reminderText, duration);
} else {
joinButtonId = componentService.generateComponentId();
Long snowFlake = SnowflakeUtils.createSnowFlake();
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(event.getMember());
createdReminder = remindService.createReminderInForUser(aUserInAServer, reminderText, duration, event.getChannel().getIdLong(), snowFlake);
}
ReminderModel remindModel = ReminderModel
.builder()
.remindText(reminderText)
.joinButtonId(joinButtonId)
.memberDisplay(MemberNameDisplay.fromMember(event.getMember()))
.userDisplay(UserDisplay.fromUser(event.getUser()))
.reminder(ReminderDisplay.fromReminder(createdReminder))
.build();
JoinReminderPayload payload = JoinReminderPayload
.builder()
.remindedUserId(event.getMember().getIdLong())
.reminderId(createdReminder.getId())
.serverId(serverId)
.build();
if(ContextUtils.isNotUserCommand(event)) {
AServer server = serverManagementService.loadServer(serverId);
JoinReminderPayload payload = JoinReminderPayload
.builder()
.remindedUserId(event.getUser().getIdLong())
.reminderId(createdReminder.getId())
.serverId(serverId)
.build();
componentPayloadService.createButtonPayload(joinButtonId, payload, REMINDER_JOIN_BUTTON_ORIGIN, server);
}
componentPayloadService.createButtonPayload(joinButtonId, payload, REMINDER_JOIN_BUTTON_ORIGIN, aUserInAServer.getServerReference());
log.info("Notifying user {} about reminder being scheduled.", event.getMember().getId());
MessageToSend messageToSend = templateService.renderEmbedTemplate(REMINDER_EMBED_KEY, remindModel, serverId);
log.info("Notifying user {} about reminder being scheduled.", event.getUser().getId());
MessageToSend messageToSend = templateService.renderEmbedTemplate(REMINDER_EMBED_KEY, remindModel, ContextUtils.serverIdOrNull(event));
return interactionService.replyMessageToSend(messageToSend, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@@ -171,6 +195,8 @@ public class Remind extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(RemindSlashCommandNames.REMIND)
.commandName("create")
.build();

View File

@@ -4,17 +4,21 @@ import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.UserCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.models.ServerChannelMessage;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.core.service.management.UserManagementService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.remind.config.RemindFeatureDefinition;
import dev.sheldan.abstracto.remind.config.RemindSlashCommandNames;
@@ -26,6 +30,7 @@ import dev.sheldan.abstracto.remind.service.management.ReminderManagementService
import dev.sheldan.abstracto.remind.service.management.ReminderParticipantManagementService;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -57,16 +62,19 @@ public class Reminders extends AbstractConditionableCommand {
@Autowired
private ReminderParticipantManagementService reminderParticipantManagementService;
@Autowired
private UserManagementService userManagementService;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
Long serverId = commandContext.getGuild().getIdLong();
Member member = commandContext.getAuthor();
MessageToSend messageToSend = getMessageToSend(serverId, member);
MessageToSend messageToSend = getServerReminders(serverId, member);
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
.thenApply(aVoid -> CommandResult.fromIgnored());
}
private MessageToSend getMessageToSend(Long serverId, Member member) {
private MessageToSend getServerReminders(Long serverId, Member member) {
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(member);
List<Reminder> activeReminders = reminderManagementService.getActiveRemindersForUser(aUserInAServer);
List<Reminder> joinedReminders = reminderParticipantManagementService.getActiveReminders(aUserInAServer)
@@ -85,17 +93,37 @@ public class Reminders extends AbstractConditionableCommand {
RemindersModel model = RemindersModel
.builder()
.reminders(reminders)
.member(member)
.userDisplay(UserDisplay.fromUser(member.getUser()))
.build();
log.info("Showing {} reminders for user {} in server {}.", activeReminders.size(), aUserInAServer.getUserReference().getId(), serverId);
return templateService.renderEmbedTemplate(REMINDERS_RESPONSE_TEMPLATE, model, serverId);
}
private MessageToSend getUserReminders(User user) {
AUser aUser = userManagementService.loadOrCreateUser(user.getIdLong());
List<Reminder> activeReminders = reminderManagementService.getActiveUserRemindersForUser(aUser);
List<ReminderDisplay> reminders = activeReminders
.stream()
.map(ReminderDisplay::fromReminder)
.collect(Collectors.toList());
RemindersModel model = RemindersModel
.builder()
.reminders(reminders)
.userDisplay(UserDisplay.fromUser(user))
.build();
return templateService.renderEmbedTemplate(REMINDERS_RESPONSE_TEMPLATE, model);
}
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
Long serverId = event.getGuild().getIdLong();
Member member = event.getMember();
MessageToSend messageToSend = getMessageToSend(serverId, member);
MessageToSend messageToSend;
if(ContextUtils.isUserCommand(event)) {
messageToSend = getUserReminders(event.getUser());
} else {
Member member = event.getMember();
Long serverId = event.getGuild().getIdLong();
messageToSend = getServerReminders(serverId, member);
}
return interactionService.replyMessageToSend(messageToSend, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@@ -110,6 +138,8 @@ public class Reminders extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(RemindSlashCommandNames.REMIND)
.commandName("list")
.build();

View File

@@ -10,6 +10,8 @@ import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParame
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.core.service.management.UserManagementService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.remind.config.RemindFeatureDefinition;
import dev.sheldan.abstracto.remind.config.RemindSlashCommandNames;
import dev.sheldan.abstracto.remind.service.ReminderService;
@@ -36,6 +38,9 @@ public class UnRemind extends AbstractConditionableCommand {
@Autowired
private UserInServerManagementService userInServerManagementService;
@Autowired
private UserManagementService userManagementService;
@Autowired
private SlashCommandParameterService slashCommandParameterService;
@@ -52,7 +57,11 @@ public class UnRemind extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
Long reminderId = slashCommandParameterService.getCommandOption(REMINDER_ID_PARAMETER, event, Long.class, Integer.class).longValue();
reminderService.unRemind(reminderId, userInServerManagementService.loadOrCreateUser(event.getMember()));
if(ContextUtils.isUserCommand(event)) {
reminderService.unRemind(reminderId, userManagementService.loadOrCreateUser(event.getUser().getIdLong()));
} else {
reminderService.unRemind(reminderId, userInServerManagementService.loadOrCreateUser(event.getMember()));
}
return interactionService.replyEmbed(UN_REMIND_RESPONSE, event)
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@@ -74,6 +83,8 @@ public class UnRemind extends AbstractConditionableCommand {
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.userInstallable(true)
.userCommandConfig(UserCommandConfig.all())
.rootCommandName(RemindSlashCommandNames.REMIND)
.commandName("cancel")
.build();

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.remind.repository;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.remind.model.database.Reminder;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -11,8 +12,10 @@ import java.util.List;
public interface ReminderRepository extends JpaRepository<Reminder, Long> {
List<Reminder> getByRemindedUserAndRemindedFalse(AUserInAServer aUserInAServer);
List<Reminder> getByRemindedAUserAndRemindedFalseAndUserCommandTrueAndServerIsNull(AUser aUser);
Reminder getByIdAndRemindedUserAndRemindedFalse(Long reminderId, AUserInAServer aUserInAServer);
Reminder getByIdAndRemindedAUserAndUserCommandTrue(Long reminderId, AUser aUser);
Reminder getByIdAndRemindedUser(Long reminderId, AUserInAServer aUserInAServer);
}

View File

@@ -3,12 +3,11 @@ package dev.sheldan.abstracto.remind.service;
import dev.sheldan.abstracto.core.models.AServerAChannelAUser;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
import dev.sheldan.abstracto.core.models.template.display.MemberNameDisplay;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.GuildService;
import dev.sheldan.abstracto.core.service.MemberService;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import dev.sheldan.abstracto.core.service.*;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
@@ -18,6 +17,7 @@ import dev.sheldan.abstracto.remind.exception.ReminderNotFoundException;
import dev.sheldan.abstracto.remind.model.database.Reminder;
import dev.sheldan.abstracto.remind.model.database.ReminderParticipant;
import dev.sheldan.abstracto.remind.model.template.commands.ExecutedReminderModel;
import dev.sheldan.abstracto.remind.model.template.commands.ReminderDisplay;
import dev.sheldan.abstracto.remind.service.management.ReminderManagementService;
import dev.sheldan.abstracto.remind.service.management.ReminderParticipantManagementService;
import dev.sheldan.abstracto.scheduling.model.JobParameters;
@@ -55,6 +55,9 @@ public class RemindServiceBean implements ReminderService {
@Autowired
private TemplateService templateService;
@Autowired
private MessageService messageService;
@Autowired
private SchedulerService schedulerService;
@@ -64,6 +67,9 @@ public class RemindServiceBean implements ReminderService {
@Autowired
private GuildService guildService;
@Autowired
private UserService userService;
@Autowired
private RemindServiceBean self;
@@ -86,15 +92,15 @@ public class RemindServiceBean implements ReminderService {
@Override
public Reminder createReminderInForUser(AUserInAServer user, String remindText, Duration remindIn, Long channelId, Long messageId) {
AChannel channel = channelManagementService.loadChannel(channelId);
AServerAChannelAUser aServerAChannelAUser = AServerAChannelAUser
.builder()
.user(user.getUserReference())
.aUserInAServer(user)
.guild(user.getServerReference())
.channel(channel)
.build();
Instant remindAt = Instant.now().plusMillis(remindIn.toMillis());
Reminder reminder = reminderManagementService.createReminder(aServerAChannelAUser, remindText, remindAt, messageId);
AServerAChannelAUser aServerAChannelAUser = AServerAChannelAUser
.builder()
.channel(channel)
.user(user.getUserReference())
.guild(user.getServerReference())
.aUserInAServer(user)
.build();
Reminder reminder = reminderManagementService.createReminder(aServerAChannelAUser, remindText, remindAt, messageId, false, false);
log.info("Creating reminder for user {} in guild {} due at {}.",
user.getUserReference().getId(), user.getServerReference().getId(), remindAt);
@@ -102,6 +108,19 @@ public class RemindServiceBean implements ReminderService {
return reminder;
}
@Override
public Reminder createReminderInForUser(AUser aUser, String remindText, Duration remindIn) {
Instant remindAt = Instant.now().plusMillis(remindIn.toMillis());
AServerAChannelAUser aServerAChannelAUser = AServerAChannelAUser
.builder()
.user(aUser)
.build();
Reminder reminder = reminderManagementService.createReminder(aServerAChannelAUser, remindText, remindAt, null, true, true);
log.info("Creating reminder for user {} due at {}.", aUser.getId(), remindAt);
scheduleReminder(remindIn, reminder);
return reminder;
}
@Override
public Reminder createReminderInForUser(AUserInAServer user, String remindText, Duration remindIn, Long channelId) {
return createReminderInForUser(user, remindText, remindIn, channelId, null);
@@ -136,30 +155,56 @@ public class RemindServiceBean implements ReminderService {
@Transactional
public void executeReminder(Long reminderId) {
Reminder reminderToRemindFor = reminderManagementService.loadReminder(reminderId);
if(reminderToRemindFor.isReminded()) {
if(reminderToRemindFor.getReminded()) {
return;
}
AServer server = reminderToRemindFor.getServer();
AChannel channel = reminderToRemindFor.getChannel();
Long userId = reminderToRemindFor.getRemindedUser().getUserReference().getId();
log.info("Executing reminder {} in channel {} in server {} for user {}.",
reminderId, channel.getId(), server.getId(), userId);
Optional<Guild> guildToAnswerIn = guildService.getGuildByIdOptional(server.getId());
if(guildToAnswerIn.isPresent()) {
Optional<GuildMessageChannel> channelToAnswerIn = channelService.getMessageChannelFromServerOptional(server.getId(), channel.getId());
// only send the message if the channel still exists, if not, only set the reminder to reminded.
if(channelToAnswerIn.isPresent()) {
memberService.getMemberInServerAsync(server.getId(), userId).thenAccept(member ->
self.sendReminderText(reminderId, channelToAnswerIn.get(), member)
).exceptionally(throwable -> {
log.warn("Member {} not anymore in server {} - not reminding.", userId, server.getId(), throwable);
return null;
});
} else {
log.warn("Channel {} in server {} to remind user did not exist anymore. Ignoring reminder {}", channel.getId(), server.getId(), reminderId);
}
Long userId = reminderToRemindFor.getRemindedAUser().getId();
if(reminderToRemindFor.getSendInDm()) {
log.info("Executing reminder {} in DMs of user {}.", reminderId, userId);
Long serverId = reminderToRemindFor.getServer() != null ? reminderToRemindFor.getServer().getId() : null;
Long channelId = reminderToRemindFor.getChannel() != null ? reminderToRemindFor.getChannel().getId() : null;
Long messageId = reminderToRemindFor.getMessageId();
Instant reminderDate = reminderToRemindFor.getReminderDate();
Instant targetDate = reminderToRemindFor.getTargetDate();
ReminderDisplay reminderDisplay = ReminderDisplay.fromReminder(reminderToRemindFor);
userService.retrieveUserForId(userId).thenCompose(user -> {
ExecutedReminderModel build = ExecutedReminderModel
.builder()
.reminderId(reminderId)
.serverId(serverId)
.channelId(channelId)
.messageId(messageId)
.reminderDisplay(reminderDisplay)
.userDisplay(UserDisplay.fromUser(user))
.duration(Duration.between(reminderDate, targetDate))
.build();
return messageService.sendEmbedToUser(user, REMINDER_TEMPLATE_TEXT, build);
}).exceptionally(throwable -> {
log.error("Failed to remind user {} about reminder {}.", userId, reminderId, throwable);
return null;
});
} else {
log.warn("Guild {} to remind user in did not exist anymore. Ignoring reminder {}.", server.getId(), reminderId);
AServer server = reminderToRemindFor.getServer();
AChannel channel = reminderToRemindFor.getChannel();
log.info("Executing reminder {} in channel {} in server {} for user {}.",
reminderId, channel.getId(), server.getId(), userId);
Optional<Guild> guildToAnswerIn = guildService.getGuildByIdOptional(server.getId());
if(guildToAnswerIn.isPresent()) {
Optional<GuildMessageChannel> channelToAnswerIn = channelService.getMessageChannelFromServerOptional(server.getId(), channel.getId());
// only send the message if the channel still exists, if not, only set the reminder to reminded.
if(channelToAnswerIn.isPresent()) {
memberService.getMemberInServerAsync(server.getId(), userId).thenCompose(member ->
self.sendReminderText(reminderId, channelToAnswerIn.get(), member)
).exceptionally(throwable -> {
log.warn("Member {} not anymore in server {} - not reminding.", userId, server.getId(), throwable);
return null;
});
} else {
log.warn("Channel {} in server {} to remind user did not exist anymore. Ignoring reminder {}", channel.getId(), server.getId(), reminderId);
}
} else {
log.warn("Guild {} to remind user in did not exist anymore. Ignoring reminder {}.", server.getId(), reminderId);
}
}
reminderManagementService.setReminded(reminderToRemindFor);
}
@@ -173,11 +218,12 @@ public class RemindServiceBean implements ReminderService {
.stream()
.map(reminderParticipant -> MemberDisplay.fromAUserInAServer(reminderParticipant.getParticipant()))
.collect(Collectors.toList());
ReminderDisplay reminderDisplay = ReminderDisplay.fromReminder(reminder);
ExecutedReminderModel build = ExecutedReminderModel
.builder()
.reminder(reminder)
.reminderParticipants(participantsDisplays)
.memberNameDisplay(MemberNameDisplay.fromMember(member))
.reminderDisplay(reminderDisplay)
.userDisplay(UserDisplay.fromUser(member.getUser()))
.duration(Duration.between(reminder.getReminderDate(), reminder.getTargetDate()))
.build();
MessageToSend messageToSend = templateService.renderEmbedTemplate(REMINDER_TEMPLATE_TEXT, build, channelToAnswerIn.getGuild().getIdLong());
@@ -195,10 +241,21 @@ public class RemindServiceBean implements ReminderService {
}
}
@Override
public void unRemind(Long reminderId, AUser aUser) {
log.info("Trying to end reminder {} for user {}.", reminderId, aUser.getId());
Reminder reminder = reminderManagementService.getReminderByAndByUserNotRemindedForUserCommand(aUser, reminderId).orElseThrow(() -> new ReminderNotFoundException(reminderId));
reminder.setReminded(true);
if(reminder.getJobTriggerKey() != null) {
log.debug("Stopping scheduled trigger {} for reminder {}.", reminder.getJobTriggerKey(), reminderId);
schedulerService.stopTrigger(reminder.getJobTriggerKey());
}
}
@Override
public void snoozeReminder(Long reminderId, AUserInAServer user, Duration newDuration) {
Reminder reminder = reminderManagementService.getReminderByAndByUser(user, reminderId).orElseThrow(() -> new ReminderNotFoundException(reminderId));
if(reminder.getTargetDate().isAfter(Instant.now()) && !reminder.isReminded()) {
if(reminder.getTargetDate().isAfter(Instant.now()) && !reminder.getReminded()) {
throw new NotPossibleToSnoozeException();
}
log.info("Snoozing reminder {} to be executed in {}.", reminderId, newDuration);

View File

@@ -1,6 +1,7 @@
package dev.sheldan.abstracto.remind.service.management;
import dev.sheldan.abstracto.core.models.AServerAChannelAUser;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.remind.exception.ReminderNotFoundException;
import dev.sheldan.abstracto.remind.model.database.Reminder;
@@ -21,20 +22,20 @@ public class ReminderManagementServiceBean implements ReminderManagementService
private ReminderRepository reminderRepository;
@Override
public Reminder createReminder(AServerAChannelAUser userToBeReminded, String text, Instant timeToBeRemindedAt, Long messageId) {
public Reminder createReminder(AServerAChannelAUser userToBeReminded, String text, Instant timeToBeRemindedAt, Long messageId, Boolean sendInDms, Boolean userCommand) {
Reminder reminder = Reminder.builder()
.channel(userToBeReminded.getChannel())
.server(userToBeReminded.getGuild())
.remindedUser(userToBeReminded.getAUserInAServer())
.remindedAUser(userToBeReminded.getUser())
.sendInDm(sendInDms)
.reminded(false)
.text(text)
.reminderDate(Instant.now())
.userCommand(userCommand)
.targetDate(timeToBeRemindedAt)
.messageId(messageId)
.build();
log.info("Creating reminder for user {} in server {} in message {} to be reminded at {}.",
userToBeReminded.getAUserInAServer().getUserReference().getId(), userToBeReminded.getGuild().getId(), messageId, timeToBeRemindedAt);
return reminderRepository.save(reminder);
}
@@ -65,6 +66,16 @@ public class ReminderManagementServiceBean implements ReminderManagementService
return reminderRepository.getByRemindedUserAndRemindedFalse(aUserInAServer);
}
@Override
public List<Reminder> getActiveUserRemindersForUser(AUser aUser) {
return reminderRepository.getByRemindedAUserAndRemindedFalseAndUserCommandTrueAndServerIsNull(aUser);
}
@Override
public Optional<Reminder> getReminderByAndByUserNotRemindedForUserCommand(AUser aUser, Long reminderId) {
return Optional.ofNullable(reminderRepository.getByIdAndRemindedAUserAndUserCommandTrue(reminderId, aUser));
}
@Override
public Optional<Reminder> getReminderByAndByUserNotReminded(AUserInAServer aUserInAServer, Long reminderId) {
return Optional.ofNullable(reminderRepository.getByIdAndRemindedUserAndRemindedFalse(reminderId, aUserInAServer));

View File

@@ -2,9 +2,35 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
<changeSet author="Sheldan" id="reminder-add_user_installable_support">
<addColumn tableName="reminder">
<column name="user_id" type="BIGINT">
<constraints nullable="true"/>
</column>
<column name="send_dm" type="BOOLEAN" value="false">
<constraints nullable="false"/>
</column>
<column name="user_command" type="BOOLEAN" value="false">
<constraints nullable="false"/>
</column>
</addColumn>
<sql>
update reminder set user_id = (select ua.user_id from user_in_server ua where ua.user_in_server_id = user_in_server_id order by ua.server_id limit 1)
</sql>
<addNotNullConstraint columnName="user_id"
tableName="reminder"
validate="true"/>
<sql>
ALTER TABLE reminder ALTER COLUMN server_id DROP NOT NULL;
ALTER TABLE reminder ALTER COLUMN channel_id DROP NOT NULL;
ALTER TABLE reminder ALTER COLUMN user_in_server_id DROP NOT NULL;
</sql>
</changeSet>
<changeSet author="Sheldan" id="reminder-resize_text">
<modifyDataType columnName="text"
newDataType="VARCHAR(4000)"
tableName="reminder"/>
newDataType="VARCHAR(4000)"
tableName="reminder"/>
</changeSet>
</databaseChangeLog>

View File

@@ -1,48 +0,0 @@
package dev.sheldan.abstracto.remind.command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.remind.service.ReminderService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class UnRemindTest {
@InjectMocks
private UnRemind testUnit;
@Mock
private ReminderService reminderService;
@Mock
private UserInServerManagementService userInServerManagementService;
@Test
public void testExecuteCommand() {
Long reminderId = 6L;
CommandContext withParameters = CommandTestUtilities.getWithParameters(Arrays.asList(reminderId));
AUserInAServer user = Mockito.mock(AUserInAServer.class);
when(userInServerManagementService.loadOrCreateUser(withParameters.getAuthor())).thenReturn(user);
CommandResult result = testUnit.execute(withParameters);
verify(reminderService, times(1)).unRemind(reminderId, user);
CommandTestUtilities.checkSuccessfulCompletion(result);
}
@Test
public void validateCommand() {
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
}
}

View File

@@ -1,267 +0,0 @@
package dev.sheldan.abstracto.remind.service;
import dev.sheldan.abstracto.core.models.AServerAChannelAUser;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.GuildService;
import dev.sheldan.abstracto.core.service.MemberService;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.remind.exception.ReminderNotFoundException;
import dev.sheldan.abstracto.remind.model.database.Reminder;
import dev.sheldan.abstracto.remind.service.management.ReminderManagementService;
import dev.sheldan.abstracto.remind.service.management.ReminderParticipantManagementService;
import dev.sheldan.abstracto.scheduling.model.JobParameters;
import dev.sheldan.abstracto.scheduling.service.SchedulerService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.unions.GuildMessageChannelUnion;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.utils.ImageProxy;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.Date;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ScheduledExecutorService;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class RemindServiceBeanTest {
@InjectMocks
private RemindServiceBean testUnit;
@Mock
private ReminderManagementService reminderManagementService;
@Mock
private ChannelManagementService channelManagementService;
@Mock
private TemplateService templateService;
@Mock
private SchedulerService schedulerService;
@Mock
private GuildService guildService;
@Mock
private MemberService memberService;
@Mock
private RemindServiceBean self;
@Mock
private ChannelService channelService;
@Mock
private Message message;
@Mock
private GuildMessageChannelUnion guildMessageChannelUnion;
@Mock
private MessageChannelUnion messageChannelUnion;
@Mock
private ScheduledExecutorService instantReminderScheduler;
@Mock
private ReminderParticipantManagementService reminderParticipantManagementService;
@Mock
private AServer server;
@Mock
private AUserInAServer aUserInAServer;
@Mock
private AUser user;
@Mock
private User jdaUser;
@Mock
private AChannel aChannel;
private static final Long REMINDER_ID = 5L;
private static final Long CHANNEL_ID = 6L;
private static final Long SERVER_ID = 8L;
private static final Long USER_ID = 9L;
@Before
public void setup() {
when(message.getIdLong()).thenReturn(5L);
when(message.getChannel()).thenReturn(messageChannelUnion);
}
@Test
public void createReminderWithScheduler() {
String remindText = "text";
String triggerKey = "trigger";
Duration duration = Duration.ofSeconds(62);
when(message.getChannel()).thenReturn(messageChannelUnion);
when(aUserInAServer.getServerReference()).thenReturn(server);
when(aUserInAServer.getUserReference()).thenReturn(user);
Instant targetDate = Instant.now().plus(duration);
Reminder createdReminder = Mockito.mock(Reminder.class);
when(createdReminder.getTargetDate()).thenReturn(targetDate);
Long messageId = 5L;
when(reminderManagementService.createReminder(any(AServerAChannelAUser.class), eq(remindText), any(Instant.class), eq(messageId))).thenReturn(createdReminder);
when(schedulerService.executeJobWithParametersOnce(eq("reminderJob"), eq("utility"), any(JobParameters.class), eq(Date.from(targetDate)))).thenReturn(triggerKey);
Reminder returnedReminder = testUnit.createReminderInForUser(aUserInAServer, remindText, duration, message);
verify(reminderManagementService, times(1)).saveReminder(createdReminder);
Assert.assertEquals(createdReminder, returnedReminder);
}
@Test
public void createReminderWithoutScheduler() {
String remindText = "text";
Duration duration = Duration.ofSeconds(50);
when(message.getChannel()).thenReturn(messageChannelUnion);
when(messageChannelUnion.getIdLong()).thenReturn(CHANNEL_ID);
when(channelManagementService.loadChannel(CHANNEL_ID)).thenReturn(aChannel);
Reminder createdReminder = Mockito.mock(Reminder.class);
when(createdReminder.getText()).thenReturn(remindText);
Long messageId = 5L;
when(aUserInAServer.getServerReference()).thenReturn(server);
when(aUserInAServer.getUserReference()).thenReturn(user);
when(reminderManagementService.createReminder(any(AServerAChannelAUser.class), eq(remindText), any(Instant.class), eq(messageId))).thenReturn(createdReminder);
Reminder returnedReminder = testUnit.createReminderInForUser(aUserInAServer, remindText, duration, message);
verify(reminderManagementService, times(0)).saveReminder(createdReminder);
Assert.assertEquals(remindText, returnedReminder.getText());
Assert.assertEquals(createdReminder.getId(), returnedReminder.getId());
}
@Test
public void testExecuteReminder() {
Reminder remindedReminder = Mockito.mock(Reminder.class);
when(remindedReminder.getRemindedUser()).thenReturn(aUserInAServer);
when(remindedReminder.getChannel()).thenReturn(aChannel);
when(remindedReminder.getServer()).thenReturn(server);
when(aChannel.getId()).thenReturn(CHANNEL_ID);
when(server.getId()).thenReturn(SERVER_ID);
when(aUserInAServer.getUserReference()).thenReturn(user);
when(user.getId()).thenReturn(USER_ID);
when(reminderManagementService.loadReminder(REMINDER_ID)).thenReturn(remindedReminder);
Guild guildMock = Mockito.mock(Guild.class);
when(guildService.getGuildByIdOptional(SERVER_ID)).thenReturn(Optional.of(guildMock));
when(channelService.getMessageChannelFromServerOptional(SERVER_ID, CHANNEL_ID)).thenReturn(Optional.of(guildMessageChannelUnion));
Member mockedMember = Mockito.mock(Member.class);
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(mockedMember));
testUnit.executeReminder(REMINDER_ID);
verify(reminderManagementService, times(1)).setReminded(remindedReminder);
}
@Test
public void testExecuteReminderFromNotFoundChannel() {
Reminder remindedReminder = Mockito.mock(Reminder.class);
when(remindedReminder.getChannel()).thenReturn(aChannel);
when(remindedReminder.getServer()).thenReturn(server);
when(server.getId()).thenReturn(SERVER_ID);
when(aChannel.getId()).thenReturn(CHANNEL_ID);
when(reminderManagementService.loadReminder(REMINDER_ID)).thenReturn(remindedReminder);
Guild guildMock = Mockito.mock(Guild.class);
when(guildService.getGuildByIdOptional(SERVER_ID)).thenReturn(Optional.of(guildMock));
when(aUserInAServer.getUserReference()).thenReturn(user);
when(remindedReminder.getRemindedUser()).thenReturn(aUserInAServer);
when(channelService.getMessageChannelFromServerOptional(SERVER_ID, CHANNEL_ID)).thenReturn(Optional.empty());
testUnit.executeReminder(REMINDER_ID);
verify(reminderManagementService, times(1)).setReminded(remindedReminder);
verify(self, times(0)).sendReminderText(anyLong(), any(), any(Member.class));
}
@Test
public void testExecuteReminderFromNotFoundGuild() {
Long reminderId = 5L;
Reminder remindedReminder = Mockito.mock(Reminder.class);
when(remindedReminder.getChannel()).thenReturn(aChannel);
when(remindedReminder.getServer()).thenReturn(server);
when(server.getId()).thenReturn(SERVER_ID);
when(remindedReminder.getRemindedUser()).thenReturn(aUserInAServer);
when(aUserInAServer.getUserReference()).thenReturn(user);
when(reminderManagementService.loadReminder(reminderId)).thenReturn(remindedReminder);
when(guildService.getGuildByIdOptional(SERVER_ID)).thenReturn(Optional.empty());
testUnit.executeReminder(reminderId);
verify(reminderManagementService, times(1)).setReminded(remindedReminder);
}
@Test
public void testExecuteRemindedReminder() {
Reminder remindedReminder = Mockito.mock(Reminder.class);
when(remindedReminder.isReminded()).thenReturn(true);
when(reminderManagementService.loadReminder(REMINDER_ID)).thenReturn(remindedReminder);
testUnit.executeReminder(REMINDER_ID);
verify(guildService, times(0)).getGuildByIdOptional(anyLong());
}
@Test
public void testUnRemindScheduledReminder() {
String triggerKey = "trigger";
Reminder reminderToUnRemind = Mockito.mock(Reminder.class);
when(reminderToUnRemind.getJobTriggerKey()).thenReturn(triggerKey);
when(aUserInAServer.getServerReference()).thenReturn(server);
when(aUserInAServer.getUserReference()).thenReturn(user);
when(reminderManagementService.getReminderByAndByUserNotReminded(aUserInAServer, REMINDER_ID)).thenReturn(Optional.of(reminderToUnRemind));
testUnit.unRemind(REMINDER_ID, aUserInAServer);
verify(schedulerService, times(1)).stopTrigger(triggerKey);
}
@Test
public void testUnRemindNonScheduledReminder() {
Reminder reminderToUnRemind = Mockito.mock(Reminder.class);
when(aUserInAServer.getServerReference()).thenReturn(server);
when(aUserInAServer.getUserReference()).thenReturn(user);
when(reminderManagementService.getReminderByAndByUserNotReminded(aUserInAServer, REMINDER_ID)).thenReturn(Optional.of(reminderToUnRemind));
testUnit.unRemind(REMINDER_ID, aUserInAServer);
verify(schedulerService, times(0)).stopTrigger(anyString());
}
@Test(expected = ReminderNotFoundException.class)
public void testUnRemindNonExistingReminder() {
when(aUserInAServer.getServerReference()).thenReturn(server);
when(aUserInAServer.getUserReference()).thenReturn(user);
when(reminderManagementService.getReminderByAndByUserNotReminded(aUserInAServer, REMINDER_ID)).thenReturn(Optional.empty());
testUnit.unRemind(REMINDER_ID, aUserInAServer);
}
@Test
public void testSendReminderText() {
Member remindedMember = Mockito.mock(Member.class);
Guild guild = Mockito.mock(Guild.class);
when(remindedMember.getGuild()).thenReturn(guild);
when(guild.getIdLong()).thenReturn(8L);
when(remindedMember.getIdLong()).thenReturn(9L);
when(remindedMember.getUser()).thenReturn(jdaUser);
when(remindedMember.getEffectiveAvatar()).thenReturn(Mockito.mock(ImageProxy.class));
when(jdaUser.getDefaultAvatar()).thenReturn(Mockito.mock(ImageProxy.class));
Reminder remindedReminder = Mockito.mock(Reminder.class);
when(remindedReminder.getTargetDate()).thenReturn(Instant.now());
when(remindedReminder.getReminderDate()).thenReturn(Instant.now());
when(reminderManagementService.loadReminder(REMINDER_ID)).thenReturn(remindedReminder);
MessageToSend messageToSend = Mockito.mock(MessageToSend.class);
when(guildMessageChannelUnion.getGuild()).thenReturn(guild);
when(templateService.renderEmbedTemplate(eq(RemindServiceBean.REMINDER_TEMPLATE_TEXT), any(), eq(SERVER_ID))).thenReturn(messageToSend);
when(channelService.sendMessageToSendToChannel(messageToSend, guildMessageChannelUnion)).thenReturn(Arrays.asList(CompletableFuture.completedFuture(null)));
CompletableFuture<Void> future = testUnit.sendReminderText(REMINDER_ID, guildMessageChannelUnion, remindedMember);
future.join();
Assert.assertFalse(future.isCompletedExceptionally());
}
}

View File

@@ -1,132 +0,0 @@
package dev.sheldan.abstracto.remind.service.management;
import dev.sheldan.abstracto.core.models.AServerAChannelAUser;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.remind.model.database.Reminder;
import dev.sheldan.abstracto.remind.repository.ReminderRepository;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class ReminderManagementServiceBeanTest {
@InjectMocks
private ReminderManagementServiceBean testUnit;
@Mock
private ReminderRepository reminderRepository;
@Mock
private AUserInAServer aUserInAServer;
@Mock
private AChannel channel;
@Mock
private AServer server;
@Mock
private Reminder reminder;
private static final Long REMINDER_ID = 8L;
@Test
public void testCreateReminder() {
AServerAChannelAUser serverAChannelAUser = Mockito.mock(AServerAChannelAUser.class);
AUser user = Mockito.mock(AUser.class);
when(aUserInAServer.getUserReference()).thenReturn(user);
when(serverAChannelAUser.getAUserInAServer()).thenReturn(aUserInAServer);
when(serverAChannelAUser.getGuild()).thenReturn(server);
when(serverAChannelAUser.getChannel()).thenReturn(channel);
String reminderText = "text";
Instant reminderTargetDate = Instant.ofEpochSecond(1590615937);
Long messageId = 5L;
ArgumentCaptor<Reminder> reminderArgumentCaptor = ArgumentCaptor.forClass(Reminder.class);
Reminder savedReminder = Mockito.mock(Reminder.class);
when(reminderRepository.save(reminderArgumentCaptor.capture())).thenReturn(savedReminder);
Reminder createdReminder = testUnit.createReminder(serverAChannelAUser, reminderText, reminderTargetDate, messageId);
Assert.assertEquals(savedReminder, createdReminder);
Reminder capturedReminder = reminderArgumentCaptor.getValue();
Assert.assertEquals(messageId, capturedReminder.getMessageId());
Assert.assertEquals(aUserInAServer, capturedReminder.getRemindedUser());
Assert.assertEquals(server, capturedReminder.getServer());
Assert.assertEquals(reminderText, capturedReminder.getText());
Assert.assertEquals(reminderTargetDate, capturedReminder.getTargetDate());
Assert.assertEquals(channel, capturedReminder.getChannel());
Assert.assertFalse(capturedReminder.isReminded());
}
@Test
public void testSetReminded() {
testUnit.setReminded(reminder);
verify(reminder, times(1)).setReminded(true);
verify(reminderRepository, times(1)).save(reminder);
}
@Test
public void testSaveReminder() {
testUnit.saveReminder(reminder);
verify(reminderRepository, times(1)).save(reminder);
}
@Test
public void testRetrieveActiveReminders() {
Reminder reminder2 = Mockito.mock(Reminder.class);
List<Reminder> reminders = Arrays.asList(reminder, reminder2);
when(reminderRepository.getByRemindedUserAndRemindedFalse(aUserInAServer)).thenReturn(reminders);
List<Reminder> activeRemindersForUser = testUnit.getActiveRemindersForUser(aUserInAServer);
for (int i = 0; i < reminders.size(); i++) {
Reminder reference = reminders.get(i);
Reminder returned = activeRemindersForUser.get(i);
Assert.assertEquals(reference, returned);
}
Assert.assertEquals(reminders.size(), activeRemindersForUser.size());
}
@Test
public void testGetReminderByIdAndNotReminded() {
when(reminderRepository.getByIdAndRemindedUserAndRemindedFalse(REMINDER_ID, aUserInAServer)).thenReturn(reminder);
Optional<Reminder> returned = testUnit.getReminderByAndByUserNotReminded(aUserInAServer, REMINDER_ID);
Assert.assertTrue(returned.isPresent());
returned.ifPresent(returnedReminder -> Assert.assertEquals(reminder, returnedReminder));
}
@Test
public void testGetReminderByIdAndNotRemindedNothingFound() {
when(reminderRepository.getByIdAndRemindedUserAndRemindedFalse(REMINDER_ID, aUserInAServer)).thenReturn(null);
Optional<Reminder> returned = testUnit.getReminderByAndByUserNotReminded(aUserInAServer, REMINDER_ID);
Assert.assertFalse(returned.isPresent());
}
@Test
public void testLoadingReminder() {
when(reminderRepository.findById(REMINDER_ID)).thenReturn(Optional.of(reminder));
Optional<Reminder> returned = testUnit.loadReminderOptional(REMINDER_ID);
Assert.assertTrue(returned.isPresent());
returned.ifPresent(returnedReminder -> Assert.assertEquals(reminder, returnedReminder));
}
@Test
public void testLoadingReminderNotFound() {
when(reminderRepository.findById(REMINDER_ID)).thenReturn(Optional.empty());
Optional<Reminder> returned = testUnit.loadReminderOptional(REMINDER_ID);
Assert.assertFalse(returned.isPresent());
}
}

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>remind</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.5.56</version>
<version>1.6.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -2,6 +2,7 @@ package dev.sheldan.abstracto.remind.model.database;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import lombok.*;
@@ -25,18 +26,22 @@ public class Reminder implements Serializable {
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_in_server_id", nullable = false)
@JoinColumn(name = "user_in_server_id")
private AUserInAServer remindedUser;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private AUser remindedAUser;
@Column(name = "message_id")
private Long messageId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "channel_id", nullable = false)
@JoinColumn(name = "channel_id")
private AChannel channel;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "server_id", nullable = false)
@JoinColumn(name = "server_id")
private AServer server;
@Column(name = "created", nullable = false, insertable = false, updatable = false)
@@ -51,9 +56,17 @@ public class Reminder implements Serializable {
@Column(name = "text")
private String text;
@Builder.Default
@Column(name = "send_dm", nullable = false)
private Boolean sendInDm = false;
@Builder.Default
@Column(name = "user_command", nullable = false)
private Boolean userCommand = false;
@Builder.Default
@Column(name = "reminded", nullable = false)
private boolean reminded = false;
private Boolean reminded = false;
@Column(name = "job_trigger_key")
private String jobTriggerKey;

View File

@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.remind.model.template.commands;
import dev.sheldan.abstracto.core.models.context.ServerContext;
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
import dev.sheldan.abstracto.core.models.template.display.MemberNameDisplay;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import dev.sheldan.abstracto.core.utils.MessageUtils;
import dev.sheldan.abstracto.remind.model.database.Reminder;
import lombok.Getter;
@@ -16,12 +17,16 @@ import java.util.List;
@Setter
@SuperBuilder
public class ExecutedReminderModel extends ServerContext {
private Reminder reminder;
private MemberNameDisplay memberNameDisplay;
private Long reminderId;
private Long serverId;
private Long channelId;
private Long messageId;
private UserDisplay userDisplay;
private ReminderDisplay reminderDisplay;
private List<MemberDisplay> reminderParticipants;
private Duration duration;
public String getMessageUrl() {
return MessageUtils.buildMessageUrl(this.reminder.getServer().getId() ,this.reminder.getChannel().getId(), this.reminder.getMessageId());
return MessageUtils.buildMessageUrl(serverId , channelId, messageId);
}
}

View File

@@ -17,6 +17,8 @@ public class ReminderDisplay {
private String text;
private Instant targetDate;
private Instant creationDate;
private Boolean sentInDm;
private Boolean userCommand;
@Builder.Default
private Boolean joined = false;
private ServerChannelMessage message;
@@ -25,15 +27,17 @@ public class ReminderDisplay {
ServerChannelMessage message = ServerChannelMessage
.builder()
.messageId(reminder.getMessageId())
.channelId(reminder.getChannel().getId())
.serverId(reminder.getServer().getId())
.channelId(reminder.getChannel() != null ? reminder.getChannel().getId() : null)
.serverId(reminder.getServer() != null ? reminder.getServer().getId() : null)
.build();
return ReminderDisplay
.builder()
.creationDate(reminder.getReminderDate())
.targetDate(reminder.getTargetDate())
.id(reminder.getId())
.reminded(reminder.isReminded())
.sentInDm(reminder.getSendInDm())
.reminded(reminder.getReminded())
.userCommand(reminder.getUserCommand())
.message(message)
.text(reminder.getText())
.build();

View File

@@ -1,7 +1,7 @@
package dev.sheldan.abstracto.remind.model.template.commands;
import dev.sheldan.abstracto.core.models.ServerChannelMessage;
import dev.sheldan.abstracto.core.models.template.display.MemberNameDisplay;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@@ -11,7 +11,7 @@ import lombok.Setter;
@Builder
public class ReminderModel {
private String remindText;
private MemberNameDisplay memberDisplay;
private UserDisplay userDisplay;
private ReminderDisplay reminder;
private ServerChannelMessage message;
private String joinButtonId;

View File

@@ -1,9 +1,9 @@
package dev.sheldan.abstracto.remind.model.template.commands;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Member;
import java.util.ArrayList;
import java.util.List;
@@ -14,5 +14,5 @@ import java.util.List;
public class RemindersModel {
@Builder.Default
private List<ReminderDisplay> reminders = new ArrayList<>();
private Member member;
private UserDisplay userDisplay;
}

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.remind.service;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.remind.model.database.Reminder;
import net.dv8tion.jda.api.entities.Message;
@@ -9,8 +10,10 @@ import java.time.Duration;
public interface ReminderService {
Reminder createReminderInForUser(AUserInAServer user, String remindText, Duration remindIn, Message message);
Reminder createReminderInForUser(AUserInAServer user, String remindText, Duration remindIn, Long channelId, Long messageId);
Reminder createReminderInForUser(AUser aUser, String remindText, Duration remindIn);
Reminder createReminderInForUser(AUserInAServer user, String remindText, Duration remindIn, Long channelId);
void executeReminder(Long reminderId);
void unRemind(Long reminderId, AUserInAServer userInAServer);
void unRemind(Long reminderId, AUser aUser);
void snoozeReminder(Long reminderId, AUserInAServer user, Duration newDuration);
}

View File

@@ -1,6 +1,7 @@
package dev.sheldan.abstracto.remind.service.management;
import dev.sheldan.abstracto.core.models.AServerAChannelAUser;
import dev.sheldan.abstracto.core.models.database.AUser;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.remind.model.database.Reminder;
@@ -9,12 +10,14 @@ import java.util.List;
import java.util.Optional;
public interface ReminderManagementService {
Reminder createReminder(AServerAChannelAUser userToBeReminded, String text, Instant timeToBeRemindedAt, Long messageId);
Reminder createReminder(AServerAChannelAUser userToBeReminded, String text, Instant timeToBeRemindedAt, Long messageId, Boolean sendInDms, Boolean userCommand);
Optional<Reminder> loadReminderOptional(Long reminderId);
Reminder loadReminder(Long reminderId);
void setReminded(Reminder reminder);
Reminder saveReminder(Reminder reminder);
List<Reminder> getActiveRemindersForUser(AUserInAServer aUserInAServer);
List<Reminder> getActiveUserRemindersForUser(AUser aUser);
Optional<Reminder> getReminderByAndByUserNotReminded(AUserInAServer aUserInAServer, Long reminderId);
Optional<Reminder> getReminderByAndByUserNotRemindedForUserCommand(AUser aUser, Long reminderId);
Optional<Reminder> getReminderByAndByUser(AUserInAServer aUserInAServer, Long reminderId);
}

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