[AB-82] adding feature mode to make it configurable whether or not the youtube video will show details or not

adding convenience method to config service
This commit is contained in:
Sheldan
2021-03-29 03:02:46 +02:00
parent 8a8e6b2347
commit 8c026d3547
7 changed files with 51 additions and 3 deletions

View File

@@ -10,10 +10,12 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.FeatureModeService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.webservices.config.WebserviceFeatureDefinition;
import dev.sheldan.abstracto.webservices.youtube.config.YoutubeWebServiceFeatureMode;
import dev.sheldan.abstracto.webservices.youtube.model.YoutubeVideo;
import dev.sheldan.abstracto.webservices.youtube.model.command.YoutubeVideoSearchCommandModel;
import dev.sheldan.abstracto.webservices.youtube.service.YoutubeSearchService;
@@ -37,15 +39,23 @@ public class YoutubeVideoSearch extends AbstractConditionableCommand {
@Autowired
private ChannelService channelService;
@Autowired
private FeatureModeService featureModeService;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
String query = (String) commandContext.getParameters().getParameters().get(0);
YoutubeVideo foundVideo = youtubeSearchService.searchOneVideoForQuery(query);
YoutubeVideoSearchCommandModel model = (YoutubeVideoSearchCommandModel) ContextConverter.slimFromCommandContext(commandContext, YoutubeVideoSearchCommandModel.class);
model.setVideo(foundVideo);
MessageToSend message = templateService.renderEmbedTemplate("youtube_search_command_response", model);
CompletableFuture<Void> infoEmbedFuture;
if(featureModeService.featureModeActive(WebserviceFeatureDefinition.YOUTUBE, commandContext.getGuild().getIdLong(), YoutubeWebServiceFeatureMode.VIDEO_DETAILS)) {
MessageToSend message = templateService.renderEmbedTemplate("youtube_search_command_response", model);
infoEmbedFuture = FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(message, commandContext.getChannel()));
} else {
infoEmbedFuture = CompletableFuture.completedFuture(null);
}
MessageToSend linkEmbed = templateService.renderEmbedTemplate("youtube_search_command_response_link", model);
CompletableFuture<Void> infoEmbedFuture = FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(message, commandContext.getChannel()));
CompletableFuture<Void> linkEmbedFuture = FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(linkEmbed, commandContext.getChannel()));
return CompletableFuture.allOf(infoEmbedFuture, linkEmbedFuture)
.thenApply(unused -> CommandResult.fromSuccess());

View File

@@ -6,4 +6,8 @@ abstracto.featureFlags.urban.enabled=false
abstracto.feature.youtube.apiKey=${YOUTUBE_API_KEY}
abstracto.feature.webservices.urban.requestURL=https://api.urbandictionary.com/v0/define?term=%s
abstracto.feature.webservices.urban.requestURL=https://api.urbandictionary.com/v0/define?term=%s
abstracto.featureModes.videoDetails.featureName=youtube
abstracto.featureModes.videoDetails.mode=videoDetails
abstracto.featureModes.videoDetails.enabled=false