Skip to content

Implement note in ModifyScheduledEventRequest #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import java.util.List;

import com.javadiscord.jdi.core.api.builders.CreateScheduledEventBuilder;
import com.javadiscord.jdi.core.api.builders.GetScheduledEventBuilder;
import com.javadiscord.jdi.core.api.builders.GetScheduledEventUsersBuilder;
import com.javadiscord.jdi.core.api.builders.ListScheduledEventsBuilder;
import com.javadiscord.jdi.core.api.builders.*;
import com.javadiscord.jdi.core.models.scheduled_event.EventUser;
import com.javadiscord.jdi.core.models.scheduled_event.ScheduledEvent;
import com.javadiscord.jdi.internal.api.guild_scheduled_event.*;
Expand All @@ -23,6 +20,10 @@ public AsyncResponse<ScheduledEvent> createScheduledEvent(CreateScheduledEventBu
return responseParser.callAndParse(ScheduledEvent.class, builder.guildId(guildId).build());
}

public AsyncResponse<ScheduledEvent> modifyScheduledEvent(ModifyScheduledEventBuilder builder) {
return responseParser.callAndParse(ScheduledEvent.class, builder.build());
}

public AsyncResponse<ScheduledEvent> deleteScheduledEvent(long scheduledEventId) {
return responseParser.callAndParse(
ScheduledEvent.class, new DeleteScheduledEventRequest(guildId, scheduledEventId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.javadiscord.jdi.core.models.guild.EntityMetadata;
import com.javadiscord.jdi.core.models.guild.PrivacyLevel;
import com.javadiscord.jdi.core.models.scheduled_event.ScheduledEntityType;
import com.javadiscord.jdi.internal.api.guild_scheduled_event.ModifyScheduledEventRequest;

public class ModifyScheduledEventBuilder {
Expand All @@ -14,9 +15,9 @@ public class ModifyScheduledEventBuilder {
private Optional<String> name;
private Optional<Integer> privacyLevel;
private Optional<Long> scheduledStartTime;
private Optional<Long> scheduledEndTim;
private Optional<Long> scheduledEndTime;
private Optional<String> description;
private Optional<Integer> entityType;
private Optional<ScheduledEntityType> entityType;
private Optional<Integer> status;
private Optional<String> image;

Expand All @@ -28,7 +29,7 @@ public ModifyScheduledEventBuilder(long guildId, long scheduledEventId) {
this.name = Optional.empty();
this.privacyLevel = Optional.empty();
this.scheduledStartTime = Optional.empty();
this.scheduledEndTim = Optional.empty();
this.scheduledEndTime = Optional.empty();
this.description = Optional.empty();
this.entityType = Optional.empty();
this.status = Optional.empty();
Expand Down Expand Up @@ -60,8 +61,8 @@ public ModifyScheduledEventBuilder scheduledStartTime(long scheduledStartTime) {
return this;
}

public ModifyScheduledEventBuilder scheduledEndTim(long scheduledEndTim) {
this.scheduledEndTim = Optional.of(scheduledEndTim);
public ModifyScheduledEventBuilder scheduledEndTime(long scheduledEndTim) {
this.scheduledEndTime = Optional.of(scheduledEndTim);
return this;
}

Expand All @@ -70,12 +71,12 @@ public ModifyScheduledEventBuilder description(String description) {
return this;
}

public ModifyScheduledEventBuilder entityType(Integer entityType) {
public ModifyScheduledEventBuilder entityType(ScheduledEntityType entityType) {
this.entityType = Optional.of(entityType);
return this;
}

public ModifyScheduledEventBuilder status(Integer status) {
public ModifyScheduledEventBuilder status(int status) {
this.status = Optional.of(status);
return this;
}
Expand All @@ -86,6 +87,20 @@ public ModifyScheduledEventBuilder image(String image) {
}

public ModifyScheduledEventRequest build() {
if (entityType.isPresent() && entityType.get() == ScheduledEntityType.EXTERNAL) {
if (entityMetadata.isEmpty() || scheduledEndTime.isEmpty()) {
throw new IllegalArgumentException(
"When entityType is EXTERNAL, both entityMetadata and scheduledEndTime must"
+ " be provided"
);
}
if (channelId.isPresent()) {
throw new IllegalArgumentException(
"When entityType is EXTERNAL, channelId must not be provided"
);
}
}

return new ModifyScheduledEventRequest(
guildId,
scheduledEventId,
Expand All @@ -94,7 +109,7 @@ public ModifyScheduledEventRequest build() {
name,
privacyLevel,
scheduledStartTime,
scheduledEndTim,
scheduledEndTime,
description,
entityType,
status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Optional;

import com.javadiscord.jdi.core.models.guild.EntityMetadata;
import com.javadiscord.jdi.core.models.scheduled_event.ScheduledEntityType;
import com.javadiscord.jdi.internal.api.DiscordRequest;
import com.javadiscord.jdi.internal.api.DiscordRequestBuilder;

Expand All @@ -18,30 +19,14 @@ public record ModifyScheduledEventRequest(
Optional<Long> scheduledStartTime,
Optional<Long> scheduledEndTime,
Optional<String> description,
Optional<Integer> entityType,
Optional<ScheduledEntityType> entityType,
Optional<Integer> status,
Optional<String> image
) implements DiscordRequest {
@Override
public DiscordRequestBuilder create() {
Map<String, Object> body = new HashMap<>();

// check if entityType = 3 (EXTERNAL)
// channelId must be set to null
// entityMetadata (entity_metadata), scheduledEndTime are all required
if (entityType.isPresent() && entityType.get() == 3) {
if (entityMetadata.isEmpty() || scheduledEndTime.isEmpty()) {
throw new IllegalArgumentException(
"When entityType is EXTERNAL, both entityMetadata and scheduledEndTime must"
+ " be provided"
);
}

body.put("channel_id", null);
} else {
channelId.ifPresent(val -> body.put("channel_id", val));
}

channelId.ifPresent(val -> body.put("channel_id", val));
entityMetadata.ifPresent(val -> body.put("entity_metadata", val));
name.ifPresent(val -> body.put("name", val));
privacyLevel.ifPresent(val -> body.put("privacy_level", val));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
package com.javadiscord.jdi.core.models.scheduled_event;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum ScheduledEntityType {
STAGE_INSTANCE,
VOICE,
EXTERNAL
EXTERNAL;

@JsonCreator
public static ScheduledEntityType fromIndex(int index) {
return ScheduledEntityType.values()[index - 1];
}

@JsonValue
public int toValue() {
return ordinal() + 1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public record ScheduledEvent(
@JsonProperty("privacy_level") PrivacyLevel privacyLevel,
@JsonProperty("status") EventStatus status,
@JsonProperty("entity_type") ScheduledEntityType entityType,
@JsonProperty("entity_id") Long entityId,
@JsonProperty("entity_id") long entityId,
@JsonProperty("entity_metadata") EntityMetadata entityMetadata,
@JsonProperty("creator") User creator,
@JsonProperty("user_count") int userCount,
Expand Down
Loading