From bf550649840be7da2e4ab7aab3d9f9fe179adc9c Mon Sep 17 00:00:00 2001 From: Sheldan <5037282+Sheldan@users.noreply.github.com> Date: Sat, 24 Apr 2021 01:38:59 +0200 Subject: [PATCH] [OPB-12] adding news/newsupdate command and introducing mechanisms for cleanup thereof changing templates to have the metaconfig moving starboard custom templates --- application/executable/pom.xml | 6 + application/oneplus-bot-modules/news/pom.xml | 41 + .../news/src/main/assembly/liquibase.xml | 18 + .../bot/modules/news/commands/News.java | 54 + .../bot/modules/news/commands/UpdateNews.java | 57 + .../bot/modules/news/config/NewsFeature.java | 23 + .../news/config/NewsFeatureDefinition.java | 15 + .../news/config/NewsModuleDefinition.java | 21 + .../modules/news/config/NewsPostTarget.java | 15 + .../modules/news/config/NewsProperties.java | 10 + .../exception/NewsPostLockedException.java | 16 + .../exception/NewsPostNotFoundException.java | 16 + .../modules/news/job/NewsPostCleanupJob.java | 31 + .../modules/news/job/NewsPostLockingJob.java | 31 + ...wsMessageSourceMessageUpdatedListener.java | 46 + .../modules/news/model/NewsMessageModel.java | 18 + .../modules/news/model/database/NewsPost.java | 51 + .../news/repository/NewsPostRepository.java | 17 + .../modules/news/service/NewsServiceBean.java | 127 ++ .../NewsPostManagementServiceBean.java | 77 + .../migrations/1.3.9-news/collection.xml | 11 + .../1.3.9-news/news-seedData/command.xml | 23 + .../1.3.9-news/news-seedData/data.xml | 13 + .../1.3.9-news/news-seedData/feature.xml | 14 + .../1.3.9-news/news-seedData/module.xml | 14 + .../1.3.9-news/news-seedData/news_jobs.xml | 28 + .../1.3.9-news/news-tables/news_post.xml | 62 + .../1.3.9-news/news-tables/tables.xml | 10 + .../resources/migrations/dbchangelog-3.8.xsd | 1377 +++++++++++++++++ .../resources/migrations/news-changeLog.xml | 10 + .../news/src/main/resources/news.properties | 7 + application/oneplus-bot-modules/pom.xml | 24 + application/pom.xml | 1 + deployment/image-packaging/pom.xml | 35 +- .../deployment/config/artifact_versions.json | 9 +- pom.xml | 4 +- .../news-templates/pom.xml | 39 + .../src/main/assembly/assembly.xml | 0 .../commands/news/news_post_embed_en_US.ftl | 12 + .../news_post_locked_exception_en_US.ftl | 1 + .../news_post_not_found_exception_en_US.ftl | 1 + .../pom.xml | 3 +- .../starboard-custom/pom.xml | 2 +- .../src/main/assembly/assembly.xml | 15 + ..._post_created_notification_embed_en_US.ftl | 0 ..._post_deleted_notification_embed_en_US.ftl | 0 ...rban_define_response_model_embed_en_US.ftl | 4 +- templates/pom.xml | 2 +- .../translations/news-translations/pom.xml | 38 + .../src/main/assembly/assembly.xml | 15 + .../news/help/news_description_en_US.ftl | 1 + .../news/help/news_long_help_en_US.ftl | 4 + .../news/help/news_parameter_text_en_US.ftl | 1 + .../news/news_post_description_en_US.ftl | 4 + .../help/updateNews_description_en_US.ftl | 1 + .../help/updateNews_long_help_en_US.ftl | 4 + .../updateNews_parameter_newsPostId_en_US.ftl | 1 + .../help/updateNews_parameter_text_en_US.ftl | 1 + .../en_US/config/feature_news_en_US.ftl | 1 + .../feature_setup_posttarget_news_en_US.ftl | 1 + .../config/module_news_description_en_US.ftl | 1 + ...ws_post_locked_exception_message_en_US.ftl | 1 + ...ws_post_not_found_exception_text_en_US.ftl | 1 + templates/translations/pom.xml | 1 + 64 files changed, 2477 insertions(+), 10 deletions(-) create mode 100644 application/oneplus-bot-modules/news/pom.xml create mode 100644 application/oneplus-bot-modules/news/src/main/assembly/liquibase.xml create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/commands/News.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/commands/UpdateNews.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsFeature.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsFeatureDefinition.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsModuleDefinition.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsPostTarget.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsProperties.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/exception/NewsPostLockedException.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/exception/NewsPostNotFoundException.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/job/NewsPostCleanupJob.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/job/NewsPostLockingJob.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/listener/NewsMessageSourceMessageUpdatedListener.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/model/NewsMessageModel.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/model/database/NewsPost.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/repository/NewsPostRepository.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/service/NewsServiceBean.java create mode 100644 application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/service/management/NewsPostManagementServiceBean.java create mode 100644 application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/collection.xml create mode 100644 application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/command.xml create mode 100644 application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/data.xml create mode 100644 application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/feature.xml create mode 100644 application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/module.xml create mode 100644 application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/news_jobs.xml create mode 100644 application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-tables/news_post.xml create mode 100644 application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-tables/tables.xml create mode 100644 application/oneplus-bot-modules/news/src/main/resources/migrations/dbchangelog-3.8.xsd create mode 100644 application/oneplus-bot-modules/news/src/main/resources/migrations/news-changeLog.xml create mode 100644 application/oneplus-bot-modules/news/src/main/resources/news.properties create mode 100644 application/oneplus-bot-modules/pom.xml create mode 100644 templates/oneplus-bot-modules-templates/news-templates/pom.xml rename templates/{oneplus-bot-modules/starboard-custom => oneplus-bot-modules-templates/news-templates}/src/main/assembly/assembly.xml (100%) create mode 100644 templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/commands/news/news_post_embed_en_US.ftl create mode 100644 templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/exception/news_post_locked_exception_en_US.ftl create mode 100644 templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/exception/news_post_not_found_exception_en_US.ftl rename templates/{oneplus-bot-modules => oneplus-bot-modules-templates}/pom.xml (87%) rename templates/{oneplus-bot-modules => oneplus-bot-modules-templates}/starboard-custom/pom.xml (95%) create mode 100644 templates/oneplus-bot-modules-templates/starboard-custom/src/main/assembly/assembly.xml rename templates/{oneplus-bot-modules => oneplus-bot-modules-templates}/starboard-custom/src/main/resources/en_US/listener/starboardNotification/starboard_post_created_notification_embed_en_US.ftl (100%) rename templates/{oneplus-bot-modules => oneplus-bot-modules-templates}/starboard-custom/src/main/resources/en_US/listener/starboardNotification/starboard_post_deleted_notification_embed_en_US.ftl (100%) create mode 100644 templates/translations/news-translations/pom.xml create mode 100644 templates/translations/news-translations/src/main/assembly/assembly.xml create mode 100644 templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_description_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_long_help_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_parameter_text_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/commands/news/news_post_description_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_description_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_long_help_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_parameter_newsPostId_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_parameter_text_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/config/feature_news_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/config/feature_setup_posttarget_news_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/config/module_news_description_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/exception/news_post_locked_exception_message_en_US.ftl create mode 100644 templates/translations/news-translations/src/main/resources/en_US/exception/news_post_not_found_exception_text_en_US.ftl diff --git a/application/executable/pom.xml b/application/executable/pom.xml index a05b144..01dd698 100644 --- a/application/executable/pom.xml +++ b/application/executable/pom.xml @@ -101,6 +101,12 @@ ${project.version} + + dev.sheldan.oneplus.bot.application.modules + news + ${project.version} + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/pom.xml b/application/oneplus-bot-modules/news/pom.xml new file mode 100644 index 0000000..1a6225e --- /dev/null +++ b/application/oneplus-bot-modules/news/pom.xml @@ -0,0 +1,41 @@ + + + + dev.sheldan.oneplus.bot.application.modules + oneplus-bot-modules + 1.3.9-SNAPSHOT + + 4.0.0 + + news + + + 8 + 8 + + + + + + maven-assembly-plugin + + + src/main/assembly/liquibase.xml + + + + + make-assembly + package + + single + + + + + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/assembly/liquibase.xml b/application/oneplus-bot-modules/news/src/main/assembly/liquibase.xml new file mode 100644 index 0000000..8b4774f --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/assembly/liquibase.xml @@ -0,0 +1,18 @@ + + liquibase + + zip + + false + + + . + ${project.basedir}/src/main/resources/migrations + + **/* + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/commands/News.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/commands/News.java new file mode 100644 index 0000000..de4939d --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/commands/News.java @@ -0,0 +1,54 @@ +package dev.sheldan.oneplus.bot.modules.news.commands; + +import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand; +import dev.sheldan.abstracto.core.command.config.CommandConfiguration; +import dev.sheldan.abstracto.core.command.config.HelpInfo; +import dev.sheldan.abstracto.core.command.config.Parameter; +import dev.sheldan.abstracto.core.command.execution.CommandContext; +import dev.sheldan.abstracto.core.command.execution.CommandResult; +import dev.sheldan.abstracto.core.config.FeatureDefinition; +import dev.sheldan.oneplus.bot.modules.news.config.NewsFeatureDefinition; +import dev.sheldan.oneplus.bot.modules.news.config.NewsModuleDefinition; +import dev.sheldan.oneplus.bot.modules.news.service.NewsServiceBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +@Component +public class News extends AbstractConditionableCommand { + + @Autowired + private NewsServiceBean newsServiceBean; + + @Override + public CompletableFuture executeAsync(CommandContext commandContext) { + String text = (String) commandContext.getParameters().getParameters().get(0); + return newsServiceBean.sendNewsPost(text, commandContext.getMessage()) + .thenApply(unused -> CommandResult.fromSuccess()); + } + + @Override + public CommandConfiguration getConfiguration() { + Parameter newsText = Parameter.builder().name("text").type(String.class).remainder(true).templated(true).build(); + List parameters = Arrays.asList(newsText); + HelpInfo helpInfo = HelpInfo.builder().templated(true).hasExample(true).build(); + return CommandConfiguration.builder() + .name("news") + .module(NewsModuleDefinition.NEWS) + .parameters(parameters) + .supportsEmbedException(true) + .async(true) + .help(helpInfo) + .templated(true) + .causesReaction(true) + .build(); + } + + @Override + public FeatureDefinition getFeature() { + return NewsFeatureDefinition.NEWS; + } +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/commands/UpdateNews.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/commands/UpdateNews.java new file mode 100644 index 0000000..faa4a3f --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/commands/UpdateNews.java @@ -0,0 +1,57 @@ +package dev.sheldan.oneplus.bot.modules.news.commands; + +import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand; +import dev.sheldan.abstracto.core.command.config.CommandConfiguration; +import dev.sheldan.abstracto.core.command.config.HelpInfo; +import dev.sheldan.abstracto.core.command.config.Parameter; +import dev.sheldan.abstracto.core.command.execution.CommandContext; +import dev.sheldan.abstracto.core.command.execution.CommandResult; +import dev.sheldan.abstracto.core.config.FeatureDefinition; +import dev.sheldan.oneplus.bot.modules.news.config.NewsFeatureDefinition; +import dev.sheldan.oneplus.bot.modules.news.config.NewsModuleDefinition; +import dev.sheldan.oneplus.bot.modules.news.service.NewsServiceBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +@Component +public class UpdateNews extends AbstractConditionableCommand { + + @Autowired + private NewsServiceBean newsServiceBean; + + @Override + public CompletableFuture executeAsync(CommandContext commandContext) { + List parameters = commandContext.getParameters().getParameters(); + Long messageId = (Long) parameters.get(0); + String postText = (String) parameters.get(1); + return newsServiceBean.updateNewsPostViaId(messageId, postText, commandContext.getMessage()) + .thenApply(unused -> CommandResult.fromSuccess()); + } + + @Override + public CommandConfiguration getConfiguration() { + Parameter newsPostId = Parameter.builder().name("newsPostId").type(Long.class).templated(true).build(); + Parameter newsText = Parameter.builder().name("text").type(String.class).remainder(true).templated(true).build(); + List parameters = Arrays.asList(newsPostId, newsText); + HelpInfo helpInfo = HelpInfo.builder().templated(true).build(); + return CommandConfiguration.builder() + .name("updateNews") + .module(NewsModuleDefinition.NEWS) + .parameters(parameters) + .supportsEmbedException(true) + .async(true) + .help(helpInfo) + .templated(true) + .causesReaction(true) + .build(); + } + + @Override + public FeatureDefinition getFeature() { + return NewsFeatureDefinition.NEWS; + } +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsFeature.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsFeature.java new file mode 100644 index 0000000..6d8fedf --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsFeature.java @@ -0,0 +1,23 @@ +package dev.sheldan.oneplus.bot.modules.news.config; + +import dev.sheldan.abstracto.core.config.FeatureConfig; +import dev.sheldan.abstracto.core.config.FeatureDefinition; +import dev.sheldan.abstracto.core.config.PostTargetEnum; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; + +@Component +public class NewsFeature implements FeatureConfig { + + @Override + public FeatureDefinition getFeature() { + return NewsFeatureDefinition.NEWS; + } + + @Override + public List getRequiredPostTargets() { + return Arrays.asList(NewsPostTarget.NEWS_TARGET); + } +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsFeatureDefinition.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsFeatureDefinition.java new file mode 100644 index 0000000..b2b971d --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsFeatureDefinition.java @@ -0,0 +1,15 @@ +package dev.sheldan.oneplus.bot.modules.news.config; + +import dev.sheldan.abstracto.core.config.FeatureDefinition; +import lombok.Getter; + +@Getter +public enum NewsFeatureDefinition implements FeatureDefinition { + NEWS("news"); + + private String key; + + NewsFeatureDefinition(String key) { + this.key = key; + } +} \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsModuleDefinition.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsModuleDefinition.java new file mode 100644 index 0000000..0ec0f5c --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsModuleDefinition.java @@ -0,0 +1,21 @@ +package dev.sheldan.oneplus.bot.modules.news.config; + +import dev.sheldan.abstracto.core.command.config.ModuleDefinition; +import dev.sheldan.abstracto.core.command.config.ModuleInfo; +import org.springframework.stereotype.Component; + +@Component +public class NewsModuleDefinition implements ModuleDefinition { + + public static final String NEWS = "news"; + + @Override + public ModuleInfo getInfo() { + return ModuleInfo.builder().name(NEWS).templated(true).build(); + } + + @Override + public String getParentModule() { + return "default"; + } +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsPostTarget.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsPostTarget.java new file mode 100644 index 0000000..29ea1af --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsPostTarget.java @@ -0,0 +1,15 @@ +package dev.sheldan.oneplus.bot.modules.news.config; + +import dev.sheldan.abstracto.core.config.PostTargetEnum; +import lombok.Getter; + +@Getter +public enum NewsPostTarget implements PostTargetEnum { + NEWS_TARGET("news"); + + private String key; + + NewsPostTarget(String key) { + this.key = key; + } +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsProperties.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsProperties.java new file mode 100644 index 0000000..965b09f --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/config/NewsProperties.java @@ -0,0 +1,10 @@ +package dev.sheldan.oneplus.bot.modules.news.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@PropertySource("classpath:news.properties") +public class NewsProperties { + +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/exception/NewsPostLockedException.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/exception/NewsPostLockedException.java new file mode 100644 index 0000000..1c2922f --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/exception/NewsPostLockedException.java @@ -0,0 +1,16 @@ +package dev.sheldan.oneplus.bot.modules.news.exception; + +import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException; +import dev.sheldan.abstracto.core.templating.Templatable; + +public class NewsPostLockedException extends AbstractoRunTimeException implements Templatable { + @Override + public String getTemplateName() { + return "news_post_locked_exception"; + } + + @Override + public Object getTemplateModel() { + return new Object(); + } +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/exception/NewsPostNotFoundException.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/exception/NewsPostNotFoundException.java new file mode 100644 index 0000000..b4e62bf --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/exception/NewsPostNotFoundException.java @@ -0,0 +1,16 @@ +package dev.sheldan.oneplus.bot.modules.news.exception; + +import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException; +import dev.sheldan.abstracto.core.templating.Templatable; + +public class NewsPostNotFoundException extends AbstractoRunTimeException implements Templatable { + @Override + public String getTemplateName() { + return "news_post_not_found_exception"; + } + + @Override + public Object getTemplateModel() { + return new Object(); + } +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/job/NewsPostCleanupJob.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/job/NewsPostCleanupJob.java new file mode 100644 index 0000000..4514588 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/job/NewsPostCleanupJob.java @@ -0,0 +1,31 @@ +package dev.sheldan.oneplus.bot.modules.news.job; + +import dev.sheldan.oneplus.bot.modules.news.service.NewsServiceBean; +import lombok.extern.slf4j.Slf4j; +import org.quartz.DisallowConcurrentExecution; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.quartz.PersistJobDataAfterExecution; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.quartz.QuartzJobBean; +import org.springframework.stereotype.Component; + +@Slf4j +@DisallowConcurrentExecution +@Component +@PersistJobDataAfterExecution +public class NewsPostCleanupJob extends QuartzJobBean { + + @Autowired + private NewsServiceBean newsServiceBean; + + @Override + protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException { + try { + log.info("Executing news post cleanup job."); + newsServiceBean.cleanUpNewsPosts(); + } catch (Exception exception) { + log.error("Failed to execute news post cleanup job.", exception); + } + } +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/job/NewsPostLockingJob.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/job/NewsPostLockingJob.java new file mode 100644 index 0000000..c550e8f --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/job/NewsPostLockingJob.java @@ -0,0 +1,31 @@ +package dev.sheldan.oneplus.bot.modules.news.job; + +import dev.sheldan.oneplus.bot.modules.news.service.NewsServiceBean; +import lombok.extern.slf4j.Slf4j; +import org.quartz.DisallowConcurrentExecution; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.quartz.PersistJobDataAfterExecution; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.quartz.QuartzJobBean; +import org.springframework.stereotype.Component; + +@Slf4j +@DisallowConcurrentExecution +@Component +@PersistJobDataAfterExecution +public class NewsPostLockingJob extends QuartzJobBean { + + @Autowired + private NewsServiceBean newsServiceBean; + + @Override + protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException { + try { + log.info("Executing news post lock job."); + newsServiceBean.lockNewsPosts(); + } catch (Exception exception) { + log.error("Failed to execute news post lock job.", exception); + } + } +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/listener/NewsMessageSourceMessageUpdatedListener.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/listener/NewsMessageSourceMessageUpdatedListener.java new file mode 100644 index 0000000..e250c19 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/listener/NewsMessageSourceMessageUpdatedListener.java @@ -0,0 +1,46 @@ +package dev.sheldan.oneplus.bot.modules.news.listener; + +import dev.sheldan.abstracto.core.config.FeatureDefinition; +import dev.sheldan.abstracto.core.listener.DefaultListenerResult; +import dev.sheldan.abstracto.core.listener.async.jda.AsyncMessageTextUpdatedListener; +import dev.sheldan.abstracto.core.models.listener.MessageTextUpdatedModel; +import dev.sheldan.oneplus.bot.modules.news.config.NewsFeatureDefinition; +import dev.sheldan.oneplus.bot.modules.news.model.database.NewsPost; +import dev.sheldan.oneplus.bot.modules.news.service.NewsServiceBean; +import dev.sheldan.oneplus.bot.modules.news.service.management.NewsPostManagementServiceBean; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Optional; + +@Component +@Slf4j +public class NewsMessageSourceMessageUpdatedListener implements AsyncMessageTextUpdatedListener { + + @Autowired + private NewsPostManagementServiceBean newsPostManagementServiceBean; + + @Autowired + private NewsServiceBean newsServiceBean; + + @Override + public DefaultListenerResult execute(MessageTextUpdatedModel model) { + Optional existingPostOptional = newsPostManagementServiceBean.getNewsPostForSourceMessage(model.getAfter().getIdLong()); + if(existingPostOptional.isPresent()) { + NewsPost newsPost = existingPostOptional.get(); + if(!newsPost.isLocked()) { + newsServiceBean.updateNewsPost(newsPost, model.getAfter()); + return DefaultListenerResult.PROCESSED; + } else { + log.info("Not updating news post {}, because it is locked.", newsPost.getSourceMessageId()); + } + } + return DefaultListenerResult.IGNORED; + } + + @Override + public FeatureDefinition getFeature() { + return NewsFeatureDefinition.NEWS; + } +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/model/NewsMessageModel.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/model/NewsMessageModel.java new file mode 100644 index 0000000..0b2da88 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/model/NewsMessageModel.java @@ -0,0 +1,18 @@ +package dev.sheldan.oneplus.bot.modules.news.model; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.Role; + +@Getter +@Setter +@Builder +public class NewsMessageModel { + private String messageText; + private Message message; + private Member author; + private Role newsRole; +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/model/database/NewsPost.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/model/database/NewsPost.java new file mode 100644 index 0000000..75717ab --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/model/database/NewsPost.java @@ -0,0 +1,51 @@ +package dev.sheldan.oneplus.bot.modules.news.model.database; + +import dev.sheldan.abstracto.core.models.database.AChannel; +import dev.sheldan.abstracto.core.models.database.AServer; +import dev.sheldan.abstracto.core.models.database.AUserInAServer; +import lombok.*; + +import javax.persistence.*; +import java.time.Instant; + +@Builder +@Entity +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "news_post") +@Getter +@Setter +@EqualsAndHashCode +public class NewsPost { + @Id + @Column(name = "source_message_id") + private Long sourceMessageId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "server_id", nullable = false) + private AServer server; + + @Column(name = "news_message_id") + private Long newsMessageId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "author_user_in_server_id", nullable = false) + private AUserInAServer author; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "source_channel_id", nullable = false) + private AChannel sourceChannel; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "news_channel_id", nullable = false) + private AChannel newsChannel; + + @Column(name = "locked") + private boolean locked; + + @Column(name = "created") + private Instant created; + + @Column(name = "updated") + private Instant updated; +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/repository/NewsPostRepository.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/repository/NewsPostRepository.java new file mode 100644 index 0000000..42e38ea --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/repository/NewsPostRepository.java @@ -0,0 +1,17 @@ +package dev.sheldan.oneplus.bot.modules.news.repository; + +import dev.sheldan.oneplus.bot.modules.news.model.database.NewsPost; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.time.Instant; +import java.util.List; +import java.util.Optional; + +@Repository +public interface NewsPostRepository extends JpaRepository { + + List findByCreatedLessThanAndLockedFalse(Instant date); + List findByUpdatedLessThanAndLockedTrue(Instant date); + Optional findByNewsMessageId(Long newsMessageId); +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/service/NewsServiceBean.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/service/NewsServiceBean.java new file mode 100644 index 0000000..72349f8 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/service/NewsServiceBean.java @@ -0,0 +1,127 @@ +package dev.sheldan.oneplus.bot.modules.news.service; + +import dev.sheldan.abstracto.core.service.ChannelService; +import dev.sheldan.abstracto.core.service.PostTargetService; +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.oneplus.bot.modules.news.config.NewsPostTarget; +import dev.sheldan.oneplus.bot.modules.news.exception.NewsPostLockedException; +import dev.sheldan.oneplus.bot.modules.news.model.NewsMessageModel; +import dev.sheldan.oneplus.bot.modules.news.model.database.NewsPost; +import dev.sheldan.oneplus.bot.modules.news.service.management.NewsPostManagementServiceBean; +import lombok.extern.slf4j.Slf4j; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.TextChannel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +@Component +@Slf4j +public class NewsServiceBean { + + @Autowired + private PostTargetService postTargetService; + + @Autowired + private TemplateService templateService; + + @Autowired + private NewsPostManagementServiceBean newsPostManagementServiceBean; + + @Autowired + private ChannelService channelService; + + @Autowired + private NewsServiceBean self; + + private static final String MESSAGE_TEMPLATE_KEY = "news_post"; + + @Value("${abstracto.feature.news.postLockSeconds}") + private Long postLockSeconds; + + @Value("${abstracto.feature.news.removalDays}") + private Long removalDays; + + @Transactional + public void lockNewsPosts() { + Instant oldestDate = Instant.now().minus(postLockSeconds, ChronoUnit.SECONDS).truncatedTo(ChronoUnit.DAYS); + log.info("Locking news posts older than {}.", oldestDate); + List oldPosts = newsPostManagementServiceBean.findNewsPostsOlderNotLocked(oldestDate); + log.info("Locking {} news posts.", oldPosts.size()); + oldPosts.forEach(newsPost -> newsPost.setLocked(true)); + } + + @Transactional + public void cleanUpNewsPosts() { + Instant oldestDate = Instant.now().minus(removalDays, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS); + log.info("Deleting news posts older than {}.", oldestDate); + List oldPosts = newsPostManagementServiceBean.findNewsPostsUpdatedOlderThanAndLocked(oldestDate); + newsPostManagementServiceBean.deleteNewsPosts(oldPosts); + } + + public CompletableFuture sendNewsPost(String text, Message commandMessage) { + NewsMessageModel model = NewsMessageModel + .builder() + .messageText(text) + .message(commandMessage) + .author(commandMessage.getMember()) + .build(); + log.info("Sending new message post based on message {}.", commandMessage.getIdLong()); + Long serverId = commandMessage.getGuild().getIdLong(); + MessageToSend messageToSend = templateService.renderEmbedTemplate(MESSAGE_TEMPLATE_KEY, model, serverId); + List> messageFutures = postTargetService.sendEmbedInPostTarget(messageToSend, NewsPostTarget.NEWS_TARGET, serverId); + return FutureUtils.toSingleFutureGeneric(messageFutures) + .thenApply(unused -> { + Message createdMessage = messageFutures.get(0).join(); + self.persistPost(commandMessage, createdMessage); + return createdMessage; + }); + } + + public CompletableFuture updateNewsPostViaId(Long postId, String postText, Message updatedMessage) { + NewsPost post = newsPostManagementServiceBean.getNewsPostForNewsMessageId(postId); + if(post.isLocked()) { + throw new NewsPostLockedException(); + } + return updateNewsPostMessage(post, updatedMessage, postText); + } + + public CompletableFuture updateNewsPost(NewsPost newsPost, Message updatedMessage) { + String contentStripped = updatedMessage.getContentRaw(); + String command = contentStripped.split(" ")[0]; + String postText = updatedMessage.getContentRaw().replaceFirst(command, ""); + return updateNewsPostMessage(newsPost, updatedMessage, postText); + } + + private CompletableFuture updateNewsPostMessage(NewsPost newsPost, Message updatedMessage, String postText) { + NewsMessageModel model = NewsMessageModel + .builder() + .messageText(postText) + .message(updatedMessage) + .author(updatedMessage.getMember()) + .build(); + Long serverId = updatedMessage.getGuild().getIdLong(); + newsPost.setUpdated(Instant.now()); + log.info("Updating news post {} with new content based on message from user {} in server {}.", + newsPost.getSourceMessageId(), updatedMessage.getIdLong(), updatedMessage.getGuild().getId()); + MessageToSend messageToSend = templateService.renderEmbedTemplate(MESSAGE_TEMPLATE_KEY, model, serverId); + TextChannel newsChannel = channelService.getTextChannelFromServer(serverId, newsPost.getNewsChannel().getId()); + return channelService.editMessageInAChannelFuture(messageToSend, newsChannel, newsPost.getNewsMessageId()) + .thenApply(message -> null); + } + + @Transactional + public void persistPost(Message commandMessage, Message createdMessage) { + log.info("Persisting news post with created message {} based on command message {}.", createdMessage.getIdLong(), commandMessage.getIdLong()); + newsPostManagementServiceBean.createNewsPost(commandMessage, createdMessage); + } + +} diff --git a/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/service/management/NewsPostManagementServiceBean.java b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/service/management/NewsPostManagementServiceBean.java new file mode 100644 index 0000000..ea2c94d --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/java/dev/sheldan/oneplus/bot/modules/news/service/management/NewsPostManagementServiceBean.java @@ -0,0 +1,77 @@ +package dev.sheldan.oneplus.bot.modules.news.service.management; + +import dev.sheldan.abstracto.core.models.database.AChannel; +import dev.sheldan.abstracto.core.models.database.AUserInAServer; +import dev.sheldan.abstracto.core.service.management.UserInServerManagementService; +import dev.sheldan.oneplus.bot.modules.news.exception.NewsPostNotFoundException; +import dev.sheldan.oneplus.bot.modules.news.model.database.NewsPost; +import dev.sheldan.oneplus.bot.modules.news.repository.NewsPostRepository; +import lombok.extern.slf4j.Slf4j; +import net.dv8tion.jda.api.entities.Message; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.persistence.EntityManager; +import java.time.Instant; +import java.util.List; +import java.util.Optional; + +@Component +@Slf4j +public class NewsPostManagementServiceBean { + + @Autowired + private NewsPostRepository newsPostRepository; + + @Autowired + private EntityManager entityManager; + + @Autowired + private UserInServerManagementService userInServerManagementService; + + public NewsPost createNewsPost(Message commandMessage, Message createdMessage) { + AChannel sourceChannel = entityManager.getReference(AChannel.class, commandMessage.getChannel().getIdLong()); + AChannel newsChannel = entityManager.getReference(AChannel.class, createdMessage.getChannel().getIdLong()); + AUserInAServer author = userInServerManagementService.loadOrCreateUser(commandMessage.getMember()); + NewsPost post = NewsPost + .builder() + .sourceChannel(sourceChannel) + .newsChannel(newsChannel) + .author(author) + .newsMessageId(createdMessage.getIdLong()) + .sourceMessageId(commandMessage.getIdLong()) + .server(author.getServerReference()) + .locked(false) + .build(); + log.debug("Created news post based on message {}.", createdMessage.getIdLong()); + return newsPostRepository.save(post); + } + + public Optional getNewsPostForSourceMessage(Long sourceMessageId) { + return newsPostRepository.findById(sourceMessageId); + } + + public Optional getNewsPostForNewsMessageIdOptional(Long sourceMessageId) { + return newsPostRepository.findByNewsMessageId(sourceMessageId); + } + + public NewsPost getNewsPostForNewsMessageId(Long sourceMessageId) { + return getNewsPostForNewsMessageIdOptional(sourceMessageId).orElseThrow(NewsPostNotFoundException::new); + } + + public List findNewsPostsOlderNotLocked(Instant pointInTime) { + log.debug("Checking for not locked news posts older than {}", pointInTime); + return newsPostRepository.findByCreatedLessThanAndLockedFalse(pointInTime); + } + + public List findNewsPostsUpdatedOlderThanAndLocked(Instant pointInTime) { + log.debug("Checking for not locked news posts updated older than {}.", pointInTime); + return newsPostRepository.findByUpdatedLessThanAndLockedTrue(pointInTime); + } + + public void deleteNewsPosts(List postsToDelete) { + log.info("Deleting {} news posts.", postsToDelete.size()); + postsToDelete.forEach(newsPost -> log.info("Deleting news post {}", newsPost.getSourceMessageId())); + newsPostRepository.deleteAll(postsToDelete); + } +} diff --git a/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/collection.xml b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/collection.xml new file mode 100644 index 0000000..b65032a --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/collection.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/command.xml b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/command.xml new file mode 100644 index 0000000..c991a99 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/command.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/data.xml b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/data.xml new file mode 100644 index 0000000..7b96c1f --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/data.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/feature.xml b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/feature.xml new file mode 100644 index 0000000..9f091c0 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/feature.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/module.xml b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/module.xml new file mode 100644 index 0000000..a9ad750 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/module.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/news_jobs.xml b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/news_jobs.xml new file mode 100644 index 0000000..34b7b0e --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-seedData/news_jobs.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-tables/news_post.xml b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-tables/news_post.xml new file mode 100644 index 0000000..6b009b6 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-tables/news_post.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + DROP TRIGGER IF EXISTS news_post_update_trigger ON news_post; + CREATE TRIGGER repost_check_channel_group_update_trigger BEFORE UPDATE ON news_post FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure(); + + + DROP TRIGGER IF EXISTS news_post_insert_trigger ON news_post; + CREATE TRIGGER repost_check_channel_group_insert_trigger BEFORE INSERT ON news_post FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure(); + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-tables/tables.xml b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-tables/tables.xml new file mode 100644 index 0000000..e7c4f70 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/migrations/1.3.9-news/news-tables/tables.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/resources/migrations/dbchangelog-3.8.xsd b/application/oneplus-bot-modules/news/src/main/resources/migrations/dbchangelog-3.8.xsd new file mode 100644 index 0000000..ebfe6d6 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/migrations/dbchangelog-3.8.xsd @@ -0,0 +1,1377 @@ + + + + + + + + + + + + + + Extension to standard XSD boolean type to allow ${} parameters + + + + + + + + + + + + + + + + Extension to standard XSD integer type to allow ${} parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + onChangeLogPreconditionOnSqlOutput determines what should + happen when evaluating this precondition in updateSQL mode. TEST: Run + precondition, FAIL: Fail precondition, IGNORE: Skip precondition check + [DEFAULT] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Used with valueClobFile to specify file encoding explicitly. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true for a cycling sequence, false for a non-cycling sequence. + Default is false. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/application/oneplus-bot-modules/news/src/main/resources/migrations/news-changeLog.xml b/application/oneplus-bot-modules/news/src/main/resources/migrations/news-changeLog.xml new file mode 100644 index 0000000..4000ce4 --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/migrations/news-changeLog.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/application/oneplus-bot-modules/news/src/main/resources/news.properties b/application/oneplus-bot-modules/news/src/main/resources/news.properties new file mode 100644 index 0000000..fce968f --- /dev/null +++ b/application/oneplus-bot-modules/news/src/main/resources/news.properties @@ -0,0 +1,7 @@ +abstracto.postTargets.news.name=news + +abstracto.featureFlags.news.featureName=news +abstracto.featureFlags.news.enabled=false + +abstracto.feature.news.removalDays=4 +abstracto.feature.news.postLockSeconds=3600 diff --git a/application/oneplus-bot-modules/pom.xml b/application/oneplus-bot-modules/pom.xml new file mode 100644 index 0000000..aa14134 --- /dev/null +++ b/application/oneplus-bot-modules/pom.xml @@ -0,0 +1,24 @@ + + + + dev.sheldan.oneplus.bot.application + application + 1.3.9-SNAPSHOT + + 4.0.0 + + dev.sheldan.oneplus.bot.application.modules + oneplus-bot-modules + pom + + news + + + + 8 + 8 + + + \ No newline at end of file diff --git a/application/pom.xml b/application/pom.xml index 233b579..971a3be 100644 --- a/application/pom.xml +++ b/application/pom.xml @@ -15,6 +15,7 @@ executable oneplus-bot-customizations + oneplus-bot-modules diff --git a/deployment/image-packaging/pom.xml b/deployment/image-packaging/pom.xml index 7da5fc9..147d72d 100644 --- a/deployment/image-packaging/pom.xml +++ b/deployment/image-packaging/pom.xml @@ -89,7 +89,7 @@ utility.zip - f + dev.sheldan.abstracto-templates.templates webservices ${abstracto.templates.version} @@ -119,6 +119,16 @@ starboard-custom.zip + + dev.sheldan.oneplus.bot.templates.modules + news-templates + ${project.version} + zip + true + ${file.basedir}/deployment/template-artifacts/ + news.zip + + dev.sheldan.abstracto-templates.translations @@ -206,6 +216,17 @@ starboard-custom.zip + + + dev.sheldan.oneplus.bot.templates.translations + news-translations + ${project.version} + zip + true + ${file.basedir}/deployment/translation-artifacts/ + news.zip + + dev.sheldan.abstracto.scheduling @@ -307,6 +328,7 @@ remind.zip + dev.sheldan.oneplus.bot.application.custom starboard-custom @@ -318,6 +340,17 @@ starboard-custom.zip + + dev.sheldan.oneplus.bot.application.modules + news + ${project.version} + liquibase + zip + true + ${file.basedir}/deployment/liquibase-artifacts/ + news.zip + + diff --git a/deployment/image-packaging/src/main/docker/deployment/config/artifact_versions.json b/deployment/image-packaging/src/main/docker/deployment/config/artifact_versions.json index 46d4452..f47623b 100644 --- a/deployment/image-packaging/src/main/docker/deployment/config/artifact_versions.json +++ b/deployment/image-packaging/src/main/docker/deployment/config/artifact_versions.json @@ -1,6 +1,8 @@ { - "template_artifacts": ["utility", "core", "entertainment", "starboard", "link-embed", "webservices", "remind", "starboard-custom", "overrides-templates-webservices", "overrides-templates-core"], - "translation_artifacts": ["utility", "core", "entertainment", "starboard", "link-embed", "webservices", "remind", "starboard-custom"], + "template_artifacts": ["utility", "core", "entertainment", "starboard", "link-embed", "webservices", "remind", + "starboard-custom", "overrides-templates-webservices", "overrides-templates-core", "news"], + "translation_artifacts": ["utility", "core", "entertainment", "starboard", "link-embed", "webservices", + "remind", "starboard-custom", "news"], "liquibase_artifacts": [ { "zip": "scheduling", "file": "scheduling-changeLog.xml" }, { "zip": "core", "file": "core-changeLog.xml" }, @@ -10,7 +12,8 @@ { "zip": "webservices", "file": "webservices-changeLog.xml"}, { "zip": "starboard", "file": "starboard-changeLog.xml"}, { "zip": "remind", "file": "remind-changeLog.xml"}, - { "zip": "starboard-custom", "file": "starboard-custom-changeLog.xml"} + { "zip": "starboard-custom", "file": "starboard-custom-changeLog.xml"}, + { "zip": "news", "file": "news-changeLog.xml"} ] } diff --git a/pom.xml b/pom.xml index 368bb90..bdcf4bb 100644 --- a/pom.xml +++ b/pom.xml @@ -19,8 +19,8 @@ 1.8 - 1.2.8 - 1.2.4 + 1.2.9-SNAPSHOT + 1.2.5-SNAPSHOT diff --git a/templates/oneplus-bot-modules-templates/news-templates/pom.xml b/templates/oneplus-bot-modules-templates/news-templates/pom.xml new file mode 100644 index 0000000..d255f33 --- /dev/null +++ b/templates/oneplus-bot-modules-templates/news-templates/pom.xml @@ -0,0 +1,39 @@ + + + + dev.sheldan.oneplus.bot.templates.modules + oneplus-bot-modules-templates + 1.3.9-SNAPSHOT + + 4.0.0 + + news-templates + pom + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + starboard-custom-templates-${project.version} + false + + src/main/assembly/assembly.xml + + + + + + + + + \ No newline at end of file diff --git a/templates/oneplus-bot-modules/starboard-custom/src/main/assembly/assembly.xml b/templates/oneplus-bot-modules-templates/news-templates/src/main/assembly/assembly.xml similarity index 100% rename from templates/oneplus-bot-modules/starboard-custom/src/main/assembly/assembly.xml rename to templates/oneplus-bot-modules-templates/news-templates/src/main/assembly/assembly.xml diff --git a/templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/commands/news/news_post_embed_en_US.ftl b/templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/commands/news/news_post_embed_en_US.ftl new file mode 100644 index 0000000..a5f6f1c --- /dev/null +++ b/templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/commands/news/news_post_embed_en_US.ftl @@ -0,0 +1,12 @@ +{ + <#assign roleMention="<@&823285857515470868>"/> + <#assign authorMention>${author.user.name}#${author.user.discriminator} + "additionalMessage": "<@safe_include "news_post_description"/>", + <#if message.attachments?size gt 0> + "imageUrl": "${message.attachments[0].proxyUrl}", + + "metaConfig": { + "allowsRoleMention": true, + "preventEmptyEmbed": true + } +} \ No newline at end of file diff --git a/templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/exception/news_post_locked_exception_en_US.ftl b/templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/exception/news_post_locked_exception_en_US.ftl new file mode 100644 index 0000000..beb5cb6 --- /dev/null +++ b/templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/exception/news_post_locked_exception_en_US.ftl @@ -0,0 +1 @@ +<#include "news_post_locked_exception_message"> \ No newline at end of file diff --git a/templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/exception/news_post_not_found_exception_en_US.ftl b/templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/exception/news_post_not_found_exception_en_US.ftl new file mode 100644 index 0000000..dbec4a4 --- /dev/null +++ b/templates/oneplus-bot-modules-templates/news-templates/src/main/resources/en_US/exception/news_post_not_found_exception_en_US.ftl @@ -0,0 +1 @@ +<#include "news_post_not_found_exception_text"> \ No newline at end of file diff --git a/templates/oneplus-bot-modules/pom.xml b/templates/oneplus-bot-modules-templates/pom.xml similarity index 87% rename from templates/oneplus-bot-modules/pom.xml rename to templates/oneplus-bot-modules-templates/pom.xml index e0fcf4c..ab61b99 100644 --- a/templates/oneplus-bot-modules/pom.xml +++ b/templates/oneplus-bot-modules-templates/pom.xml @@ -8,11 +8,12 @@ 4.0.0 dev.sheldan.oneplus.bot.templates.modules - oneplus-bot-modules + oneplus-bot-modules-templates pom 1.3.9-SNAPSHOT starboard-custom + news-templates diff --git a/templates/oneplus-bot-modules/starboard-custom/pom.xml b/templates/oneplus-bot-modules-templates/starboard-custom/pom.xml similarity index 95% rename from templates/oneplus-bot-modules/starboard-custom/pom.xml rename to templates/oneplus-bot-modules-templates/starboard-custom/pom.xml index fce81cc..e1ffb53 100644 --- a/templates/oneplus-bot-modules/starboard-custom/pom.xml +++ b/templates/oneplus-bot-modules-templates/starboard-custom/pom.xml @@ -2,7 +2,7 @@ dev.sheldan.oneplus.bot.templates.modules - oneplus-bot-modules + oneplus-bot-modules-templates 1.3.9-SNAPSHOT 4.0.0 diff --git a/templates/oneplus-bot-modules-templates/starboard-custom/src/main/assembly/assembly.xml b/templates/oneplus-bot-modules-templates/starboard-custom/src/main/assembly/assembly.xml new file mode 100644 index 0000000..aca1e51 --- /dev/null +++ b/templates/oneplus-bot-modules-templates/starboard-custom/src/main/assembly/assembly.xml @@ -0,0 +1,15 @@ + + zip + false + + zip + + + + . + ${project.basedir}/src/main/resources + + + \ No newline at end of file diff --git a/templates/oneplus-bot-modules/starboard-custom/src/main/resources/en_US/listener/starboardNotification/starboard_post_created_notification_embed_en_US.ftl b/templates/oneplus-bot-modules-templates/starboard-custom/src/main/resources/en_US/listener/starboardNotification/starboard_post_created_notification_embed_en_US.ftl similarity index 100% rename from templates/oneplus-bot-modules/starboard-custom/src/main/resources/en_US/listener/starboardNotification/starboard_post_created_notification_embed_en_US.ftl rename to templates/oneplus-bot-modules-templates/starboard-custom/src/main/resources/en_US/listener/starboardNotification/starboard_post_created_notification_embed_en_US.ftl diff --git a/templates/oneplus-bot-modules/starboard-custom/src/main/resources/en_US/listener/starboardNotification/starboard_post_deleted_notification_embed_en_US.ftl b/templates/oneplus-bot-modules-templates/starboard-custom/src/main/resources/en_US/listener/starboardNotification/starboard_post_deleted_notification_embed_en_US.ftl similarity index 100% rename from templates/oneplus-bot-modules/starboard-custom/src/main/resources/en_US/listener/starboardNotification/starboard_post_deleted_notification_embed_en_US.ftl rename to templates/oneplus-bot-modules-templates/starboard-custom/src/main/resources/en_US/listener/starboardNotification/starboard_post_deleted_notification_embed_en_US.ftl diff --git a/templates/overrides/template-overrides/webservices/src/main/resources/en_US/urban/commands/urbanDefine/urban_define_response_model_embed_en_US.ftl b/templates/overrides/template-overrides/webservices/src/main/resources/en_US/urban/commands/urbanDefine/urban_define_response_model_embed_en_US.ftl index 1527188..2f45b6b 100644 --- a/templates/overrides/template-overrides/webservices/src/main/resources/en_US/urban/commands/urbanDefine/urban_define_response_model_embed_en_US.ftl +++ b/templates/overrides/template-overrides/webservices/src/main/resources/en_US/urban/commands/urbanDefine/urban_define_response_model_embed_en_US.ftl @@ -13,5 +13,7 @@ } ], "additionalMessage": "${definition.definition?json_string}", - "messageLimit": 1 + "metaConfig": { + "messageLimit": 1 + } } \ No newline at end of file diff --git a/templates/pom.xml b/templates/pom.xml index a75eefa..8e78b1f 100644 --- a/templates/pom.xml +++ b/templates/pom.xml @@ -8,7 +8,7 @@ - oneplus-bot-modules + oneplus-bot-modules-templates translations overrides diff --git a/templates/translations/news-translations/pom.xml b/templates/translations/news-translations/pom.xml new file mode 100644 index 0000000..3efe6e3 --- /dev/null +++ b/templates/translations/news-translations/pom.xml @@ -0,0 +1,38 @@ + + + + dev.sheldan.oneplus.bot.templates.translations + translations + 1.3.9-SNAPSHOT + + 4.0.0 + + news-translations + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + starboard-custom-templates-${project.version} + false + + src/main/assembly/assembly.xml + + + + + + + + + \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/assembly/assembly.xml b/templates/translations/news-translations/src/main/assembly/assembly.xml new file mode 100644 index 0000000..aca1e51 --- /dev/null +++ b/templates/translations/news-translations/src/main/assembly/assembly.xml @@ -0,0 +1,15 @@ + + zip + false + + zip + + + + . + ${project.basedir}/src/main/resources + + + \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_description_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_description_en_US.ftl new file mode 100644 index 0000000..46f544b --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_description_en_US.ftl @@ -0,0 +1 @@ +Posts a news post in the news channel \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_long_help_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_long_help_en_US.ftl new file mode 100644 index 0000000..1e5ed23 --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_long_help_en_US.ftl @@ -0,0 +1,4 @@ +Creates a news with the provided text and any attachments in the `news` post target with the defined template. +The news post can be updated via editing the original message containing the command or by the command `updateNews`. +This is only possible as long as the news post has not been locked. This is the case a few hours after posting it. +The news posts are completely removed from the database a few days after locking them. \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_parameter_text_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_parameter_text_en_US.ftl new file mode 100644 index 0000000..93a009c --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/commands/news/help/news_parameter_text_en_US.ftl @@ -0,0 +1 @@ +The text the news post should contain \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/commands/news/news_post_description_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/commands/news/news_post_description_en_US.ftl new file mode 100644 index 0000000..308a0ab --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/commands/news/news_post_description_en_US.ftl @@ -0,0 +1,4 @@ +${messageText} + +${roleMention?json_string} +- ${authorMention} \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_description_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_description_en_US.ftl new file mode 100644 index 0000000..94f6c66 --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_description_en_US.ftl @@ -0,0 +1 @@ +Command used to update an existing news post content \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_long_help_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_long_help_en_US.ftl new file mode 100644 index 0000000..5ce4d39 --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_long_help_en_US.ftl @@ -0,0 +1,4 @@ +This command can be used to update the news post complete. +This will effectively render the template new (including author) and replace the contents of the existing news post. +Editing the news post does not re-ping any roles. +This is only possible as long as the news post was not locked and is still stored in the database. \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_parameter_newsPostId_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_parameter_newsPostId_en_US.ftl new file mode 100644 index 0000000..7aee32a --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_parameter_newsPostId_en_US.ftl @@ -0,0 +1 @@ +The ID of the news post message which was created. \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_parameter_text_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_parameter_text_en_US.ftl new file mode 100644 index 0000000..85f416d --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/commands/updateNews/help/updateNews_parameter_text_en_US.ftl @@ -0,0 +1 @@ +The new text the news post should receive. \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/config/feature_news_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/config/feature_news_en_US.ftl new file mode 100644 index 0000000..da26bbe --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/config/feature_news_en_US.ftl @@ -0,0 +1 @@ +News \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/config/feature_setup_posttarget_news_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/config/feature_setup_posttarget_news_en_US.ftl new file mode 100644 index 0000000..7e516f6 --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/config/feature_setup_posttarget_news_en_US.ftl @@ -0,0 +1 @@ +The channel in which the news should be posted in. Currently: ${currentTarget} \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/config/module_news_description_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/config/module_news_description_en_US.ftl new file mode 100644 index 0000000..926c2e4 --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/config/module_news_description_en_US.ftl @@ -0,0 +1 @@ +Module used to post & update news in the server \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/exception/news_post_locked_exception_message_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/exception/news_post_locked_exception_message_en_US.ftl new file mode 100644 index 0000000..6927553 --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/exception/news_post_locked_exception_message_en_US.ftl @@ -0,0 +1 @@ +News post is locked and cannot be edited. \ No newline at end of file diff --git a/templates/translations/news-translations/src/main/resources/en_US/exception/news_post_not_found_exception_text_en_US.ftl b/templates/translations/news-translations/src/main/resources/en_US/exception/news_post_not_found_exception_text_en_US.ftl new file mode 100644 index 0000000..fd3d22a --- /dev/null +++ b/templates/translations/news-translations/src/main/resources/en_US/exception/news_post_not_found_exception_text_en_US.ftl @@ -0,0 +1 @@ +News post not found. \ No newline at end of file diff --git a/templates/translations/pom.xml b/templates/translations/pom.xml index fa8a81d..620b8a7 100644 --- a/templates/translations/pom.xml +++ b/templates/translations/pom.xml @@ -12,5 +12,6 @@ pom starboard-custom-translations + news-translations \ No newline at end of file