[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,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="experienceModule" value="(SELECT id FROM module WHERE name = 'assignableRoles')"/>
<property name="experienceFeature" value="(SELECT id FROM feature WHERE key = 'assignableRole')"/>
<changeSet author="Sheldan" id="assignable_roles-commands">

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="feature.xml" relativeToChangelogFile="true"/>
<include file="module.xml" relativeToChangelogFile="true"/>
<include file="command.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="assignable_role-feature-insertion">
<insert tableName="feature">
<column name="key" value="assignableRole"/>

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="assignable_role-module-insertion">
<insert tableName="module">
<column name="name" value="assignableRoles"/>

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="assignable_role-table">
<createTable tableName="assignable_role">
<column autoIncrement="true" 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" >
<changeSet author="Sheldan" id="assignable_role_place-table">
<createTable tableName="assignable_role_place">
<column autoIncrement="true" 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" >
<changeSet author="Sheldan" id="assignable_role_place_post-table">
<createTable tableName="assignable_role_place_post">
<column autoIncrement="true" 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" >
<changeSet author="Sheldan" id="assigned_role_user-table">
<createTable tableName="assigned_role_user">
<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="assignable_role_place.xml" relativeToChangelogFile="true"/>
<include file="assignable_role_place_post.xml" relativeToChangelogFile="true"/>
<include file="assignable_role.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" >
<include file="assignableRoles-tables/tables.xml" relativeToChangelogFile="true"/>
<include file="assignableRoles-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="1.0-assignableRoles/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

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="entertainment-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" >
<property name="entertainmentModule" value="(SELECT id FROM module WHERE name = 'entertainment')"/>
<property name="entertainmentFeature" value="(SELECT id FROM feature WHERE key = 'entertainment')"/>

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="feature.xml" relativeToChangelogFile="true"/>
<include file="module.xml" relativeToChangelogFile="true"/>
<include file="command.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="entertainment_feature-insertion">
<insert tableName="feature">
<column name="key" value="entertainment"/>

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="entertainment-module-insertion">
<insert tableName="module">
<column name="name" value="entertainment"/>

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="entertainment-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" >
<property name="entertainmentModule" value="(SELECT id FROM module WHERE name = 'entertainment')"/>
<property name="entertainmentFeature" value="(SELECT id FROM feature WHERE key = 'entertainment')"/>

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="command.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="entertainment-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" >
<property name="entertainmentModule" value="(SELECT id FROM module WHERE name = 'entertainment')"/>
<property name="entertainmentFeature" value="(SELECT id FROM feature WHERE key = 'entertainment')"/>

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

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-entertainment/collection.xml" relativeToChangelogFile="true"/>
<include file="1.2.8-entertainment/collection.xml" relativeToChangelogFile="true"/>
<include file="1.2.9-entertainment/collection.xml" relativeToChangelogFile="true"/>

View File

@@ -10,6 +10,7 @@ import dev.sheldan.abstracto.core.service.management.UserInServerManagementServi
import dev.sheldan.abstracto.experience.config.ExperienceFeatureDefinition;
import dev.sheldan.abstracto.experience.service.AUserExperienceService;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -29,6 +30,10 @@ public class ExperienceTrackerListener implements AsyncMessageReceivedListener {
@Override
public DefaultListenerResult execute(MessageReceivedModel model) {
Message message = model.getMessage();
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
return DefaultListenerResult.IGNORED;
}
AUserInAServer cause = userInServerManagementService.loadOrCreateUser(model.getServerId(), model.getMessage().getAuthor().getIdLong());
userExperienceService.addExperience(cause);
return DefaultListenerResult.PROCESSED;

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="experience-tables/tables.xml" relativeToChangelogFile="true"/>
<include file="experience-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" >
<property name="experienceModule" value="(SELECT id FROM module WHERE name = 'experience')"/>
<property name="experienceFeature" value="(SELECT id FROM feature WHERE key = 'experience')"/>
<changeSet author="Sheldan" id="experience-commands">

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="experience_level.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="experience-job-insert">
<insert tableName="scheduler_job">
<column name="name" value="experienceJob"/>

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="experience_levels-insert">
<insert tableName="experience_level">
<column name="level" value="0"/>

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="experience_feature-insertion">
<insert tableName="feature">
<column name="key" value="experience"/>

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="experience-module-insertion">
<insert tableName="module">
<column name="name" value="experience"/>

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="disabled_experience_role-table">
<createTable tableName="disabled_experience_role">
<column autoIncrement="true" 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" >
<changeSet author="Sheldan" id="experience_level-table">
<createTable tableName="experience_level">
<column name="level" type="INTEGER">

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="experience_role-table">
<createTable tableName="experience_role">
<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="experience_level.xml" relativeToChangelogFile="true"/>
<include file="experience_role.xml" relativeToChangelogFile="true"/>
<include file="user_experience.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="user_experience-table">
<createTable tableName="user_experience">
<column name="id" type="BIGINT">

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

View File

@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.experience.service.AUserExperienceService;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageType;
import net.dv8tion.jda.api.entities.User;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,6 +41,10 @@ public class ExperienceTrackerListenerTest {
public void testExperienceTracking() {
AUserInAServer userInAServer = Mockito.mock(AUserInAServer.class);
Message mockedMessage = Mockito.mock(Message.class);
when(mockedMessage.isFromGuild()).thenReturn(true);
when(mockedMessage.isWebhookMessage()).thenReturn(false);
MessageType type = MessageType.DEFAULT;
when(mockedMessage.getType()).thenReturn(type);
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(userInAServer);
when(model.getMessage()).thenReturn(mockedMessage);
when(model.getServerId()).thenReturn(SERVER_ID);

View File

@@ -0,0 +1,64 @@
<?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>invite-filter</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>invite-filter-impl</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>
<dependencies>
<dependency>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>invite-filter-int</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.sheldan.abstracto.core</groupId>
<artifactId>core-int</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.sheldan.abstracto.core</groupId>
<artifactId>metrics-int</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -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>

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.moderation.command;
package dev.sheldan.abstracto.invitefilter.command;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
@@ -7,14 +7,15 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.moderation.config.ModerationModuleDefinition;
import dev.sheldan.abstracto.moderation.config.feature.ModerationFeatureDefinition;
import dev.sheldan.abstracto.moderation.service.InviteLinkFilterServiceBean;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterFeatureDefinition;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterModerationModuleDefinition;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterServiceBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@Component
public class AllowInvite extends AbstractConditionableCommand {
@@ -23,10 +24,10 @@ public class AllowInvite extends AbstractConditionableCommand {
private InviteLinkFilterServiceBean inviteLinkFilterServiceBean;
@Override
public CommandResult execute(CommandContext commandContext) {
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
String inviteLink = (String) commandContext.getParameters().getParameters().get(0);
inviteLinkFilterServiceBean.allowInvite(inviteLink, commandContext.getGuild().getIdLong());
return CommandResult.fromSuccess();
return inviteLinkFilterServiceBean.allowInvite(inviteLink, commandContext.getGuild().getIdLong(), commandContext.getJda())
.thenApply(unused -> CommandResult.fromSuccess());
}
@Override
@@ -36,8 +37,9 @@ public class AllowInvite extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("allowInvite")
.module(ModerationModuleDefinition.MODERATION)
.module(InviteFilterModerationModuleDefinition.MODERATION)
.templated(true)
.async(true)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
@@ -47,6 +49,6 @@ public class AllowInvite extends AbstractConditionableCommand {
@Override
public FeatureDefinition getFeature() {
return ModerationFeatureDefinition.INVITE_FILTER;
return InviteFilterFeatureDefinition.INVITE_FILTER;
}
}

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.moderation.command;
package dev.sheldan.abstracto.invitefilter.command;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
@@ -7,14 +7,15 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.moderation.config.ModerationModuleDefinition;
import dev.sheldan.abstracto.moderation.config.feature.ModerationFeatureDefinition;
import dev.sheldan.abstracto.moderation.service.InviteLinkFilterServiceBean;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterFeatureDefinition;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterModerationModuleDefinition;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterServiceBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@Component
public class DisAllowInvite extends AbstractConditionableCommand {
@@ -23,10 +24,10 @@ public class DisAllowInvite extends AbstractConditionableCommand {
private InviteLinkFilterServiceBean inviteLinkFilterServiceBean;
@Override
public CommandResult execute(CommandContext commandContext) {
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
String inviteLink = (String) commandContext.getParameters().getParameters().get(0);
inviteLinkFilterServiceBean.disAllowInvite(inviteLink, commandContext.getGuild().getIdLong());
return CommandResult.fromSuccess();
return inviteLinkFilterServiceBean.disAllowInvite(inviteLink, commandContext.getGuild().getIdLong(), commandContext.getJda())
.thenApply(unused -> CommandResult.fromSuccess());
}
@Override
@@ -36,8 +37,9 @@ public class DisAllowInvite extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("disAllowInvite")
.module(ModerationModuleDefinition.MODERATION)
.module(InviteFilterModerationModuleDefinition.MODERATION)
.templated(true)
.async(true)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
@@ -47,6 +49,6 @@ public class DisAllowInvite extends AbstractConditionableCommand {
@Override
public FeatureDefinition getFeature() {
return ModerationFeatureDefinition.INVITE_FILTER;
return InviteFilterFeatureDefinition.INVITE_FILTER;
}
}

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.moderation.command;
package dev.sheldan.abstracto.invitefilter.command;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
@@ -8,33 +8,37 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.config.FeatureMode;
import dev.sheldan.abstracto.moderation.config.ModerationModuleDefinition;
import dev.sheldan.abstracto.moderation.config.feature.ModerationFeatureDefinition;
import dev.sheldan.abstracto.moderation.config.feature.mode.InviteFilterMode;
import dev.sheldan.abstracto.moderation.service.InviteLinkFilterService;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterFeatureDefinition;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterMode;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterModerationModuleDefinition;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@Component
@Slf4j
public class RemoveTrackedInviteLinks extends AbstractConditionableCommand {
@Autowired
private InviteLinkFilterService inviteLinkFilterService;
@Override
public CommandResult execute(CommandContext commandContext) {
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
if(!parameters.isEmpty()) {
String invite = (String) parameters.get(0);
inviteLinkFilterService.clearAllUses(invite, commandContext.getGuild().getIdLong());
return inviteLinkFilterService.clearAllUsedOfCode(invite, commandContext.getGuild().getIdLong(), commandContext.getJda())
.thenApply(unused -> CommandResult.fromSuccess());
} else {
inviteLinkFilterService.clearAllTrackedInviteCodes(commandContext.getGuild().getIdLong());
}
return CommandResult.fromSuccess();
return CompletableFuture.completedFuture(CommandResult.fromSuccess());
}
@Override
@@ -44,8 +48,9 @@ public class RemoveTrackedInviteLinks extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("removeTrackedInviteLinks")
.module(ModerationModuleDefinition.MODERATION)
.module(InviteFilterModerationModuleDefinition.MODERATION)
.templated(true)
.async(true)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
@@ -55,7 +60,7 @@ public class RemoveTrackedInviteLinks extends AbstractConditionableCommand {
@Override
public FeatureDefinition getFeature() {
return ModerationFeatureDefinition.INVITE_FILTER;
return InviteFilterFeatureDefinition.INVITE_FILTER;
}
@Override

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.moderation.command;
package dev.sheldan.abstracto.invitefilter.command;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
@@ -11,14 +11,14 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.config.FeatureMode;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.moderation.config.ModerationModuleDefinition;
import dev.sheldan.abstracto.moderation.config.feature.ModerationFeatureDefinition;
import dev.sheldan.abstracto.moderation.config.feature.mode.InviteFilterMode;
import dev.sheldan.abstracto.moderation.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.moderation.model.template.command.TrackedInviteLinksModel;
import dev.sheldan.abstracto.moderation.service.InviteLinkFilterService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterFeatureDefinition;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterMode;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterModerationModuleDefinition;
import dev.sheldan.abstracto.invitefilter.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.invitefilter.model.template.command.TrackedInviteLinksModel;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -65,7 +65,7 @@ public class ShowTrackedInviteLinks extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("showTrackedInviteLinks")
.module(ModerationModuleDefinition.MODERATION)
.module(InviteFilterModerationModuleDefinition.MODERATION)
.templated(true)
.async(true)
.supportsEmbedException(true)
@@ -76,7 +76,7 @@ public class ShowTrackedInviteLinks extends AbstractConditionableCommand {
@Override
public FeatureDefinition getFeature() {
return ModerationFeatureDefinition.INVITE_FILTER;
return InviteFilterFeatureDefinition.INVITE_FILTER;
}
@Override

View File

@@ -0,0 +1,10 @@
package dev.sheldan.abstracto.invitefilter.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource("classpath:invite-filter-config.properties")
public class InviteFilterConfig {
}

View File

@@ -0,0 +1,31 @@
package dev.sheldan.abstracto.invitefilter.listener;
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
import dev.sheldan.abstracto.core.listener.sync.entity.AsyncChannelGroupCreatedListener;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import dev.sheldan.abstracto.core.models.listener.ChannelGroupCreatedListenerModel;
import dev.sheldan.abstracto.core.service.management.ChannelGroupManagementService;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService;
import dev.sheldan.abstracto.invitefilter.service.management.InviteFilterChannelGroupManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class InviteFilterAsyncChannelGroupCreatedListener implements AsyncChannelGroupCreatedListener {
@Autowired
private InviteFilterChannelGroupManagement inviteFilterChannelGroupManagement;
@Autowired
private ChannelGroupManagementService channelGroupManagementService;
@Override
public DefaultListenerResult execute(ChannelGroupCreatedListenerModel model) {
AChannelGroup channelGroup = channelGroupManagementService.findChannelGroupById(model.getChannelGroupId());
if(channelGroup.getChannelGroupType().getGroupTypeKey().equals(InviteLinkFilterService.INVITE_FILTER_CHANNEL_GROUP_TYPE)) {
inviteFilterChannelGroupManagement.createInviteFilterChannelGroup(channelGroup);
return DefaultListenerResult.PROCESSED;
}
return DefaultListenerResult.IGNORED;
}
}

View File

@@ -0,0 +1,31 @@
package dev.sheldan.abstracto.invitefilter.listener;
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
import dev.sheldan.abstracto.core.listener.sync.entity.ChannelGroupDeletedListener;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import dev.sheldan.abstracto.core.models.listener.ChannelGroupDeletedListenerModel;
import dev.sheldan.abstracto.core.service.management.ChannelGroupManagementService;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService;
import dev.sheldan.abstracto.invitefilter.service.management.InviteFilterChannelGroupManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class InviteFilterChannelGroupDeletedListener implements ChannelGroupDeletedListener {
@Autowired
private InviteFilterChannelGroupManagement inviteFilterChannelGroupManagement;
@Autowired
private ChannelGroupManagementService channelGroupManagementService;
@Override
public DefaultListenerResult execute(ChannelGroupDeletedListenerModel model) {
AChannelGroup channelGroup = channelGroupManagementService.findChannelGroupById(model.getChannelGroupId());
if(channelGroup.getChannelGroupType().getGroupTypeKey().equals(InviteLinkFilterService.INVITE_FILTER_CHANNEL_GROUP_TYPE)) {
inviteFilterChannelGroupManagement.deleteInviteFilterChannelGroup(channelGroup);
return DefaultListenerResult.PROCESSED;
}
return DefaultListenerResult.IGNORED;
}
}

View File

@@ -0,0 +1,209 @@
package dev.sheldan.abstracto.invitefilter.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.metric.service.CounterMetric;
import dev.sheldan.abstracto.core.metric.service.MetricService;
import dev.sheldan.abstracto.core.metric.service.MetricTag;
import dev.sheldan.abstracto.core.models.ServerUser;
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
import dev.sheldan.abstracto.core.service.*;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterFeatureDefinition;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterMode;
import dev.sheldan.abstracto.invitefilter.config.InviteFilterPostTarget;
import dev.sheldan.abstracto.invitefilter.model.template.listener.DeletedInvite;
import dev.sheldan.abstracto.invitefilter.model.template.listener.DeletedInvitesNotificationModel;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Invite;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.MessageType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import static dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService.INVITE_FILTER_CHANNEL_GROUP_TYPE;
import static dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService.INVITE_FILTER_EFFECT_KEY;
@Component
@Slf4j
public class InviteLinkFilterListener implements AsyncMessageReceivedListener {
@Autowired
private InviteLinkFilterService inviteLinkFilterService;
@Autowired
private FeatureModeService featureModeService;
@Autowired
private PostTargetService postTargetService;
@Autowired
private TemplateService templateService;
@Autowired
private MetricService metricService;
@Autowired
private MessageService messageService;
@Autowired
private ChannelGroupService channelGroupService;
@Autowired
private RoleImmunityService roleImmunityService;
public static final String MODERATION_PURGE_METRIC = "invite.filter";
public static final String CONSEQUENCE = "consequence";
private static final CounterMetric MESSAGE_INVITE_FILTERED =
CounterMetric
.builder()
.tagList(Arrays.asList(MetricTag.getTag(CONSEQUENCE, "filtered")))
.name(MODERATION_PURGE_METRIC)
.build();
public static final String INVITE_LINK_DELETED_NOTIFICATION_EMBED_TEMPLATE_KEY = "invite_link_deleted_notification";
private void sendDeletionNotification(List<String> codes, Message message) {
Long serverId = message.getGuild().getIdLong();
if(!postTargetService.postTargetDefinedInServer(InviteFilterPostTarget.INVITE_DELETE_LOG, serverId)) {
log.info("Post target {} not defined for server {} - not sending invite link deletion notification.", InviteFilterPostTarget.INVITE_DELETE_LOG.getKey(), serverId);
return;
}
DeletedInvitesNotificationModel model = DeletedInvitesNotificationModel
.builder()
.author(message.getMember())
.guild(message.getGuild())
.message(message)
.channel(message.getChannel())
.invites(groupInvites(codes))
.build();
log.info("Sending notification about {} deleted invite links in guild {} from user {} in channel {} in message {}.",
codes.size(), serverId, message.getAuthor().getIdLong(), message.getChannel().getIdLong(), message.getIdLong());
MessageToSend messageToSend = templateService.renderEmbedTemplate(INVITE_LINK_DELETED_NOTIFICATION_EMBED_TEMPLATE_KEY, model, message.getGuild().getIdLong());
List<CompletableFuture<Message>> messageFutures = postTargetService.sendEmbedInPostTarget(messageToSend, InviteFilterPostTarget.INVITE_DELETE_LOG, serverId);
FutureUtils.toSingleFutureGeneric(messageFutures).thenAccept(unused ->
log.debug("Successfully send notification about deleted invite link in message {}.", message.getIdLong())
).exceptionally(throwable -> {
log.error("Failed to send notification about deleted invite link in message {}.", message.getIdLong());
return null;
});
}
private List<DeletedInvite> groupInvites(List<String> codes) {
return codes
.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
.entrySet()
.stream()
.map(functionLongEntry -> new DeletedInvite(functionLongEntry.getKey(), functionLongEntry.getValue()))
.collect(Collectors.toList());
}
@Override
public FeatureDefinition getFeature() {
return InviteFilterFeatureDefinition.INVITE_FILTER;
}
@PostConstruct
public void postConstruct() {
metricService.registerCounter(MESSAGE_INVITE_FILTERED, "Amount of messages containing an invite filtered");
}
private boolean isInviteFilterActiveInChannel(MessageChannel channel) {
return channelGroupService.isChannelInEnabledChannelGroupOfType(INVITE_FILTER_CHANNEL_GROUP_TYPE, channel.getIdLong());
}
@Override
public DefaultListenerResult execute(MessageReceivedModel model) {
Message message = model.getMessage();
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
return DefaultListenerResult.IGNORED;
}
List<String> foundInvites = new ArrayList<>();
Matcher matcher = Message.INVITE_PATTERN.matcher(message.getContentRaw());
while(matcher.find()) {
foundInvites.add(matcher.group("code"));
}
if(foundInvites.isEmpty()){
return DefaultListenerResult.IGNORED;
}
if(!isInviteFilterActiveInChannel(model.getMessage().getChannel())) {
return DefaultListenerResult.IGNORED;
}
if(roleImmunityService.isImmune(message.getMember(), INVITE_FILTER_EFFECT_KEY)) {
log.info("Not checking for invites in message, because author {} in channel {} in guild {} is immune against invite filter.",
message.getMember().getIdLong(), message.getGuild().getIdLong(), message.getChannel().getIdLong());
return DefaultListenerResult.IGNORED;
}
List<CompletableFuture<Invite>> inviteList = new ArrayList<>();
JDA jda = model.getMessage().getJDA();
foundInvites.forEach(s -> inviteList.add(inviteLinkFilterService.resolveInvite(jda, s)));
CompletableFutureList<Invite> list = new CompletableFutureList<>(inviteList);
list.getMainFuture().whenComplete((unused, throwable) -> {
List<Invite> invites = list.getObjects();
Long serverId = message.getGuild().getIdLong();
ServerUser author = ServerUser.builder().userId(message.getAuthor().getIdLong()).serverId(message.getGuild().getIdLong()).build();
boolean toDelete = false;
Map<Long, String> targetServers = new HashMap<>();
List<String> deletedInvites = new ArrayList<>();
for (Invite invite : invites) {
if (invite.getType().equals(Invite.InviteType.GUILD)
&& inviteLinkFilterService.isCodeFiltered(invite.getGuild().getIdLong(), author)) {
toDelete = true;
deletedInvites.add(invite.getCode());
targetServers.put(invite.getGuild().getIdLong(), invite.getGuild().getName());
}
}
List<String> unResolvedInvites = new ArrayList<>();
foundInvites.forEach(possibleUnresolvedInvite -> {
if(invites.stream().noneMatch(invite -> invite.getCode().equals(possibleUnresolvedInvite))) {
unResolvedInvites.add(possibleUnresolvedInvite);
}
});
for(String unresolvedInvite : unResolvedInvites) {
if(inviteLinkFilterService.isCodeFiltered(unresolvedInvite, author)) {
toDelete = true;
deletedInvites.add(unresolvedInvite);
}
}
if(toDelete) {
metricService.incrementCounter(MESSAGE_INVITE_FILTERED);
messageService.deleteMessage(message);
boolean trackUsages = featureModeService.featureModeActive(InviteFilterFeatureDefinition.INVITE_FILTER, serverId, InviteFilterMode.TRACK_USES);
if(trackUsages) {
targetServers.forEach((targetServerId, serverName) -> inviteLinkFilterService.storeFilteredInviteLinkUsage(targetServerId, serverName, author));
}
boolean sendNotification = featureModeService.featureModeActive(InviteFilterFeatureDefinition.INVITE_FILTER, serverId, InviteFilterMode.FILTER_NOTIFICATIONS);
if(sendNotification) {
sendDeletionNotification(deletedInvites, message);
}
}
});
return DefaultListenerResult.PROCESSED;
}
}

View File

@@ -1,7 +1,7 @@
package dev.sheldan.abstracto.moderation.repository;
package dev.sheldan.abstracto.invitefilter.repository;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.moderation.model.database.AllowedInviteLink;
import dev.sheldan.abstracto.invitefilter.model.database.AllowedInviteLink;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -10,7 +10,8 @@ import java.util.Optional;
@Repository
public interface AllowedInviteLinkRepository extends JpaRepository<AllowedInviteLink, Long> {
Optional<AllowedInviteLink> findByCodeAndServer(String code, AServer server);
Optional<AllowedInviteLink> findByTargetServerIdAndServer(Long targetServerId, AServer server);
Optional<AllowedInviteLink> findByTargetServerIdAndServer_Id(Long targetServerId, Long serverId);
Optional<AllowedInviteLink> findByCodeAndServer_Id(String code, Long serverId);
}

View File

@@ -1,7 +1,7 @@
package dev.sheldan.abstracto.moderation.repository;
package dev.sheldan.abstracto.invitefilter.repository;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.moderation.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.invitefilter.model.database.FilteredInviteLink;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -11,13 +11,13 @@ import java.util.Optional;
@Repository
public interface FilteredInviteLinkRepository extends JpaRepository<FilteredInviteLink, Long> {
Optional<FilteredInviteLink> findByCodeAndServer(String code, AServer server);
Optional<FilteredInviteLink> findByTargetServerIdAndServer(Long targetServerId, AServer server);
Optional<FilteredInviteLink> findByCodeAndServer_Id(String code, Long serverId);
Optional<FilteredInviteLink> findByTargetServerIdAndServer_Id(Long targetServerId, Long serverId);
void deleteByServer_Id(Long serverId);
void deleteByCodeAndServer_Id(String code, Long serverId);
void deleteByTargetServerIdAndServer_Id(Long targetServerId, Long serverId);
List<FilteredInviteLink> findAllByServer_IdOrderByUsesDesc(Long serverId, Pageable pageable);
}

View File

@@ -0,0 +1,9 @@
package dev.sheldan.abstracto.invitefilter.repository;
import dev.sheldan.abstracto.invitefilter.model.database.InviteFilterChannelGroup;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface InviteFilterChannelGroupRepository extends JpaRepository<InviteFilterChannelGroup, Long> {
}

View File

@@ -0,0 +1,173 @@
package dev.sheldan.abstracto.invitefilter.service;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.ServerUser;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.invitefilter.exception.InvalidInviteException;
import dev.sheldan.abstracto.invitefilter.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.invitefilter.service.management.AllowedInviteLinkManagement;
import dev.sheldan.abstracto.invitefilter.service.management.FilteredInviteLinkManagement;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Invite;
import net.dv8tion.jda.api.entities.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Component
@Slf4j
public class InviteLinkFilterServiceBean implements InviteLinkFilterService {
@Autowired
private AllowedInviteLinkManagement allowedInviteLinkManagement;
@Autowired
private FilteredInviteLinkManagement filteredInviteLinkManagement;
@Autowired
private ServerManagementService serverManagementService;
@Autowired
private InviteLinkFilterServiceBean self;
private static final Pattern INVITE_CODE_PATTERN = Pattern.compile("(?<code>[a-z0-9-]+)", Pattern.CASE_INSENSITIVE);
@Override
public boolean isCodeFiltered(Long targetServerId, ServerUser serverUser) {
return !isCodeAllowed(targetServerId, serverUser);
}
@Override
public boolean isCodeFiltered(String code, ServerUser serverUser) {
return !isCodeAllowed(code, serverUser);
}
@Override
public boolean isCodeAllowed(Long targetServerId, ServerUser serverUser) {
return allowedInviteLinkManagement.allowedInviteLinkExists(serverUser, targetServerId);
}
@Override
public boolean isCodeAllowed(String code, ServerUser serverUser) {
return allowedInviteLinkManagement.allowedInviteLinkExists(serverUser, code);
}
@Override
public boolean isCodeAllowed(Long targetServerId, Long serverId) {
return allowedInviteLinkManagement.allowedInviteLinkExists(serverId, targetServerId);
}
@Override
public void storeFilteredInviteLinkUsage(Long targetServerId, String serverName, ServerUser serverUser) {
Optional<FilteredInviteLink> inviteLinkOptional = filteredInviteLinkManagement.findInviteLinkViaTargetID(serverUser.getServerId(), targetServerId);
if(inviteLinkOptional.isPresent()) {
inviteLinkOptional.ifPresent(filteredInviteLink -> filteredInviteLink.setUses(filteredInviteLink.getUses() + 1));
} else {
AServer server = serverManagementService.loadServer(serverUser.getServerId());
filteredInviteLinkManagement.createFilteredInviteLink(server, targetServerId, serverName);
}
}
@Override
public CompletableFuture<Void> allowInvite(String inviteLink, Long serverId, JDA jda) {
String inviteCode = extractCode(inviteLink);
return self.resolveInvite(jda, inviteCode)
.thenAccept(invite -> self.allowInviteInServer(serverId, invite));
}
public void allowInviteInServer(Long serverId, Invite invite) {
if(!invite.getType().equals(Invite.InviteType.GUILD)) {
throw new AbstractoRunTimeException("Invite is not for a guild.");
}
Long targetServerId = invite.getGuild().getIdLong();
if(self.isCodeAllowed(targetServerId, serverId)) {
return;
}
AServer server = serverManagementService.loadServer(serverId);
allowedInviteLinkManagement.createAllowedInviteLink(server, targetServerId, invite.getCode());
}
private String extractCode(String invite) {
Matcher matcher = Message.INVITE_PATTERN.matcher(invite);
String inviteCode;
if(matcher.find()) {
inviteCode = matcher.group("code");
} else {
Matcher codeOnlyMatcher = INVITE_CODE_PATTERN.matcher(invite);
if(codeOnlyMatcher.find()) {
inviteCode = codeOnlyMatcher.group("code");
} else {
throw new InvalidInviteException("Invalid invite was provided.");
}
}
return inviteCode;
}
@Override
public CompletableFuture<Void> disAllowInvite(String fullInvite, Long serverId, JDA jda) {
String inviteCode = extractCode(fullInvite);
return self.resolveInvite(jda, inviteCode)
.thenAccept(resolvedInvite -> self.disallowInviteInServer(serverId, resolvedInvite));
}
@Transactional
public void disallowInviteInServer(Long serverId, Invite resolvedInvite) {
if(!resolvedInvite.getType().equals(Invite.InviteType.GUILD)) {
throw new AbstractoRunTimeException("Invite is not for a guild.");
}
Long targetServerId = resolvedInvite.getGuild().getIdLong();
AServer server = serverManagementService.loadServer(serverId);
allowedInviteLinkManagement.removeAllowedInviteLink(server, targetServerId);
}
@Override
public void clearAllTrackedInviteCodes(Long serverId) {
filteredInviteLinkManagement.clearFilteredInviteLinks(serverId);
}
@Override
public void clearAllUses(Long targetServerId, Long serverId) {
filteredInviteLinkManagement.clearFilteredInviteLink(targetServerId, serverId);
}
@Override
public CompletableFuture<Void> clearAllUsedOfCode(String invite, Long serverId, JDA jda) {
return resolveInvite(jda, invite)
.thenAccept(resolvedInvite -> self.clearUsesOfInvite(serverId, resolvedInvite))
.exceptionally(throwable -> {
log.warn("Failed to to clear tracked invite uses via invite resolving.", throwable);
return null;
});
}
@Transactional
public void clearUsesOfInvite(Long serverId, Invite resolvedInvite) {
if(resolvedInvite.getType().equals(Invite.InviteType.GUILD)) {
self.clearAllUses(resolvedInvite.getGuild().getIdLong(), serverId);
} else {
throw new AbstractoRunTimeException("Given invite was from a group channel.");
}
}
@Override
public List<FilteredInviteLink> getTopFilteredInviteLinks(Long serverId, Integer count) {
return filteredInviteLinkManagement.getTopFilteredInviteLink(serverId, count);
}
@Override
public List<FilteredInviteLink> getTopFilteredInviteLinks(Long serverId) {
return getTopFilteredInviteLinks(serverId, 5);
}
@Override
public CompletableFuture<Invite> resolveInvite(JDA jda, String code) {
return Invite.resolve(jda, extractCode(code)).submit();
}
}

View File

@@ -0,0 +1,53 @@
package dev.sheldan.abstracto.invitefilter.service.management;
import dev.sheldan.abstracto.core.models.ServerUser;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.invitefilter.exception.AllowedInviteLinkNotFound;
import dev.sheldan.abstracto.invitefilter.model.database.AllowedInviteLink;
import dev.sheldan.abstracto.invitefilter.repository.AllowedInviteLinkRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class AllowedInviteLinkManagementBean implements AllowedInviteLinkManagement {
@Autowired
private AllowedInviteLinkRepository repository;
@Override
public AllowedInviteLink createAllowedInviteLink(AServer server, Long targetServerId, String code) {
AllowedInviteLink inviteLink = AllowedInviteLink.builder().targetServerId(targetServerId).code(code).server(server).build();
return repository.save(inviteLink);
}
@Override
public void removeAllowedInviteLink(AServer server, Long targetServerId) {
AllowedInviteLink existingCode = findAllowedInviteLinkByCode(server, targetServerId);
repository.delete(existingCode);
}
@Override
public AllowedInviteLink findAllowedInviteLinkByCode(AServer server, Long targetServerId) {
return repository.findByTargetServerIdAndServer(targetServerId, server).orElseThrow(() -> new AllowedInviteLinkNotFound("Allowed invite code not found."));
}
@Override
public boolean allowedInviteLinkExists(AServer server, Long targetServerId) {
return repository.findByTargetServerIdAndServer(targetServerId, server).isPresent();
}
@Override
public boolean allowedInviteLinkExists(Long serverId, Long targetServerId) {
return repository.findByTargetServerIdAndServer_Id(targetServerId, serverId).isPresent();
}
@Override
public boolean allowedInviteLinkExists(ServerUser serverUser, Long targetServerId) {
return repository.findByTargetServerIdAndServer_Id(targetServerId, serverUser.getServerId()).isPresent();
}
@Override
public boolean allowedInviteLinkExists(ServerUser serverUser, String code) {
return repository.findByCodeAndServer_Id(code, serverUser.getServerId()).isPresent();
}
}

View File

@@ -1,8 +1,8 @@
package dev.sheldan.abstracto.moderation.service.management;
package dev.sheldan.abstracto.invitefilter.service.management;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.moderation.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.moderation.repository.FilteredInviteLinkRepository;
import dev.sheldan.abstracto.invitefilter.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.invitefilter.repository.FilteredInviteLinkRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;
@@ -17,24 +17,25 @@ public class FilteredInviteLinkManagementBean implements FilteredInviteLinkManag
private FilteredInviteLinkRepository repository;
@Override
public FilteredInviteLink createFilteredInviteLink(AServer server, String code) {
public FilteredInviteLink createFilteredInviteLink(AServer server, Long targetServerId, String serverName) {
FilteredInviteLink inviteLink = FilteredInviteLink
.builder()
.code(code)
.server(server)
.serverName(serverName)
.targetServerId(targetServerId)
.uses(1L)
.build();
return repository.save(inviteLink);
}
@Override
public Optional<FilteredInviteLink> findInviteLinkViaCode(AServer server, String code) {
return repository.findByCodeAndServer(code, server);
public Optional<FilteredInviteLink> findInviteLinkViaTargetID(AServer server, Long targetServerId) {
return repository.findByTargetServerIdAndServer(targetServerId, server);
}
@Override
public Optional<FilteredInviteLink> findInviteLinkViaCode(Long serverId, String code) {
return repository.findByCodeAndServer_Id(code, serverId);
public Optional<FilteredInviteLink> findInviteLinkViaTargetID(Long serverId, Long targetServerId) {
return repository.findByTargetServerIdAndServer_Id(targetServerId, serverId);
}
@Override
@@ -48,13 +49,13 @@ public class FilteredInviteLinkManagementBean implements FilteredInviteLinkManag
}
@Override
public void clearFilteredInviteLink(String code, Long serverId) {
repository.deleteByCodeAndServer_Id(code, serverId);
public void clearFilteredInviteLink(Long targetServerId, Long serverId) {
repository.deleteByTargetServerIdAndServer_Id(targetServerId, serverId);
}
@Override
public void clearFilteredInviteLink(String code, AServer server) {
clearFilteredInviteLink(code, server.getId());
public void clearFilteredInviteLink(Long targetServerId, AServer server) {
clearFilteredInviteLink(targetServerId, server.getId());
}
@Override

View File

@@ -0,0 +1,58 @@
package dev.sheldan.abstracto.invitefilter.service.management;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import dev.sheldan.abstracto.invitefilter.model.database.InviteFilterChannelGroup;
import dev.sheldan.abstracto.invitefilter.repository.InviteFilterChannelGroupRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public class InviteFilterChannelGroupManagementBean implements InviteFilterChannelGroupManagement {
@Autowired
private InviteFilterChannelGroupRepository repository;
@Override
public InviteFilterChannelGroup loadInviteFilterChannelGroupById(Long channelGroupId) {
return repository.findById(channelGroupId).orElseThrow(() -> new AbstractoRunTimeException("Invite filter channel group not found."));
}
@Override
public Optional<InviteFilterChannelGroup> loadInviteFilterChannelGroupByIdOptional(Long channelGroupId) {
return repository.findById(channelGroupId);
}
@Override
public boolean inviteFilterChannelGroupExists(Long channelGroupId) {
return loadInviteFilterChannelGroupByIdOptional(channelGroupId).isPresent();
}
@Override
public Optional<InviteFilterChannelGroup> loadInviteFilterChannelGroupByChannelGroupOptional(AChannelGroup channelGroup) {
return loadInviteFilterChannelGroupByChannelGroupOptional(channelGroup);
}
@Override
public InviteFilterChannelGroup loadInviteFilterChannelGroupByChannelGroup(AChannelGroup channelGroup) {
return loadInviteFilterChannelGroupById(channelGroup.getId());
}
@Override
public InviteFilterChannelGroup createInviteFilterChannelGroup(AChannelGroup channelGroup) {
InviteFilterChannelGroup group = InviteFilterChannelGroup
.builder()
.channelGroup(channelGroup)
.id(channelGroup.getId())
.build();
return repository.save(group);
}
@Override
public void deleteInviteFilterChannelGroup(AChannelGroup channelGroup) {
InviteFilterChannelGroup foundGroup = loadInviteFilterChannelGroupByChannelGroup(channelGroup);
repository.delete(foundGroup);
}
}

View File

@@ -0,0 +1,13 @@
abstracto.featureFlags.inviteFilter.featureName=inviteFilter
abstracto.featureFlags.inviteFilter.enabled=false
abstracto.postTargets.inviteDeleteLog.name=inviteDeleteLog
abstracto.featureModes.trackUses.featureName=inviteFilter
abstracto.featureModes.trackUses.mode=trackUses
abstracto.featureModes.trackUses.enabled=true
abstracto.featureModes.filterNotifications.featureName=inviteFilter
abstracto.featureModes.filterNotifications.mode=filterNotifications
abstracto.featureModes.filterNotifications.enabled=true

View File

@@ -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="inviteFilter-tables/tables.xml" relativeToChangelogFile="true"/>
<include file="inviteFilter-seedData/data.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -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="invite_filter_channel_group_type-insertion">
<insert tableName="channel_group_type">
<column name="group_type_key" value="inviteFilter"/>
</insert>
</changeSet>
</databaseChangeLog>

View File

@@ -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" >
<property name="moderationModule" value="(SELECT id FROM module WHERE name = 'moderation')"/>
<property name="inviteLinkFilteringFeature" value="(SELECT id FROM feature WHERE key = 'inviteFilter')"/>
<changeSet author="Sheldan" id="moderation_inviteFilter-commands">
<insert tableName="command">
<column name="name" value="allowInvite"/>
<column name="module_id" valueComputed="${moderationModule}"/>
<column name="feature_id" valueComputed="${inviteLinkFilteringFeature}"/>
</insert>
<insert tableName="command">
<column name="name" value="disAllowInvite"/>
<column name="module_id" valueComputed="${moderationModule}"/>
<column name="feature_id" valueComputed="${inviteLinkFilteringFeature}"/>
</insert>
<insert tableName="command">
<column name="name" value="removeTrackedInviteLinks"/>
<column name="module_id" valueComputed="${moderationModule}"/>
<column name="feature_id" valueComputed="${inviteLinkFilteringFeature}"/>
</insert>
<insert tableName="command">
<column name="name" value="showTrackedInviteLinks"/>
<column name="module_id" valueComputed="${moderationModule}"/>
<column name="feature_id" valueComputed="${inviteLinkFilteringFeature}"/>
</insert>
</changeSet>
</databaseChangeLog>

View File

@@ -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" >
<include file="module.xml" relativeToChangelogFile="true"/>
<include file="feature.xml" relativeToChangelogFile="true"/>
<include file="effect_types.xml" relativeToChangelogFile="true"/>
<include file="command.xml" relativeToChangelogFile="true"/>
<include file="channel_group_types.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -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="invite_filter_effect_type-insertion">
<insert tableName="effect_type">
<column name="effect_type_key" value="inviteFilterDeletion"/>
</insert>
</changeSet>
</databaseChangeLog>

View File

@@ -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="inviteFilter_feature-insertion">
<insert tableName="feature">
<column name="key" value="inviteFilter"/>
</insert>
</changeSet>
</databaseChangeLog>

View File

@@ -0,0 +1,19 @@
<?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="invite-link-moderation-module-insertion">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
SELECT COUNT(*) FROM module WHERE name='moderation';
</sqlCheck>
</preConditions>
<insert tableName="module">
<column name="name" value="moderation"/>
</insert>
</changeSet>
</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="allowed_invite_link-table">
<createTable tableName="allowed_invite_link">
@@ -16,6 +16,9 @@
<constraints nullable="true"/>
</column>
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
<column name="target_server_id" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="code" type="VARCHAR(32)">
<constraints nullable="false"/>
</column>
@@ -27,6 +30,9 @@
<column name="code"/>
<column name="server_id"/>
</createIndex>
<createIndex indexName="idx_allowed_invite_target_server" tableName="allowed_invite_link">
<column name="target_server_id"/>
</createIndex>
<addForeignKeyConstraint baseColumnNames="server_id" baseTableName="allowed_invite_link" constraintName="fk_allowed_invite_link_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
<sql>
DROP TRIGGER IF EXISTS allowed_invite_link_update_trigger ON allowed_invite_link;

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="filtered_invite_link-table">
<createTable tableName="filtered_invite_link">
@@ -19,18 +19,21 @@
<column name="uses" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="code" type="VARCHAR(32)">
<column name="target_server_id" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="server_id" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="server_name" type="VARCHAR(100)">
<constraints nullable="false"/>
</column>
</createTable>
<createIndex indexName="idx_filtered_invite_link_server" tableName="filtered_invite_link">
<column name="server_id"/>
</createIndex>
<createIndex indexName="idx_filtered_invite_link_code_server" tableName="filtered_invite_link">
<column name="code"/>
<createIndex indexName="idx_filtered_invite_link_target_server_server" tableName="filtered_invite_link">
<column name="target_server_id"/>
<column name="server_id"/>
</createIndex>
<addForeignKeyConstraint baseColumnNames="server_id" baseTableName="filtered_invite_link" constraintName="fk_filtered_invite_link_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>

View File

@@ -0,0 +1,32 @@
<?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="invite_filter_channel_group-table">
<createTable tableName="invite_filter_channel_group">
<column name="id" type="BIGINT">
<constraints nullable="true"/>
</column>
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
<constraints nullable="true"/>
</column>
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
</createTable>
<addForeignKeyConstraint baseColumnNames="id" baseTableName="invite_filter_channel_group" constraintName="fk_invite_filter_channel_group_group"
deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="channel_group" validate="true"/>
<sql>
DROP TRIGGER IF EXISTS invite_filter_channel_group_update_trigger ON invite_filter_channel_group;
CREATE TRIGGER invite_filter_channel_group_update_trigger BEFORE UPDATE ON invite_filter_channel_group FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
</sql>
<sql>
DROP TRIGGER IF EXISTS invite_filter_channel_group_insert_trigger ON invite_filter_channel_group;
CREATE TRIGGER invite_filter_channel_group_insert_trigger BEFORE INSERT ON invite_filter_channel_group FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
</sql>
</changeSet>
</databaseChangeLog>

View File

@@ -0,0 +1,12 @@
<?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="allowed_invite_link.xml" relativeToChangelogFile="true"/>
<include file="filtered_invite_link.xml" relativeToChangelogFile="true"/>
<include file="invite_filter_channel_group.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

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

@@ -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.2.11-inviteFilter/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -1,11 +1,10 @@
package dev.sheldan.abstracto.moderation.command.invite;
package dev.sheldan.abstracto.invitefilter.command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.moderation.command.AllowInvite;
import dev.sheldan.abstracto.moderation.service.InviteLinkFilterServiceBean;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterServiceBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -13,9 +12,9 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class AllowInviteTest {
@@ -31,9 +30,10 @@ public class AllowInviteTest {
@Test
public void testExecuteCommand() {
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(INVITE_STRING));
CommandResult result = testUnit.execute(parameters);
CommandTestUtilities.checkSuccessfulCompletion(result);
verify(inviteLinkFilterServiceBean, times(1)).allowInvite(INVITE_STRING, parameters.getGuild().getIdLong());
when(inviteLinkFilterServiceBean.allowInvite(INVITE_STRING, parameters.getGuild().getIdLong(), parameters.getJda()))
.thenReturn(CompletableFuture.completedFuture(null));
CompletableFuture<CommandResult> result = testUnit.executeAsync(parameters);
CommandTestUtilities.checkSuccessfulCompletionAsync(result);
}
@Test

View File

@@ -1,11 +1,10 @@
package dev.sheldan.abstracto.moderation.command.invite;
package dev.sheldan.abstracto.invitefilter.command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.moderation.command.DisAllowInvite;
import dev.sheldan.abstracto.moderation.service.InviteLinkFilterServiceBean;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterServiceBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -13,9 +12,9 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class DisAllowInviteTest {
@@ -31,9 +30,10 @@ public class DisAllowInviteTest {
@Test
public void testExecuteCommand() {
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(INVITE_STRING));
CommandResult result = testUnit.execute(parameters);
CommandTestUtilities.checkSuccessfulCompletion(result);
verify(inviteLinkFilterServiceBean, times(1)).disAllowInvite(INVITE_STRING, parameters.getGuild().getIdLong());
when(inviteLinkFilterServiceBean.disAllowInvite(INVITE_STRING, parameters.getGuild().getIdLong(), parameters.getJda()))
.thenReturn(CompletableFuture.completedFuture(null));
CompletableFuture<CommandResult> result = testUnit.executeAsync(parameters);
CommandTestUtilities.checkSuccessfulCompletionAsync(result);
}
@Test

View File

@@ -1,21 +1,22 @@
package dev.sheldan.abstracto.moderation.command.invite;
package dev.sheldan.abstracto.invitefilter.command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.moderation.command.RemoveTrackedInviteLinks;
import dev.sheldan.abstracto.moderation.service.InviteLinkFilterService;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService;
import net.dv8tion.jda.api.entities.Guild;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class RemoveTrackedInviteLinksTest {
@@ -27,21 +28,24 @@ public class RemoveTrackedInviteLinksTest {
private InviteLinkFilterService inviteLinkFilterService;
private static final String INVITE_STRING = "invite";
private static final Long SERVER_ID = 2L;
@Test
public void testExecuteCommandNoParameter() {
CommandContext parameters = CommandTestUtilities.getNoParameters();
CommandResult result = testUnit.execute(parameters);
CommandTestUtilities.checkSuccessfulCompletion(result);
CompletableFuture<CommandResult> result = testUnit.executeAsync(parameters);
CommandTestUtilities.checkSuccessfulCompletionAsync(result);
verify(inviteLinkFilterService, times(1)).clearAllTrackedInviteCodes(parameters.getGuild().getIdLong());
}
@Test
public void testExecuteCommandForSpecificInvite() {
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(INVITE_STRING));
CommandResult result = testUnit.execute(parameters);
CommandTestUtilities.checkSuccessfulCompletion(result);
verify(inviteLinkFilterService, times(1)).clearAllUses(INVITE_STRING, parameters.getGuild().getIdLong());
when(parameters.getGuild().getIdLong()).thenReturn(SERVER_ID);
when(inviteLinkFilterService.clearAllUsedOfCode(INVITE_STRING, SERVER_ID, parameters.getJda()))
.thenReturn(CompletableFuture.completedFuture(null));
CompletableFuture<CommandResult> result = testUnit.executeAsync(parameters);
CommandTestUtilities.checkSuccessfulCompletionAsync(result);
}
@Test

View File

@@ -1,16 +1,15 @@
package dev.sheldan.abstracto.moderation.command.invite;
package dev.sheldan.abstracto.invitefilter.command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
import dev.sheldan.abstracto.moderation.command.ShowTrackedInviteLinks;
import dev.sheldan.abstracto.moderation.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.moderation.model.template.command.TrackedInviteLinksModel;
import dev.sheldan.abstracto.moderation.service.InviteLinkFilterService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.invitefilter.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.invitefilter.model.template.command.TrackedInviteLinksModel;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -21,7 +20,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import static dev.sheldan.abstracto.moderation.command.ShowTrackedInviteLinks.TRACKED_INVITE_LINKS_EMBED_TEMPLATE_KEY;
import static dev.sheldan.abstracto.invitefilter.command.ShowTrackedInviteLinks.TRACKED_INVITE_LINKS_EMBED_TEMPLATE_KEY;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)

View File

@@ -0,0 +1,108 @@
package dev.sheldan.abstracto.invitefilter.listener;
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
import dev.sheldan.abstracto.core.service.ChannelGroupService;
import dev.sheldan.abstracto.core.service.RoleImmunityService;
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.concurrent.CompletableFuture;
import static dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService.INVITE_FILTER_CHANNEL_GROUP_TYPE;
import static dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService.INVITE_FILTER_EFFECT_KEY;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class InviteLinkFilterListenerTest {
@InjectMocks
private InviteLinkFilterListener testUnit;
@Mock
private InviteLinkFilterService inviteLinkFilterService;
@Mock
private Message message;
@Mock
private User author;
@Mock
private Member member;
@Mock
private MessageChannel messageChannel;
@Mock
private Guild guild;
@Mock
private MessageReceivedModel model;
@Mock
private ChannelGroupService channelGroupService;
@Mock
private RoleImmunityService roleImmunityService;
@Mock
private JDA jda;
@Mock
private Invite invite;
private static final Long SERVER_ID = 1L;
private static final Long CHANNEL_ID = 2L;
private static final Long USER_ID = 3L;
private static final String INVITE_CODE = "code";
private static final String INVITE_LINK = "discord.gg/" + INVITE_CODE;
@Test
public void testExecutionWithNoInvite() {
when(message.getContentRaw()).thenReturn("text");
setupBasicMessage();
setupFiltering();
when(model.getMessage()).thenReturn(message);
DefaultListenerResult result = testUnit.execute(model);
Assert.assertEquals(DefaultListenerResult.IGNORED, result);
}
@Test
public void testExecutionWithOneInvite() {
setupFiltering();
when(message.getContentRaw()).thenReturn(INVITE_LINK);
setupBasicMessage();
when(inviteLinkFilterService.resolveInvite(jda, INVITE_CODE)).thenReturn(CompletableFuture.completedFuture(invite));
when(model.getMessage()).thenReturn(message);
DefaultListenerResult result = testUnit.execute(model);
Assert.assertEquals(DefaultListenerResult.PROCESSED, result);
}
private void setupFiltering() {
when(channelGroupService.isChannelInEnabledChannelGroupOfType(INVITE_FILTER_CHANNEL_GROUP_TYPE, CHANNEL_ID)).thenReturn(true);
when(roleImmunityService.isImmune(member, INVITE_FILTER_EFFECT_KEY)).thenReturn(false);
}
private void setupBasicMessage() {
when(messageChannel.getIdLong()).thenReturn(CHANNEL_ID);
when(message.getChannel()).thenReturn(messageChannel);
when(message.getAuthor()).thenReturn(author);
when(message.getMember()).thenReturn(member);
when(author.getIdLong()).thenReturn(USER_ID);
when(message.getGuild()).thenReturn(guild);
when(guild.getIdLong()).thenReturn(SERVER_ID);
when(message.isFromGuild()).thenReturn(true);
when(message.isWebhookMessage()).thenReturn(false);
when(message.getJDA()).thenReturn(jda);
MessageType type = MessageType.DEFAULT;
when(message.getType()).thenReturn(type);
}
}

View File

@@ -1,12 +1,14 @@
package dev.sheldan.abstracto.moderation.service;
package dev.sheldan.abstracto.invitefilter.service;
import dev.sheldan.abstracto.core.models.ServerUser;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.moderation.exception.InvalidInviteException;
import dev.sheldan.abstracto.moderation.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.moderation.service.management.AllowedInviteLinkManagement;
import dev.sheldan.abstracto.moderation.service.management.FilteredInviteLinkManagement;
import dev.sheldan.abstracto.invitefilter.exception.InvalidInviteException;
import dev.sheldan.abstracto.invitefilter.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.invitefilter.service.management.AllowedInviteLinkManagement;
import dev.sheldan.abstracto.invitefilter.service.management.FilteredInviteLinkManagement;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Invite;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -18,6 +20,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import static org.mockito.Mockito.*;
@@ -42,14 +45,25 @@ public class InviteLinkFilterServiceBeanTest {
@Mock
private ServerUser serverUser;
private static final String INVITE_CODE = "asdf";
private static final String FULL_INVITE = "discord.gg/" + INVITE_CODE;
@Mock
private JDA jda;
@Mock
private InviteLinkFilterServiceBean self;
@Mock
private Invite invite;
private static final Long TARGET_SERVER_ID = 3L;
private static final String CODE = "c";
private static final String FULL_INVITE = "discord.gg/" + CODE;
private static final Long SERVER_ID = 1L;
private static final String SERVER_NAME = "test";
@Test
public void testIsCodeAllowedViaId() {
when(allowedInviteLinkManagement.allowedInviteLinkExists(SERVER_ID, FULL_INVITE)).thenReturn(true);
boolean codeAllowed = testUnit.isCodeAllowed(FULL_INVITE, SERVER_ID);
when(allowedInviteLinkManagement.allowedInviteLinkExists(SERVER_ID, TARGET_SERVER_ID)).thenReturn(true);
boolean codeAllowed = testUnit.isCodeAllowed(TARGET_SERVER_ID, SERVER_ID);
Assert.assertTrue(codeAllowed);
}
@@ -72,8 +86,8 @@ public class InviteLinkFilterServiceBeanTest {
when(serverUser.getServerId()).thenReturn(SERVER_ID);
FilteredInviteLink mockedFilteredInviteLink = Mockito.mock(FilteredInviteLink.class);
when(mockedFilteredInviteLink.getUses()).thenReturn(1L);
when(filteredInviteLinkManagement.findInviteLinkViaCode(SERVER_ID, FULL_INVITE)).thenReturn(Optional.of(mockedFilteredInviteLink));
testUnit.storeFilteredInviteLinkUsage(FULL_INVITE, serverUser);
when(filteredInviteLinkManagement.findInviteLinkViaTargetID(SERVER_ID, TARGET_SERVER_ID)).thenReturn(Optional.of(mockedFilteredInviteLink));
testUnit.storeFilteredInviteLinkUsage(TARGET_SERVER_ID, SERVER_NAME, serverUser);
verify(mockedFilteredInviteLink, times(1)).setUses(2L);
}
@@ -81,44 +95,42 @@ public class InviteLinkFilterServiceBeanTest {
public void testStoreFilteredInviteLinkUsageNotPresent() {
when(serverUser.getServerId()).thenReturn(SERVER_ID);
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
when(filteredInviteLinkManagement.findInviteLinkViaCode(SERVER_ID, FULL_INVITE)).thenReturn(Optional.empty());
testUnit.storeFilteredInviteLinkUsage(FULL_INVITE, serverUser);
verify(filteredInviteLinkManagement, times(1)).createFilteredInviteLink(server, FULL_INVITE);
when(filteredInviteLinkManagement.findInviteLinkViaTargetID(SERVER_ID, TARGET_SERVER_ID)).thenReturn(Optional.empty());
testUnit.storeFilteredInviteLinkUsage(TARGET_SERVER_ID, SERVER_NAME, serverUser);
verify(filteredInviteLinkManagement, times(1)).createFilteredInviteLink(server, TARGET_SERVER_ID, SERVER_NAME);
}
@Test
public void testAllowInvite() {
when(allowedInviteLinkManagement.allowedInviteLinkExists(SERVER_ID, INVITE_CODE)).thenReturn(false);
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
testUnit.allowInvite(FULL_INVITE, SERVER_ID);
verify(allowedInviteLinkManagement, times(1)).createAllowedInviteLink(server, INVITE_CODE);
when(self.resolveInvite(jda, CODE)).thenReturn(CompletableFuture.completedFuture(invite));
testUnit.allowInvite(FULL_INVITE, SERVER_ID, jda);
verify(self, times(1)).allowInviteInServer(SERVER_ID, invite);
}
@Test(expected = InvalidInviteException.class)
public void testAllowInviteIllegalInvite() {
testUnit.allowInvite("#", SERVER_ID);
testUnit.allowInvite("#", SERVER_ID, jda);
}
@Test
public void testAllowInviteInviteCode() {
when(allowedInviteLinkManagement.allowedInviteLinkExists(SERVER_ID, INVITE_CODE)).thenReturn(false);
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
testUnit.allowInvite(INVITE_CODE, SERVER_ID);
verify(allowedInviteLinkManagement, times(1)).createAllowedInviteLink(server, INVITE_CODE);
when(self.resolveInvite(jda, CODE)).thenReturn(CompletableFuture.completedFuture(invite));
testUnit.allowInvite(FULL_INVITE, SERVER_ID, jda);
verify(self, times(1)).allowInviteInServer(SERVER_ID, invite);
}
@Test
public void testAllowInviteAlreadyPresent() {
when(allowedInviteLinkManagement.allowedInviteLinkExists(SERVER_ID, INVITE_CODE)).thenReturn(true);
testUnit.allowInvite(FULL_INVITE, SERVER_ID);
verify(allowedInviteLinkManagement, times(0)).createAllowedInviteLink(any(AServer.class), anyString());
when(self.resolveInvite(jda, CODE)).thenReturn(CompletableFuture.completedFuture(invite));
testUnit.allowInvite(FULL_INVITE, SERVER_ID, jda);
verify(self, times(1)).allowInviteInServer(SERVER_ID, invite);
}
@Test
public void testDisallowInvite() {
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
testUnit.disAllowInvite(FULL_INVITE, SERVER_ID);
verify(allowedInviteLinkManagement, times(1)).removeAllowedInviteLink(server, INVITE_CODE);
when(self.resolveInvite(jda, CODE)).thenReturn(CompletableFuture.completedFuture(invite));
testUnit.disAllowInvite(FULL_INVITE, SERVER_ID, jda);
verify(self, times(1)).disallowInviteInServer(SERVER_ID, invite);
}
@Test
@@ -129,8 +141,8 @@ public class InviteLinkFilterServiceBeanTest {
@Test
public void testClearAllUses() {
testUnit.clearAllUses(FULL_INVITE, SERVER_ID);
verify(filteredInviteLinkManagement, times(1)).clearFilteredInviteLink(INVITE_CODE, SERVER_ID);
testUnit.clearAllUses(TARGET_SERVER_ID, SERVER_ID);
verify(filteredInviteLinkManagement, times(1)).clearFilteredInviteLink(TARGET_SERVER_ID, SERVER_ID);
}
@Test

View File

@@ -1,10 +1,10 @@
package dev.sheldan.abstracto.moderation.service.management;
package dev.sheldan.abstracto.invitefilter.service.management;
import dev.sheldan.abstracto.core.models.ServerUser;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.moderation.exception.AllowedInviteLinkNotFound;
import dev.sheldan.abstracto.moderation.model.database.AllowedInviteLink;
import dev.sheldan.abstracto.moderation.repository.AllowedInviteLinkRepository;
import dev.sheldan.abstracto.invitefilter.exception.AllowedInviteLinkNotFound;
import dev.sheldan.abstracto.invitefilter.model.database.AllowedInviteLink;
import dev.sheldan.abstracto.invitefilter.repository.AllowedInviteLinkRepository;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,7 +31,8 @@ public class AllowedInviteLinkManagementBeanTest {
private AllowedInviteLink mockedInviteLink;
private static final Long SERVER_ID = 1L;
private static final String INVITE = "invite";
private static final Long INVITE = 3L;
private static final String CODE = "c";
@Captor
private ArgumentCaptor<AllowedInviteLink> linkCaptor;
@@ -39,50 +40,50 @@ public class AllowedInviteLinkManagementBeanTest {
@Test
public void testCreateAllowedInviteLink() {
when(repository.save(linkCaptor.capture())).thenReturn(mockedInviteLink);
AllowedInviteLink allowedInviteLink = testUnit.createAllowedInviteLink(server, INVITE);
AllowedInviteLink allowedInviteLink = testUnit.createAllowedInviteLink(server, INVITE, CODE);
verify(repository, times(1)).save(linkCaptor.capture());
Assert.assertEquals(allowedInviteLink, mockedInviteLink);
AllowedInviteLink repositoryAllowedInviteLink = linkCaptor.getValue();
Assert.assertEquals(server, repositoryAllowedInviteLink.getServer());
Assert.assertEquals(INVITE, repositoryAllowedInviteLink.getCode());
Assert.assertEquals(INVITE, repositoryAllowedInviteLink.getTargetServerId());
}
@Test
public void testRemoveAllowedInviteLink() {
when(repository.findByCodeAndServer(INVITE, server)).thenReturn(Optional.of(mockedInviteLink));
when(repository.findByTargetServerIdAndServer(INVITE, server)).thenReturn(Optional.of(mockedInviteLink));
testUnit.removeAllowedInviteLink(server, INVITE);
verify(repository, times(1)).delete(mockedInviteLink);
}
@Test(expected = AllowedInviteLinkNotFound.class)
public void testRemoveNotPresentAllowedInviteLink() {
when(repository.findByCodeAndServer(INVITE, server)).thenReturn(Optional.empty());
when(repository.findByTargetServerIdAndServer(INVITE, server)).thenReturn(Optional.empty());
testUnit.removeAllowedInviteLink(server, INVITE);
}
@Test
public void testFindAllowedInviteLinkByCode() {
when(repository.findByCodeAndServer(INVITE, server)).thenReturn(Optional.of(mockedInviteLink));
when(repository.findByTargetServerIdAndServer(INVITE, server)).thenReturn(Optional.of(mockedInviteLink));
AllowedInviteLink allowedInviteLinkByCode = testUnit.findAllowedInviteLinkByCode(server, INVITE);
Assert.assertEquals(mockedInviteLink, allowedInviteLinkByCode);
}
@Test(expected = AllowedInviteLinkNotFound.class)
public void testFindNotPresentAllowedInviteLinkByCode() {
when(repository.findByCodeAndServer(INVITE, server)).thenReturn(Optional.empty());
when(repository.findByTargetServerIdAndServer(INVITE, server)).thenReturn(Optional.empty());
testUnit.findAllowedInviteLinkByCode(server, INVITE);
}
@Test
public void testAllowedInviteLinkExists() {
when(repository.findByCodeAndServer(INVITE, server)).thenReturn(Optional.of(mockedInviteLink));
when(repository.findByTargetServerIdAndServer(INVITE, server)).thenReturn(Optional.of(mockedInviteLink));
boolean exists = testUnit.allowedInviteLinkExists(server, INVITE);
Assert.assertTrue(exists);
}
@Test
public void testAllowedInviteLinkExistsViaId() {
when(repository.findByCodeAndServer_Id(INVITE, SERVER_ID)).thenReturn(Optional.of(mockedInviteLink));
when(repository.findByTargetServerIdAndServer_Id(INVITE, SERVER_ID)).thenReturn(Optional.of(mockedInviteLink));
boolean exists = testUnit.allowedInviteLinkExists(SERVER_ID, INVITE);
Assert.assertTrue(exists);
}
@@ -91,7 +92,7 @@ public class AllowedInviteLinkManagementBeanTest {
public void testAllowedInviteLinkExistsViaServerUser() {
ServerUser serverUser = Mockito.mock(ServerUser.class);
when(serverUser.getServerId()).thenReturn(SERVER_ID);
when(repository.findByCodeAndServer_Id(INVITE, SERVER_ID)).thenReturn(Optional.of(mockedInviteLink));
when(repository.findByTargetServerIdAndServer_Id(INVITE, SERVER_ID)).thenReturn(Optional.of(mockedInviteLink));
boolean exists = testUnit.allowedInviteLinkExists(serverUser, INVITE);
Assert.assertTrue(exists);
}

View File

@@ -1,8 +1,8 @@
package dev.sheldan.abstracto.moderation.service.management;
package dev.sheldan.abstracto.invitefilter.service.management;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.moderation.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.moderation.repository.FilteredInviteLinkRepository;
import dev.sheldan.abstracto.invitefilter.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.invitefilter.repository.FilteredInviteLinkRepository;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,8 +32,9 @@ public class FilteredInviteLinkManagementBeanTest {
@Mock
private FilteredInviteLink mockedFilteredLink;
private static final String INVITE = "invite";
private static final Long TARGET_SERVER_ID = 2L;
private static final Long SERVER_ID = 1L;
private static final String SERVER_NAME = "serverName";
@Captor
private ArgumentCaptor<FilteredInviteLink> linkCaptor;
@@ -41,27 +42,27 @@ public class FilteredInviteLinkManagementBeanTest {
@Test
public void testCreateFilteredInviteLink() {
when(repository.save(linkCaptor.capture())).thenReturn(mockedFilteredLink);
FilteredInviteLink filteredInviteLink = testUnit.createFilteredInviteLink(server, INVITE);
FilteredInviteLink filteredInviteLink = testUnit.createFilteredInviteLink(server, TARGET_SERVER_ID, SERVER_NAME);
verify(repository, times(1)).save(linkCaptor.capture());
Assert.assertEquals(filteredInviteLink, mockedFilteredLink);
FilteredInviteLink repositoryFilteredInviteLink = linkCaptor.getValue();
Assert.assertEquals(server, repositoryFilteredInviteLink.getServer());
Assert.assertEquals(INVITE, repositoryFilteredInviteLink.getCode());
Assert.assertEquals(TARGET_SERVER_ID, repositoryFilteredInviteLink.getTargetServerId());
Assert.assertEquals(1, repositoryFilteredInviteLink.getUses().intValue());
}
@Test
public void testFindInviteLinkViaCode() {
when(repository.findByCodeAndServer(INVITE, server)).thenReturn(Optional.of(mockedFilteredLink));
Optional<FilteredInviteLink> filteredInviteLinkOptional = testUnit.findInviteLinkViaCode(server, INVITE);
when(repository.findByTargetServerIdAndServer(TARGET_SERVER_ID, server)).thenReturn(Optional.of(mockedFilteredLink));
Optional<FilteredInviteLink> filteredInviteLinkOptional = testUnit.findInviteLinkViaTargetID(server, TARGET_SERVER_ID);
Assert.assertTrue(filteredInviteLinkOptional.isPresent());
filteredInviteLinkOptional.ifPresent(filteredInviteLink -> Assert.assertEquals(mockedFilteredLink, filteredInviteLink));
}
@Test
public void testFindInviteLinkViaCodeById() {
when(repository.findByCodeAndServer_Id(INVITE, SERVER_ID)).thenReturn(Optional.of(mockedFilteredLink));
Optional<FilteredInviteLink> filteredInviteLinkOptional = testUnit.findInviteLinkViaCode(SERVER_ID, INVITE);
when(repository.findByTargetServerIdAndServer_Id(TARGET_SERVER_ID, SERVER_ID)).thenReturn(Optional.of(mockedFilteredLink));
Optional<FilteredInviteLink> filteredInviteLinkOptional = testUnit.findInviteLinkViaTargetID(SERVER_ID, TARGET_SERVER_ID);
Assert.assertTrue(filteredInviteLinkOptional.isPresent());
filteredInviteLinkOptional.ifPresent(filteredInviteLink -> Assert.assertEquals(mockedFilteredLink, filteredInviteLink));
}
@@ -81,15 +82,15 @@ public class FilteredInviteLinkManagementBeanTest {
@Test
public void testClearFilteredInviteLinkViaId() {
testUnit.clearFilteredInviteLink(INVITE, SERVER_ID);
verify(repository, times(1)).deleteByCodeAndServer_Id(INVITE, SERVER_ID);
testUnit.clearFilteredInviteLink(TARGET_SERVER_ID, SERVER_ID);
verify(repository, times(1)).deleteByTargetServerIdAndServer_Id(TARGET_SERVER_ID, SERVER_ID);
}
@Test
public void testClearFilteredInviteLink() {
when(server.getId()).thenReturn(SERVER_ID);
testUnit.clearFilteredInviteLink(INVITE, server);
verify(repository, times(1)).deleteByCodeAndServer_Id(INVITE, SERVER_ID);
testUnit.clearFilteredInviteLink(TARGET_SERVER_ID, server);
verify(repository, times(1)).deleteByTargetServerIdAndServer_Id(TARGET_SERVER_ID, SERVER_ID);
}
@Test

View File

@@ -0,0 +1,27 @@
<?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>invite-filter</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>invite-filter-int</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>dev.sheldan.abstracto.core</groupId>
<artifactId>core-int</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -1,9 +1,9 @@
package dev.sheldan.abstracto.moderation.config.feature;
package dev.sheldan.abstracto.invitefilter.config;
import dev.sheldan.abstracto.core.config.FeatureConfig;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.config.FeatureMode;
import dev.sheldan.abstracto.core.config.PostTargetEnum;
import dev.sheldan.abstracto.moderation.config.posttarget.InviteFilterPostTarget;
import org.springframework.stereotype.Component;
import java.util.Arrays;
@@ -13,7 +13,7 @@ import java.util.List;
public class InviteFilterFeatureConfig implements FeatureConfig {
@Override
public FeatureDefinition getFeature() {
return ModerationFeatureDefinition.INVITE_FILTER;
return InviteFilterFeatureDefinition.INVITE_FILTER;
}
@Override
@@ -21,4 +21,8 @@ public class InviteFilterFeatureConfig implements FeatureConfig {
return Arrays.asList(InviteFilterPostTarget.INVITE_DELETE_LOG);
}
@Override
public List<FeatureMode> getAvailableModes() {
return Arrays.asList(InviteFilterMode.FILTER_NOTIFICATIONS, InviteFilterMode.TRACK_USES);
}
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.invitefilter.config;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import lombok.Getter;
@Getter
public enum InviteFilterFeatureDefinition implements FeatureDefinition {
INVITE_FILTER("inviteFilter");
private final String key;
InviteFilterFeatureDefinition(String key) {
this.key = key;
}
}

View File

@@ -1,10 +1,10 @@
package dev.sheldan.abstracto.moderation.config.feature.mode;
package dev.sheldan.abstracto.invitefilter.config;
import dev.sheldan.abstracto.core.config.FeatureMode;
import lombok.Getter;
@Getter
public enum InviteFilterMode implements FeatureMode {
public enum InviteFilterMode implements FeatureMode {
TRACK_USES("trackUses"), FILTER_NOTIFICATIONS("filterNotifications");
private final String key;

View File

@@ -0,0 +1,21 @@
package dev.sheldan.abstracto.invitefilter.config;
import dev.sheldan.abstracto.core.command.config.ModuleDefinition;
import dev.sheldan.abstracto.core.command.config.ModuleInfo;
import org.springframework.stereotype.Component;
@Component
public class InviteFilterModerationModuleDefinition implements ModuleDefinition {
public static final String MODERATION = "moderation";
@Override
public ModuleInfo getInfo() {
return ModuleInfo.builder().name(MODERATION).templated(true).build();
}
@Override
public String getParentModule() {
return "default";
}
}

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.moderation.config.posttarget;
package dev.sheldan.abstracto.invitefilter.config;
import dev.sheldan.abstracto.core.config.PostTargetEnum;
import lombok.Getter;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.moderation.exception;
package dev.sheldan.abstracto.invitefilter.exception;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.templating.Templatable;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.moderation.exception;
package dev.sheldan.abstracto.invitefilter.exception;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.templating.Templatable;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.moderation.model.database;
package dev.sheldan.abstracto.invitefilter.model.database;
import dev.sheldan.abstracto.core.models.database.AServer;
import lombok.*;
@@ -21,13 +21,16 @@ public class AllowedInviteLink {
@Column(name = "id")
private Long id;
@Column(name = "code")
private String code;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "server_id", nullable = false)
private AServer server;
@Column(name = "target_server_id")
private Long targetServerId;
@Column(name = "code")
private String code;
@Column(name = "created")
private Instant created;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.moderation.model.database;
package dev.sheldan.abstracto.invitefilter.model.database;
import dev.sheldan.abstracto.core.models.database.AServer;
import lombok.*;
@@ -21,13 +21,16 @@ public class FilteredInviteLink {
@Column(name = "id")
private Long id;
@Column(name = "code")
private String code;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "server_id", nullable = false)
private AServer server;
@Column(name = "target_server_id")
private Long targetServerId;
@Column(name = "server_name")
private String serverName;
/**
* The amount of times, this invite code has been tried.
*/

View File

@@ -0,0 +1,33 @@
package dev.sheldan.abstracto.invitefilter.model.database;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import lombok.*;
import javax.persistence.*;
import java.time.Instant;
@Builder
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "invite_filter_channel_group")
@Getter
@Setter
@EqualsAndHashCode
public class InviteFilterChannelGroup {
@Id
@Column(name = "id")
private Long id;
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@PrimaryKeyJoinColumn
private AChannelGroup channelGroup;
@Column(name = "created")
private Instant created;
@Column(name = "updated")
private Instant updated;
}

View File

@@ -1,7 +1,7 @@
package dev.sheldan.abstracto.moderation.model.template.command;
package dev.sheldan.abstracto.invitefilter.model.template.command;
import dev.sheldan.abstracto.core.models.context.SlimUserInitiatedServerContext;
import dev.sheldan.abstracto.moderation.model.database.FilteredInviteLink;
import dev.sheldan.abstracto.invitefilter.model.database.FilteredInviteLink;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

View File

@@ -1,12 +1,9 @@
package dev.sheldan.abstracto.moderation.model.template.listener;
package dev.sheldan.abstracto.invitefilter.model.template.listener;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
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 java.util.List;
@@ -15,7 +12,7 @@ import java.util.List;
@Builder
public class DeletedInvitesNotificationModel {
private Guild guild;
private TextChannel channel;
private MessageChannel channel;
private Member author;
private Message message;
private List<DeletedInvite> invites;

View File

@@ -0,0 +1,28 @@
package dev.sheldan.abstracto.invitefilter.service;
import dev.sheldan.abstracto.core.models.ServerUser;
import dev.sheldan.abstracto.invitefilter.model.database.FilteredInviteLink;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Invite;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public interface InviteLinkFilterService {
String INVITE_FILTER_CHANNEL_GROUP_TYPE = "inviteFilter";
String INVITE_FILTER_EFFECT_KEY = "inviteFilterDeletion";
boolean isCodeFiltered(Long targetServerId, ServerUser serverUser);
boolean isCodeFiltered(String code, ServerUser serverUser);
boolean isCodeAllowed(Long targetServerId, ServerUser serverUser);
boolean isCodeAllowed(String code, ServerUser serverUser);
boolean isCodeAllowed(Long targetServerId, Long serverId);
void storeFilteredInviteLinkUsage(Long targetServerId, String serverName, ServerUser serverUser);
CompletableFuture<Void> allowInvite(String invite, Long serverId, JDA jda);
CompletableFuture<Void> disAllowInvite(String invite, Long serverId, JDA jda);
void clearAllTrackedInviteCodes(Long serverId);
void clearAllUses(Long targetServerId, Long serverId);
CompletableFuture<Void> clearAllUsedOfCode(String code, Long serverId, JDA jda);
List<FilteredInviteLink> getTopFilteredInviteLinks(Long serverId, Integer count);
List<FilteredInviteLink> getTopFilteredInviteLinks(Long serverId);
CompletableFuture<Invite> resolveInvite(JDA jda, String code);
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.invitefilter.service.management;
import dev.sheldan.abstracto.core.models.ServerUser;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.invitefilter.model.database.AllowedInviteLink;
public interface AllowedInviteLinkManagement {
AllowedInviteLink createAllowedInviteLink(AServer server, Long targetServerId, String code);
void removeAllowedInviteLink(AServer server, Long targetServerId);
AllowedInviteLink findAllowedInviteLinkByCode(AServer server, Long targetServerId);
boolean allowedInviteLinkExists(AServer server, Long targetServerId);
boolean allowedInviteLinkExists(Long serverId, Long targetServerId);
boolean allowedInviteLinkExists(ServerUser serverUser, Long targetServerId);
boolean allowedInviteLinkExists(ServerUser serverUser, String code);
}

View File

@@ -0,0 +1,18 @@
package dev.sheldan.abstracto.invitefilter.service.management;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.invitefilter.model.database.FilteredInviteLink;
import java.util.List;
import java.util.Optional;
public interface FilteredInviteLinkManagement {
FilteredInviteLink createFilteredInviteLink(AServer server, Long targetServerId, String serverName);
Optional<FilteredInviteLink> findInviteLinkViaTargetID(AServer server, Long targetServerId);
Optional<FilteredInviteLink> findInviteLinkViaTargetID(Long serverId, Long targetServerId);
void clearFilteredInviteLinks(Long serverId);
void clearFilteredInviteLinks(AServer server);
void clearFilteredInviteLink(Long targetServerId, Long serverId);
void clearFilteredInviteLink(Long targetServerId, AServer server);
List<FilteredInviteLink> getTopFilteredInviteLink(Long serverId, Integer count);
}

View File

@@ -0,0 +1,16 @@
package dev.sheldan.abstracto.invitefilter.service.management;
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
import dev.sheldan.abstracto.invitefilter.model.database.InviteFilterChannelGroup;
import java.util.Optional;
public interface InviteFilterChannelGroupManagement {
InviteFilterChannelGroup loadInviteFilterChannelGroupById(Long channelGroupId);
Optional<InviteFilterChannelGroup> loadInviteFilterChannelGroupByIdOptional(Long channelGroupId);
boolean inviteFilterChannelGroupExists(Long channelGroupId);
Optional<InviteFilterChannelGroup> loadInviteFilterChannelGroupByChannelGroupOptional(AChannelGroup channelGroup);
InviteFilterChannelGroup loadInviteFilterChannelGroupByChannelGroup(AChannelGroup channelGroup);
InviteFilterChannelGroup createInviteFilterChannelGroup(AChannelGroup channelGroup);
void deleteInviteFilterChannelGroup(AChannelGroup channelGroup);
}

View File

@@ -0,0 +1,19 @@
<?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>abstracto-modules</artifactId>
<groupId>dev.sheldan.abstracto.modules</groupId>
<version>1.2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>invite-filter</artifactId>
<packaging>pom</packaging>
<modules>
<module>invite-filter-int</module>
<module>invite-filter-impl</module>
</modules>
</project>

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()) {

Some files were not shown because too many files have changed in this diff Show More