mirror of
https://github.com/Sheldan/OnePlusBot.git
synced 2026-01-03 16:27:46 +00:00
[OPB-32] fixing always exporting user ID in faq config when in reality it was bot ID
sorting faq commands and channel groups in export response alphabetically
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package dev.sheldan.oneplus.bot.modules.faq.converter;
|
package dev.sheldan.oneplus.bot.modules.faq.converter;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import dev.sheldan.abstracto.core.service.BotService;
|
||||||
import dev.sheldan.oneplus.bot.modules.faq.models.command.config.*;
|
import dev.sheldan.oneplus.bot.modules.faq.models.command.config.*;
|
||||||
import dev.sheldan.oneplus.bot.modules.faq.models.database.FAQChannelGroupCommand;
|
import dev.sheldan.oneplus.bot.modules.faq.models.database.FAQChannelGroupCommand;
|
||||||
import dev.sheldan.oneplus.bot.modules.faq.models.database.FAQCommand;
|
import dev.sheldan.oneplus.bot.modules.faq.models.database.FAQCommand;
|
||||||
@@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -18,9 +20,16 @@ public class FAQCommandConfigConverter {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Gson gson;
|
private Gson gson;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BotService botService;
|
||||||
|
|
||||||
public String serializeCommands(List<FAQCommand> asList) {
|
public String serializeCommands(List<FAQCommand> asList) {
|
||||||
|
Long botId = botService.getInstance().getSelfUser().getIdLong();
|
||||||
|
asList.sort(Comparator.comparing(FAQCommand::getName));
|
||||||
List<FaqCommandConfig> config = asList.stream().map(faqCommand -> {
|
List<FaqCommandConfig> config = asList.stream().map(faqCommand -> {
|
||||||
List<FaqCommandResponseConfig> commandResponseConfigs = convertGroupCommands(faqCommand.getGroupResponses());
|
List<FAQChannelGroupCommand> responses = faqCommand.getGroupResponses();
|
||||||
|
responses.sort(Comparator.comparing(groupCommand -> groupCommand.getChannelGroup().getChannelGroup().getGroupName()));
|
||||||
|
List<FaqCommandResponseConfig> commandResponseConfigs = convertGroupCommands(responses, botId);
|
||||||
List<String> aliases;
|
List<String> aliases;
|
||||||
if(faqCommand.getAliases() != null) {
|
if(faqCommand.getAliases() != null) {
|
||||||
aliases = faqCommand.getAliases().stream().map(faqCommandAlias -> faqCommandAlias.getId().getAlias()).collect(Collectors.toList());
|
aliases = faqCommand.getAliases().stream().map(faqCommandAlias -> faqCommandAlias.getId().getAlias()).collect(Collectors.toList());
|
||||||
@@ -39,9 +48,9 @@ public class FAQCommandConfigConverter {
|
|||||||
return gson.toJson(config);
|
return gson.toJson(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<FaqCommandResponseConfig> convertGroupCommands(List<FAQChannelGroupCommand> responses) {
|
private List<FaqCommandResponseConfig> convertGroupCommands(List<FAQChannelGroupCommand> responses, Long botUserId) {
|
||||||
return responses.stream().map(faqChannelGroupCommand -> {
|
return responses.stream().map(faqChannelGroupCommand -> {
|
||||||
List<FaqCommandResponseMessageConfig> responseConfigs = convertCommandResponses(faqChannelGroupCommand.getResponses());
|
List<FaqCommandResponseMessageConfig> responseConfigs = convertCommandResponses(faqChannelGroupCommand.getResponses(), botUserId);
|
||||||
return FaqCommandResponseConfig
|
return FaqCommandResponseConfig
|
||||||
.builder()
|
.builder()
|
||||||
.channelGroupName(faqChannelGroupCommand.getChannelGroup().getChannelGroup().getGroupName())
|
.channelGroupName(faqChannelGroupCommand.getChannelGroup().getChannelGroup().getGroupName())
|
||||||
@@ -50,13 +59,14 @@ public class FAQCommandConfigConverter {
|
|||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<FaqCommandResponseMessageConfig> convertCommandResponses(List<FAQCommandResponse> responses) {
|
private List<FaqCommandResponseMessageConfig> convertCommandResponses(List<FAQCommandResponse> responses, Long botUserId) {
|
||||||
return responses.stream().map(this::convertCommandResponse).collect(Collectors.toList());
|
return responses.stream().map(response -> convertCommandResponse(response, botUserId)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private FaqCommandResponseMessageConfig convertCommandResponse(FAQCommandResponse response) {
|
private FaqCommandResponseMessageConfig convertCommandResponse(FAQCommandResponse response, Long botUserId) {
|
||||||
FaqCommandResponseEmbedConfig embedConfig = null;
|
FaqCommandResponseEmbedConfig embedConfig = null;
|
||||||
if(response.getDescription() != null) {
|
if(response.getDescription() != null) {
|
||||||
|
boolean useBot = response.getAuthorUserId().equals(botUserId);
|
||||||
FaqCommandResponseEmbedColorConfig colorConfig = FaqCommandResponseEmbedColorConfig
|
FaqCommandResponseEmbedColorConfig colorConfig = FaqCommandResponseEmbedColorConfig
|
||||||
.builder()
|
.builder()
|
||||||
.red(response.getRed())
|
.red(response.getRed())
|
||||||
@@ -65,8 +75,8 @@ public class FAQCommandConfigConverter {
|
|||||||
.build();
|
.build();
|
||||||
FaqCommandResponseEmbedAuthorConfig authorConfig = FaqCommandResponseEmbedAuthorConfig
|
FaqCommandResponseEmbedAuthorConfig authorConfig = FaqCommandResponseEmbedAuthorConfig
|
||||||
.builder()
|
.builder()
|
||||||
.userId(response.getAuthorUserId())
|
.userId(useBot ? null : response.getAuthorUserId())
|
||||||
.useBot(null)
|
.useBot(useBot)
|
||||||
.build();
|
.build();
|
||||||
embedConfig = FaqCommandResponseEmbedConfig
|
embedConfig = FaqCommandResponseEmbedConfig
|
||||||
.builder()
|
.builder()
|
||||||
|
|||||||
Reference in New Issue
Block a user