mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-24 13:44:33 +00:00
[AB-268] adding button feature mode to suggestions which allows for hidden suggestion votes
moving gateway metric to separate service in case JDA is not ready yet
This commit is contained in:
@@ -2,8 +2,6 @@ package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.logging.OkHttpLogger;
|
||||
import dev.sheldan.abstracto.core.metric.OkHttpMetrics;
|
||||
import dev.sheldan.abstracto.core.metric.service.CounterMetric;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricService;
|
||||
import dev.sheldan.abstracto.core.models.SystemInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
@@ -15,9 +13,7 @@ import okhttp3.OkHttpClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.time.Duration;
|
||||
@@ -37,14 +33,6 @@ public class BotServiceBean implements BotService {
|
||||
@Autowired
|
||||
private OkHttpLogger okHttpLogger;
|
||||
|
||||
@Autowired
|
||||
private MetricService metricService;
|
||||
|
||||
public static final String DISCORD_GATEWAY_PING = "discord.gateway.ping";
|
||||
private static final CounterMetric DISCORD_GATE_WAY_PING_METRIC = CounterMetric
|
||||
.builder()
|
||||
.name(DISCORD_GATEWAY_PING)
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public void login() throws LoginException {
|
||||
@@ -84,11 +72,4 @@ public class BotServiceBean implements BotService {
|
||||
.build();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
metricService.registerGauge(DISCORD_GATE_WAY_PING_METRIC, this, value -> value.getInstance().getGatewayPing(),
|
||||
"Gateway ping");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.button.ButtonConfigModel;
|
||||
import net.dv8tion.jda.api.entities.Emoji;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
@@ -17,7 +18,6 @@ import java.util.stream.Collectors;
|
||||
@Component
|
||||
public class ComponentServiceBean implements ComponentService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
|
||||
@@ -110,6 +110,11 @@ public class ComponentServiceBean implements ComponentService {
|
||||
return actionRows.stream().map(ActionRow::of).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ButtonConfigModel createButtonConfigModel() {
|
||||
return ButtonConfigModel.builder().buttonId(generateComponentId()).build();
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> setAllButtonStatesTo(Message message, Boolean disabled) {
|
||||
List<ActionRow> actionRows = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.AsyncStartupListener;
|
||||
import dev.sheldan.abstracto.core.metric.service.CounterMetric;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DiscordStartupService implements AsyncStartupListener {
|
||||
|
||||
public static final String DISCORD_GATEWAY_PING = "discord.gateway.ping";
|
||||
private static final CounterMetric DISCORD_GATE_WAY_PING_METRIC = CounterMetric
|
||||
.builder()
|
||||
.name(DISCORD_GATEWAY_PING)
|
||||
.build();
|
||||
|
||||
@Autowired
|
||||
private MetricService metricService;
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
metricService.registerGauge(DISCORD_GATE_WAY_PING_METRIC, botService, value -> value.getInstance().getGatewayPing(),
|
||||
"Gateway ping");
|
||||
}
|
||||
}
|
||||
@@ -304,7 +304,7 @@ public class ReactionServiceBean implements ReactionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(AEmote emote, Long serverId, Long channelId, Long messageId, Long userId) {
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageAsync(AEmote emote, Long serverId, Long channelId, Long messageId, Long userId) {
|
||||
Guild guild = guildService.getGuildById(serverId);
|
||||
Integer emoteId = emote.getId();
|
||||
CompletableFuture<Member> memberFuture = guild.retrieveMemberById(userId).submit();
|
||||
@@ -312,13 +312,18 @@ public class ReactionServiceBean implements ReactionService {
|
||||
|
||||
return CompletableFuture.allOf(memberFuture, messageFuture).thenCompose(aVoid ->
|
||||
memberFuture.thenCompose(member ->
|
||||
self.removeReactionOfUserFromMessageWithFuture(emoteId, messageFuture.join(), memberFuture.join())
|
||||
self.removeReactionOfUserFromMessageAsync(emoteId, messageFuture.join(), memberFuture.join())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(AEmote emote, Long serverId, Long channelId, Long messageId) {
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageAsync(AEmote emote, CachedMessage cachedMessage, Member member) {
|
||||
return removeReactionOfUserFromMessageAsync(emote, cachedMessage.getServerId(), cachedMessage.getChannelId(), cachedMessage.getMessageId(), member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageAsync(AEmote emote, Long serverId, Long channelId, Long messageId) {
|
||||
Integer emoteId = emote.getId();
|
||||
CompletableFuture<Message> messageFuture = channelService.retrieveMessageInChannel(serverId, channelId, messageId);
|
||||
return messageFuture.thenCompose(message ->
|
||||
@@ -327,14 +332,19 @@ public class ReactionServiceBean implements ReactionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(AEmote emote, Long serverId, Long channelId, Long messageId, Member member) {
|
||||
Integer emoteId = emote.getId();
|
||||
return channelService.retrieveMessageInChannel(serverId, channelId, messageId)
|
||||
.thenCompose(message -> self.removeReactionOfUserFromMessageWithFuture(emoteId, message, member));
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageAsync(AEmote emote, Long serverId, Long channelId, Long messageId, Member member) {
|
||||
if(emote.getId() == null) {
|
||||
return channelService.retrieveMessageInChannel(serverId, channelId, messageId)
|
||||
.thenCompose(message -> self.removeReaction(message, emote.getEmoteKey(), member.getUser()));
|
||||
} else {
|
||||
Integer emoteId = emote.getId();
|
||||
return channelService.retrieveMessageInChannel(serverId, channelId, messageId)
|
||||
.thenCompose(message -> self.removeReactionOfUserFromMessageAsync(emoteId, message, member));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(AEmote emote, Message message, Member member) {
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageAsync(AEmote emote, Message message, Member member) {
|
||||
if(Boolean.TRUE.equals(emote.getCustom())) {
|
||||
Emote emoteById = botService.getInstance().getEmoteById(emote.getEmoteId());
|
||||
if(emoteById == null) {
|
||||
@@ -350,23 +360,23 @@ public class ReactionServiceBean implements ReactionService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(Integer emoteId, Message message, Member member) {
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageAsync(Integer emoteId, Message message, Member member) {
|
||||
AEmote emote = emoteManagementService.loadEmote(emoteId);
|
||||
return removeReactionOfUserFromMessageWithFuture(emote, message, member);
|
||||
return removeReactionOfUserFromMessageAsync(emote, message, member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(AEmote emote, Message message, Long userId) {
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageAsync(AEmote emote, Message message, Long userId) {
|
||||
Integer emoteId = emote.getId();
|
||||
return message.getGuild().retrieveMemberById(userId).submit().thenCompose(member ->
|
||||
self.removeReactionOfUserFromMessageWithFuture(emoteId, message, member)
|
||||
self.removeReactionOfUserFromMessageAsync(emoteId, message, member)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(Integer emoteId, Message message, Long userId) {
|
||||
public CompletableFuture<Void> removeReactionOfUserFromMessageAsync(Integer emoteId, Message message, Long userId) {
|
||||
return message.getGuild().retrieveMemberById(userId).submit().thenCompose(member ->
|
||||
self.removeReactionOfUserFromMessageWithFuture(emoteId, message, member)
|
||||
self.removeReactionOfUserFromMessageAsync(emoteId, message, member)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user