mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-16 04:21:49 +00:00
[AB-104] adding server wide member individual command cooldown and commands to set/reset this cooldown configuration on a command level
removing custom cooldown handling from payday and slots commands
This commit is contained in:
@@ -9,8 +9,6 @@ import dev.sheldan.abstracto.entertainment.dto.CreditGambleResult;
|
|||||||
import dev.sheldan.abstracto.entertainment.dto.PayDayResult;
|
import dev.sheldan.abstracto.entertainment.dto.PayDayResult;
|
||||||
import dev.sheldan.abstracto.entertainment.dto.SlotsResult;
|
import dev.sheldan.abstracto.entertainment.dto.SlotsResult;
|
||||||
import dev.sheldan.abstracto.entertainment.exception.NotEnoughCreditsException;
|
import dev.sheldan.abstracto.entertainment.exception.NotEnoughCreditsException;
|
||||||
import dev.sheldan.abstracto.entertainment.exception.PayDayCooldownException;
|
|
||||||
import dev.sheldan.abstracto.entertainment.exception.SlotsCooldownException;
|
|
||||||
import dev.sheldan.abstracto.entertainment.model.command.CreditsLeaderboardEntry;
|
import dev.sheldan.abstracto.entertainment.model.command.CreditsLeaderboardEntry;
|
||||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyLeaderboardResult;
|
import dev.sheldan.abstracto.entertainment.model.database.EconomyLeaderboardResult;
|
||||||
import dev.sheldan.abstracto.entertainment.model.database.EconomyUser;
|
import dev.sheldan.abstracto.entertainment.model.database.EconomyUser;
|
||||||
@@ -19,14 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static dev.sheldan.abstracto.entertainment.config.EconomyFeatureConfig.PAYDAY_COOLDOWN_CONFIG_KEY;
|
|
||||||
import static dev.sheldan.abstracto.entertainment.config.EconomyFeatureConfig.SLOTS_COOLDOWN_CONFIG_KEY;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class EconomyServiceBean implements EconomyService {
|
public class EconomyServiceBean implements EconomyService {
|
||||||
|
|
||||||
@@ -70,42 +62,6 @@ public class EconomyServiceBean implements EconomyService {
|
|||||||
private static final Integer TRIPLE_FACTOR = 10;
|
private static final Integer TRIPLE_FACTOR = 10;
|
||||||
private static final Integer DOUBLE_FACTOR = 2;
|
private static final Integer DOUBLE_FACTOR = 2;
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canTriggerPayDay(AUserInAServer aUserInAServer) {
|
|
||||||
Optional<EconomyUser> userOptional = economyUserManagementService.getUser(aUserInAServer);
|
|
||||||
return userOptional.map(this::canTriggerPayDay).orElse(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canTriggerSlots(AUserInAServer aUserInAServer) {
|
|
||||||
Optional<EconomyUser> userOptional = economyUserManagementService.getUser(aUserInAServer);
|
|
||||||
return userOptional.map(this::canTriggerSlots).orElse(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canTriggerPayDay(EconomyUser economyUser) {
|
|
||||||
return slotsTriggerIn(economyUser).isNegative();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canTriggerSlots(EconomyUser economyUser) {
|
|
||||||
return payDayTriggerIn(economyUser).isNegative();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Duration payDayTriggerIn(EconomyUser economyUser) {
|
|
||||||
Long cooldownSeconds = configService.getLongValueOrConfigDefault(PAYDAY_COOLDOWN_CONFIG_KEY, economyUser.getServer().getId());
|
|
||||||
Instant minTimeStamp = Instant.now().minus(cooldownSeconds, ChronoUnit.SECONDS);
|
|
||||||
return Duration.between(economyUser.getLastPayDay(), minTimeStamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Duration slotsTriggerIn(EconomyUser economyUser) {
|
|
||||||
Long cooldownSeconds = configService.getLongValueOrConfigDefault(SLOTS_COOLDOWN_CONFIG_KEY, economyUser.getServer().getId());
|
|
||||||
Instant minTimeStamp = Instant.now().minus(cooldownSeconds, ChronoUnit.SECONDS);
|
|
||||||
return Duration.between(economyUser.getLastSlots(), minTimeStamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EconomyUser addCredits(AUserInAServer aUserInAServer, Long credits) {
|
public EconomyUser addCredits(AUserInAServer aUserInAServer, Long credits) {
|
||||||
Optional<EconomyUser> existingUserOptional = economyUserManagementService.getUser(aUserInAServer);
|
Optional<EconomyUser> existingUserOptional = economyUserManagementService.getUser(aUserInAServer);
|
||||||
@@ -137,11 +93,6 @@ public class EconomyServiceBean implements EconomyService {
|
|||||||
Long creditsToAdd = configService.getLongValueOrConfigDefault(EconomyFeatureConfig.PAYDAY_CREDITS_CONFIG_KEY,
|
Long creditsToAdd = configService.getLongValueOrConfigDefault(EconomyFeatureConfig.PAYDAY_CREDITS_CONFIG_KEY,
|
||||||
aUserInAServer.getServerReference().getId());
|
aUserInAServer.getServerReference().getId());
|
||||||
EconomyUser economyUser = addCredits(aUserInAServer, creditsToAdd);
|
EconomyUser economyUser = addCredits(aUserInAServer, creditsToAdd);
|
||||||
Duration durationForPayday = payDayTriggerIn(economyUser);
|
|
||||||
if (durationForPayday.isNegative()) {
|
|
||||||
throw new PayDayCooldownException(durationForPayday.abs());
|
|
||||||
}
|
|
||||||
economyUser.setLastPayDay(Instant.now());
|
|
||||||
return PayDayResult
|
return PayDayResult
|
||||||
.builder()
|
.builder()
|
||||||
.currentCredits(economyUser.getCredits())
|
.currentCredits(economyUser.getCredits())
|
||||||
@@ -160,17 +111,12 @@ public class EconomyServiceBean implements EconomyService {
|
|||||||
if(user.getCredits() < bid) {
|
if(user.getCredits() < bid) {
|
||||||
throw new NotEnoughCreditsException();
|
throw new NotEnoughCreditsException();
|
||||||
}
|
}
|
||||||
Duration durationForSlots = slotsTriggerIn(user);
|
|
||||||
if (durationForSlots.isNegative()) {
|
|
||||||
throw new SlotsCooldownException(durationForSlots.abs());
|
|
||||||
}
|
|
||||||
SlotGame slotGame = playSlots();
|
SlotGame slotGame = playSlots();
|
||||||
Integer factor = slotGame.getResultFactor();
|
Integer factor = slotGame.getResultFactor();
|
||||||
Long creditChange = bid * factor;
|
Long creditChange = bid * factor;
|
||||||
addCredits(user, -bid);
|
addCredits(user, -bid);
|
||||||
addCredits(user, creditChange);
|
addCredits(user, creditChange);
|
||||||
|
|
||||||
user.setLastSlots(Instant.now());
|
|
||||||
return SlotsResult
|
return SlotsResult
|
||||||
.builder()
|
.builder()
|
||||||
.bid(bid)
|
.bid(bid)
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ public class EconomyUserManagementServiceBean implements EconomyUserManagementSe
|
|||||||
.builder()
|
.builder()
|
||||||
.id(aUserInAServer.getUserInServerId())
|
.id(aUserInAServer.getUserInServerId())
|
||||||
.server(aUserInAServer.getServerReference())
|
.server(aUserInAServer.getServerReference())
|
||||||
.lastPayDay(Instant.now().minus(1, ChronoUnit.DAYS))
|
|
||||||
.lastSlots(Instant.now().minus(1, ChronoUnit.DAYS))
|
|
||||||
.credits(0L)
|
.credits(0L)
|
||||||
.user(aUserInAServer)
|
.user(aUserInAServer)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -10,13 +10,6 @@ abstracto.featureFlags.entertainment.enabled=false
|
|||||||
abstracto.systemConfigs.paydayCredits.name=paydayCredits
|
abstracto.systemConfigs.paydayCredits.name=paydayCredits
|
||||||
abstracto.systemConfigs.paydayCredits.longValue=120
|
abstracto.systemConfigs.paydayCredits.longValue=120
|
||||||
|
|
||||||
# maybe replace this by command cooldowns which are globally on the server, instead of only channel group based
|
|
||||||
abstracto.systemConfigs.paydayCooldown.name=paydayCooldown
|
|
||||||
abstracto.systemConfigs.paydayCooldown.longValue=300
|
|
||||||
|
|
||||||
abstracto.systemConfigs.slotsCooldown.name=slotsCooldown
|
|
||||||
abstracto.systemConfigs.slotsCooldown.longValue=30
|
|
||||||
|
|
||||||
abstracto.featureFlags.economy.featureName=economy
|
abstracto.featureFlags.economy.featureName=economy
|
||||||
abstracto.featureFlags.economy.enabled=false
|
abstracto.featureFlags.economy.enabled=false
|
||||||
|
|
||||||
|
|||||||
@@ -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="system_config.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="economy_user.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?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="economy_user-delete-cooldown-columns">
|
||||||
|
<dropColumn tableName="economy_user">
|
||||||
|
<column name="last_pay_day" />
|
||||||
|
<column name="last_slots" />
|
||||||
|
</dropColumn>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -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="economy_cooldown-system-config-deletions">
|
||||||
|
<delete tableName="system_config">
|
||||||
|
<where>name='paydayCooldown'</where>
|
||||||
|
</delete>
|
||||||
|
<delete tableName="system_config">
|
||||||
|
<where>name='slotsCooldown'</where>
|
||||||
|
</delete>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -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="cleanup/deletions.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -12,4 +12,5 @@
|
|||||||
<include file="1.4.0/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.4.0/collection.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="1.4.3/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.4.3/collection.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="1.4.11/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.4.11/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="1.5.8/collection.xml" relativeToChangelogFile="true"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
@@ -11,8 +11,6 @@ import java.util.List;
|
|||||||
public class EconomyFeatureConfig implements FeatureConfig {
|
public class EconomyFeatureConfig implements FeatureConfig {
|
||||||
|
|
||||||
public static final String PAYDAY_CREDITS_CONFIG_KEY = "paydayCredits";
|
public static final String PAYDAY_CREDITS_CONFIG_KEY = "paydayCredits";
|
||||||
public static final String PAYDAY_COOLDOWN_CONFIG_KEY = "paydayCooldown";
|
|
||||||
public static final String SLOTS_COOLDOWN_CONFIG_KEY = "slotsCooldown";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FeatureDefinition getFeature() {
|
public FeatureDefinition getFeature() {
|
||||||
@@ -21,6 +19,6 @@ public class EconomyFeatureConfig implements FeatureConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getRequiredSystemConfigKeys() {
|
public List<String> getRequiredSystemConfigKeys() {
|
||||||
return Arrays.asList(PAYDAY_CREDITS_CONFIG_KEY, PAYDAY_COOLDOWN_CONFIG_KEY, SLOTS_COOLDOWN_CONFIG_KEY);
|
return Arrays.asList(PAYDAY_CREDITS_CONFIG_KEY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package dev.sheldan.abstracto.entertainment.exception;
|
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
|
|
||||||
import dev.sheldan.abstracto.entertainment.model.exception.PayDayCooldownExceptionModel;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
public class PayDayCooldownException extends AbstractoTemplatableException {
|
|
||||||
|
|
||||||
private final PayDayCooldownExceptionModel model;
|
|
||||||
|
|
||||||
public PayDayCooldownException(Duration duration) {
|
|
||||||
this.model = PayDayCooldownExceptionModel
|
|
||||||
.builder()
|
|
||||||
.tryAgainDuration(duration)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTemplateName() {
|
|
||||||
return "payday_cooldown_exception";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getTemplateModel() {
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package dev.sheldan.abstracto.entertainment.exception;
|
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
|
|
||||||
import dev.sheldan.abstracto.entertainment.model.exception.SlotsCooldownExceptionModel;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
public class SlotsCooldownException extends AbstractoTemplatableException {
|
|
||||||
|
|
||||||
private final SlotsCooldownExceptionModel model;
|
|
||||||
|
|
||||||
public SlotsCooldownException(Duration duration) {
|
|
||||||
this.model = SlotsCooldownExceptionModel
|
|
||||||
.builder()
|
|
||||||
.tryAgainDuration(duration)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTemplateName() {
|
|
||||||
return "slots_cooldown_exception";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getTemplateModel() {
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -33,12 +33,6 @@ public class EconomyUser implements Serializable {
|
|||||||
@Column(name = "credits", nullable = false)
|
@Column(name = "credits", nullable = false)
|
||||||
private Long credits;
|
private Long credits;
|
||||||
|
|
||||||
@Column(name = "last_slots", nullable = false)
|
|
||||||
private Instant lastSlots;
|
|
||||||
|
|
||||||
@Column(name = "last_pay_day", nullable = false)
|
|
||||||
private Instant lastPayDay;
|
|
||||||
|
|
||||||
@Column(name = "created", nullable = false, insertable = false, updatable = false)
|
@Column(name = "created", nullable = false, insertable = false, updatable = false)
|
||||||
private Instant created;
|
private Instant created;
|
||||||
|
|
||||||
|
|||||||
@@ -10,16 +10,9 @@ import dev.sheldan.abstracto.entertainment.model.database.EconomyUser;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface EconomyService {
|
public interface EconomyService {
|
||||||
boolean canTriggerPayDay(AUserInAServer aUserInAServer);
|
|
||||||
boolean canTriggerSlots(AUserInAServer aUserInAServer);
|
|
||||||
boolean canTriggerPayDay(EconomyUser economyUser);
|
|
||||||
boolean canTriggerSlots(EconomyUser economyUser);
|
|
||||||
Duration payDayTriggerIn(EconomyUser economyUser);
|
|
||||||
Duration slotsTriggerIn(EconomyUser economyUser);
|
|
||||||
EconomyUser addCredits(AUserInAServer aUserInAServer, Long credits);
|
EconomyUser addCredits(AUserInAServer aUserInAServer, Long credits);
|
||||||
void addCredits(EconomyUser economyUser, Long credits);
|
void addCredits(EconomyUser economyUser, Long credits);
|
||||||
void addPayDayCredits(AUserInAServer aUserInAServer);
|
void addPayDayCredits(AUserInAServer aUserInAServer);
|
||||||
|
|||||||
@@ -241,7 +241,13 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
|
|||||||
durationInSeconds = Math.max(durationInSeconds, channelGroup.getMemberCoolDown());
|
durationInSeconds = Math.max(durationInSeconds, channelGroup.getMemberCoolDown());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Duration.ofSeconds(durationInSeconds);
|
if(durationInSeconds > 0) {
|
||||||
|
return Duration.ofSeconds(durationInSeconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ACommandInAServer commandInServer = commandInServerManagementService.getCommandForServer(aCommand, serverIdChannelId.getServerId());
|
||||||
|
if(commandInServer.getMemberCooldown() != null) {
|
||||||
|
return commandInServer.getMemberCooldown();
|
||||||
}
|
}
|
||||||
if(commandConfiguration.getCoolDownConfig() != null) {
|
if(commandConfiguration.getCoolDownConfig() != null) {
|
||||||
return commandConfiguration.getCoolDownConfig().getMemberCoolDown();
|
return commandConfiguration.getCoolDownConfig().getMemberCoolDown();
|
||||||
@@ -261,7 +267,7 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Duration coolDown = getServerCoolDownForCommand(command, serverId);
|
Duration coolDown = getServerCoolDownForCommand(command, serverId);
|
||||||
if(coolDown.equals(Duration.ZERO)) {
|
if(Duration.ZERO.equals(coolDown) || coolDown == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("Updating cooldowns for command {} in server {}.", command.getConfiguration().getName(), serverId);
|
log.info("Updating cooldowns for command {} in server {}.", command.getConfiguration().getName(), serverId);
|
||||||
@@ -288,7 +294,7 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Duration coolDown = getChannelGroupCoolDownForCommand(command, serverIdChannelId);
|
Duration coolDown = getChannelGroupCoolDownForCommand(command, serverIdChannelId);
|
||||||
if(coolDown.equals(Duration.ZERO)) {
|
if(Duration.ZERO.equals(coolDown) || coolDown == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("Updating cooldowns for command {} in server {} in channel {}.",
|
log.info("Updating cooldowns for command {} in server {} in channel {}.",
|
||||||
@@ -358,7 +364,7 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Duration coolDown = getMemberCoolDownForCommand(command, serverChannelUserId.toServerChannelId());
|
Duration coolDown = getMemberCoolDownForCommand(command, serverChannelUserId.toServerChannelId());
|
||||||
if(coolDown.equals(Duration.ZERO)) {
|
if(Duration.ZERO.equals(coolDown) || coolDown == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("Updating cooldowns for command {} in server {} in channel {} for user {}.",
|
log.info("Updating cooldowns for command {} in server {} in channel {} for user {}.",
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
|||||||
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
import dev.sheldan.abstracto.core.command.model.database.AModule;
|
import dev.sheldan.abstracto.core.command.model.database.AModule;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandRegistry;
|
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||||
@@ -33,6 +31,7 @@ import dev.sheldan.abstracto.core.utils.CompletableFutureList;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
@@ -40,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -209,6 +209,12 @@ public class CommandServiceBean implements CommandService {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setServerCooldownTo(String commandName, Guild guild, Duration duration) {
|
||||||
|
ACommand aCommand = commandManagementService.findCommandByName(commandName);
|
||||||
|
commandInServerManagementService.getCommandForServer(aCommand, guild.getIdLong()).setMemberCooldown(duration);
|
||||||
|
}
|
||||||
|
|
||||||
private CompletableFuture<ConditionResult> checkConditions(SlashCommandInteractionEvent slashCommandInteractionEvent, Command command, List<CommandCondition> conditions) {
|
private CompletableFuture<ConditionResult> checkConditions(SlashCommandInteractionEvent slashCommandInteractionEvent, Command command, List<CommandCondition> conditions) {
|
||||||
if(conditions != null && !conditions.isEmpty()) {
|
if(conditions != null && !conditions.isEmpty()) {
|
||||||
List<CompletableFuture<ConditionResult>> futures = new ArrayList<>();
|
List<CompletableFuture<ConditionResult>> futures = new ArrayList<>();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -47,6 +48,11 @@ public class CommandInServerManagementServiceBean implements CommandInServerMana
|
|||||||
return repository.findByServerReferenceAndCommandReference(server, command).orElseThrow(CommandNotFoundException::new);
|
return repository.findByServerReferenceAndCommandReference(server, command).orElseThrow(CommandNotFoundException::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCooldownForCommandInServer(ACommand command, AServer server, Duration duration) {
|
||||||
|
getCommandForServer(command, server).setMemberCooldown(duration);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ACommandInAServer getCommandForServer(ACommand command, Long serverId) {
|
public ACommandInAServer getCommandForServer(ACommand command, Long serverId) {
|
||||||
return repository.findByServerReference_IdAndCommandReference(serverId, command);
|
return repository.findByServerReference_IdAndCommandReference(serverId, command);
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package dev.sheldan.abstracto.core.commands.config.cooldown;
|
||||||
|
|
||||||
|
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.config.features.CoreFeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||||
|
import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RemoveCommandMemberCooldown extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
private static final String REMOVE_COMMAND_MEMBER_COOLDOWN_COMMAND = "removeCommandMemberCooldown";
|
||||||
|
private static final String COMMAND_NAME_PARAMETER = "commandName";
|
||||||
|
private static final String REMOVE_COMMAND_MEMBER_COOLDOWN_RESPONSE_TEMPLATE_KEY = "removeCommandMemberCooldown_response";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SlashCommandParameterService slashCommandParameterService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandService commandService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
|
String commandName = slashCommandParameterService.getCommandOption(COMMAND_NAME_PARAMETER, event, String.class);
|
||||||
|
commandService.setServerCooldownTo(commandName, event.getGuild(), null);
|
||||||
|
return interactionService.replyEmbed(REMOVE_COMMAND_MEMBER_COOLDOWN_RESPONSE_TEMPLATE_KEY, event)
|
||||||
|
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandConfiguration getConfiguration() {
|
||||||
|
Parameter commandName = Parameter
|
||||||
|
.builder()
|
||||||
|
.name(COMMAND_NAME_PARAMETER)
|
||||||
|
.type(String.class)
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
List<Parameter> parameters = Arrays.asList(commandName);
|
||||||
|
HelpInfo helpInfo = HelpInfo
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||||
|
.builder()
|
||||||
|
.enabled(true)
|
||||||
|
.rootCommandName(CoreSlashCommandNames.COOLDOWN)
|
||||||
|
.groupName("commandMember")
|
||||||
|
.commandName("remove")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return CommandConfiguration.builder()
|
||||||
|
.name(REMOVE_COMMAND_MEMBER_COOLDOWN_COMMAND)
|
||||||
|
.module(ConfigModuleDefinition.CONFIG)
|
||||||
|
.parameters(parameters)
|
||||||
|
.slashCommandConfig(slashCommandConfig)
|
||||||
|
.templated(true)
|
||||||
|
.supportsEmbedException(true)
|
||||||
|
.help(helpInfo)
|
||||||
|
.causesReaction(true)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return CoreFeatureDefinition.CORE_FEATURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package dev.sheldan.abstracto.core.commands.config.cooldown;
|
||||||
|
|
||||||
|
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.config.features.CoreFeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||||
|
import dev.sheldan.abstracto.core.commands.config.ConfigModuleDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.CoreSlashCommandNames;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||||
|
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||||
|
import dev.sheldan.abstracto.core.utils.ParseUtils;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SetCommandMemberCooldown extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
private static final String SET_COMMAND_MEMBER_COOLDOWN = "setCommandMemberCooldown";
|
||||||
|
private static final String COMMAND_NAME_PARAMETER = "commandName";
|
||||||
|
private static final String COOLDOWN_DURATION_PARAMETER = "duration";
|
||||||
|
private static final String SET_COOLDOWN_MEMBER_RESPONSE_TEMPLATE_KEY = "setCommandMemberCooldown_response";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandService commandService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SlashCommandParameterService slashCommandParameterService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InteractionService interactionService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
|
String commandName = slashCommandParameterService.getCommandOption(COMMAND_NAME_PARAMETER, event, String.class);
|
||||||
|
String cooldownDurationString = slashCommandParameterService.getCommandOption(COOLDOWN_DURATION_PARAMETER, event, Duration.class, String.class);
|
||||||
|
Duration duration = ParseUtils.parseDuration(cooldownDurationString);
|
||||||
|
commandService.setServerCooldownTo(commandName, event.getGuild(), duration);
|
||||||
|
return interactionService.replyEmbed(SET_COOLDOWN_MEMBER_RESPONSE_TEMPLATE_KEY, event)
|
||||||
|
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandConfiguration getConfiguration() {
|
||||||
|
Parameter commandName = Parameter
|
||||||
|
.builder()
|
||||||
|
.name(COMMAND_NAME_PARAMETER)
|
||||||
|
.type(String.class)
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
Parameter cooldownDuration = Parameter
|
||||||
|
.builder()
|
||||||
|
.name(COOLDOWN_DURATION_PARAMETER)
|
||||||
|
.type(Duration.class)
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
List<Parameter> parameters = Arrays.asList(commandName, cooldownDuration);
|
||||||
|
HelpInfo helpInfo = HelpInfo
|
||||||
|
.builder()
|
||||||
|
.templated(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||||
|
.builder()
|
||||||
|
.enabled(true)
|
||||||
|
.rootCommandName(CoreSlashCommandNames.COOLDOWN)
|
||||||
|
.groupName("commandMember")
|
||||||
|
.commandName("set")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return CommandConfiguration.builder()
|
||||||
|
.name(SET_COMMAND_MEMBER_COOLDOWN)
|
||||||
|
.module(ConfigModuleDefinition.CONFIG)
|
||||||
|
.parameters(parameters)
|
||||||
|
.slashCommandConfig(slashCommandConfig)
|
||||||
|
.templated(true)
|
||||||
|
.supportsEmbedException(true)
|
||||||
|
.help(helpInfo)
|
||||||
|
.causesReaction(true)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return CoreFeatureDefinition.CORE_FEATURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?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="coreFeature" value="(SELECT id FROM feature WHERE key = 'core')"/>
|
||||||
|
<property name="configModule" value="(SELECT id FROM module WHERE name = 'config')"/>
|
||||||
|
<changeSet author="Sheldan" id="cooldown-command" >
|
||||||
|
<insert tableName="command">
|
||||||
|
<column name="name" value="setCommandMemberCooldown"/>
|
||||||
|
<column name="module_id" valueComputed="${configModule}"/>
|
||||||
|
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||||
|
</insert>
|
||||||
|
<insert tableName="command">
|
||||||
|
<column name="name" value="removeCommandMemberCooldown"/>
|
||||||
|
<column name="module_id" valueComputed="${configModule}"/>
|
||||||
|
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||||
|
</insert>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -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="command.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?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="command_in_server-add-server-member-cooldown">
|
||||||
|
<addColumn tableName="command_in_server" >
|
||||||
|
<column name="member_cooldown" type="BIGINT">
|
||||||
|
<constraints nullable="true" />
|
||||||
|
</column>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -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="command_in_server.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -24,4 +24,5 @@
|
|||||||
<include file="1.3.10/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.3.10/collection.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="1.3.13/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.3.13/collection.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="1.4.0/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.4.0/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="1.5.8/collection.xml" relativeToChangelogFile="true"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
@@ -6,6 +6,7 @@ import lombok.*;
|
|||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -51,6 +52,9 @@ public class ACommandInAServer implements Serializable {
|
|||||||
@Column(name = "slash_command_id")
|
@Column(name = "slash_command_id")
|
||||||
private Long slashCommandId;
|
private Long slashCommandId;
|
||||||
|
|
||||||
|
@Column(name = "member_cooldown")
|
||||||
|
private Duration memberCooldown;
|
||||||
|
|
||||||
@Column(name = "created", nullable = false, insertable = false, updatable = false)
|
@Column(name = "created", nullable = false, insertable = false, updatable = false)
|
||||||
private Instant created;
|
private Instant created;
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
|||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public interface CommandService {
|
public interface CommandService {
|
||||||
@@ -30,4 +32,5 @@ public interface CommandService {
|
|||||||
UnParsedCommandParameter getUnParsedCommandParameter(String messageContent, Message message);
|
UnParsedCommandParameter getUnParsedCommandParameter(String messageContent, Message message);
|
||||||
CompletableFuture<Parameters> getParametersForCommand(String commandName, Message messageContainingContent);
|
CompletableFuture<Parameters> getParametersForCommand(String commandName, Message messageContainingContent);
|
||||||
Parameter cloneParameter(Parameter parameter);
|
Parameter cloneParameter(Parameter parameter);
|
||||||
|
void setServerCooldownTo(String commandName, Guild guild, Duration duration);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
|||||||
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface CommandInServerManagementService {
|
public interface CommandInServerManagementService {
|
||||||
@@ -11,6 +12,7 @@ public interface CommandInServerManagementService {
|
|||||||
ACommandInAServer createCommandInServer(ACommand command, AServer server, Long commandId);
|
ACommandInAServer createCommandInServer(ACommand command, AServer server, Long commandId);
|
||||||
boolean doesCommandExistInServer(ACommand command, AServer server);
|
boolean doesCommandExistInServer(ACommand command, AServer server);
|
||||||
ACommandInAServer getCommandForServer(ACommand command, AServer server);
|
ACommandInAServer getCommandForServer(ACommand command, AServer server);
|
||||||
|
void setCooldownForCommandInServer(ACommand command, AServer server, Duration duration);
|
||||||
ACommandInAServer getCommandForServer(ACommand command, Long serverId);
|
ACommandInAServer getCommandForServer(ACommand command, Long serverId);
|
||||||
ACommandInAServer getCommandForServer(Long commandInServerId);
|
ACommandInAServer getCommandForServer(Long commandInServerId);
|
||||||
List<ACommandInAServer> getCommandsForServer(List<Long> commandInServerId);
|
List<ACommandInAServer> getCommandsForServer(List<Long> commandInServerId);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.core.interaction.slash;
|
|||||||
public class CoreSlashCommandNames {
|
public class CoreSlashCommandNames {
|
||||||
public static final String UTILITY = "utility";
|
public static final String UTILITY = "utility";
|
||||||
public static final String CONFIG = "config";
|
public static final String CONFIG = "config";
|
||||||
|
public static final String COOLDOWN = "cooldown";
|
||||||
public static final String FEATURE = "feature";
|
public static final String FEATURE = "feature";
|
||||||
public static final String CHANNELS = "channels";
|
public static final String CHANNELS = "channels";
|
||||||
public static final String POST_TARGET = "posttarget";
|
public static final String POST_TARGET = "posttarget";
|
||||||
|
|||||||
Reference in New Issue
Block a user