mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-27 14:23:56 +00:00
added ability to delete embedded posts (only the author and the person embedding can delete them) (this requires the embeds to be stored, they are deleted if the embed is deleted)
added filter to only handle reactions not done by the bot introduced completable future to the delete message wrapper fixed multi embed handling always resulting in two embeds added logging of template exceptions refactored link embed handling to be in a service instead of the listener
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.service.Bot;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserManagementService;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
@@ -49,9 +50,15 @@ public class ReactionUpdatedListener extends ListenerAdapter {
|
||||
@Autowired
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Autowired
|
||||
private Bot bot;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void onGuildMessageReactionAdd(@Nonnull GuildMessageReactionAddEvent event) {
|
||||
if(event.getUserIdLong() == bot.getInstance().getSelfUser().getIdLong()) {
|
||||
return;
|
||||
}
|
||||
CompletableFuture<CachedMessage> asyncMessageFromCache = messageCache.getMessageFromCache(event.getGuild().getIdLong(), event.getChannel().getIdLong(), event.getMessageIdLong());
|
||||
asyncMessageFromCache.thenAccept(cachedMessage -> {
|
||||
CompletableFuture<CachedReaction> future = new CompletableFuture<>();
|
||||
@@ -108,6 +115,9 @@ public class ReactionUpdatedListener extends ListenerAdapter {
|
||||
@Override
|
||||
@Transactional
|
||||
public void onGuildMessageReactionRemove(@Nonnull GuildMessageReactionRemoveEvent event) {
|
||||
if(event.getUserIdLong() == bot.getInstance().getSelfUser().getIdLong()) {
|
||||
return;
|
||||
}
|
||||
CompletableFuture<CachedMessage> asyncMessageFromCache = messageCache.getMessageFromCache(event.getGuild().getIdLong(), event.getChannel().getIdLong(), event.getMessageIdLong());
|
||||
asyncMessageFromCache.thenAccept(cachedMessage -> {
|
||||
CompletableFuture<CachedReaction> future = new CompletableFuture<>();
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -69,16 +70,15 @@ public class BotService implements Bot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMessage(Long serverId, Long channelId, Long messageId) {
|
||||
public CompletableFuture<Void> deleteMessage(Long serverId, Long channelId, Long messageId) {
|
||||
Optional<TextChannel> textChannelOptional = getTextChannelFromServer(serverId, channelId);
|
||||
if(textChannelOptional.isPresent()) {
|
||||
TextChannel textChannel = textChannelOptional.get();
|
||||
textChannel.deleteMessageById(messageId).queue(aVoid -> {}, throwable -> {
|
||||
log.warn("Failed to delete message {} in channel {} in guild {}", messageId, channelId, serverId, throwable);
|
||||
});
|
||||
return textChannel.deleteMessageById(messageId).submit();
|
||||
} else {
|
||||
log.warn("Could not find channel {} in guild {} to delete message {} in.", channelId, serverId, messageId);
|
||||
}
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -51,4 +52,9 @@ public class MessageServiceBean implements MessageService {
|
||||
throw new GuildException(String.format("Cannot add reaction, guild %s not found.", serverId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> deleteMessageInChannelInServer(Long serverId, Long channelId, Long messageId) {
|
||||
return bot.deleteMessage(serverId, channelId, messageId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"author": {
|
||||
"name": "${author.effectiveName}",
|
||||
"avatar": "${author.user.effectiveAvatarUrl}"
|
||||
},
|
||||
"color" : {
|
||||
"r": 200,
|
||||
"g": 0,
|
||||
"b": 255
|
||||
},
|
||||
<#if embeddedMessage.content?has_content || embeddedMessage.embeds?size gt 0>
|
||||
"description": "${embeddedMessage.content}
|
||||
<#list embeddedMessage.embeds>
|
||||
Embeds:
|
||||
<#items as embed>
|
||||
Description: ${embed.description} <#if embed.imageUrl?has_content> ImageUrl: ${embed.imageUrl} </#if>
|
||||
</#items>
|
||||
</#list>
|
||||
",
|
||||
</#if>
|
||||
<#if embeddedMessage.attachmentUrls?size gt 0>
|
||||
"imageUrl": "${embeddedMessage.attachmentUrls[0]}",
|
||||
</#if>
|
||||
"fields": [
|
||||
{
|
||||
"name": "Quoted by",
|
||||
"value": "${embeddingUser.asMention} from [${sourceChannel.name}](${embeddedMessage.messageUrl})"
|
||||
}
|
||||
],
|
||||
"timeStamp": "${embeddedMessage.timeCreated}"
|
||||
}
|
||||
Reference in New Issue
Block a user