added experience tracking and automatic role assigning at given levels

includes: set role command to set a role to a given level (it clears out previous levels)
automatic level config generation on startup
min/max/multiplier configuration
job to persist the xp of the previous minute
added delayed scheduler start, so that events have a discord context in order to function
added role listener to automatically add and mark roles when they are created/deleted
fixed user in a server not being created correctly
added role service to give users role given by id
added server reference to role
This commit is contained in:
Sheldan
2020-04-11 17:21:55 +02:00
parent 87c97d5069
commit 6a31dfde8a
72 changed files with 1165 additions and 80 deletions

View File

@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.moderation.service;
import dev.sheldan.abstracto.core.exception.GuildException;
import dev.sheldan.abstracto.core.models.context.ServerContext;
import dev.sheldan.abstracto.core.service.Bot;
import dev.sheldan.abstracto.core.service.BotService;
import dev.sheldan.abstracto.core.service.PostTargetService;
import dev.sheldan.abstracto.templating.service.TemplateService;
import lombok.extern.slf4j.Slf4j;
@@ -21,7 +21,7 @@ public class BanServiceBean implements BanService {
private static final String BAN_ID_LOG_TEMPLATE = "banid_log";
private static final String BAN_LOG_TARGET = "banLog";
@Autowired
private Bot bot;
private BotService botService;
@Autowired
private TemplateService templateService;
@@ -44,7 +44,7 @@ public class BanServiceBean implements BanService {
}
private void banUser(Long guildId, Long userId, String reason) {
Optional<Guild> guildByIdOptional = bot.getGuildById(guildId);
Optional<Guild> guildByIdOptional = botService.getGuildById(guildId);
if(guildByIdOptional.isPresent()) {
log.info("Banning user {} in guild {}.", userId, guildId);
guildByIdOptional.get().ban(userId.toString(), 0, reason).queue();

View File

@@ -1,7 +1,7 @@
package dev.sheldan.abstracto.moderation.service;
import dev.sheldan.abstracto.core.exception.GuildException;
import dev.sheldan.abstracto.core.service.Bot;
import dev.sheldan.abstracto.core.service.BotService;
import dev.sheldan.abstracto.core.service.PostTargetService;
import dev.sheldan.abstracto.moderation.models.template.commands.KickLogModel;
import dev.sheldan.abstracto.templating.service.TemplateService;
@@ -20,7 +20,7 @@ public class KickServiceBean implements KickService {
private static final String KICK_LOG_TEMPLATE = "kick_log";
private static final String WARN_LOG_TARGET = "warnLog";
@Autowired
private Bot bot;
private BotService botService;
@Autowired
private TemplateService templateService;
@@ -30,7 +30,7 @@ public class KickServiceBean implements KickService {
@Override
public void kickMember(Member member, String reason, KickLogModel kickLogModel) {
Optional<Guild> guildById = bot.getGuildById(kickLogModel.getGuild().getIdLong());
Optional<Guild> guildById = botService.getGuildById(kickLogModel.getGuild().getIdLong());
if(guildById.isPresent()) {
guildById.get().kick(member, reason).queue();
this.sendKickLog(kickLogModel);

View File

@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.moderation.service;
import dev.sheldan.abstracto.core.exception.ChannelException;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.service.Bot;
import dev.sheldan.abstracto.core.service.BotService;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.TextChannel;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,7 +16,7 @@ import java.util.Optional;
public class SlowModeServiceBean implements SlowModeService {
@Autowired
private Bot bot;
private BotService botService;
@Override
public void setSlowMode(TextChannel channel, Duration duration) {
@@ -29,7 +29,7 @@ public class SlowModeServiceBean implements SlowModeService {
@Override
public void setSlowMode(AChannel channel, Duration duration) {
Optional<TextChannel> textChannelOptional = bot.getTextChannelFromServer(channel.getServer().getId(), channel.getId());
Optional<TextChannel> textChannelOptional = botService.getTextChannelFromServer(channel.getServer().getId(), channel.getId());
if(textChannelOptional.isPresent()) {
TextChannel textChannel = textChannelOptional.get();
this.setSlowMode(textChannel, duration);

View File

@@ -12,7 +12,7 @@ import dev.sheldan.abstracto.moderation.service.management.WarnManagementService
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.service.management.UserManagementService;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.Bot;
import dev.sheldan.abstracto.core.service.BotService;
import dev.sheldan.abstracto.core.service.PostTargetService;
import dev.sheldan.abstracto.templating.service.TemplateService;
import lombok.extern.slf4j.Slf4j;
@@ -48,7 +48,7 @@ public class WarnServiceBean implements WarnService {
private TemplateService templateService;
@Autowired
private Bot bot;
private BotService botService;
private static final String WARN_LOG_TEMPLATE = "warn_log";
private static final String WARN_NOTIFICATION_TEMPLATE = "warn_notification";
@@ -60,9 +60,9 @@ public class WarnServiceBean implements WarnService {
AServer serverOfWarning = warnedAUserInAServer.getServerReference();
log.info("User {} is warning {} in server {} because of {}", warningAUser.getId(), warnedAUser.getId(), serverOfWarning.getId(), reason);
Warning warning = warnManagementService.createWarning(warnedAUserInAServer, warningAUserInAServer, reason);
JDA instance = bot.getInstance();
JDA instance = botService.getInstance();
User userBeingWarned = instance.getUserById(warnedAUser.getId());
Optional<Guild> guildById = bot.getGuildById(serverOfWarning.getId());
Optional<Guild> guildById = botService.getGuildById(serverOfWarning.getId());
String guildName = "<defaultName>";
if(guildById.isPresent()) {
guildName = guildById.get().getName();