Skip to content

Commit

Permalink
emojis & guild & role fix (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweisz authored Apr 16, 2024
1 parent 3f83a52 commit 949fbba
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.javadiscord.jdi.internal.api.impl.emojis;

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

import java.util.List;
import java.util.Map;

public record CreateEmojiRequest(
long guildId,
String name,
String image, // https://discord.com/developers/docs/reference#image-data
List<Long> roles)
implements DiscordRequest {

@Override
public DiscordRequestBuilder create() {
return new DiscordRequestBuilder()
.post()
.path("/guilds/%s/emojis".formatted(guildId))
.body(
Map.of(
"name", name,
"image", image,
"roles", roles));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.javadiscord.jdi.internal.api.impl.emojis;

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

public record DeleteEmojiRequest(long guildId, long emojiId) implements DiscordRequest {

@Override
public DiscordRequestBuilder create() {
return new DiscordRequestBuilder()
.delete()
.path("/guilds/%s/emojis/%s".formatted(guildId, emojiId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.javadiscord.jdi.internal.api.impl.emojis;

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

public record GetEmojiRequest(long guildId, long emojiId) implements DiscordRequest {

@Override
public DiscordRequestBuilder create() {
return new DiscordRequestBuilder()
.get()
.path("/guilds/%s/emojis/%s".formatted(guildId, emojiId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.javadiscord.jdi.internal.api.impl.emojis;

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

public record GetEmojisRequest(long guildId) implements DiscordRequest {

@Override
public DiscordRequestBuilder create() {
return new DiscordRequestBuilder().get().path("/guilds/%s/emojis".formatted(guildId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.javadiscord.jdi.internal.api.impl.emojis;

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

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

public record ModifyEmojiRequest(
long guildId, long emojiId, Optional<String> name, Optional<List<Long>> roles)
implements DiscordRequest {

@Override
public DiscordRequestBuilder create() {
Map<String, Object> body = new HashMap<>();
name.ifPresent(val -> body.put("name", val));
roles.ifPresent(val -> body.put("roles", val));

return new DiscordRequestBuilder()
.patch()
.path("/guilds/%s/emojis/%s".formatted(guildId, emojiId))
.body(body);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record Guild(
@JsonProperty("id") long id,
@JsonProperty("name") String name,
@JsonProperty("icon") String icon,
@JsonProperty("slash") String slash,
@JsonProperty("splash") String splash,
@JsonProperty("discovery_splash") String discoverySplash,
@JsonProperty("owner") boolean owner,
@JsonProperty("ownerId") long ownerId,
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/javadiscord/jdi/internal/models/guild/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

@JsonIgnoreProperties(ignoreUnknown = true)
public record Role(
long id,
String name,
String color,
boolean hoist,
String icon,
@JsonProperty("id") long id,
@JsonProperty("name") String name,
@JsonProperty("color") String color,
@JsonProperty("color") boolean hoist,
@JsonProperty("icon") String icon,
@JsonProperty("unicode_emoji") String unicodeEmoji,
int position,
String permissions,
boolean managed,
boolean mentionable,
Tags tags,
int flags) {}
@JsonProperty("position") int position,
@JsonProperty("permissions") String permissions,
@JsonProperty("managed") boolean managed,
@JsonProperty("mentionable") boolean mentionable,
@JsonProperty("tags") Tags tags,
@JsonProperty("flags") int flags) {}

0 comments on commit 949fbba

Please sign in to comment.