Skip to content
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

[Quote images] Set the boundary to the quoted user's highest role color, if they are in the server and they have a role color. #7

Merged
merged 2 commits into from
Jan 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 @@ -28,6 +28,7 @@
import net.neoforged.camelot.util.jda.ButtonManager;
import org.jetbrains.annotations.Nullable;

import java.awt.*;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -348,9 +349,9 @@ protected void execute(SlashCommandEvent event) {
final CompletableFuture<QuotesModule.MemberLike> memberLike = new CompletableFuture<>();
if (quote.author().userId() != 0) {
event.getGuild().retrieveMemberById(quote.author().userId())
.map(mem -> new QuotesModule.MemberLike(mem.getEffectiveName(), mem.getEffectiveAvatarUrl()))
.map(mem -> new QuotesModule.MemberLike(mem.getEffectiveName(), mem.getEffectiveAvatarUrl(), mem.getColor()))
.onErrorFlatMap(ErrorResponse.UNKNOWN_MEMBER::test, _ -> event.getJDA().retrieveUserById(quote.author().userId())
.map(user -> new QuotesModule.MemberLike(user.getEffectiveName(), user.getEffectiveAvatarUrl()))
.map(user -> new QuotesModule.MemberLike(user.getEffectiveName(), user.getEffectiveAvatarUrl(), new Color(0xA55200)))
.onErrorMap(ErrorResponse.UNKNOWN_USER::test, _ -> null))
.queue(memberLike::complete);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/neoforged/camelot/module/QuotesModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void updateAuthors(final JDA jda, final QuotesDAO db) {
}));
}

public record MemberLike(String name, String avatar) {}
public record MemberLike(String name, String avatar, Color color) {}

public byte[] makeQuoteImage(final Guild guild, final @Nullable MemberLike member, final Quote quote) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down Expand Up @@ -144,7 +144,7 @@ public byte[] makeQuoteImage(final Guild guild, final @Nullable MemberLike membe
final var outBuf = new BufferedImage(outline.getWidth(), outline.getHeight(),
BufferedImage.TYPE_INT_ARGB);
final var outGraphics = outBuf.createGraphics();
outGraphics.setColor(new Color(0xA55200));
outGraphics.setColor(member == null ? new Color(0xA55200) : member.color());
outGraphics.fillRect(0, 0, outline.getWidth(), outline.getHeight());
outGraphics.dispose();
BufferedImage outlineImg = outBuf;
Expand Down