Skip to content

Commit

Permalink
Stage Requests API (#42)
Browse files Browse the repository at this point in the history
Implement Stage Requests
  • Loading branch information
nateweisz authored Apr 13, 2024
1 parent 01f79d0 commit e4392c3
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.javadiscord.jdi.internal.api.impl.stage;

import com.javadiscord.jdi.internal.api.DiscordRequest;
import com.javadiscord.jdi.internal.api.DiscordRequestBuilder;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public record CreateStageRequest(
long channelId,
String topic,
int privacyLevel,
Optional<Boolean> sendStartNotification,
Optional<Long> guildScheduledEventId)
implements DiscordRequest {

@Override
public DiscordRequestBuilder create() {
// all of these except get supports X-Audit-Log-Reason header, not sure how we are handling
// so I will leave out for now
Map<String, Object> body = new HashMap<>();
body.put("channel_id", channelId);
body.put("topic", topic);
body.put("privacy_level", privacyLevel);
sendStartNotification.ifPresent(val -> body.put("send_start_notification", val));
guildScheduledEventId.ifPresent(val -> body.put("guild_scheduled_event_id", val));

return new DiscordRequestBuilder().post().path("/stage-instances").body(body);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.javadiscord.jdi.internal.api.impl.stage;

import com.javadiscord.jdi.internal.api.DiscordRequest;
import com.javadiscord.jdi.internal.api.DiscordRequestBuilder;

public record DeleteStageRequest(String channelId) implements DiscordRequest {
@Override
public DiscordRequestBuilder create() {
return new DiscordRequestBuilder()
.delete()
.path("/stage-instances/%s".formatted(channelId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.javadiscord.jdi.internal.api.impl.stage;

import com.javadiscord.jdi.internal.api.DiscordRequest;
import com.javadiscord.jdi.internal.api.DiscordRequestBuilder;

public record GetStageRequest(String channelId) implements DiscordRequest {
@Override
public DiscordRequestBuilder create() {
return new DiscordRequestBuilder().get().path("/stage-instances/%s".formatted(channelId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.javadiscord.jdi.internal.api.impl.stage;

import com.javadiscord.jdi.internal.api.DiscordRequest;
import com.javadiscord.jdi.internal.api.DiscordRequestBuilder;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public record ModifyStageRequest(
String channelId, Optional<String> topic, Optional<Integer> privacyLevel)
implements DiscordRequest {
@Override
public DiscordRequestBuilder create() {
Map<String, Object> body = new HashMap<>();
topic.ifPresent(val -> body.put("topic", val));
privacyLevel.ifPresent(val -> body.put("privacy_level", privacyLevel));
return new DiscordRequestBuilder()
.patch()
.path("/stage-instances/%s".formatted(channelId))
.body(body);
}
}

0 comments on commit e4392c3

Please sign in to comment.