mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-18 04:50:38 +00:00
[AB-300] adding ability to determine the channel names for modmail
This commit is contained in:
@@ -39,6 +39,7 @@ import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
|
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
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 org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -62,6 +63,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
* The config key to use for the ID of the category to create {@link MessageChannel} in
|
* The config key to use for the ID of the category to create {@link MessageChannel} in
|
||||||
*/
|
*/
|
||||||
public static final String MODMAIL_CATEGORY = "modmailCategory";
|
public static final String MODMAIL_CATEGORY = "modmailCategory";
|
||||||
|
public static final String TEXT_CHANNEL_NAME_TEMPLATE_KEY = "modMail_channel_name";
|
||||||
/**
|
/**
|
||||||
* The template key used for default mod mail exceptions
|
* The template key used for default mod mail exceptions
|
||||||
*/
|
*/
|
||||||
@@ -189,7 +191,16 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
metricService.incrementCounter(MODMAIL_THREAD_CREATED_COUNTER);
|
metricService.incrementCounter(MODMAIL_THREAD_CREATED_COUNTER);
|
||||||
User user = member.getUser();
|
User user = member.getUser();
|
||||||
log.info("Creating modmail channel for user {} in category {} on server {}.", user.getId(), categoryId, serverId);
|
log.info("Creating modmail channel for user {} in category {} on server {}.", user.getId(), categoryId, serverId);
|
||||||
CompletableFuture<TextChannel> textChannelFuture = channelService.createTextChannel(user.getName() + user.getDiscriminator(), server, categoryId);
|
ModMailChannelNameModel model = ModMailChannelNameModel
|
||||||
|
.builder()
|
||||||
|
.serverId(serverId)
|
||||||
|
.userId(member.getIdLong())
|
||||||
|
.randomText(RandomStringUtils.randomAlphanumeric(25))
|
||||||
|
.uuid(UUID.randomUUID().toString())
|
||||||
|
.currentDate(Instant.now())
|
||||||
|
.build();
|
||||||
|
String channelName = templateService.renderTemplate(TEXT_CHANNEL_NAME_TEMPLATE_KEY, model, serverId);
|
||||||
|
CompletableFuture<TextChannel> textChannelFuture = channelService.createTextChannel(channelName, server, categoryId);
|
||||||
return textChannelFuture.thenCompose(channel -> {
|
return textChannelFuture.thenCompose(channel -> {
|
||||||
undoActions.add(UndoActionInstance.getChannelDeleteAction(serverId, channel.getIdLong()));
|
undoActions.add(UndoActionInstance.getChannelDeleteAction(serverId, channel.getIdLong()));
|
||||||
return self.performModMailThreadSetup(member, initialMessage, channel, userInitiated, undoActions, feedBackChannel);
|
return self.performModMailThreadSetup(member, initialMessage, channel, userInitiated, undoActions, feedBackChannel);
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package dev.sheldan.abstracto.modmail.model.template;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class ModMailChannelNameModel {
|
||||||
|
private Long serverId;
|
||||||
|
private Long userId;
|
||||||
|
private Instant currentDate;
|
||||||
|
private String randomText;
|
||||||
|
private String uuid;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user