mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-11 11:44:32 +00:00
[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:
@@ -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());
|
||||
|
||||
@@ -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
|
||||
@@ -2,13 +2,22 @@ package dev.sheldan.abstracto.webservices.youtube.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import dev.sheldan.abstracto.webservices.config.WebserviceFeatureDefinition;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class YoutubeFeatureConfig implements FeatureConfig {
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return WebserviceFeatureDefinition.YOUTUBE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureMode> getAvailableModes() {
|
||||
return Arrays.asList(YoutubeWebServiceFeatureMode.VIDEO_DETAILS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.webservices.youtube.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum YoutubeWebServiceFeatureMode implements FeatureMode {
|
||||
VIDEO_DETAILS("videoDetails");
|
||||
|
||||
private final String key;
|
||||
|
||||
YoutubeWebServiceFeatureMode(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import dev.sheldan.abstracto.core.models.database.AConfig;
|
||||
import dev.sheldan.abstracto.core.models.property.SystemConfigProperty;
|
||||
import dev.sheldan.abstracto.core.service.management.ConfigManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementService;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -73,6 +74,11 @@ public class ConfigServiceBean implements ConfigService {
|
||||
return config.getLongValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getBooleanValueOrConfigDefault(String name, Long serverId) {
|
||||
return BooleanUtils.toBoolean(getStringValueOrConfigDefault(name, serverId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDoubleValue(String name, Long serverId, Double value) {
|
||||
if(configManagementService.configExists(serverId, name)) {
|
||||
|
||||
@@ -11,6 +11,7 @@ public interface ConfigService {
|
||||
String getStringValue(String name, Long serverId, String defaultValue);
|
||||
String getStringValueOrConfigDefault(String name, Long serverId);
|
||||
Long getLongValue(String name, Long serverId, Long defaultValue);
|
||||
Boolean getBooleanValueOrConfigDefault(String name, Long serverId);
|
||||
AConfig setOrCreateConfigValue(Long serverId, String name, AConfig value);
|
||||
void setDoubleValue(String name, Long serverId, Double value);
|
||||
void setLongValue(String name, Long serverId, Long value);
|
||||
|
||||
@@ -6,6 +6,9 @@ Integrates different web APIs to be used via the bot.
|
||||
=== Youtube
|
||||
Feature key: `youtube`
|
||||
|
||||
==== Feature modes
|
||||
`videoDetails`:: if enabled, the video shown with video details. Disabled by default.
|
||||
|
||||
==== Command
|
||||
Search for a youtube video::
|
||||
* Usage: `youtubeSearch <query>`
|
||||
|
||||
Reference in New Issue
Block a user