[SIS-24] adding ability to only search quotes of a given parameter for a text

changing quote search to return a random matching quote
adding local function to tilt to update packages
This commit is contained in:
Sheldan
2023-09-03 00:48:15 +02:00
parent 7a37f7e040
commit a26503650e
6 changed files with 51 additions and 10 deletions

View File

@@ -8,11 +8,11 @@ local_resource(
' mvn install && ' + ' mvn install && ' +
' rm -rf application/executable/target/jar-staging && ' + ' rm -rf application/executable/target/jar-staging && ' +
' unzip -o application/executable/target/sissi-exec.jar -d application/executable/target/jar-staging && ' + ' unzip -o application/executable/target/sissi-exec.jar -d application/executable/target/jar-staging && ' +
' rsync --delete --inplace --checksum --exclude="*-SNAPSHOT.jar" -r application/executable/target/jar-staging/ application/executable/target/jar && ' + ' rsync --delete --delete-excluded --inplace --checksum --exclude="*-SNAPSHOT.jar" -r application/executable/target/jar-staging/ application/executable/target/jar && ' +
' rm -rf application/executable/target/jar/snapshots && ' + ' rm -rf application/executable/target/jar/snapshots && ' +
' mkdir application/executable/target/jar/snapshots && ' + ' mkdir application/executable/target/jar/snapshots && ' +
' rsync --delete --inplace --checksum --include="*/" --include="*-SNAPSHOT.jar" --exclude="*" -r application/executable/target/jar-staging/BOOT-INF/lib/ application/executable/target/jar/snapshots', ' rsync --delete --delete-excluded --inplace --checksum --include="*/" --include="*-SNAPSHOT.jar" --exclude="*" -r application/executable/target/jar-staging/BOOT-INF/lib/ application/executable/target/jar/snapshots',
deps=['pom.xml']) deps=['pom.xml'], auto_init=False, trigger_mode = TRIGGER_MODE_MANUAL)
docker_build_with_restart( docker_build_with_restart(
registry + 'sissi-bot', registry + 'sissi-bot',
@@ -34,4 +34,6 @@ docker_build(registry + 'sissi-template-data', 'deployment/image-packaging/src/m
k8s_yaml(helm('deployment/helm/sissi', values= k8s_yaml(helm('deployment/helm/sissi', values=
['./../Sissi-environments/argocd/apps/sissi/values/local/values.yaml', ['./../Sissi-environments/argocd/apps/sissi/values/local/values.yaml',
'secrets://./../Sissi-environments/argocd/apps/sissi/values/local/values.secrets.yaml'] 'secrets://./../Sissi-environments/argocd/apps/sissi/values/local/values.secrets.yaml']
)) ))
local_resource('fetch-packages', 'mvn install -f deployment/image-packaging/pom.xml', auto_init=False, trigger_mode = TRIGGER_MODE_MANUAL)

View File

@@ -21,6 +21,7 @@ import dev.sheldan.sissi.module.quotes.config.QuotesModuleDefinition;
import dev.sheldan.sissi.module.quotes.exception.QuoteNotFoundException; import dev.sheldan.sissi.module.quotes.exception.QuoteNotFoundException;
import dev.sheldan.sissi.module.quotes.model.database.Quote; import dev.sheldan.sissi.module.quotes.model.database.Quote;
import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean; import dev.sheldan.sissi.module.quotes.service.QuoteServiceBean;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.interactions.InteractionHook;
@@ -28,7 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Collections; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@@ -38,6 +39,7 @@ public class QuoteSearch extends AbstractConditionableCommand {
private static final String QUOTE_SEARCH_COMMAND = "quoteSearch"; private static final String QUOTE_SEARCH_COMMAND = "quoteSearch";
private static final String QUERY_PARAMETER = "query"; private static final String QUERY_PARAMETER = "query";
private static final String MEMBER_PARAMETER = "member";
@Autowired @Autowired
private QuoteServiceBean quoteServiceBean; private QuoteServiceBean quoteServiceBean;
@@ -80,7 +82,14 @@ public class QuoteSearch extends AbstractConditionableCommand {
String query = slashCommandParameterService.getCommandOption(QUERY_PARAMETER, event, String.class); String query = slashCommandParameterService.getCommandOption(QUERY_PARAMETER, event, String.class);
AServer server = serverManagementService.loadServer(event.getGuild().getIdLong()); AServer server = serverManagementService.loadServer(event.getGuild().getIdLong());
Optional<Quote> possibleQuote = quoteServiceBean.searchQuote(query, server); Optional<Quote> possibleQuote;
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER, event)) {
Member targetMember = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER, event, Member.class);
possibleQuote = quoteServiceBean.searchQuote(query, server, targetMember);
} else {
possibleQuote = quoteServiceBean.searchQuote(query, server);
}
Quote quoteToDisplay = possibleQuote.orElseThrow(QuoteNotFoundException::new); Quote quoteToDisplay = possibleQuote.orElseThrow(QuoteNotFoundException::new);
return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay) return quoteServiceBean.renderQuoteToMessageToSend(quoteToDisplay)
.thenCompose(messageToSend -> self.replyMessage(event, messageToSend)) .thenCompose(messageToSend -> self.replyMessage(event, messageToSend))
@@ -100,7 +109,17 @@ public class QuoteSearch extends AbstractConditionableCommand {
.name(QUERY_PARAMETER) .name(QUERY_PARAMETER)
.type(String.class) .type(String.class)
.build(); .build();
List<Parameter> parameters = Collections.singletonList(searchParameter);
Parameter memberParameter = Parameter
.builder()
.templated(true)
.name(MEMBER_PARAMETER)
.slashCommandOnly(true)
.optional(true)
.type(Member.class)
.build();
List<Parameter> parameters = Arrays.asList(searchParameter, memberParameter);
HelpInfo helpInfo = HelpInfo HelpInfo helpInfo = HelpInfo
.builder() .builder()
.templated(true) .templated(true)

View File

@@ -12,6 +12,7 @@ import java.util.List;
@Repository @Repository
public interface QuoteRepository extends JpaRepository<Quote, ServerSpecificId> { public interface QuoteRepository extends JpaRepository<Quote, ServerSpecificId> {
List<Quote> findByTextContainingAndServer(String text, AServer server); List<Quote> findByTextContainingAndServer(String text, AServer server);
List<Quote> findByTextContainingAndServerAndAuthor(String text, AServer server, AUserInAServer author);
List<Quote> findByServer(AServer server); List<Quote> findByServer(AServer server);
List<Quote> findByAuthor(AUserInAServer author); List<Quote> findByAuthor(AUserInAServer author);
Long countByAuthor(AUserInAServer author); Long countByAuthor(AUserInAServer author);

View File

@@ -214,9 +214,27 @@ public class QuoteServiceBean {
return Optional.empty(); return Optional.empty();
} }
if(foundQuotes.size() > 1) { if(foundQuotes.size() > 1) {
log.info("Found multiple quotes in server {}, returning first one.", server.getId()); log.info("Found multiple quotes in server {}, returning random one.", server.getId());
int randomIndex = secureRandom.nextInt(foundQuotes.size());
return Optional.of(foundQuotes.get(randomIndex));
} else {
return Optional.of(foundQuotes.get(0));
}
}
public Optional<Quote> searchQuote(String query, AServer server, Member targetMember) {
AUserInAServer author = userInServerManagementService.loadOrCreateUser(targetMember);
List<Quote> foundQuotes = quoteRepository.findByTextContainingAndServerAndAuthor(query, server, author);
if(foundQuotes.isEmpty()) {
return Optional.empty();
}
if(foundQuotes.size() > 1) {
log.info("Found multiple quotes in server {}, returning random one.", server.getId());
int randomIndex = secureRandom.nextInt(foundQuotes.size());
return Optional.of(foundQuotes.get(randomIndex));
} else {
return Optional.of(foundQuotes.get(0));
} }
return Optional.of(foundQuotes.get(0));
} }
public QuoteStatsModel getQuoteStats(Member member) { public QuoteStatsModel getQuoteStats(Member member) {

View File

@@ -1,3 +1,3 @@
This command can be used to search through all quotes by a text query. This command can be used to search through all quotes by a text query.
It will return quotes in which the text of the quote contains the given query. It will return quotes in which the text of the quote contains the given query.
If there are more quotes found, the first one is returned. If there are more quotes found, a random one is returned.