mirror of
https://github.com/Sheldan/OnePlusBot.git
synced 2026-04-15 21:06:35 +00:00
[OPB-19] adding referral link functionality
changing name for setups feature aligning starboard custom module name
This commit is contained in:
@@ -124,7 +124,13 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
|
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
|
||||||
<artifactId>setups</artifactId>
|
<artifactId>setup</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
|
||||||
|
<artifactId>referral</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<module>news</module>
|
<module>news</module>
|
||||||
<module>setups</module>
|
<module>setup</module>
|
||||||
|
<module>referral</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
41
application/oneplus-bot-modules/referral/pom.xml
Normal file
41
application/oneplus-bot-modules/referral/pom.xml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
|
||||||
|
<artifactId>oneplus-bot-modules</artifactId>
|
||||||
|
<version>1.3.11-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>referral</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<descriptors>
|
||||||
|
<descriptor>src/main/assembly/liquibase.xml</descriptor>
|
||||||
|
</descriptors>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ReferralBeanConfig {
|
||||||
|
@Bean(value = "referralDelayExecutor")
|
||||||
|
public ScheduledExecutorService getDelayedExecutor() {
|
||||||
|
return Executors.newSingleThreadScheduledExecutor();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.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 ReferralFeature implements FeatureConfig {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return ReferralFeatureDefinition.REFERRAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PostTargetEnum> getRequiredPostTargets() {
|
||||||
|
return Arrays.asList(ReferralPostTarget.REFERRAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.config;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum ReferralFeatureDefinition implements FeatureDefinition {
|
||||||
|
REFERRAL("referral");
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
ReferralFeatureDefinition(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.config;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum ReferralPostTarget implements PostTargetEnum {
|
||||||
|
REFERRAL("referral");
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
ReferralPostTarget(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@PropertySource("classpath:referral.properties")
|
||||||
|
public class ReferralProperties {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.listener;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||||
|
import dev.sheldan.abstracto.core.listener.async.jda.AsyncMessageReceivedListener;
|
||||||
|
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||||
|
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||||
|
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||||
|
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||||
|
import dev.sheldan.abstracto.core.service.MessageService;
|
||||||
|
import dev.sheldan.abstracto.core.service.management.PostTargetManagement;
|
||||||
|
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.config.ReferralFeatureDefinition;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.config.ReferralPostTarget;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.model.template.Referral;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.model.template.ReferralPostModel;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.model.template.ReferralTooRecentModel;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.service.ReferralServiceBean;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class ReferralListener implements AsyncMessageReceivedListener {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PostTargetManagement postTargetManagement;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageService messageService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReferralServiceBean referralServiceBean;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ChannelService channelService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReferralListener self;
|
||||||
|
|
||||||
|
@Qualifier("referralDelayExecutor")
|
||||||
|
@Autowired
|
||||||
|
private ScheduledExecutorService scheduledExecutorService;
|
||||||
|
|
||||||
|
@Value("${oneplus.bot.referral.deleteDelaySeconds}")
|
||||||
|
private Long deleteDelaySeconds;
|
||||||
|
|
||||||
|
@Value("${oneplus.bot.referral.maxReferralCount}")
|
||||||
|
private Long maxReferralLinksPerPost;
|
||||||
|
|
||||||
|
private static final String NO_REFERRAL_LINK_FOUND_TEMPLATE_KEY = "referralListener_no_referral_link_found";
|
||||||
|
private static final String REFERRAL_POST_TOO_RECENT_TEMPLATE_KEY = "referralListener_too_recent_post";
|
||||||
|
private static final String REFERRAL_POST_EMBED_TEMPLATE_KEY = "referralListener_referral_post";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DefaultListenerResult execute(MessageReceivedModel model) {
|
||||||
|
Long serverId = model.getServerId();
|
||||||
|
Optional<PostTarget> referralPostTargetOptional = postTargetManagement.getPostTargetOptional(ReferralPostTarget.REFERRAL, serverId);
|
||||||
|
if(referralPostTargetOptional.isPresent()) {
|
||||||
|
PostTarget referralTarget = referralPostTargetOptional.get();
|
||||||
|
Message message = model.getMessage();
|
||||||
|
if (message.getChannel().getIdLong() == referralTarget.getChannelReference().getId()) {
|
||||||
|
Long authorId = message.getAuthor().getIdLong();
|
||||||
|
if (!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
|
||||||
|
log.info("Deleting illegal message by user {} in referral channel in server {}.", authorId, serverId);
|
||||||
|
messageService.deleteMessage(message).exceptionally(deletionErrorConsumer(message));
|
||||||
|
return DefaultListenerResult.IGNORED;
|
||||||
|
}
|
||||||
|
if(message.getAuthor().isBot()) {
|
||||||
|
log.debug("Ignoring message from a bot user {} in referral channel in server {}.", authorId, serverId);
|
||||||
|
return DefaultListenerResult.IGNORED;
|
||||||
|
}
|
||||||
|
List<Referral> foundReferrals = referralServiceBean.getReferralsFromMessage(message);
|
||||||
|
if(foundReferrals.isEmpty()) {
|
||||||
|
log.info("Did not find referrals in message {} by user {} in server {} - deleting message.",
|
||||||
|
message.getIdLong(), authorId, serverId);
|
||||||
|
deleteAndNotify(message, NO_REFERRAL_LINK_FOUND_TEMPLATE_KEY, new Object());
|
||||||
|
return DefaultListenerResult.IGNORED;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Found {} referral links in message {} by user {} in server {}.",
|
||||||
|
foundReferrals.size(), message.getIdLong(), authorId, serverId);
|
||||||
|
|
||||||
|
Instant nextReferralDate = referralServiceBean.getNextReferralDate(message.getMember());
|
||||||
|
if(nextReferralDate.isAfter(Instant.now())) {
|
||||||
|
log.info("Referrals in message {} by user {} in server {} was before allowed repost date {} - deleting message.",
|
||||||
|
message.getIdLong(), authorId, serverId, nextReferralDate);
|
||||||
|
ReferralTooRecentModel templateModel = ReferralTooRecentModel
|
||||||
|
.builder()
|
||||||
|
.nextReferralDate(nextReferralDate)
|
||||||
|
.build();
|
||||||
|
deleteAndNotify(message, REFERRAL_POST_TOO_RECENT_TEMPLATE_KEY, templateModel);
|
||||||
|
return DefaultListenerResult.PROCESSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(foundReferrals.size() > maxReferralLinksPerPost) {
|
||||||
|
log.info("More referral links ({}) than allowed ({}) in message {} in server {} by user {}.",
|
||||||
|
foundReferrals.size(), maxReferralLinksPerPost, message.getIdLong(), serverId, authorId);
|
||||||
|
foundReferrals = foundReferrals.subList(0, maxReferralLinksPerPost.intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
ReferralPostModel postModel = ReferralPostModel
|
||||||
|
.builder()
|
||||||
|
.referrals(foundReferrals)
|
||||||
|
.postingMember(message.getMember())
|
||||||
|
.build();
|
||||||
|
ServerUser serverUser = ServerUser.fromMember(message.getMember());
|
||||||
|
CompletableFutureList<Message> sendFutures = new CompletableFutureList<>(channelService
|
||||||
|
.sendEmbedTemplateInMessageChannelList(REFERRAL_POST_EMBED_TEMPLATE_KEY, postModel, message.getChannel()));
|
||||||
|
CompletableFuture<Void> deletionFuture = messageService.deleteMessage(message);
|
||||||
|
CompletableFuture.allOf(sendFutures.getMainFuture(), deletionFuture)
|
||||||
|
.thenAccept(unused -> self.updateReferralStateInDatabase(serverUser))
|
||||||
|
.exceptionally(throwable -> {
|
||||||
|
log.error("Failed to delete or persist referral message from user {} in server {}.", authorId, serverId, throwable);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DefaultListenerResult.IGNORED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void updateReferralStateInDatabase(ServerUser serverUser) {
|
||||||
|
referralServiceBean.updateDbState(serverUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteAndNotify(Message message, String usedTemplate, Object usedModel) {
|
||||||
|
CompletableFutureList<Message> futures = new CompletableFutureList<>(channelService
|
||||||
|
.sendEmbedTemplateInMessageChannelList(usedTemplate, usedModel, message.getChannel()));
|
||||||
|
futures.getMainFuture().thenAccept(unused ->
|
||||||
|
scheduledExecutorService.schedule(() ->
|
||||||
|
futures.getObjects().forEach(createdMessage -> messageService.deleteMessage(createdMessage)),
|
||||||
|
deleteDelaySeconds, TimeUnit.SECONDS));
|
||||||
|
futures.getMainFuture().exceptionally(throwable -> {
|
||||||
|
log.error("Failed to send denial about setups with template {} message {} in channel {} in server {} by {}.",
|
||||||
|
usedTemplate, message.getIdLong(), message.getChannel().getIdLong(), message.getGuild().getIdLong(), message.getAuthor().getIdLong());
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
messageService.deleteMessage(message).exceptionally(deletionErrorConsumer(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Function<Throwable, Void> deletionErrorConsumer(Message message) {
|
||||||
|
return throwable -> {
|
||||||
|
log.error("Failed to delete setups message {} in channel {} in server {} by {}.",
|
||||||
|
message.getIdLong(), message.getChannel().getIdLong(), message.getGuild().getIdLong(), message.getAuthor().getIdLong());
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return ReferralFeatureDefinition.REFERRAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.model;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum ReferralType {
|
||||||
|
SMARTPHONE("smartphone"), ACCESSORIES("accessories"), SMARTPHONE_INDIA("smartphoneIndia");
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
ReferralType(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.model.database;
|
||||||
|
|
||||||
|
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 = "referral_user_in_server")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class ReferralUserInAServer {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link AUserInAServer user} which is represented by this object
|
||||||
|
*/
|
||||||
|
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||||
|
@PrimaryKeyJoinColumn
|
||||||
|
private AUserInAServer user;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "server_id", nullable = false)
|
||||||
|
private AServer server;
|
||||||
|
|
||||||
|
@Column(name = "last_referral_post")
|
||||||
|
private Instant lastReferralPost;
|
||||||
|
|
||||||
|
@Column(name = "created")
|
||||||
|
private Instant created;
|
||||||
|
|
||||||
|
@Column(name = "updated")
|
||||||
|
private Instant updated;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.model.template;
|
||||||
|
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.model.ReferralType;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class Referral {
|
||||||
|
private String referralLink;
|
||||||
|
private String referralIdentifier;
|
||||||
|
private ReferralType type;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.model.template;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class ReferralPostModel {
|
||||||
|
private Member postingMember;
|
||||||
|
private List<Referral> referrals;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.model.template;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class ReferralTooRecentModel {
|
||||||
|
private Instant nextReferralDate;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.repository;
|
||||||
|
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.model.database.ReferralUserInAServer;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ReferralUserInAServerRepository extends JpaRepository<ReferralUserInAServer, Long> {
|
||||||
|
Optional<ReferralUserInAServer> findByServer_IdAndUser_UserReference_Id(Long serverId, Long userId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.service;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.model.ReferralType;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.model.database.ReferralUserInAServer;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.model.template.Referral;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.service.management.ReferralUserManagementServiceBean;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ReferralServiceBean {
|
||||||
|
|
||||||
|
@Value("${oneplus.bot.referral.referralRepostDays}")
|
||||||
|
private Long repostDurationDays;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReferralUserManagementServiceBean referralUserManagementServiceBean;
|
||||||
|
|
||||||
|
private final Pattern referralPattern = Pattern.compile("(?<whole>https?://(?:www\\.)?oneplus\\.(?:[a-z]{1,63})[^\\s]*invite(?:#(?<identifier>[^\\s]+)|.+=([^\\s&]+)))");
|
||||||
|
|
||||||
|
public List<Referral> getReferralsFromMessage(Message message) {
|
||||||
|
List<Referral> referrals = new ArrayList<>();
|
||||||
|
Matcher matcher = referralPattern.matcher(message.getContentRaw());
|
||||||
|
while(matcher.find()) {
|
||||||
|
String fullUrl = matcher.group("whole");
|
||||||
|
String referralIdentifier = matcher.group("identifier");
|
||||||
|
Referral referral = Referral
|
||||||
|
.builder()
|
||||||
|
.referralLink(fullUrl)
|
||||||
|
.type(getType(referralIdentifier, fullUrl))
|
||||||
|
.referralIdentifier(referralIdentifier)
|
||||||
|
.build();
|
||||||
|
referrals.add(referral);
|
||||||
|
}
|
||||||
|
return referrals;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReferralType getType(String identifier, String fullUrl) {
|
||||||
|
if(identifier.length() < 20) {
|
||||||
|
return ReferralType.SMARTPHONE;
|
||||||
|
} else if(fullUrl.contains(".in")) {
|
||||||
|
return ReferralType.SMARTPHONE_INDIA;
|
||||||
|
} else {
|
||||||
|
return ReferralType.ACCESSORIES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDbState(ServerUser serverUser) {
|
||||||
|
Optional<ReferralUserInAServer> userOptional = referralUserManagementServiceBean.getReferralFromDb(serverUser);
|
||||||
|
if(userOptional.isPresent()) {
|
||||||
|
userOptional.get().setLastReferralPost(Instant.now());
|
||||||
|
} else {
|
||||||
|
referralUserManagementServiceBean.createReferralUser(serverUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant getNextReferralDate(Member member) {
|
||||||
|
ServerUser serverUser = ServerUser.fromMember(member);
|
||||||
|
Optional<ReferralUserInAServer> userOptional = referralUserManagementServiceBean.getReferralFromDb(serverUser);
|
||||||
|
return userOptional.map(referralUserInAServer -> referralUserInAServer
|
||||||
|
.getLastReferralPost()
|
||||||
|
.plus(repostDurationDays, ChronoUnit.DAYS))
|
||||||
|
.orElse(Instant.now());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.referral.service.management;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||||
|
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||||
|
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.model.database.ReferralUserInAServer;
|
||||||
|
import dev.sheldan.oneplus.bot.modules.referral.repository.ReferralUserInAServerRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ReferralUserManagementServiceBean {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReferralUserInAServerRepository repository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserInServerManagementService userInServerManagementService;
|
||||||
|
|
||||||
|
public Optional<ReferralUserInAServer> getReferralFromDb(ServerUser serverUser) {
|
||||||
|
return repository.findByServer_IdAndUser_UserReference_Id(serverUser.getServerId(), serverUser.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferralUserInAServer createReferralUser(ServerUser serverUser) {
|
||||||
|
AUserInAServer userInAServer = userInServerManagementService.loadOrCreateUser(serverUser);
|
||||||
|
ReferralUserInAServer user = ReferralUserInAServer
|
||||||
|
.builder()
|
||||||
|
.user(userInAServer)
|
||||||
|
.id(userInAServer.getUserInServerId())
|
||||||
|
.lastReferralPost(Instant.now())
|
||||||
|
.server(userInAServer.getServerReference())
|
||||||
|
.build();
|
||||||
|
return repository.save(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
|
<include file="referral-tables/tables.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="referral-seedData/data.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -6,5 +6,5 @@
|
|||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
<include file="1.3.11-setups/collection.xml" relativeToChangelogFile="true"/>
|
<include file="feature.xml" relativeToChangelogFile="true"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
|
<changeSet author="Sheldan" id="referral_feature-insertion">
|
||||||
|
<insert tableName="feature">
|
||||||
|
<column name="key" value="referral"/>
|
||||||
|
</insert>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
|
<changeSet author="Sheldan" id="referral_user_in_server-table">
|
||||||
|
<createTable tableName="referral_user_in_server">
|
||||||
|
<column name="id" type="BIGINT">
|
||||||
|
<constraints nullable="false" primaryKey="true" primaryKeyName="referral_user_in_server_pkey"/>
|
||||||
|
</column>
|
||||||
|
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||||
|
<column name="last_referral_post" type="TIMESTAMP WITHOUT TIME ZONE" />
|
||||||
|
<column name="server_id" type="BIGINT">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
<addForeignKeyConstraint baseColumnNames="server_id" baseTableName="referral_user_in_server" constraintName="fk_referral_user_in_server_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
|
||||||
|
<addForeignKeyConstraint baseColumnNames="id" baseTableName="referral_user_in_server" constraintName="fk_referral_user_in_server_user" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="user_in_server_id" referencedTableName="user_in_server" validate="true"/>
|
||||||
|
<sql>
|
||||||
|
DROP TRIGGER IF EXISTS referral_user_in_server_update_trigger ON referral_user_in_server;
|
||||||
|
CREATE TRIGGER referral_user_in_server_update_trigger BEFORE UPDATE ON referral_user_in_server FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||||
|
</sql>
|
||||||
|
<sql>
|
||||||
|
DROP TRIGGER IF EXISTS referral_user_in_server_insert_trigger ON referral_user_in_server;
|
||||||
|
CREATE TRIGGER referral_user_in_server_insert_trigger BEFORE INSERT ON referral_user_in_server FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||||
|
</sql>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
|
<include file="referral_user_in_server.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
|
<include file="1.3.11-referral/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
abstracto.postTargets.referral.name=referral
|
||||||
|
|
||||||
|
abstracto.featureFlags.referral.featureName=referral
|
||||||
|
abstracto.featureFlags.referral.enabled=false
|
||||||
|
|
||||||
|
oneplus.bot.referral.maxReferralCount=2
|
||||||
|
oneplus.bot.referral.deleteDelaySeconds=7
|
||||||
|
oneplus.bot.referral.referralRepostDays=14
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>setups</artifactId>
|
<artifactId>setup</artifactId>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
|
||||||
|
<id>liquibase</id>
|
||||||
|
<formats>
|
||||||
|
<format>zip</format>
|
||||||
|
</formats>
|
||||||
|
<includeBaseDirectory>false</includeBaseDirectory>
|
||||||
|
<fileSets>
|
||||||
|
<fileSet>
|
||||||
|
<outputDirectory>.</outputDirectory>
|
||||||
|
<directory>${project.basedir}/src/main/resources/migrations</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
</fileSet>
|
||||||
|
</fileSets>
|
||||||
|
</assembly>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.oneplus.bot.modules.setups.config;
|
package dev.sheldan.oneplus.bot.modules.setup.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -7,8 +7,8 @@ import java.util.concurrent.Executors;
|
|||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SetupsBeanConfig {
|
public class SetupBeanConfig {
|
||||||
@Bean(value = "setupsDelayedExecutor")
|
@Bean(value = "setupDelayedExecutor")
|
||||||
public ScheduledExecutorService getDelayedExecutor() {
|
public ScheduledExecutorService getDelayedExecutor() {
|
||||||
return Executors.newSingleThreadScheduledExecutor();
|
return Executors.newSingleThreadScheduledExecutor();
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.oneplus.bot.modules.setups.config;
|
package dev.sheldan.oneplus.bot.modules.setup.config;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
@@ -8,23 +8,23 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static dev.sheldan.oneplus.bot.modules.setups.listener.SetupsListener.SETUPS_UPVOTE_EMOTE_KEY;
|
import static dev.sheldan.oneplus.bot.modules.setup.listener.SetupListener.SETUP_UPVOTE_EMOTE_KEY;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class SetupsFeature implements FeatureConfig {
|
public class SetupFeatureConfig implements FeatureConfig {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FeatureDefinition getFeature() {
|
public FeatureDefinition getFeature() {
|
||||||
return SetupsFeatureDefinition.SETUPS;
|
return SetupFeatureDefinition.SETUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PostTargetEnum> getRequiredPostTargets() {
|
public List<PostTargetEnum> getRequiredPostTargets() {
|
||||||
return Arrays.asList(SetupsPostTarget.SETUPS);
|
return Arrays.asList(SetupPostTarget.SETUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getRequiredEmotes() {
|
public List<String> getRequiredEmotes() {
|
||||||
return Arrays.asList(SETUPS_UPVOTE_EMOTE_KEY);
|
return Arrays.asList(SETUP_UPVOTE_EMOTE_KEY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.setup.config;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum SetupFeatureDefinition implements FeatureDefinition {
|
||||||
|
SETUP("setup");
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
SetupFeatureDefinition(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.sheldan.oneplus.bot.modules.setup.config;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum SetupPostTarget implements PostTargetEnum {
|
||||||
|
SETUP("setup");
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
SetupPostTarget(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package dev.sheldan.oneplus.bot.modules.setups.config;
|
package dev.sheldan.oneplus.bot.modules.setup.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@PropertySource("classpath:setups.properties")
|
@PropertySource("classpath:setup.properties")
|
||||||
public class SetupsProperties {
|
public class SetupProperties {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.oneplus.bot.modules.setups.listener;
|
package dev.sheldan.oneplus.bot.modules.setup.listener;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||||
@@ -8,9 +8,9 @@ import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
|||||||
import dev.sheldan.abstracto.core.service.MessageService;
|
import dev.sheldan.abstracto.core.service.MessageService;
|
||||||
import dev.sheldan.abstracto.core.service.ReactionService;
|
import dev.sheldan.abstracto.core.service.ReactionService;
|
||||||
import dev.sheldan.abstracto.core.service.management.PostTargetManagement;
|
import dev.sheldan.abstracto.core.service.management.PostTargetManagement;
|
||||||
import dev.sheldan.oneplus.bot.modules.setups.config.SetupsFeatureDefinition;
|
import dev.sheldan.oneplus.bot.modules.setup.config.SetupFeatureDefinition;
|
||||||
import dev.sheldan.oneplus.bot.modules.setups.config.SetupsPostTarget;
|
import dev.sheldan.oneplus.bot.modules.setup.config.SetupPostTarget;
|
||||||
import dev.sheldan.oneplus.bot.modules.setups.service.SetupsService;
|
import dev.sheldan.oneplus.bot.modules.setup.service.SetupServiceBean;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -24,19 +24,19 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SetupsListener implements AsyncMessageReceivedListener {
|
public class SetupListener implements AsyncMessageReceivedListener {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PostTargetManagement postTargetManagement;
|
private PostTargetManagement postTargetManagement;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SetupsService setupsService;
|
private SetupServiceBean setupServiceBean;
|
||||||
|
|
||||||
@Qualifier("setupsDelayedExecutor")
|
@Qualifier("setupDelayedExecutor")
|
||||||
@Autowired
|
@Autowired
|
||||||
private ScheduledExecutorService scheduledExecutorService;
|
private ScheduledExecutorService scheduledExecutorService;
|
||||||
|
|
||||||
@Value("${abstracto.setups.deletionDelaySeconds}")
|
@Value("${oneplus.bot.setup.deletionDelaySeconds}")
|
||||||
private Long deletionDelay;
|
private Long deletionDelay;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -45,43 +45,47 @@ public class SetupsListener implements AsyncMessageReceivedListener {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ReactionService reactionService;
|
private ReactionService reactionService;
|
||||||
|
|
||||||
public static final String SETUPS_UPVOTE_EMOTE_KEY = "setupsUpvote";
|
public static final String SETUP_UPVOTE_EMOTE_KEY = "setupUpvote";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DefaultListenerResult execute(MessageReceivedModel model) {
|
public DefaultListenerResult execute(MessageReceivedModel model) {
|
||||||
Optional<PostTarget> setupsPostTargetOptional = postTargetManagement.getPostTargetOptional(SetupsPostTarget.SETUPS, model.getServerId());
|
Long serverId = model.getServerId();
|
||||||
if(setupsPostTargetOptional.isPresent()) {
|
Optional<PostTarget> setupPostTargetOptional = postTargetManagement.getPostTargetOptional(SetupPostTarget.SETUP, serverId);
|
||||||
PostTarget setupsTarget = setupsPostTargetOptional.get();
|
if(setupPostTargetOptional.isPresent()) {
|
||||||
|
PostTarget setupTarget = setupPostTargetOptional.get();
|
||||||
Message originalMessage = model.getMessage();
|
Message originalMessage = model.getMessage();
|
||||||
if(originalMessage.getChannel().getIdLong() == setupsTarget.getChannelReference().getId()) {
|
if(originalMessage.getChannel().getIdLong() == setupTarget.getChannelReference().getId()) {
|
||||||
Long serverId = model.getServerId();
|
if(!originalMessage.isFromGuild() || originalMessage.isWebhookMessage() || originalMessage.getType().isSystem()) {
|
||||||
boolean currentlyInvalid = setupsService.currentlyInvalid(originalMessage);
|
messageService.deleteMessage(originalMessage);
|
||||||
|
return DefaultListenerResult.IGNORED;
|
||||||
|
}
|
||||||
|
boolean currentlyInvalid = setupServiceBean.currentlyInvalid(originalMessage);
|
||||||
if(currentlyInvalid) {
|
if(currentlyInvalid) {
|
||||||
if(setupsService.mightContainEmbed(originalMessage)) {
|
if(setupServiceBean.mightContainEmbed(originalMessage)) {
|
||||||
log.info("Setup message did not contain embeds not attachments, but a link - waiting for embeds on message {}" +
|
log.info("Setup message did not contain embeds not attachments, but a link - waiting for embeds on message {}" +
|
||||||
" in channel {} in guild {} by user {}.", originalMessage.getIdLong(), originalMessage.getChannel().getIdLong(),
|
" in channel {} in guild {} by user {}.", originalMessage.getIdLong(), originalMessage.getChannel().getIdLong(),
|
||||||
originalMessage.getGuild().getIdLong(), originalMessage.getAuthor().getIdLong());
|
originalMessage.getGuild().getIdLong(), originalMessage.getAuthor().getIdLong());
|
||||||
scheduledExecutorService.schedule(() -> {
|
scheduledExecutorService.schedule(() -> {
|
||||||
messageService.loadMessage(originalMessage).thenAccept(loadedMessage -> {
|
messageService.loadMessage(originalMessage).thenAccept(loadedMessage -> {
|
||||||
if(setupsService.currentlyInvalid(loadedMessage)) {
|
if(setupServiceBean.currentlyInvalid(loadedMessage)) {
|
||||||
log.info("Message did not contain attachments nor embeds after a delay - deleting setups message {}.", loadedMessage.getIdLong());
|
log.info("Message did not contain attachments nor embeds after a delay - deleting setup message {}.", loadedMessage.getIdLong());
|
||||||
messageService.deleteMessage(loadedMessage);
|
messageService.deleteMessage(loadedMessage);
|
||||||
} else {
|
} else {
|
||||||
log.info("Message contained embeds/attachments after a delay - message was accepted {}.", loadedMessage.getIdLong());
|
log.info("Message contained embeds/attachments after a delay - message was accepted {}.", loadedMessage.getIdLong());
|
||||||
reactionService.addReactionToMessage(SETUPS_UPVOTE_EMOTE_KEY, serverId, loadedMessage);
|
reactionService.addReactionToMessage(SETUP_UPVOTE_EMOTE_KEY, serverId, loadedMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, deletionDelay, TimeUnit.SECONDS);
|
}, deletionDelay, TimeUnit.SECONDS);
|
||||||
} else {
|
} else {
|
||||||
log.info("Did not find any attachments nor embeds and no link to lead to any embeds - deleting setup message {} in channel {} in server {}" +
|
log.info("Did not find any attachments nor embeds and no link to lead to any embeds - deleting setup message {} in channel {} in server {}" +
|
||||||
"by user {} for setups.", originalMessage.getIdLong(), originalMessage.getChannel().getIdLong(), originalMessage.getGuild().getIdLong(),
|
"by user {} for setup.", originalMessage.getIdLong(), originalMessage.getChannel().getIdLong(), originalMessage.getGuild().getIdLong(),
|
||||||
originalMessage.getAuthor().getIdLong());
|
originalMessage.getAuthor().getIdLong());
|
||||||
messageService.deleteMessage(originalMessage);
|
messageService.deleteMessage(originalMessage);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("Accepting setups message {} in channel {} in guild {} from user {}.", originalMessage.getIdLong(),
|
log.info("Accepting setup message {} in channel {} in guild {} from user {}.", originalMessage.getIdLong(),
|
||||||
originalMessage.getChannel().getIdLong(), originalMessage.getGuild().getIdLong(), originalMessage.getAuthor().getIdLong());
|
originalMessage.getChannel().getIdLong(), originalMessage.getGuild().getIdLong(), originalMessage.getAuthor().getIdLong());
|
||||||
reactionService.addReactionToMessage(SETUPS_UPVOTE_EMOTE_KEY, serverId, originalMessage);
|
reactionService.addReactionToMessage(SETUP_UPVOTE_EMOTE_KEY, serverId, originalMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +94,6 @@ public class SetupsListener implements AsyncMessageReceivedListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FeatureDefinition getFeature() {
|
public FeatureDefinition getFeature() {
|
||||||
return SetupsFeatureDefinition.SETUPS;
|
return SetupFeatureDefinition.SETUP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.oneplus.bot.modules.setups.service;
|
package dev.sheldan.oneplus.bot.modules.setup.service;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.EmbedType;
|
import net.dv8tion.jda.api.entities.EmbedType;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
@@ -8,7 +8,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class SetupsService {
|
public class SetupServiceBean {
|
||||||
|
|
||||||
private static final Pattern URL_REGEX = Pattern.compile("((https?|ftp)://|(www|ftp)\\.)?[a-z0-9-]+(\\.[a-z0-9-]+)+([/?].*)?");
|
private static final Pattern URL_REGEX = Pattern.compile("((https?|ftp)://|(www|ftp)\\.)?[a-z0-9-]+(\\.[a-z0-9-]+)+([/?].*)?");
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@
|
|||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
<include file="setups-seedData/data.xml" relativeToChangelogFile="true"/>
|
<include file="setup-seedData/data.xml" relativeToChangelogFile="true"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
@@ -6,9 +6,9 @@
|
|||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
<changeSet author="Sheldan" id="setups_default_emote-insert">
|
<changeSet author="Sheldan" id="setup_default_emote-insert">
|
||||||
<insert tableName="default_emote">
|
<insert tableName="default_emote">
|
||||||
<column name="emote_key" value="setupsUpvote"/>
|
<column name="emote_key" value="setupUpvote"/>
|
||||||
<column name="name" value="👍"/>
|
<column name="name" value="👍"/>
|
||||||
</insert>
|
</insert>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
@@ -6,9 +6,9 @@
|
|||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
<changeSet author="Sheldan" id="setups_feature-insertion">
|
<changeSet author="Sheldan" id="setup_feature-insertion">
|
||||||
<insert tableName="feature">
|
<insert tableName="feature">
|
||||||
<column name="key" value="setups"/>
|
<column name="key" value="setup"/>
|
||||||
</insert>
|
</insert>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||||
|
<include file="1.3.11-setup/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
abstracto.postTargets.setup.name=setup
|
||||||
|
|
||||||
|
abstracto.featureFlags.setup.featureName=setup
|
||||||
|
abstracto.featureFlags.setup.enabled=false
|
||||||
|
|
||||||
|
oneplus.bot.setup.deletionDelaySeconds=3
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package dev.sheldan.oneplus.bot.modules.setups.config;
|
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public enum SetupsFeatureDefinition implements FeatureDefinition {
|
|
||||||
SETUPS("setups");
|
|
||||||
|
|
||||||
private String key;
|
|
||||||
|
|
||||||
SetupsFeatureDefinition(String key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package dev.sheldan.oneplus.bot.modules.setups.config;
|
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public enum SetupsPostTarget implements PostTargetEnum {
|
|
||||||
SETUPS("setups");
|
|
||||||
|
|
||||||
private String key;
|
|
||||||
|
|
||||||
SetupsPostTarget(String key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
abstracto.postTargets.setups.name=setups
|
|
||||||
|
|
||||||
abstracto.featureFlags.setups.featureName=setups
|
|
||||||
abstracto.featureFlags.setups.enabled=false
|
|
||||||
|
|
||||||
abstracto.setups.deletionDelaySeconds=3
|
|
||||||
@@ -159,6 +159,16 @@
|
|||||||
<destFileName>news.zip</destFileName>
|
<destFileName>news.zip</destFileName>
|
||||||
</artifactItem>
|
</artifactItem>
|
||||||
|
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>dev.sheldan.oneplus.bot.templates.modules</groupId>
|
||||||
|
<artifactId>referral-templates</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<type>zip</type>
|
||||||
|
<overWrite>true</overWrite>
|
||||||
|
<outputDirectory>${file.basedir}/deployment/template-artifacts/</outputDirectory>
|
||||||
|
<destFileName>referral.zip</destFileName>
|
||||||
|
</artifactItem>
|
||||||
|
|
||||||
<!-- translation artefacts -->
|
<!-- translation artefacts -->
|
||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>dev.sheldan.abstracto-templates.translations</groupId>
|
<groupId>dev.sheldan.abstracto-templates.translations</groupId>
|
||||||
@@ -268,7 +278,7 @@
|
|||||||
|
|
||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>dev.sheldan.oneplus.bot.templates.translations</groupId>
|
<groupId>dev.sheldan.oneplus.bot.templates.translations</groupId>
|
||||||
<artifactId>starboard-custom</artifactId>
|
<artifactId>starboard-custom-translations</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<type>zip</type>
|
<type>zip</type>
|
||||||
<overWrite>true</overWrite>
|
<overWrite>true</overWrite>
|
||||||
@@ -289,12 +299,22 @@
|
|||||||
|
|
||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>dev.sheldan.oneplus.bot.templates.translations</groupId>
|
<groupId>dev.sheldan.oneplus.bot.templates.translations</groupId>
|
||||||
<artifactId>setups-translations</artifactId>
|
<artifactId>setup-translations</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<type>zip</type>
|
<type>zip</type>
|
||||||
<overWrite>true</overWrite>
|
<overWrite>true</overWrite>
|
||||||
<outputDirectory>${file.basedir}/deployment/translation-artifacts/</outputDirectory>
|
<outputDirectory>${file.basedir}/deployment/translation-artifacts/</outputDirectory>
|
||||||
<destFileName>setups.zip</destFileName>
|
<destFileName>setup.zip</destFileName>
|
||||||
|
</artifactItem>
|
||||||
|
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>dev.sheldan.oneplus.bot.templates.translations</groupId>
|
||||||
|
<artifactId>referral-translations</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<type>zip</type>
|
||||||
|
<overWrite>true</overWrite>
|
||||||
|
<outputDirectory>${file.basedir}/deployment/translation-artifacts/</outputDirectory>
|
||||||
|
<destFileName>referral.zip</destFileName>
|
||||||
</artifactItem>
|
</artifactItem>
|
||||||
|
|
||||||
<!-- liquibase artifacts -->
|
<!-- liquibase artifacts -->
|
||||||
@@ -456,13 +476,24 @@
|
|||||||
|
|
||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
|
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
|
||||||
<artifactId>setups</artifactId>
|
<artifactId>setup</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<classifier>liquibase</classifier>
|
<classifier>liquibase</classifier>
|
||||||
<type>zip</type>
|
<type>zip</type>
|
||||||
<overWrite>true</overWrite>
|
<overWrite>true</overWrite>
|
||||||
<outputDirectory>${file.basedir}/deployment/liquibase-artifacts/</outputDirectory>
|
<outputDirectory>${file.basedir}/deployment/liquibase-artifacts/</outputDirectory>
|
||||||
<destFileName>setups.zip</destFileName>
|
<destFileName>setup.zip</destFileName>
|
||||||
|
</artifactItem>
|
||||||
|
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
|
||||||
|
<artifactId>referral</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<classifier>liquibase</classifier>
|
||||||
|
<type>zip</type>
|
||||||
|
<overWrite>true</overWrite>
|
||||||
|
<outputDirectory>${file.basedir}/deployment/liquibase-artifacts/</outputDirectory>
|
||||||
|
<destFileName>referral.zip</destFileName>
|
||||||
</artifactItem>
|
</artifactItem>
|
||||||
|
|
||||||
<!-- overrides -->
|
<!-- overrides -->
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
"suggestion", "invite-filter",
|
"suggestion", "invite-filter",
|
||||||
"starboard-custom",
|
"starboard-custom",
|
||||||
"overrides-templates-webservices", "overrides-templates-core", "overrides-templates-logging",
|
"overrides-templates-webservices", "overrides-templates-core", "overrides-templates-logging",
|
||||||
"news"],
|
"news", "referral"],
|
||||||
"translation_artifacts": ["utility", "core", "entertainment", "starboard", "link-embed", "webservices", "suggestion",
|
"translation_artifacts": ["utility", "core", "entertainment", "starboard", "link-embed", "webservices", "suggestion",
|
||||||
"remind", "logging", "invite-filter",
|
"remind", "logging", "invite-filter",
|
||||||
"starboard-custom",
|
"starboard-custom",
|
||||||
"news", "setups"],
|
"news", "setup", "referral"],
|
||||||
"liquibase_artifacts": [
|
"liquibase_artifacts": [
|
||||||
{ "zip": "scheduling", "file": "scheduling-changeLog.xml" },
|
{ "zip": "scheduling", "file": "scheduling-changeLog.xml" },
|
||||||
{ "zip": "core", "file": "core-changeLog.xml" },
|
{ "zip": "core", "file": "core-changeLog.xml" },
|
||||||
@@ -20,7 +20,8 @@
|
|||||||
{ "zip": "logging", "file": "logging-changeLog.xml"},
|
{ "zip": "logging", "file": "logging-changeLog.xml"},
|
||||||
{ "zip": "suggestion", "file": "suggestion-changeLog.xml"},
|
{ "zip": "suggestion", "file": "suggestion-changeLog.xml"},
|
||||||
{ "zip": "invite-filter", "file": "inviteFilter-changeLog.xml"},
|
{ "zip": "invite-filter", "file": "inviteFilter-changeLog.xml"},
|
||||||
{ "zip": "setups", "file": "setups-changeLog.xml"},
|
{ "zip": "setup", "file": "setup-changeLog.xml"},
|
||||||
|
{ "zip": "referral", "file": "referral-changeLog.xml"},
|
||||||
{ "zip": "starboard-custom", "file": "starboard-custom-changeLog.xml"},
|
{ "zip": "starboard-custom", "file": "starboard-custom-changeLog.xml"},
|
||||||
{ "zip": "news", "file": "news-changeLog.xml"}
|
{ "zip": "news", "file": "news-changeLog.xml"}
|
||||||
]
|
]
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@@ -19,8 +19,8 @@
|
|||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<!-- edit in release.yml as well -->
|
<!-- edit in release.yml as well -->
|
||||||
<!-- when releasing a new opbot version, update the docker-compose as well-->
|
<!-- when releasing a new opbot version, update the docker-compose as well-->
|
||||||
<abstracto.version>1.2.10</abstracto.version>
|
<abstracto.version>1.2.11</abstracto.version>
|
||||||
<abstracto.templates.version>1.2.6</abstracto.templates.version>
|
<abstracto.templates.version>1.2.7</abstracto.templates.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
|||||||
@@ -12,8 +12,9 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.3.11-SNAPSHOT</version>
|
<version>1.3.11-SNAPSHOT</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>starboard-custom</module>
|
<module>starboard-custom-templates</module>
|
||||||
<module>news-templates</module>
|
<module>news-templates</module>
|
||||||
|
<module>referral-templates</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>oneplus-bot-modules-templates</artifactId>
|
||||||
|
<groupId>dev.sheldan.oneplus.bot.templates.modules</groupId>
|
||||||
|
<version>1.3.11-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>referral-templates</artifactId>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<finalName>referral-templates-${project.version}</finalName>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
|
<descriptors>
|
||||||
|
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
||||||
|
</descriptors>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"additionalMessage": "<@safe_include "no_referral_link_found"/>"
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
<#include "abstracto_color">,
|
||||||
|
<#include "member_author">
|
||||||
|
<#assign member=postingMember>
|
||||||
|
<@member_author member=member/>,
|
||||||
|
<#include "full_member_info">
|
||||||
|
"description": "<@safe_include "referralListener_referral_post_description"/>",
|
||||||
|
"fields": [
|
||||||
|
<#list referrals as referral><#assign referral=referral>
|
||||||
|
{
|
||||||
|
"name": "<@safe_include "referral_link_type_${referral.type.key}"/>",
|
||||||
|
"value": "[${referral.referralIdentifier?json_string}](${referral.referralLink?json_string})"
|
||||||
|
}
|
||||||
|
<#sep>,
|
||||||
|
</#list>
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
<#include "abstracto_color">,
|
||||||
|
"description": "<@safe_include "too_recent_referral_post"/>",
|
||||||
|
"timeStamp": "${nextReferralDate}"
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>starboard-custom-translations</module>
|
<module>starboard-custom-translations</module>
|
||||||
<module>news-translations</module>
|
<module>news-translations</module>
|
||||||
<module>setups-translations</module>
|
<module>setup-translations</module>
|
||||||
|
<module>referral-translations</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
||||||
39
templates/translations/referral-translations/pom.xml
Normal file
39
templates/translations/referral-translations/pom.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>translations</artifactId>
|
||||||
|
<groupId>dev.sheldan.oneplus.bot.templates.translations</groupId>
|
||||||
|
<version>1.3.11-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>referral-translations</artifactId>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<finalName>referral-translations-${project.version}</finalName>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
|
<descriptors>
|
||||||
|
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
||||||
|
</descriptors>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||||
|
<id>zip</id>
|
||||||
|
<includeBaseDirectory>false</includeBaseDirectory>
|
||||||
|
<formats>
|
||||||
|
<format>zip</format>
|
||||||
|
</formats>
|
||||||
|
<fileSets>
|
||||||
|
<fileSet>
|
||||||
|
<outputDirectory>.</outputDirectory>
|
||||||
|
<directory>${project.basedir}/src/main/resources</directory>
|
||||||
|
</fileSet>
|
||||||
|
</fileSets>
|
||||||
|
</assembly>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Referral
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
The channel in which the referral codes should be handled in. Currently: ${currentTarget}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Accessories
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Smartphone (India)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Smartphone
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
No referral link found.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Sent by <@full_member_info member=member/>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
The last referral post was too recent. See the footer for the next time you can retry
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>setups-translations</artifactId>
|
<artifactId>setup-translations</artifactId>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<goal>single</goal>
|
<goal>single</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<finalName>setups-translations-${project.version}</finalName>
|
<finalName>setup-translations-${project.version}</finalName>
|
||||||
<appendAssemblyId>false</appendAssemblyId>
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
<descriptors>
|
<descriptors>
|
||||||
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||||
|
<id>zip</id>
|
||||||
|
<includeBaseDirectory>false</includeBaseDirectory>
|
||||||
|
<formats>
|
||||||
|
<format>zip</format>
|
||||||
|
</formats>
|
||||||
|
<fileSets>
|
||||||
|
<fileSet>
|
||||||
|
<outputDirectory>.</outputDirectory>
|
||||||
|
<directory>${project.basedir}/src/main/resources</directory>
|
||||||
|
</fileSet>
|
||||||
|
</fileSets>
|
||||||
|
</assembly>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Setup
|
||||||
@@ -1 +0,0 @@
|
|||||||
Setups
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>starboard-custom</artifactId>
|
<artifactId>starboard-custom-translations</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
Reference in New Issue
Block a user