Skip to content

Commit

Permalink
Allow setting only the URL of an embed
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Sep 24, 2024
1 parent f60f8d8 commit c1532ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/main/java/net/neoforged/camelot/script/ScriptMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ public MessageEmbed asEmbed() {
final EmbedBuilder builder = new EmbedBuilder();
builder.setDescription(getString("description"));

stringOrObject("title", builder::setTitle, obj -> builder.setTitle(obj.getString("value"), obj.getString("url")));
stringOrObject("title", builder::setTitle, obj -> {
var title = obj.getString("value");
if (title == null || title.isBlank()) {
builder.setUrl(obj.getString("url"));
} else {
builder.setTitle(title, obj.getString("url"));
}
});

getList("fields").stream().map(ScriptMap::new).forEach(field -> builder.addField(
Objects.requireNonNull(field.getString("name")),
Expand Down
8 changes: 4 additions & 4 deletions trickTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ export interface Privileged {

declare namespace Embeds {
export type Title = {
value: string | null;
url: string | null;
value?: string | null;
url?: string | null;
}

export type Footer = {
value: string | null,
iconUrl: string | null
value?: string | null,
iconUrl?: string | null
}

export type Field = {
Expand Down

0 comments on commit c1532ba

Please sign in to comment.