Compare commits

..

13 Commits

Author SHA1 Message Date
Sheldan
d2c17cb1fc [maven-release-plugin] prepare release abstracto-application-1.2.2 2021-03-24 14:30:07 +01:00
Sheldan
9de7a59295 [AB-210] fixing some issues in which futures were not completed, when lists were empty
fixing async issue with caching reactions
adding a few more log statements to caching
2021-03-24 14:17:00 +01:00
Sheldan
f9d0e5fa00 [AB-208] fixing order of top starboard posts for individual members 2021-03-24 11:08:56 +01:00
Sheldan
ef421961ca [AB-211] fixing lovecalc having optional parameters 2021-03-24 11:03:51 +01:00
Sheldan
fe8519489c [maven-release-plugin] prepare for next development iteration 2021-03-23 22:19:14 +01:00
Sheldan
72c73b8b34 [maven-release-plugin] prepare release abstracto-application-1.2.1 2021-03-23 22:19:08 +01:00
Sheldan
2b3b0f42c4 [AB-207] fixing command being disabled, if its part of a channel group, but the given channel is not part of that channel group
fixing null pointer in channel group created listener
fixing connection string in config deploy tool
2021-03-23 22:08:08 +01:00
Sheldan
92b8e1dd8b [maven-release-plugin] prepare for next development iteration 2021-03-22 21:46:09 +01:00
Sheldan
b94801192e [maven-release-plugin] prepare release abstracto-application-1.2 2021-03-22 21:46:02 +01:00
Sheldan
f5f0cbcb1e [AB-206] fixing missing command channel group type
fixing not setting the server for creating a command in a channel
adding exceptions for incorrect channel group type
2021-03-22 21:35:28 +01:00
Sheldan
47f33758c9 [AB-204] setting wget to silent in docker file to reduce log output 2021-03-22 01:23:49 +01:00
Sheldan
0a79fe2318 [AB-204] fixing registry prefix in release job 2021-03-22 01:19:55 +01:00
Sheldan
da97f040f9 [maven-release-plugin] prepare for next development iteration 2021-03-22 00:53:40 +01:00
72 changed files with 290 additions and 89 deletions

View File

@@ -46,5 +46,5 @@ jobs:
working-directory: ./abstracto-application/installer/src/main/docker/deployment
run: docker-compose build && docker-compose push
env:
REGISTRY_PREFIX: docker.pkg.github.com/sheldan/abstracto
REGISTRY_PREFIX: docker.pkg.github.com/sheldan/abstracto/
VERSION: ${{ env.version }}

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>assignable-roles</artifactId>
<version>1.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -49,8 +49,8 @@ public class LoveCalc extends AbstractConditionableCommand {
@Override
public CommandConfiguration getConfiguration() {
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder().name("firstSubject").type(String.class).templated(true).optional(true).build());
parameters.add(Parameter.builder().name("secondSubject").type(String.class).templated(true).optional(true).build());
parameters.add(Parameter.builder().name("firstSubject").type(String.class).templated(true).build());
parameters.add(Parameter.builder().name("secondSubject").type(String.class).templated(true).build());
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("loveCalc")

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>entertainment</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>repost-detection</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>repost-detection</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.1</version>
<version>1.2.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.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

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

View File

@@ -32,6 +32,7 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@@ -223,7 +224,7 @@ public class StarboardServiceBean implements StarboardService {
Long receivedStars = starboardPostManagementService.retrieveReceivedStarsOfUserInServer(member.getGuild().getIdLong(), member.getIdLong());
Long givenStars = starboardPostManagementService.retrieveGivenStarsOfUserInServer(member.getGuild().getIdLong(), member.getIdLong());
List<StarboardPost> topPosts = starboardPostManagementService.retrieveTopPostsForUserInServer(member.getGuild().getIdLong(), member.getIdLong(), count);
List<StarStatsPost> starStatsPosts = topPosts.stream().map(this::fromStarboardPost).collect(Collectors.toList());
List<StarStatsPost> starStatsPosts = topPosts.stream().map(this::fromStarboardPost).sorted(Comparator.comparingInt(StarStatsPost::getStarCount).reversed()).collect(Collectors.toList());
List<String> emotes = new ArrayList<>();
for (int i = 1; i < count + 1; i++) {
emotes.add(getStarboardRankingEmote(member.getGuild().getIdLong(), i));

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>starboard</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.1</version>
<version>1.2.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.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

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

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>statistic</artifactId>
<version>1.1</version>
<version>1.2.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.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

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

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>suggestion</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.1</version>
<version>1.2.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.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

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

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>utility</artifactId>
<version>1.1</version>
<version>1.2.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.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.core</groupId>
<artifactId>core</artifactId>
<version>1.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

View File

@@ -2,6 +2,8 @@ package dev.sheldan.abstracto.core.command;
public class CommandConstants {
public static final String COMMAND_CHANNEL_GROUP_KEY = "command";
private CommandConstants() {
}

View File

@@ -33,9 +33,13 @@ public class ChannelGroupCommandServiceBean implements ChannelGroupCommandServic
return false;
}
}
// empty -> no groups, command enabled
// not empty -> has groups, command is disabled in all
return allChannelGroupsOfCommand.isEmpty();
/*
if we are here this means either:
the command has no channel groups assigned -> enabled
the command has one or more channel group and is enabled in these ones -> enabled
the command has a channel group with channels (and it might be enabled/disabled, does not matter), but the given channel is not part of that group -> ok
*/
return true;
}
@Override

View File

@@ -34,6 +34,7 @@ public class ChannelGroupCommandManagementServiceBean implements ChannelGroupCom
AChannelGroupCommand channelGroupCommand = AChannelGroupCommand
.builder()
.command(command)
.server(group.getServer())
.group(group)
.enabled(false)
.build();

View File

@@ -25,6 +25,7 @@ public class AsyncChannelGroupCreatedListenerManager {
@TransactionalEventListener
public void executeListener(ChannelGroupCreatedListenerModel createdGroup){
if(listener == null) return;
listener.forEach(asyncChannelGroupCreatedListener ->
listenerService.executeListener(asyncChannelGroupCreatedListener, createdGroup, channelGroupCreatedExecutor)
);

View File

@@ -4,7 +4,6 @@ import dev.sheldan.abstracto.core.metric.OkHttpMetrics;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
import net.dv8tion.jda.internal.utils.IOUtil;
import okhttp3.OkHttpClient;
@@ -26,7 +25,7 @@ public class BotServiceBean implements BotService {
@Override
public void login() throws LoginException {
JDABuilder builder = JDABuilder.create(System.getenv("TOKEN"), GatewayIntent.GUILD_MEMBERS, GUILD_VOICE_STATES,
JDABuilder builder = JDABuilder.create(System.getenv("TOKEN"), GUILD_VOICE_STATES,
GUILD_EMOJIS, GUILD_MEMBERS, GUILD_MESSAGE_REACTIONS, GUILD_MESSAGES,
GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGE_REACTIONS, DIRECT_MESSAGES, GUILD_PRESENCES);

View File

@@ -86,6 +86,7 @@ public class CacheEntityServiceBean implements CacheEntityService {
}
List<MessageEmbed.Field> fields = embed.getFields();
if(!fields.isEmpty()) {
log.trace("Caching {} fields.", fields.size());
List<CachedEmbedField> cachedEmbedFields = new ArrayList<>();
fields.forEach(field -> {
CachedEmbedField build = CachedEmbedField
@@ -159,16 +160,27 @@ public class CacheEntityServiceBean implements CacheEntityService {
List<ServerUser> aUsers = new ArrayList<>();
users.forEachAsync(user -> {
log.trace("Loading user {} for reaction.", user.getIdLong());
concreteSelf.loadUser(reaction, aUsers, user);
return false;
}).thenAccept(o -> future.complete(builder.build()))
.exceptionally(throwable -> {
log.error("Failed to load reaction users.", throwable);
return null;
});
builder.users(aUsers);
builder.self(reaction.isSelf());
builder.emote(getCachedEmoteFromEmote(reaction.getReactionEmote(), reaction.getGuild()));
}).thenAccept(o -> {
log.trace("Users have been loaded. Completing future.");
builder.users(aUsers);
builder.self(reaction.isSelf());
builder.emote(getCachedEmoteFromEmote(reaction.getReactionEmote(), reaction.getGuild()));
future.complete(builder.build());
})
.exceptionally(throwable -> {
log.error("Failed to load reaction users.", throwable);
return null;
});
if(users.isEmpty()) {
log.trace("Reaction had no users. Completing future anyway.");
builder.users(aUsers);
builder.self(reaction.isSelf());
builder.emote(getCachedEmoteFromEmote(reaction.getReactionEmote(), reaction.getGuild()));
future.complete(builder.build());
}
return future;
}
@@ -183,22 +195,25 @@ public class CacheEntityServiceBean implements CacheEntityService {
public CompletableFuture<CachedMessage> buildCachedMessageFromMessage(Message message) {
CompletableFuture<CachedMessage> future = new CompletableFuture<>();
List<CachedAttachment> attachments = new ArrayList<>();
log.trace("Caching {} attachments.", message.getAttachments().size());
message.getAttachments().forEach(attachment ->
attachments.add(getCachedAttachment(attachment))
);
log.trace("Caching {} embeds.", message.getEmbeds().size());
List<CachedEmbed> embeds = new ArrayList<>();
message.getEmbeds().forEach(embed ->
embeds.add(getCachedEmbedFromEmbed(embed))
);
log.trace("Caching {} emotes.", message.getEmbeds().size());
List<CachedEmote> emotes = new ArrayList<>();
if(message.isFromGuild()) {
message.getEmotesBag().forEach(emote -> emotes.add(getCachedEmoteFromEmote(emote, message.getGuild())));
}
List<CompletableFuture<CachedReactions>> futures = new ArrayList<>();
log.trace("Caching {} reactions.", message.getReactions().size());
message.getReactions().forEach(messageReaction -> futures.add(getCachedReactionFromReaction(messageReaction)));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(aVoid ->
{
CachedAuthor cachedAuthor = CachedAuthor.builder().authorId(message.getAuthor().getIdLong()).isBot(message.getAuthor().isBot()).build();
@@ -222,6 +237,23 @@ public class CacheEntityServiceBean implements CacheEntityService {
log.error("Failed to load reactions for message {}. ", message.getId(), throwable);
return null;
});
if(message.getReactions().isEmpty()) {
CachedAuthor cachedAuthor = CachedAuthor.builder().authorId(message.getAuthor().getIdLong()).isBot(message.getAuthor().isBot()).build();
CachedMessage.CachedMessageBuilder builder = CachedMessage.builder()
.author(cachedAuthor)
.messageId(message.getIdLong())
.channelId(message.getChannel().getIdLong())
.content(message.getContentRaw())
.embeds(embeds)
.emotes(emotes)
.timeCreated(Instant.from(message.getTimeCreated()))
.attachments(attachments);
if(message.isFromGuild()) {
builder.serverId(message.getGuild().getIdLong());
}
future.complete(builder
.build());
}
return future;
}

View File

@@ -19,6 +19,8 @@ import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
import static dev.sheldan.abstracto.core.command.CommandConstants.COMMAND_CHANNEL_GROUP_KEY;
@Component
public class ChannelGroupServiceBean implements ChannelGroupService {
@@ -95,10 +97,7 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
@Override
public void disableCommandInChannelGroup(String commandName, String channelGroupName, Long serverId) {
AServer server = serverManagementService.loadOrCreate(serverId);
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
if(channelGroup == null) {
throw new ChannelGroupNotFoundException(channelGroupName, channelGroupManagementService.getAllAvailableAsString(server));
}
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServerAndType(channelGroupName, server, COMMAND_CHANNEL_GROUP_KEY);
ACommand command = commandManagementService.findCommandByName(commandName);
if(command == null) {
throw new CommandNotFoundException();
@@ -109,10 +108,7 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
@Override
public void enableCommandInChannelGroup(String commandName, String channelGroupName, Long serverId) {
AServer server = serverManagementService.loadOrCreate(serverId);
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
if(channelGroup == null) {
throw new ChannelGroupNotFoundException(channelGroupName, channelGroupManagementService.getAllAvailableAsString(server));
}
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServerAndType(channelGroupName, server, COMMAND_CHANNEL_GROUP_KEY);
ACommand command = commandManagementService.findCommandByName(commandName);
if(command == null) {
throw new CommandNotFoundException();

View File

@@ -42,7 +42,7 @@ public class MessageCacheBean implements MessageCache {
@Override
@CachePut(key = "#message.id")
public CompletableFuture<CachedMessage> putMessageInCache(Message message) {
log.trace("Adding message {} to cache", message.getId());
log.info("Adding message {} to cache.", message.getId());
return cacheEntityService.buildCachedMessageFromMessage(message);
}
@@ -50,26 +50,27 @@ public class MessageCacheBean implements MessageCache {
@Override
@CachePut(key = "#message.messageId.toString()")
public CompletableFuture<CachedMessage> putMessageInCache(CachedMessage message) {
log.trace("Adding cached message to cache");
log.info("Adding cached message {} to cache.", message.getMessageId());
return CompletableFuture.completedFuture(message);
}
@Override
@Cacheable(key = "#message.id")
public CompletableFuture<CachedMessage> getMessageFromCache(Message message) {
log.trace("Retrieving message {}", message.getId());
log.trace("Retrieving message {}.", message.getId());
return getMessageFromCache(message.getGuild().getIdLong(), message.getChannel().getIdLong(), message.getIdLong());
}
@Override
@Cacheable(key = "#messageId.toString()")
public CompletableFuture<CachedMessage> getMessageFromCache(Long guildId, Long textChannelId, Long messageId) {
log.trace("Retrieving message {} with parameters.", messageId);
log.info("Retrieving message {}.", messageId);
return concreteSelf.loadMessage(guildId, textChannelId, messageId);
}
@Override
public CompletableFuture<CachedMessage> loadMessage(Long guildId, Long textChannelId, Long messageId) {
log.info("Loading message {} from channel {} in server {}.", messageId, textChannelId, guildId);
CompletableFuture<CachedMessage> future = new CompletableFuture<>();
Optional<Guild> guildOptional = guildService.getGuildByIdOptional(guildId);
if(guildOptional.isPresent()) {

View File

@@ -139,9 +139,13 @@ public class ChannelGroupManagementServiceBean implements ChannelGroupManagement
public AChannelGroup findByNameAndServerAndType(String name, AServer server, String expectedType) {
String lowerName = name.toLowerCase();
Optional<AChannelGroup> channelOptional = channelGroupRepository.findByGroupNameAndServerAndChannelGroupType_GroupTypeKey(lowerName, server, expectedType);
return channelOptional.orElseThrow( () -> {
List<String> channelGroupNames = extractChannelGroupNames(findAllInServerWithType(server.getId(), expectedType));
return new ChannelGroupNotFoundException(name.toLowerCase(), channelGroupNames);
return channelOptional.orElseThrow(() -> {
if(channelGroupRepository.existsByGroupNameAndServer(lowerName, server)) {
return new ChannelGroupIncorrectTypeException(name.toLowerCase(), expectedType);
} else {
List<String> channelGroupNames = extractChannelGroupNames(findAllInServerWithType(server.getId(), expectedType));
return new ChannelGroupNotFoundException(name.toLowerCase(), channelGroupNames);
}
});
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../dbchangelog-3.8.xsd" >
<include file="core-seedData/data.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -0,0 +1,14 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
<changeSet author="Sheldan" id="command-channelGroupType-insertion">
<insert tableName="channel_group_type">
<column name="group_type_key" value="command"/>
</insert>
</changeSet>
</databaseChangeLog>

View File

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

View File

@@ -9,4 +9,5 @@
<include file="1.0-core/collection.xml" relativeToChangelogFile="true"/>
<include file="1.0-templating/collection.xml" relativeToChangelogFile="true"/>
<include file="1.1-core/collection.xml" relativeToChangelogFile="true"/>
<include file="1.2-core/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -0,0 +1,86 @@
package dev.sheldan.abstracto.core.command.service;
import dev.sheldan.abstracto.core.command.models.database.ACommand;
import dev.sheldan.abstracto.core.command.service.management.ChannelGroupCommandManagementService;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import dev.sheldan.abstracto.core.models.database.AChannelGroupCommand;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import org.junit.Assert;
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 org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.Arrays;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ChannelGroupCommandServiceBeanTest {
@InjectMocks
private ChannelGroupCommandServiceBean testUnit;
@Mock
private ChannelGroupCommandManagementService channelGroupCommandService;
@Mock
private ChannelManagementService channelManagementService;
@Mock
private ACommand command;
@Mock
private AChannel channel;
@Mock
private AChannel secondChannel;
@Mock
private AChannelGroupCommand channelGroupCommand;
@Mock
private AChannelGroup channelGroup;
private static final Long CHANNEL_ID = 4L;
private static final Long CHANNEL_ID_2 = 2L;
@Test
public void testNoChannelGroup() {
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(new ArrayList<>());
Assert.assertTrue(testUnit.isCommandEnabled(command, channel));
}
@Test
public void testOneDisabledChannelGroup() {
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(Arrays.asList(channelGroupCommand));
when(channelGroupCommand.getGroup()).thenReturn(channelGroup);
when(channelGroup.getChannels()).thenReturn(Arrays.asList(channel));
when(channelGroupCommand.getEnabled()).thenReturn(false);
Assert.assertFalse(testUnit.isCommandEnabled(command, channel));
}
@Test
public void testOneEnabledChannelGroup() {
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(Arrays.asList(channelGroupCommand));
when(channelGroupCommand.getGroup()).thenReturn(channelGroup);
when(channelGroup.getChannels()).thenReturn(Arrays.asList(channel));
when(channelGroupCommand.getEnabled()).thenReturn(true);
Assert.assertTrue(testUnit.isCommandEnabled(command, channel));
}
@Test
public void testDisabledInOneGroupChannelIsNotPartOf() {
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(Arrays.asList(channelGroupCommand));
when(channelGroupCommand.getGroup()).thenReturn(channelGroup);
when(channelGroup.getChannels()).thenReturn(Arrays.asList(secondChannel));
when(channel.getId()).thenReturn(CHANNEL_ID);
when(secondChannel.getId()).thenReturn(CHANNEL_ID_2);
Assert.assertTrue(testUnit.isCommandEnabled(command, channel));
}
}

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.core</groupId>
<artifactId>core</artifactId>
<version>1.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

View File

@@ -0,0 +1,24 @@
package dev.sheldan.abstracto.core.command.exception;
import dev.sheldan.abstracto.core.command.models.exception.ChannelGroupIncorrectTypeExceptionModel;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.templating.Templatable;
public class ChannelGroupIncorrectTypeException extends AbstractoRunTimeException implements Templatable {
private final ChannelGroupIncorrectTypeExceptionModel model;
public ChannelGroupIncorrectTypeException(String key, String correctType) {
super("Channel group has the incorrect type.");
this.model = ChannelGroupIncorrectTypeExceptionModel.builder().name(key).correctType(correctType).build();
}
@Override
public String getTemplateName() {
return "channel_group_not_found_exception";
}
@Override
public Object getTemplateModel() {
return model;
}
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.core.command.models.exception;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
@Getter
@Setter
@Builder
public class ChannelGroupIncorrectTypeExceptionModel implements Serializable {
private String name;
private String correctType;
}

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>core</artifactId>
<groupId>dev.sheldan.abstracto.core</groupId>
<version>1.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>core</artifactId>
<groupId>dev.sheldan.abstracto.core</groupId>
<version>1.1</version>
<version>1.2.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.1</version>
<version>1.2.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.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>coverage</artifactId>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>abstracto-application</artifactId>
<groupId>dev.sheldan.abstracto</groupId>
<version>1.1</version>
<version>1.2.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.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -11,16 +11,16 @@ RUN apt-get update \
# Install liquibase
RUN mkdir -p /liqiubase \
&& wget https://github.com/liquibase/liquibase/releases/download/v${liquibase_version}/liquibase-${liquibase_version}.zip -O /tmp/liquibase.zip \
&& wget -nv https://github.com/liquibase/liquibase/releases/download/v${liquibase_version}/liquibase-${liquibase_version}.zip -O /tmp/liquibase.zip \
&& unzip /tmp/liquibase.zip -d /liquibase
RUN mkdir -p /java \
&& wget https://corretto.aws/downloads/latest/amazon-corretto-8-x64-linux-jdk.tar.gz -O /tmp/java.tar.gz \
&& wget -nv https://corretto.aws/downloads/latest/amazon-corretto-8-x64-linux-jdk.tar.gz -O /tmp/java.tar.gz \
&& tar -xf /tmp/java.tar.gz --strip-components=1 -C /java
# Install postgres driver
RUN mkdir -p /postgres \
&& wget https://jdbc.postgresql.org/download/postgresql-${postgres_driver_version}.jar -O /postgres/driver.jar
&& wget -nv https://jdbc.postgresql.org/download/postgresql-${postgres_driver_version}.jar -O /postgres/driver.jar
# Install ansible and required libraries

View File

@@ -5,7 +5,7 @@ from sqlalchemy.sql import text
def deploy_template_folder(db_config, folder):
engine = db.create_engine('postgres://%s:%s@%s:%s/%s' % (db_config.user, db_config.password, db_config.host, db_config.port, db_config.database))
engine = db.create_engine('postgresql://%s:%s@%s:%s/%s' % (db_config.user, db_config.password, db_config.host, db_config.port, db_config.database))
if not os.path.isdir(folder):
print("Given path was not a folder. Exiting.")

View File

@@ -12,7 +12,7 @@ fi
if [ "x$EXECUTE_TEMPLATES" = 'xtrue' ]; then
DEPLOY_TEMPLATES=yes
fi
exit_code = 0
exit_code=0
if [ "x$EXECUTE_DEPLOYMENT" = 'xtrue' ]; then
python3 -u python/main.py $DEPLOY_TEMPLATES $DEPLOY_LIQUIBASE
exit_code=$?

View File

@@ -11,7 +11,7 @@
<groupId>dev.sheldan.abstracto</groupId>
<artifactId>abstracto-application</artifactId>
<version>1.1</version>
<version>1.2.2</version>
<packaging>pom</packaging>
<modules>
@@ -35,7 +35,7 @@
<scm>
<url>https://maven.pkg.github.com/Sheldan/abstracto</url>
<developerConnection>scm:git:git@github.com:Sheldan/abstracto.git</developerConnection>
<tag>abstracto-application-1.1</tag>
<tag>abstracto-application-1.2.2</tag>
</scm>
<repositories>

View File

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

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.scheduling</groupId>
<artifactId>scheduling</artifactId>
<version>1.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.abstracto.scheduling</groupId>
<artifactId>scheduling</artifactId>
<version>1.1</version>
<version>1.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>