Skip to content

Commit

Permalink
Let InteractionOriginalResponseUpdater implement Deletable.
Browse files Browse the repository at this point in the history
 - Update the documentation to specify that audit log reason support depends on discord.
  • Loading branch information
Saladoc committed Feb 2, 2023
1 parent cc2864f commit be3cb13
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/**
* An entity that can be deleted.
*
* <p>Note that not all entities implementing this might actually support giving an audit reason. If this is the case,
* the audit reason will silently be dropped - or rather sent to and ignored by discords side.</p>
*/
public interface Deletable {

Expand All @@ -30,7 +33,7 @@ default CompletableFuture<Void> delete() {
/**
* Deletes the entity.
*
* @param reason The audit log reason for the deletion.
* @param reason The audit log reason for the deletion, if supported.
* @return A future to tell if the deletion was successful.
*/
CompletableFuture<Void> delete(String reason);
Expand All @@ -55,7 +58,7 @@ default CompletableFuture<Void> deleteAfter(long duration, TimeUnit unit) {
*
* @param duration The duration.
* @param unit The unit for the duration.
* @param auditLogReason The reason to log for the audit log.
* @param auditLogReason The reason to log for the audit log, if supported.
* @return A future that completes when the entity has been deleted.
*/
default CompletableFuture<Void> deleteAfter(long duration, TimeUnit unit, String auditLogReason) {
Expand All @@ -80,7 +83,7 @@ default CompletableFuture<Void> deleteAfter(Duration duration) {
* <p><b>Caution:</b> If the bot shuts down before the scheduled time, the entity will not be deleted.</p>
*
* @param duration The duration.
* @param auditLogReason The reason to log for the audit log.
* @param auditLogReason The reason to log for the audit log, if supported.
* @return A future that completes when the entity has been deleted.
*/
default CompletableFuture<Void> deleteAfter(Duration duration, String auditLogReason) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.javacord.api.entity.message.Message;
import org.javacord.api.entity.message.MessageFlag;
import org.javacord.api.interaction.InteractionBase;

import java.util.EnumSet;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -31,6 +32,15 @@ public interface InteractionMessageBuilderDelegate extends MessageBuilderBaseDel
*/
CompletableFuture<Void> deleteInitialResponse(InteractionBase interaction);

/**
* Delete the original response message.
*
* @param interaction The interaction.
* @param auditLogMessage The audit log message to attach.
* @return The completable future when the message has been deleted.
*/
CompletableFuture<Void> deleteInitialResponse(InteractionBase interaction, String auditLogMessage);

/**
* Edits the message.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.javacord.api.interaction.callback;

import org.javacord.api.entity.Deletable;
import org.javacord.api.entity.message.Message;

import java.util.concurrent.CompletableFuture;

public interface InteractionOriginalResponseUpdater
extends ExtendedInteractionMessageBuilderBase<InteractionOriginalResponseUpdater> {
extends ExtendedInteractionMessageBuilderBase<InteractionOriginalResponseUpdater>, Deletable {
/**
* Updates your initial response to the interaction.
* Note: You can not update the message using any of the edit methods on the message entity as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.javacord.core.util.rest.RestEndpoint;
import org.javacord.core.util.rest.RestMethod;
import org.javacord.core.util.rest.RestRequest;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -59,6 +60,17 @@ public CompletableFuture<Void> deleteInitialResponse(InteractionBase interaction
.execute(result -> null);
}

@Override
public CompletableFuture<Void> deleteInitialResponse(InteractionBase interaction, String reason) {
return new RestRequest<Void>(interaction.getApi(),
RestMethod.DELETE, RestEndpoint.ORIGINAL_INTERACTION_RESPONSE)
.setUrlParameters(Long.toUnsignedString(interaction.getApplicationId()), interaction.getToken())
.setAuditLogReason(reason)
.consumeGlobalRatelimit(false)
.includeAuthorizationHeader(false)
.execute(result -> null);
}

@Override
public CompletableFuture<Message> editOriginalResponse(InteractionBase interaction) {
RestRequest<Message> request = new RestRequest<Message>(interaction.getApi(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.javacord.core.interaction;

import org.javacord.api.DiscordApi;
import org.javacord.api.entity.Icon;
import org.javacord.api.entity.Mentionable;
import org.javacord.api.entity.message.Message;
Expand All @@ -11,6 +12,7 @@
import org.javacord.api.entity.message.mention.AllowedMentions;
import org.javacord.api.interaction.InteractionBase;
import org.javacord.api.interaction.callback.InteractionOriginalResponseUpdater;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
Expand Down Expand Up @@ -52,11 +54,21 @@ public CompletableFuture<Message> update() {
return this.delegate.editOriginalResponse(interaction);
}

@Override
public DiscordApi getApi() {
return this.interaction.getApi();
}

@Override
public CompletableFuture<Void> delete() {
return this.delegate.deleteInitialResponse(interaction);
}

@Override
public CompletableFuture<Void> delete(String reason) {
return this.delegate.deleteInitialResponse(interaction, reason);
}

@Override
public InteractionOriginalResponseUpdater appendCode(String language, String code) {
delegate.appendCode(language, code);
Expand Down

0 comments on commit be3cb13

Please sign in to comment.