diff --git a/common/src/main/java/live/turna/phenyl/common/message/Formatter.java b/common/src/main/java/live/turna/phenyl/common/message/Formatter.java index b9b6d7b..d4097e2 100644 --- a/common/src/main/java/live/turna/phenyl/common/message/Formatter.java +++ b/common/src/main/java/live/turna/phenyl/common/message/Formatter.java @@ -40,8 +40,8 @@ public Formatter(P plugin, String[] format, String color, MessageChain message) phenyl = plugin; this.format = format; this.color = color; - this.message = message; - this.messageString = message.contentToString(); + this.message = processAt(message); + this.messageString = this.message.contentToString(); this.images = this.message.stream().filter(Image.class::isInstance).toList(); List replyList = this.message.stream().filter(QuoteReply.class::isInstance).toList(); if (!replyList.isEmpty()) this.quote = (QuoteReply) replyList.get(0); @@ -277,4 +277,22 @@ String quoteReply() { return ""; } } + + MessageChain processAt(MessageChain message) { + MessageSource source = message.get(MessageSource.Key); + if (source == null) return message; + // convert @id to @username + for (SingleMessage singleMessage : message) { + if (singleMessage instanceof At at) { + MessageChainBuilder builder = new MessageChainBuilder(); + SingleMessage atName = new PlainText("@" + new MiraiUtils(phenyl).getUserNameOrNameCardOrNick(source.getTargetId(), at.getTarget())); + builder.addAll(message.subList(0, message.indexOf(at))); + builder.append(atName); + if (message.indexOf(at) < message.size()) + builder.addAll(message.subList(message.indexOf(at) + 1, message.size())); + message = builder.build(); + } + } + return message; + } } \ No newline at end of file