Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Commit 2eb52cc

Browse files
committed
add contentpattern configuration
1 parent d1b3eac commit 2eb52cc

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

src/api/main/java/com/ampznetwork/chatmod/api/model/config/ChatModules.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import lombok.Singular;
1212
import lombok.experimental.SuperBuilder;
1313
import org.comroid.api.attr.Named;
14+
import org.intellij.lang.annotations.Language;
1415
import org.jetbrains.annotations.NotNull;
1516
import org.jetbrains.annotations.Nullable;
1617
import org.jetbrains.annotations.Range;
@@ -41,7 +42,7 @@ public static abstract class NamedBaseConfig implements Named {
4142
@SuperBuilder
4243
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
4344
public static abstract class ProviderConfig extends NamedBaseConfig {
44-
@Range(from = -1, to = Integer.MAX_VALUE) protected @Default int autoReconnectDelay = 5;
45+
@Range(from = -1, to = Integer.MAX_VALUE) protected @Default int autoReconnectDelay = 5;
4546

4647
public abstract String providerType();
4748
}
@@ -110,7 +111,8 @@ public final String providerType() {
110111
@SuperBuilder
111112
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
112113
public static class AurionChatProviderConfig extends RabbitMqProviderConfig {
113-
protected @NotNull @Default String exchange = "aurion.chat";
114+
protected @NotNull @Default String exchange = "aurion.chat";
115+
protected @Nullable @Default @Language("RegExp") String contentPattern = "\\[[\\w&§]+]\\s[\\w&§]+\\s[\\w-_&§]+:\\s(.*)";
114116

115117
@Override
116118
public final String providerType() {

src/core/main/java/com/ampznetwork/chatmod/core/module/impl/LinkToAurionChatModule.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import java.util.Optional;
3434
import java.util.UUID;
3535
import java.util.logging.Level;
36+
import java.util.regex.Pattern;
37+
38+
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.*;
3639

3740
@Value
3841
@ToString(callSuper = true)
@@ -71,40 +74,29 @@ public PacketAdapter upgradeToNative(ChatMessagePacket packet) {
7174
//todo: lookup linked user
7275
sender = Player.builder().id(new UUID(0, 0)).name(packet.getMessage().getSenderName()).build();
7376
}
74-
return new PacketAdapter(packet.getPacketType(),
77+
return new PacketAdapter(packet.getPacketType().getAurionPacketType(), packet.getPacketType(),
7578
packet.getSource(),
7679
packet.getRoute(),
7780
new AurionPlayer(sender.getId(), sender.getName(), null, null),
7881
packet.getChannel(),
7982
mod.getPlayerAdapter().getPlayer(sender.getId()).map(Player::getName).orElseGet(packet.getMessage()::getSenderName),
80-
GsonComponentSerializer.gson().serialize(packet.getMessage().getFullText())).setMod(mod);
83+
GsonComponentSerializer.gson().serialize(packet.getMessage().getFullText()), config).setMod(mod);
8184
}
8285

8386
@Value
8487
public static class PacketAdapter extends AurionPacket implements ChatMessagePacket {
85-
@Expose PacketType packetType;
88+
@Expose PacketType packetType;
89+
ChatModules.AurionChatProviderConfig config;
8690
@Getter(onMethod_ = @__(@JsonIgnore)) @Setter(onMethod_ = @__(@JsonIgnore)) @NonFinal ModuleContainer mod;
8791

88-
public PacketAdapter(
89-
Type type, String source, List<String> route, @Nullable AurionPlayer player, @Nullable String channel,
90-
@Nullable String displayName, @NotNull String tellRawData
91-
) {
92-
this(type, PacketType.of(type), source, route, player, channel, displayName, tellRawData);
93-
}
94-
95-
public PacketAdapter(
96-
PacketType packetType, String source, List<String> route, @Nullable AurionPlayer player, @Nullable String channel,
97-
@Nullable String displayName, @NotNull String tellRawData
98-
) {
99-
this(packetType.getAurionPacketType(), packetType, source, route, player, channel, displayName, tellRawData);
100-
}
101-
10292
public PacketAdapter(
10393
Type type, PacketType packetType, String source, List<String> route, @Nullable AurionPlayer player, @Nullable String channel,
104-
@Nullable String displayName, @NotNull String tellRawData
94+
@Nullable String displayName, @NotNull String tellRawData,
95+
ChatModules.AurionChatProviderConfig config
10596
) {
10697
super(type == null ? AurionPacket.Type.CHAT : type, source, route == null ? new ArrayList<>() : route, player, channel, displayName, tellRawData);
10798
this.packetType = packetType;
99+
this.config = config;
108100
}
109101

110102
@Override
@@ -123,7 +115,15 @@ public ChatMessage getMessage() {
123115
.flatMap(mod.getPlayerAdapter()::getPlayer)
124116
.or(() -> optional.map(AurionPlayer::getName).flatMap(mod.getPlayerAdapter()::getPlayer))
125117
.orElseThrow(() -> new NoSuchElementException("Player not found"));
126-
return new ChatMessage(sender, mod.getPlayerAdapter().getDisplayName(sender.getId()), getDisplayString(), (TextComponent) getComponent());
118+
TextComponent component;
119+
if (config.getContentPattern() == null)
120+
component = (TextComponent) getComponent();
121+
else {
122+
var txt = legacySection().serialize(getComponent());
123+
var matcher = Pattern.compile(config.getContentPattern()).matcher(txt);
124+
component = legacySection().deserialize(matcher.find() ? matcher.group(1) : txt);
125+
}
126+
return new ChatMessage(sender, mod.getPlayerAdapter().getDisplayName(sender.getId()), getDisplayString(), component);
127127
}
128128
}
129129
}

0 commit comments

Comments
 (0)