[AB-240] changing invite filter to actively filter the server instead of only being based on the code

moving invite filter to separate module
updating to newer liquibase version
changing concept of immune roles which are directly associated to commands to immune roles which are immune against certain effects. these effects can be configured directly by the command (and a condition checks this effect), but they can be used in services as well, unrelated to commands
adding checks to not execute message received listeners for the wrong message types
adding metric support for 502 status
fixing duplicating help entries when two module definitions with the same key are present
This commit is contained in:
Sheldan
2021-05-10 20:45:34 +02:00
parent 9ae35a7e9d
commit e31d257e6f
389 changed files with 21069 additions and 18187 deletions

View File

@@ -36,6 +36,9 @@ public class RepostMessageReceivedListener implements AsyncMessageReceivedListen
@Override
public DefaultListenerResult execute(MessageReceivedModel model) {
Message message = model.getMessage();
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
return DefaultListenerResult.IGNORED;
}
AChannel channel = channelManagementService.loadChannel(message.getTextChannel().getIdLong());
if(repostCheckChannelService.duplicateCheckEnabledForChannel(channel)) {
repostService.processMessageAttachmentRepostCheck(message);

View File

@@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface RepostCheckChannelRepository extends JpaRepository<RepostCheckChannelGroup, Long> {
public interface RepostCheckChannelGroupRepository extends JpaRepository<RepostCheckChannelGroup, Long> {
}

View File

@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.repostdetection.service.management;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import dev.sheldan.abstracto.repostdetection.exception.RepostCheckChannelGroupNotFoundException;
import dev.sheldan.abstracto.repostdetection.model.database.RepostCheckChannelGroup;
import dev.sheldan.abstracto.repostdetection.repository.RepostCheckChannelRepository;
import dev.sheldan.abstracto.repostdetection.repository.RepostCheckChannelGroupRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -13,26 +13,26 @@ import java.util.Optional;
public class RepostCheckChannelGroupManagementBean implements RepostCheckChannelGroupManagement {
@Autowired
private RepostCheckChannelRepository repository;
private RepostCheckChannelGroupRepository repository;
@Override
public RepostCheckChannelGroup loadRepostChannelGroupById(Long channelGroupId) {
return loadRepostChanelGroupByIdOptional(channelGroupId).orElseThrow(() -> new RepostCheckChannelGroupNotFoundException(channelGroupId));
return loadRepostChannelGroupByIdOptional(channelGroupId).orElseThrow(() -> new RepostCheckChannelGroupNotFoundException(channelGroupId));
}
@Override
public Optional<RepostCheckChannelGroup> loadRepostChanelGroupByIdOptional(Long channelGroupId) {
public Optional<RepostCheckChannelGroup> loadRepostChannelGroupByIdOptional(Long channelGroupId) {
return repository.findById(channelGroupId);
}
@Override
public boolean repostCheckChannelGroupExists(Long channelGroupId) {
return loadRepostChanelGroupByIdOptional(channelGroupId).isPresent();
return loadRepostChannelGroupByIdOptional(channelGroupId).isPresent();
}
@Override
public Optional<RepostCheckChannelGroup> loadRepostChannelGroupByChannelGroupOptional(AChannelGroup channelGroup) {
return loadRepostChanelGroupByIdOptional(channelGroup.getId());
return loadRepostChannelGroupByIdOptional(channelGroup.getId());
}
@Override

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<include file="repost-detection-tables/tables.xml" relativeToChangelogFile="true"/>
<include file="repost-detection-seedData/data.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<changeSet author="Sheldan" id="repost_channel_group_type-insertion">
<insert tableName="channel_group_type">
<column name="group_type_key" value="repostDetection"/>

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<property name="repostDetectionModule" value="(SELECT id FROM module WHERE name = 'repostDetection')"/>
<property name="repostDetectionFeature" value="(SELECT id FROM feature WHERE key = 'repostDetection')"/>

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<include file="default_emote.xml" relativeToChangelogFile="true"/>
<include file="feature.xml" relativeToChangelogFile="true"/>
<include file="module.xml" relativeToChangelogFile="true"/>

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<changeSet author="Sheldan" id="repost-detection_default_emote-insert">
<insert tableName="default_emote">
<column name="emote_key" value="repostMarker"/>

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<changeSet author="Sheldan" id="repost-detection_feature-insertion">
<insert tableName="feature">
<column name="key" value="repostDetection"/>

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<changeSet author="Sheldan" id="repost-detection-module-insertion">
<insert tableName="module">
<column name="name" value="repostDetection"/>

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<changeSet author="Sheldan" id="posted_image-table">
<createTable tableName="posted_image">
<column name="message_id" type="BIGINT" >

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<changeSet author="Sheldan" id="repost-table">
<createTable tableName="repost">
<column name="message_id" type="BIGINT" >

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<changeSet author="Sheldan" id="repost_check_channel_group-table">
<createTable tableName="repost_check_channel_group">
<column name="id" type="BIGINT">

View File

@@ -3,9 +3,9 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.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/pro dbchangelog.xsd" >
<include file="repost_check_channel_group.xml" relativeToChangelogFile="true"/>
<include file="posted_image.xml" relativeToChangelogFile="true"/>
<include file="repost.xml" relativeToChangelogFile="true"/>

View File

@@ -257,6 +257,7 @@
<xsd:attributeGroup name="changeLogAttributes">
<xsd:attribute name="logicalFilePath" type="xsd:string"/>
<xsd:attribute name="context" type="xsd:string"/>
<xsd:attribute name="changeLogId" type="xsd:string"/>
<xsd:attribute name="objectQuotingStrategy" type="objectQuotingStrategy" default="LEGACY"/>
</xsd:attributeGroup>
@@ -277,11 +278,12 @@
<xsd:attribute name="created" type="xsd:string"/>
<xsd:attribute name="runOrder" type="xsd:string"/>
<xsd:attribute name="ignore" type="booleanExp"/>
<xsd:attribute name="runWith" type="xsd:string" />
</xsd:attributeGroup>
<!-- Attributes for changes -->
<xsd:attributeGroup name="changeAttributes">
<xsd:anyAttribute namespace="##any" processContents="lax"/>
<xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:attributeGroup>
<!-- Attributes for constraints -->
@@ -306,7 +308,7 @@
<xsd:attribute name="validateNullable" type="booleanExp"/>
<xsd:attribute name="validateUnique" type="booleanExp"/>
<xsd:attribute name="validatePrimaryKey" type="booleanExp"/>
<xsd:attribute name="validateForeignKey " type="booleanExp"/>
<xsd:attribute name="validateForeignKey" type="booleanExp"/>
</xsd:attributeGroup>
<xsd:attributeGroup name="column">
@@ -420,9 +422,10 @@
<xsd:attribute name="incrementBy" type="xsd:string"/>
<xsd:attribute name="maxValue" type="xsd:string"/>
<xsd:attribute name="minValue" type="xsd:string"/>
<xsd:attribute name="ordered" type="booleanExp"/>
<xsd:attribute name="ordered" type="xsd:string"/>
<xsd:attribute name="cacheSize" type="xsd:string"/>
<xsd:attribute name="cycle" type="booleanExp">
<xsd:attribute name="dataType" type="xsd:string" />
<xsd:attribute name="cycle" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
true for a cycling sequence, false for a non-cycling sequence.
@@ -481,11 +484,15 @@
<xsd:attributeGroup ref="changeAttributes"/>
<xsd:attributeGroup ref="tableNameAttribute"/>
<xsd:attribute name="constraintName" type="xsd:string"/>
<xsd:attribute name="dropIndex" type="booleanExp"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="addUniqueConstraint">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
</xsd:choice>
<xsd:attributeGroup ref="changeAttributes"/>
<xsd:attributeGroup ref="tableNameAttribute"/>
<xsd:attribute name="columnNames" type="xsd:string"
@@ -616,6 +623,7 @@
<xsd:attribute name="header" type="xsd:string"/>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string"/>
<xsd:attribute name="allowUpdate" type="booleanExp"/>
<xsd:attribute name="defaultValue" type="xsd:string"/>
<xsd:attribute name="defaultValueNumeric" type="xsd:string"/>
<xsd:attribute name="defaultValueDate" type="xsd:string"/>
@@ -919,6 +927,7 @@
<xsd:attribute name="schemaName" type="xsd:string"/>
<xsd:attribute name="tableName" type="xsd:string" use="required"/>
<xsd:attribute name="columnName" type="xsd:string" use="required"/>
<xsd:attribute name="columnDataType" type="xsd:string"/>
<xsd:attribute name="remarks" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
@@ -957,6 +966,7 @@
<xsd:attributeGroup ref="tableNameAttribute"/>
<xsd:attribute name="tablespace" type="xsd:string"/>
<xsd:attribute name="remarks" type="xsd:string"/>
<xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:complexType>
</xsd:element>
@@ -1124,7 +1134,7 @@
<xsd:complexType>
<xsd:attributeGroup ref="changeAttributes"/>
<xsd:attribute name="tag" type="xsd:string" use="required"/>
<xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:complexType>
</xsd:element>
@@ -1226,7 +1236,6 @@
<xsd:complexType>
<xsd:attributeGroup ref="changeAttributes"/>
<xsd:attributeGroup ref="sequenceAttributes"/>
<xsd:attribute name="dataType" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
@@ -1283,7 +1292,7 @@
</xsd:sequence>
<xsd:attributeGroup ref="changeAttributes"/>
<xsd:attribute name="class" type="xsd:string" use="required"/>
<xsd:anyAttribute processContents="lax" />
</xsd:complexType>
</xsd:element>
@@ -1374,4 +1383,4 @@
</xsd:sequence>
</xsd:group>
</xsd:schema>
</xsd:schema>

View File

@@ -3,8 +3,8 @@
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-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog-3.8.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/pro dbchangelog.xsd" >
<include file="1.0-repost-detection/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -5,10 +5,7 @@ import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.repostdetection.service.RepostCheckChannelService;
import dev.sheldan.abstracto.repostdetection.service.RepostService;
import net.dv8tion.jda.api.entities.EmbedType;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -93,6 +90,10 @@ public class RepostMessageReceivedListenerTest {
private void setupRepostCheckEnabled(boolean b) {
when(message.getTextChannel()).thenReturn(textChannel);
when(message.isFromGuild()).thenReturn(true);
when(message.isWebhookMessage()).thenReturn(false);
MessageType type = MessageType.DEFAULT;
when(message.getType()).thenReturn(type);
when(model.getMessage()).thenReturn(message);
when(textChannel.getIdLong()).thenReturn(CHANNEL_ID);
when(channelManagementService.loadChannel(CHANNEL_ID)).thenReturn(channel);

View File

@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.repostdetection.service.management;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import dev.sheldan.abstracto.repostdetection.exception.RepostCheckChannelGroupNotFoundException;
import dev.sheldan.abstracto.repostdetection.model.database.RepostCheckChannelGroup;
import dev.sheldan.abstracto.repostdetection.repository.RepostCheckChannelRepository;
import dev.sheldan.abstracto.repostdetection.repository.RepostCheckChannelGroupRepository;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -21,7 +21,7 @@ public class RepostCheckChannelGroupManagementBeanTest {
private RepostCheckChannelGroupManagementBean testUnit;
@Mock
private RepostCheckChannelRepository repository;
private RepostCheckChannelGroupRepository repository;
@Mock
private RepostCheckChannelGroup checkChannelGroup;
@@ -50,7 +50,7 @@ public class RepostCheckChannelGroupManagementBeanTest {
@Test
public void testLoadRepostChannelGroupByIdOptional() {
when(repository.findById(CHANNEL_GROUP_ID)).thenReturn(Optional.of(checkChannelGroup));
Optional<RepostCheckChannelGroup> resultChannelGroupOptional = testUnit.loadRepostChanelGroupByIdOptional(CHANNEL_GROUP_ID);
Optional<RepostCheckChannelGroup> resultChannelGroupOptional = testUnit.loadRepostChannelGroupByIdOptional(CHANNEL_GROUP_ID);
Assert.assertTrue(resultChannelGroupOptional.isPresent());
resultChannelGroupOptional.ifPresent(repostCheckChannelGroup -> Assert.assertEquals(checkChannelGroup, repostCheckChannelGroup));
}