-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove old classes, add new embed class with placeholder functionality
- Loading branch information
1 parent
7c88a89
commit 01afd7c
Showing
14 changed files
with
238 additions
and
773 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
core/src/main/java/com/github/kaktushose/jda/commands/embeds/Embed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.github.kaktushose.jda.commands.embeds; | ||
|
||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.entities.MessageEmbed; | ||
import net.dv8tion.jda.api.utils.data.DataObject; | ||
import net.dv8tion.jda.api.utils.messages.MessageCreateData; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.awt.*; | ||
import java.time.temporal.TemporalAccessor; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class Embed { | ||
|
||
private final EmbedBuilder embedBuilder; | ||
|
||
public Embed(EmbedBuilder embedBuilder) { | ||
this.embedBuilder = embedBuilder; | ||
} | ||
|
||
public Embed title(String title) { | ||
embedBuilder.setTitle(title); | ||
return this; | ||
} | ||
|
||
|
||
public Embed title(String title, String url) { | ||
embedBuilder.setTitle(title, url); | ||
return this; | ||
} | ||
|
||
public Embed description(CharSequence description) { | ||
embedBuilder.setDescription(description); | ||
return this; | ||
} | ||
|
||
public Embed color(int color) { | ||
embedBuilder.setColor(color); | ||
return this; | ||
} | ||
|
||
public Embed color(Color color) { | ||
embedBuilder.setColor(color); | ||
return this; | ||
} | ||
|
||
public Embed timestamp(TemporalAccessor accessor) { | ||
embedBuilder.setTimestamp(accessor); | ||
return this; | ||
} | ||
|
||
public Embed footer(String footer) { | ||
embedBuilder.setFooter(footer); | ||
return this; | ||
} | ||
|
||
public Embed footer(String footer, String iconUrl) { | ||
embedBuilder.setFooter(footer, iconUrl); | ||
return this; | ||
} | ||
|
||
public Embed thumbnail(String url) { | ||
embedBuilder.setThumbnail(url); | ||
return this; | ||
} | ||
|
||
public Embed image(String url) { | ||
embedBuilder.setImage(url); | ||
return this; | ||
} | ||
|
||
public Embed author(String name) { | ||
embedBuilder.setAuthor(name); | ||
return this; | ||
} | ||
|
||
public Embed author(String name, String url) { | ||
embedBuilder.setAuthor(name, url); | ||
return this; | ||
} | ||
|
||
public Embed author(String name, String url, String iconUrl) { | ||
embedBuilder.setAuthor(name, url, iconUrl); | ||
return this; | ||
} | ||
|
||
// TODO fields API | ||
|
||
public Embed placeholder(String placeholder, Object value) { | ||
DataObject object = embedBuilder.build().toData(); | ||
String json = object.toString(); | ||
json = json.replaceAll( | ||
String.format(Pattern.quote("{%s}"), Matcher.quoteReplacement(placeholder)), | ||
String.valueOf(value) | ||
); | ||
return new Embed(EmbedBuilder.fromData(DataObject.fromJson(json))); | ||
} | ||
|
||
public Embed placeholder(Map<String, Object> values) { | ||
values.forEach(this::placeholder); | ||
return this; | ||
} | ||
|
||
public @NotNull MessageCreateData toMessageCreateData() { | ||
return MessageCreateData.fromEmbeds(embedBuilder.build()); | ||
} | ||
|
||
public MessageEmbed build() { | ||
return embedBuilder.build(); | ||
} | ||
} |
119 changes: 0 additions & 119 deletions
119
core/src/main/java/com/github/kaktushose/jda/commands/embeds/EmbedCache.java
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
core/src/main/java/com/github/kaktushose/jda/commands/embeds/EmbedConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.kaktushose.jda.commands.embeds; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Locale; | ||
import java.util.function.Supplier; | ||
|
||
public interface EmbedConfiguration { | ||
|
||
EmbedConfiguration source(@NotNull EmbedDataSource source); | ||
|
||
default EmbedConfiguration placeholder(String key, Object value) { | ||
return placeholder(key, () -> value); | ||
} | ||
|
||
<T> EmbedConfiguration placeholder(String key, Supplier<T> supplier); | ||
|
||
EmbedConfiguration localization(Locale locale, EmbedDataSource embedDataSource); | ||
|
||
} |
Oops, something went wrong.