[OPB-30] porting mod mode command

enabling anti raid module
This commit is contained in:
Sheldan
2021-07-14 02:09:29 +02:00
parent 86eac5f2a5
commit 8a38dd3d1a
31 changed files with 1838 additions and 6 deletions

View File

@@ -125,6 +125,11 @@
<artifactId>logging-impl</artifactId>
</dependency>
<dependency>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>anti-raid-impl</artifactId>
</dependency>
<dependency>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>invite-filter-impl</artifactId>
@@ -156,6 +161,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.sheldan.oneplus.bot.application.custom</groupId>
<artifactId>moderation-custom</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.sheldan.oneplus.bot.application.modules</groupId>
<artifactId>news</artifactId>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>oneplus-bot-customizations</artifactId>
<groupId>dev.sheldan.oneplus.bot.application.custom</groupId>
<version>1.5.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>moderation-custom</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>moderation-int</artifactId>
<version>${abstracto.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/liquibase.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

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

@@ -0,0 +1,52 @@
package dev.sheldan.oneplus.bot.custom.moderation.commands;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.moderation.config.ModerationModuleDefinition;
import dev.sheldan.oneplus.bot.custom.moderation.config.ModerationCustomFeatureDefinition;
import dev.sheldan.oneplus.bot.custom.moderation.service.ModModeServiceBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
@Component
public class ModMode extends AbstractConditionableCommand {
@Autowired
private ModModeServiceBean modModeServiceBean;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
Boolean newState = (Boolean) commandContext.getParameters().getParameters().get(0);
return modModeServiceBean.setModModeTo(commandContext.getGuild(), newState)
.thenApply(unused -> CommandResult.fromSuccess());
}
@Override
public CommandConfiguration getConfiguration() {
Parameter newStateParameter = Parameter.builder().name("newState").templated(true).type(Boolean.class).build();
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("modMode")
.async(true)
.module(ModerationModuleDefinition.MODERATION)
.parameters(Collections.singletonList(newStateParameter))
.help(helpInfo)
.templated(true)
.supportsEmbedException(true)
.causesReaction(true)
.build();
}
@Override
public FeatureDefinition getFeature() {
return ModerationCustomFeatureDefinition.MODERATION_CUSTOM;
}
}

View File

@@ -0,0 +1,35 @@
package dev.sheldan.oneplus.bot.custom.moderation.config;
import dev.sheldan.abstracto.core.config.FeatureConfig;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.moderation.config.feature.ModerationFeatureConfig;
import dev.sheldan.oneplus.bot.custom.moderation.service.ModModeServiceBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
@Component
public class ModerationCustomFeature implements FeatureConfig {
@Autowired
private ModerationFeatureConfig moderationFeatureConfig;
@Override
public FeatureDefinition getFeature() {
return ModerationCustomFeatureDefinition.MODERATION_CUSTOM;
}
@Override
public List<FeatureConfig> getRequiredFeatures() {
return Arrays.asList(moderationFeatureConfig);
}
@Override
public List<String> getRequiredSystemConfigKeys() {
return Arrays.asList(ModModeServiceBean.MODMODE_ROLE_CONFIG_KEY,
ModModeServiceBean.MODMODE_CHANGED_ROLE_COLOR_CONFIG_KEY);
}
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.oneplus.bot.custom.moderation.config;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import lombok.Getter;
@Getter
public enum ModerationCustomFeatureDefinition implements FeatureDefinition {
MODERATION_CUSTOM("moderationCustom");
private String key;
ModerationCustomFeatureDefinition(String key) {
this.key = key;
}
}

View File

@@ -0,0 +1,10 @@
package dev.sheldan.oneplus.bot.custom.moderation.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource("classpath:moderation-custom.properties")
public class ModerationCustomProperties {
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.oneplus.bot.custom.moderation.exception;
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
public class ModRoleNotFoundException extends AbstractoTemplatableException {
@Override
public String getTemplateName() {
return "mod_role_not_found_exception";
}
@Override
public Object getTemplateModel() {
return new Object();
}
}

View File

@@ -0,0 +1,55 @@
package dev.sheldan.oneplus.bot.custom.moderation.service;
import dev.sheldan.abstracto.core.service.ConfigService;
import dev.sheldan.oneplus.bot.custom.moderation.exception.ModRoleNotFoundException;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.awt.*;
import java.util.concurrent.CompletableFuture;
@Component
@Slf4j
public class ModModeServiceBean {
public static final String MODMODE_ROLE_CONFIG_KEY = "modModeRoleId";
public static final String MODMODE_CHANGED_ROLE_COLOR_CONFIG_KEY = "modModeNewRoleColor";
@Autowired
private ConfigService configService;
public CompletableFuture<Void> setModModeTo(Guild guild, Boolean newState) {
if(Boolean.TRUE.equals(newState)) {
return enableModMode(guild);
} else {
return disableModMoe(guild);
}
}
private CompletableFuture<Void> enableModMode(Guild guild) {
Color colorToSet = getColorFromConfig(MODMODE_CHANGED_ROLE_COLOR_CONFIG_KEY, guild);
return setModRoleTo(guild, colorToSet);
}
private CompletableFuture<Void> disableModMoe(Guild guild) {
return setModRoleTo(guild, null);
}
private Color getColorFromConfig(String key, Guild guild) {
String colorString = configService.getStringValueOrConfigDefault(key, guild.getIdLong());
String[] parts = colorString.split(",");
return new Color(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
}
private CompletableFuture<Void> setModRoleTo(Guild guild, Color color) {
Long roleId = configService.getLongValue(MODMODE_ROLE_CONFIG_KEY, guild.getIdLong());
Role modRole = guild.getRoleById(roleId);
if(modRole != null) {
return modRole.getManager().setColor(color).submit();
} else {
throw new ModRoleNotFoundException();
}
}
}

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

View File

@@ -0,0 +1,18 @@
<?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="moderationCustomFeature" value="(SELECT id FROM feature WHERE key = 'moderationCustom')"/>
<property name="moderationModule" value="(SELECT id FROM module WHERE name = 'moderation')"/>
<changeSet author="Sheldan" id="moderationCustom_modmode-commands">
<insert tableName="command">
<column name="name" value="modMode"/>
<column name="module_id" valueComputed="${moderationModule}"/>
<column name="feature_id" valueComputed="${moderationCustomFeature}"/>
</insert>
</changeSet>
</databaseChangeLog>

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="feature.xml" relativeToChangelogFile="true"/>
<include file="command.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="moderation_custom_feature-insertion">
<insert tableName="feature">
<column name="key" value="moderationCustom"/>
</insert>
</changeSet>
</databaseChangeLog>

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

View File

@@ -0,0 +1,8 @@
abstracto.featureFlags.moderationCustom.featureName=moderationCustom
abstracto.featureFlags.moderationCustom.enabled=false
abstracto.systemConfigs.modModeRoleId.name=modModeRoleId
abstracto.systemConfigs.modModeRoleId.longValue=0
abstracto.systemConfigs.modModeNewRoleColor.name=modModeNewRoleColor
abstracto.systemConfigs.modModeNewRoleColor.stringValue=0,0,0

View File

@@ -14,5 +14,6 @@
<modules>
<module>starboard-custom</module>
<module>dynamic-activity-custom</module>
<module>moderation-custom</module>
</modules>
</project>

View File

@@ -26,4 +26,4 @@ PGADMIN_DEFAULT_EMAIL=sheldan@sheldan.dev
PGADMIN_DEFAULT_PASSWORD=admin
TOKEN=<INSERT TOKEN>
YOUTUBE_API_KEY=<INSERT KEY>
ONEPLUS_BOT_VERSION=1.5.1
ONEPLUS_BOT_VERSION=1.5.2

View File

@@ -73,6 +73,16 @@
<destFileName>assignable-roles.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>dev.sheldan.abstracto-templates.templates</groupId>
<artifactId>anti-raid</artifactId>
<version>${abstracto.templates.version}</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>${file.basedir}/deployment/template-artifacts/</outputDirectory>
<destFileName>anti-raid.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>dev.sheldan.abstracto-templates.templates</groupId>
<artifactId>voice-channel-context</artifactId>
@@ -282,6 +292,16 @@
<destFileName>assignable-roles.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>dev.sheldan.abstracto-templates.translations</groupId>
<artifactId>anti-raid</artifactId>
<version>${abstracto.templates.version}</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>${file.basedir}/deployment/translation-artifacts/</outputDirectory>
<destFileName>anti-raid.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>dev.sheldan.abstracto-templates.translations</groupId>
<artifactId>voice-channel-context</artifactId>
@@ -442,6 +462,16 @@
<destFileName>starboard-custom.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>dev.sheldan.oneplus.bot.templates.translations</groupId>
<artifactId>moderation-custom</artifactId>
<version>${project.version}</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>${file.basedir}/deployment/translation-artifacts/</outputDirectory>
<destFileName>moderation-custom.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>dev.sheldan.oneplus.bot.templates.translations</groupId>
<artifactId>dynamic-activity-custom-translations</artifactId>
@@ -527,6 +557,17 @@
<destFileName>assignable-roles.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>anti-raid-impl</artifactId>
<version>${abstracto.version}</version>
<classifier>liquibase</classifier>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>${file.basedir}/deployment/liquibase-artifacts/</outputDirectory>
<destFileName>anti-raid.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>voice-channel-context-impl</artifactId>
@@ -727,6 +768,17 @@
<destFileName>starboard-custom.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>dev.sheldan.oneplus.bot.application.custom</groupId>
<artifactId>moderation-custom</artifactId>
<version>${project.version}</version>
<classifier>liquibase</classifier>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>${file.basedir}/deployment/liquibase-artifacts/</outputDirectory>
<destFileName>moderation-custom.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>dev.sheldan.oneplus.bot.application.custom</groupId>
<artifactId>dynamic-activity-custom</artifactId>

View File

@@ -1,15 +1,15 @@
{
"template_artifacts": ["utility", "core", "entertainment", "starboard", "link-embed", "webservices", "remind", "logging",
"suggestion", "invite-filter", "profanity-filter", "statistic", "experience-tracking", "moderation", "modmail", "assignable-roles",
"voice-channel-context",
"voice-channel-context", "anti-raid",
"starboard-custom",
"overrides-templates-webservices", "overrides-templates-core", "overrides-templates-logging", "overrides-templates-statistic",
"overrides-templates-modmail", "overrides-templates-moderation",
"news", "referral", "faq"],
"translation_artifacts": ["utility", "core", "entertainment", "starboard", "link-embed", "webservices", "suggestion",
"remind", "logging", "invite-filter", "profanity-filter", "statistic", "experience-tracking", "moderation", "modmail", "assignable-roles",
"voice-channel-context",
"starboard-custom", "dynamic-activity-custom-translations",
"voice-channel-context", "anti-raid",
"starboard-custom", "dynamic-activity-custom-translations", "moderation-custom",
"overrides-translation-moderation",
"news", "setup", "referral", "faq"],
"liquibase_artifacts": [
@@ -31,10 +31,12 @@
{ "zip": "modmail", "file": "modMail-changeLog.xml"},
{ "zip": "assignable-roles", "file": "assignableRoles-changeLog.xml"},
{ "zip": "voice-channel-context", "file": "voiceChannelContext-changeLog.xml"},
{ "zip": "anti-raid", "file": "antiRaid-changeLog.xml"},
{ "zip": "dynamic-activity", "file": "dynamicActivity-changeLog.xml"},
{ "zip": "setup", "file": "setup-changeLog.xml"},
{ "zip": "referral", "file": "referral-changeLog.xml"},
{ "zip": "starboard-custom", "file": "starboard-custom-changeLog.xml"},
{ "zip": "moderation-custom", "file": "moderation-custom-changeLog.xml"},
{ "zip": "dynamic-activity-custom", "file": "dynamicActivity-custom-changeLog.xml"},
{ "zip": "news", "file": "news-changeLog.xml"},
{ "zip": "faq", "file": "faq-changeLog.xml"}

View File

@@ -19,8 +19,8 @@
<maven.compiler.source>1.8</maven.compiler.source>
<!-- edit in release.yml as well -->
<!-- when releasing a new opbot version, update the .env as well-->
<abstracto.version>1.3.2</abstracto.version>
<abstracto.templates.version>1.2.15</abstracto.templates.version>
<abstracto.version>1.3.3-SNAPSHOT</abstracto.version>
<abstracto.templates.version>1.2.16-SNAPSHOT</abstracto.templates.version>
</properties>
<modules>

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>translations</artifactId>
<groupId>dev.sheldan.oneplus.bot.templates.translations</groupId>
<version>1.5.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>moderation-custom</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>moderation-custom-translations-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,15 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>zip</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<outputDirectory>.</outputDirectory>
<directory>${project.basedir}/src/main/resources</directory>
</fileSet>
</fileSets>
</assembly>

View File

@@ -0,0 +1 @@
Switches the moderation role to a different color

View File

@@ -0,0 +1 @@
The color the moderation role should take when mod mode is active. Default: ${defaultValue}

View File

@@ -0,0 +1 @@
The ID of the moderation role. Default: ${defaultValue}

View File

@@ -0,0 +1 @@
Moderation role was not configured correctly. Role could not be found. Setup the feature.

View File

@@ -17,5 +17,6 @@
<module>referral-translations</module>
<module>faq-translations</module>
<module>dynamic-activity-custom-translations</module>
<module>moderation-custom</module>
</modules>
</project>