Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
twonirwana committed Nov 20, 2024
1 parent f5c2fd3 commit 2ab130b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import de.janno.discord.bot.BaseCommandUtils;
import de.janno.discord.bot.persistance.MessageConfigDTO;
import de.janno.discord.bot.persistance.MessageDataDTO;
import de.janno.discord.bot.persistance.PersistenceManager;
Expand Down Expand Up @@ -189,7 +188,6 @@ protected abstract ConfigAndState<C, S> getMessageDataAndUpdateWithButtonValue(@
@NonNull String invokingUserName);



//visible for welcome command
public abstract Optional<MessageConfigDTO> createMessageConfig(@NonNull UUID configUUID,
@Nullable Long guildId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,6 @@ protected Collection<CommandDefinitionOption> additionalCommandOptions() {
return BaseCommandOptions.autoCompleteColorOption(autoCompleteRequest, userLocale);
}

/**
* On the creation of a message an empty state need to be saved so we know the message exists and we can remove it later, even on concurrent actions
*/

protected @NonNull MessageDataDTO createEmptyMessageData(@NonNull UUID configUUID,
@Nullable Long guildId,
long channelId,
long messageId) {
return BaseCommandUtils.createCleanupAndSaveEmptyMessageData(configUUID, guildId, channelId, messageId, getCommandId(), persistenceManager);
}


@Override
public final @NonNull Mono<Void> handleSlashCommandEvent(@NonNull SlashEventAdaptor event, @NonNull Supplier<UUID> uuidSupplier, @NonNull Locale userLocale) {
Stopwatch stopwatch = Stopwatch.createStarted();
Expand Down Expand Up @@ -183,17 +171,15 @@ protected Collection<CommandDefinitionOption> additionalCommandOptions() {
final Optional<MessageConfigDTO> newMessageConfig = createMessageConfig(configUUID, guildId, channelId, event.getUserId(), config);
newMessageConfig.ifPresent(persistenceManager::saveMessageConfig);
return event.sendMessage(createSlashResponseMessage(configUUID, config, channelId))
.doOnNext(messageId -> createEmptyMessageData(configUUID, guildId, channelId, messageId))
.doOnNext(messageId -> BaseCommandUtils.createCleanupAndSaveEmptyMessageData(configUUID, guildId, channelId, messageId, getCommandId(), persistenceManager))
.then();
}))
.doAfterTerminate(() -> {
log.info("{}: {} in start={}ms reply={}ms",
event.getRequester().toLogString(),
commandString.replace("`", "").replace("\n", " "),
untilAck.toMillis(),
stopwatch.elapsed(TimeUnit.MILLISECONDS)
);
});
.doAfterTerminate(() -> log.info("{}: {} in start={}ms reply={}ms",
event.getRequester().toLogString(),
commandString.replace("`", "").replace("\n", " "),
untilAck.toMillis(),
stopwatch.elapsed(TimeUnit.MILLISECONDS)
));
} else if (event.getOption(HELP_OPTION_NAME).isPresent()) {
BotMetrics.incrementSlashHelpMetricCounter(getCommandId());
return event.replyWithEmbedOrMessageDefinition(getHelpMessage(event.getRequester().getUserLocal()), true);
Expand Down

0 comments on commit 2ab130b

Please sign in to comment.