[AB-64] adding voice context channel feature

This commit is contained in:
Sheldan
2021-07-12 00:56:15 +02:00
parent 7e7591a4b3
commit c7514a6bad
40 changed files with 2327 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
<?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.3.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>voice-channel-context</artifactId>
<packaging>pom</packaging>
<modules>
<module>voice-channel-context-int</module>
<module>voice-channel-context-impl</module>
</modules>
<dependencies>
<dependency>
<groupId>dev.sheldan.abstracto.core</groupId>
<artifactId>core-int</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>voice-channel-context</artifactId>
<version>1.3.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>voice-channel-context-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>voice-channel-context-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>
</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

@@ -0,0 +1,57 @@
package dev.sheldan.abstracto.vccontext.command;
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
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.vccontext.config.VoiceChannelContextFeatureDefinition;
import dev.sheldan.abstracto.vccontext.service.VoiceChannelContextService;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.VoiceChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
@Component
public class CreateVoiceChannelContext extends AbstractConditionableCommand {
@Autowired
private VoiceChannelContextService voiceChannelContextService;
@Override
public CommandResult execute(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
VoiceChannel channel = (VoiceChannel) parameters.get(0);
Role role = (Role) parameters.get(1);
voiceChannelContextService.createVoiceChannelContext(channel, role);
return CommandResult.fromSuccess();
}
@Override
public CommandConfiguration getConfiguration() {
Parameter voiceChannel = Parameter.builder().name("voiceChannel").type(VoiceChannel.class).templated(true).build();
Parameter contextRole = Parameter.builder().name("role").type(Role.class).templated(true).build();
List<Parameter> parameters = Arrays.asList(voiceChannel, contextRole);
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("createVoiceChannelContext")
.module(UtilityModuleDefinition.UTILITY)
.templated(true)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
.help(helpInfo)
.build();
}
@Override
public FeatureDefinition getFeature() {
return VoiceChannelContextFeatureDefinition.VOICE_CHANNEL_CONTEXT;
}
}

View File

@@ -0,0 +1,59 @@
package dev.sheldan.abstracto.vccontext.command;
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
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.core.models.database.AChannel;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.vccontext.config.VoiceChannelContextFeatureDefinition;
import dev.sheldan.abstracto.vccontext.service.VoiceChannelContextService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
@Component
public class DeleteVoiceChannelContext extends AbstractConditionableCommand {
@Autowired
private VoiceChannelContextService voiceChannelContextService;
@Autowired
private ChannelManagementService channelManagementService;
@Override
public CommandResult execute(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
AChannel channel = (AChannel) parameters.get(0);
AChannel actualChannel = channelManagementService.loadChannel(channel.getId());
voiceChannelContextService.deleteVoiceChannelContext(actualChannel);
return CommandResult.fromSuccess();
}
@Override
public CommandConfiguration getConfiguration() {
Parameter voiceChannel = Parameter.builder().name("channel").type(AChannel.class).templated(true).build();
List<Parameter> parameters = Arrays.asList(voiceChannel);
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("deleteVoiceChannelContext")
.module(UtilityModuleDefinition.UTILITY)
.templated(true)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
.help(helpInfo)
.build();
}
@Override
public FeatureDefinition getFeature() {
return VoiceChannelContextFeatureDefinition.VOICE_CHANNEL_CONTEXT;
}
}

View File

@@ -0,0 +1,10 @@
package dev.sheldan.abstracto.vccontext.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource("classpath:voice-channel-context-config.properties")
public class VoiceChannelContextConfig {
}

View File

@@ -0,0 +1,56 @@
package dev.sheldan.abstracto.vccontext.listener;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
import dev.sheldan.abstracto.core.listener.async.jda.AsyncVoiceChannelJoinedListener;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.listener.VoiceChannelJoinedModel;
import dev.sheldan.abstracto.core.service.RoleService;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.vccontext.config.VoiceChannelContextFeatureDefinition;
import dev.sheldan.abstracto.vccontext.model.VoiceChannelContext;
import dev.sheldan.abstracto.vccontext.service.management.VoiceChannelContextManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
@Slf4j
public class VoiceChannelContextJoinedListener implements AsyncVoiceChannelJoinedListener {
@Autowired
private VoiceChannelContextManagementService voiceChannelContextManagementService;
@Autowired
private ChannelManagementService channelManagementService;
@Autowired
private RoleService roleService;
@Override
public DefaultListenerResult execute(VoiceChannelJoinedModel model) {
log.info("Member {} joined voice channel {}.", model.getMember().getIdLong(), model.getChannel().getIdLong());
AChannel aChannel = channelManagementService.loadChannel(model.getChannel().getIdLong());
Optional<VoiceChannelContext> voiceChannelContextOptional = voiceChannelContextManagementService.getVoiceChannelContextForChannel(aChannel);
if(voiceChannelContextOptional.isPresent()) {
VoiceChannelContext context = voiceChannelContextOptional.get();
log.info("Channel {} is a voice channel with context - applying role {}.", aChannel.getId(), context.getRole().getId());
Long roleId = context.getRole().getId();
roleService.addRoleToMemberAsync(model.getMember(), context.getRole())
.thenAccept(unused -> log.info("Successfully applied role {} to member {} for channel {}.", roleId, model.getMember().getId(), model.getChannel().getId()))
.exceptionally(throwable -> {
log.error("Failed to apply role {} to member {} for channel {}.", roleId, model.getMember().getId(), model.getChannel().getId(), throwable);
return null;
});
return DefaultListenerResult.PROCESSED;
}
return DefaultListenerResult.IGNORED;
}
@Override
public FeatureDefinition getFeature() {
return VoiceChannelContextFeatureDefinition.VOICE_CHANNEL_CONTEXT;
}
}

View File

@@ -0,0 +1,56 @@
package dev.sheldan.abstracto.vccontext.listener;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
import dev.sheldan.abstracto.core.listener.async.jda.AsyncVoiceChannelLeftListener;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.listener.VoiceChannelLeftModel;
import dev.sheldan.abstracto.core.service.RoleService;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.vccontext.config.VoiceChannelContextFeatureDefinition;
import dev.sheldan.abstracto.vccontext.model.VoiceChannelContext;
import dev.sheldan.abstracto.vccontext.service.management.VoiceChannelContextManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
@Slf4j
public class VoiceChannelContextLeftListener implements AsyncVoiceChannelLeftListener {
@Autowired
private VoiceChannelContextManagementService voiceChannelContextManagementService;
@Autowired
private ChannelManagementService channelManagementService;
@Autowired
private RoleService roleService;
@Override
public DefaultListenerResult execute(VoiceChannelLeftModel model) {
log.info("Member {} left voice channel {}.", model.getMember().getIdLong(), model.getChannel().getIdLong());
AChannel aChannel = channelManagementService.loadChannel(model.getChannel().getIdLong());
Optional<VoiceChannelContext> voiceChannelContextOptional = voiceChannelContextManagementService.getVoiceChannelContextForChannel(aChannel);
if(voiceChannelContextOptional.isPresent()) {
VoiceChannelContext context = voiceChannelContextOptional.get();
log.info("Channel {} is a voice channel with context - removing role {}.", aChannel.getId(), context.getRole().getId());
Long roleId = context.getRole().getId();
roleService.removeRoleFromMemberAsync(model.getMember(), context.getRole())
.thenAccept(unused -> log.info("Successfully removed role {} from member {} for channel {}.", roleId, model.getMember().getId(), model.getChannel().getId()))
.exceptionally(throwable -> {
log.error("Failed to remove role {} from member {} for channel {}.", roleId, model.getMember().getId(), model.getChannel().getId(), throwable);
return null;
});
return DefaultListenerResult.PROCESSED;
}
return DefaultListenerResult.IGNORED;
}
@Override
public FeatureDefinition getFeature() {
return VoiceChannelContextFeatureDefinition.VOICE_CHANNEL_CONTEXT;
}
}

View File

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

View File

@@ -0,0 +1,48 @@
package dev.sheldan.abstracto.vccontext.service;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
import dev.sheldan.abstracto.vccontext.exception.VoiceChannelContextAlreadyExistsException;
import dev.sheldan.abstracto.vccontext.exception.VoiceChannelContextNotExistsException;
import dev.sheldan.abstracto.vccontext.model.VoiceChannelContext;
import dev.sheldan.abstracto.vccontext.service.management.VoiceChannelContextManagementService;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.VoiceChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public class VoiceChannelContextServiceBean implements VoiceChannelContextService {
@Autowired
private VoiceChannelContextManagementService voiceChannelContextManagementService;
@Autowired
private ChannelManagementService channelManagementService;
@Autowired
private RoleManagementService roleManagementService;
@Override
public VoiceChannelContext createVoiceChannelContext(VoiceChannel voiceChannel, Role role) {
AChannel channel = channelManagementService.loadChannel(voiceChannel.getIdLong());
if(voiceChannelContextManagementService.getVoiceChannelContextForChannel(channel).isPresent()) {
throw new VoiceChannelContextAlreadyExistsException();
}
ARole arole = roleManagementService.findRole(role.getIdLong());
return voiceChannelContextManagementService.createVoiceChannelContext(channel, arole);
}
@Override
public void deleteVoiceChannelContext(AChannel channel) {
Optional<VoiceChannelContext> ctxOptional = voiceChannelContextManagementService.getVoiceChannelContextForChannel(channel);
if(!ctxOptional.isPresent()) {
throw new VoiceChannelContextNotExistsException();
}
ctxOptional.ifPresent(context -> voiceChannelContextManagementService.deleteVoiceChannelContext(context));
}
}

View File

@@ -0,0 +1,43 @@
package dev.sheldan.abstracto.vccontext.service.management;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.vccontext.model.VoiceChannelContext;
import dev.sheldan.abstracto.vccontext.repository.VoiceChannelContextRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public class VoiceChannelContextManagementServiceBean implements VoiceChannelContextManagementService {
@Autowired
private VoiceChannelContextRepository repository;
@Override
public VoiceChannelContext createVoiceChannelContext(AChannel channel, ARole role) {
VoiceChannelContext context = VoiceChannelContext
.builder()
.id(channel.getId())
.role(role)
.channel(channel)
.build();
return repository.save(context);
}
@Override
public void deleteVoiceChannelContext(AChannel channel) {
repository.deleteById(channel.getId());
}
@Override
public void deleteVoiceChannelContext(VoiceChannelContext context) {
repository.delete(context);
}
@Override
public Optional<VoiceChannelContext> getVoiceChannelContextForChannel(AChannel channel) {
return repository.findById(channel.getId());
}
}

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

View File

@@ -0,0 +1,25 @@
<?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="utilityModule" value="(SELECT id FROM module WHERE name = 'utility')"/>
<property name="voiceChannelContextFeature" value="(SELECT id FROM feature WHERE key = 'voiceChannelContext')"/>
<changeSet author="Sheldan" id="voiceChannelContext-commands">
<insert tableName="command">
<column name="name" value="createVoiceChannelContext"/>
<column name="module_id" valueComputed="${utilityModule}"/>
<column name="feature_id" valueComputed="${voiceChannelContextFeature}"/>
</insert>
<insert tableName="command">
<column name="name" value="deleteVoiceChannelContext"/>
<column name="module_id" valueComputed="${utilityModule}"/>
<column name="feature_id" valueComputed="${voiceChannelContextFeature}"/>
</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="voice_channel_context_feature-insertion">
<insert tableName="feature">
<column name="key" value="voiceChannelContext"/>
</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="voice_channel_context.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -0,0 +1,31 @@
<?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="voice_channel_context-table">
<createTable tableName="voice_channel_context">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="voice_channel_context_pkey"/>
</column>
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
<constraints nullable="false"/>
</column>
<column name="role_id" type="BIGINT">
<constraints nullable="false" />
</column>
</createTable>
<addForeignKeyConstraint baseColumnNames="id" baseTableName="voice_channel_context" constraintName="fk_voice_channel_context_channel" deferrable="false"
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="channel" validate="true"/>
<addForeignKeyConstraint baseColumnNames="role_id" baseTableName="voice_channel_context" constraintName="fk_voice_channel_context_role" deferrable="false"
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id"
referencedTableName="role" validate="true"/>
<sql>
DROP TRIGGER IF EXISTS voice_channel_context_insert_trigger ON voice_channel_context;
CREATE TRIGGER voice_channel_context_insert_trigger BEFORE INSERT ON voice_channel_context FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
</sql>
</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.3.1/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -0,0 +1,2 @@
abstracto.featureFlags.voiceChannelContext.featureName=voiceChannelContext
abstracto.featureFlags.voiceChannelContext.enabled=false

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>dev.sheldan.abstracto.modules</groupId>
<artifactId>voice-channel-context</artifactId>
<version>1.3.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>voice-channel-context-int</artifactId>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.vccontext.config;
import dev.sheldan.abstracto.core.config.FeatureConfig;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import org.springframework.stereotype.Component;
@Component
public class VoiceChannelContextFeatureConfig implements FeatureConfig {
@Override
public FeatureDefinition getFeature() {
return VoiceChannelContextFeatureDefinition.VOICE_CHANNEL_CONTEXT;
}
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.vccontext.config;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import lombok.Getter;
@Getter
public enum VoiceChannelContextFeatureDefinition implements FeatureDefinition {
VOICE_CHANNEL_CONTEXT("voiceChannelContext");
private String key;
VoiceChannelContextFeatureDefinition(String key) {
this.key = key;
}
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.vccontext.exception;
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
public class VoiceChannelContextAlreadyExistsException extends AbstractoTemplatableException {
@Override
public String getTemplateName() {
return "voice_channel_context_already_exists_exception";
}
@Override
public Object getTemplateModel() {
return new Object();
}
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.vccontext.exception;
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
public class VoiceChannelContextNotExistsException extends AbstractoTemplatableException {
@Override
public String getTemplateName() {
return "voice_channel_context_not_exists_exception";
}
@Override
public Object getTemplateModel() {
return new Object();
}
}

View File

@@ -0,0 +1,32 @@
package dev.sheldan.abstracto.vccontext.model;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.ARole;
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Table(name="voice_channel_context")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@EqualsAndHashCode
public class VoiceChannelContext implements Serializable {
@Id
@Column(name = "id", nullable = false)
private Long id;
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@PrimaryKeyJoinColumn
private AChannel channel;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_id", nullable = false)
private ARole role;
}

View File

@@ -0,0 +1,11 @@
package dev.sheldan.abstracto.vccontext.service;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.vccontext.model.VoiceChannelContext;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.VoiceChannel;
public interface VoiceChannelContextService {
VoiceChannelContext createVoiceChannelContext(VoiceChannel voiceChannel, Role role);
void deleteVoiceChannelContext(AChannel channel);
}

View File

@@ -0,0 +1,14 @@
package dev.sheldan.abstracto.vccontext.service.management;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.vccontext.model.VoiceChannelContext;
import java.util.Optional;
public interface VoiceChannelContextManagementService {
VoiceChannelContext createVoiceChannelContext(AChannel channel, ARole role);
void deleteVoiceChannelContext(AChannel channel);
void deleteVoiceChannelContext(VoiceChannelContext context);
Optional<VoiceChannelContext> getVoiceChannelContextForChannel(AChannel channel);
}