Skip to content

Commit

Permalink
feat: support FlashImage
Browse files Browse the repository at this point in the history
  • Loading branch information
xslingcn committed May 9, 2022
1 parent e4cbaed commit 270d6d2
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public Component get() {
return groupCardFallback();
}

if (message.size() == 2 && message.get(1) instanceof FlashImage flashImage)
return groupFlashImage(flashImage);

// match messages with images
if (images != null && !images.isEmpty()) {
return groupImage();
Expand Down Expand Up @@ -203,6 +206,19 @@ Component groupImage() {
return result.build();
}

Component groupFlashImage(FlashImage flashImage) {
String url = net.mamoe.mirai.Mirai.getInstance().queryImageUrl(phenyl.getMirai().getBot(), flashImage.getImage());
return Component.text(altColor(format[0]))
.append(Component.text("[", NamedTextColor.GRAY))
.append(Component.text(messageString.substring(1, messageString.length() - 1), NamedTextColor.DARK_AQUA)
.clickEvent(ClickEvent.openUrl(url))
.hoverEvent(HoverEvent.showText(Component.text(i18n("clickToView") + url, NamedTextColor.YELLOW))))
.append(Component.text("]", NamedTextColor.GRAY))
.append(Component.text(format.length > 1
? altColor(color + format[1])
: ""));
}

Component groupLink() {
int linkCount = 0;
String pattern = "(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
Expand Down

0 comments on commit 270d6d2

Please # to comment.