[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

@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.linkembed.listener;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.config.ListenerPriority;
import dev.sheldan.abstracto.core.listener.ConsumableListenerResult;
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
import dev.sheldan.abstracto.core.listener.sync.jda.MessageReceivedListener;
import dev.sheldan.abstracto.core.metric.service.CounterMetric;
import dev.sheldan.abstracto.core.metric.service.MetricService;
@@ -61,6 +62,9 @@ public class MessageEmbedListener implements MessageReceivedListener {
@Override
public ConsumableListenerResult execute(MessageReceivedModel model) {
Message message = model.getMessage();
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
return ConsumableListenerResult.IGNORED;
}
String messageRaw = message.getContentRaw();
List<MessageEmbedLink> links = messageEmbedService.getLinksInMessage(messageRaw);
if(!links.isEmpty()) {

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="link-embed-tables/tables.xml" relativeToChangelogFile="true"/>
<include file="link-embed-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" >
<include file="default_emote.xml" relativeToChangelogFile="true"/>
<include file="feature.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="link-embed_default_emote-insert">
<insert tableName="default_emote">
<column name="emote_key" value="removeEmbed"/>

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="link-embed_feature-insertion">
<insert tableName="feature">
<column name="key" value="linkEmbeds"/>

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="embedded_message-table">
<createTable tableName="embedded_message">
<column name="embedding_message_id" type="BIGINT">

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="embedded_message.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

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="link-embed-seedData/data.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

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="linkEmbedCleanupJob.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="linkEmbed-cleanup-insert">
<insert tableName="scheduler_job">
<column name="name" value="linkEmbedCleanupJob"/>

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,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="1.0-link-embed/collection.xml" relativeToChangelogFile="true"/>
<include file="1.2.8-link-embed/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -9,10 +9,7 @@ import dev.sheldan.abstracto.core.service.MessageService;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.linkembed.model.MessageEmbedLink;
import dev.sheldan.abstracto.linkembed.service.MessageEmbedService;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -82,6 +79,7 @@ public class MessageEmbedListenerTest {
public void testNoLinkFoundExecution() {
String text = "text";
when(message.getContentRaw()).thenReturn(text);
setupMessageConfig();
List<MessageEmbedLink> foundMessageLinks = new ArrayList<>();
when(messageEmbedService.getLinksInMessage(text)).thenReturn(foundMessageLinks);
when(model.getMessage()).thenReturn(message);
@@ -89,6 +87,13 @@ public class MessageEmbedListenerTest {
verify(messageService, times(0)).deleteMessage(message);
}
private void setupMessageConfig() {
when(message.isFromGuild()).thenReturn(true);
when(message.isWebhookMessage()).thenReturn(false);
MessageType type = MessageType.DEFAULT;
when(message.getType()).thenReturn(type);
}
@Test
public void testOnlyOneLinkFoundExecution() {
String linkText = "link";
@@ -113,6 +118,7 @@ public class MessageEmbedListenerTest {
String text = linkText + "more text";
AUserInAServer userInAServer = Mockito.mock(AUserInAServer.class);
when(message.getContentRaw()).thenReturn(text);
setupMessageConfig();
MessageEmbedLink foundLink = Mockito.mock(MessageEmbedLink.class);
when(foundLink.getMessageId()).thenReturn(FIRST_MESSAGE_ID);
when(foundLink.getServerId()).thenReturn(SECOND_SERVER_ID);
@@ -145,7 +151,7 @@ public class MessageEmbedListenerTest {
when(embeddingUser.getUserInServerId()).thenReturn(USER_IN_SERVER_ID);
String completeMessage = firstText.concat(secondText);
when(message.getContentRaw()).thenReturn(completeMessage);
setupMessageConfig();
Member author = Mockito.mock(Member.class);
when(message.getMember()).thenReturn(author);
when(message.getGuild()).thenReturn(guild);
@@ -177,7 +183,7 @@ public class MessageEmbedListenerTest {
AUserInAServer userInAServer = Mockito.mock(AUserInAServer.class);
when(userInAServer.getUserInServerId()).thenReturn(USER_IN_SERVER_ID);
when(message.getContentRaw()).thenReturn(text);
setupMessageConfig();
Member author = Mockito.mock(Member.class);
when(message.getMember()).thenReturn(author);
when(userInServerManagementService.loadOrCreateUser(author)).thenReturn(userInAServer);
@@ -206,6 +212,7 @@ public class MessageEmbedListenerTest {
private void executeLinkEmbedTest(String linkText, String text) {
AUserInAServer userInAServer = Mockito.mock(AUserInAServer.class);
when(message.getContentRaw()).thenReturn(text);
setupMessageConfig();
MessageEmbedLink foundLink = Mockito.mock(MessageEmbedLink.class);
when(foundLink.getWholeUrl()).thenReturn(linkText);
when(foundLink.getMessageId()).thenReturn(FIRST_MESSAGE_ID);