Fixed a format
This commit is contained in:
@@ -47,12 +47,19 @@ settings menu edits the prefix and the chat-message format. For example, in
|
|||||||
`tiktok.yml`:
|
`tiktok.yml`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
prefix: "&#FE2C55[TikTok] &r| "
|
prefix: "&#FE2C55[TikTok]&r"
|
||||||
events:
|
events:
|
||||||
|
chat: "{prefix} | {username} > {message}"
|
||||||
join: "&e@{username} joined"
|
join: "&e@{username} joined"
|
||||||
like: "{prefix}{username} sent {data.likeCount} likes"
|
like: "{prefix}{username} sent {data.likeCount} likes"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The default prefix is just the platform tag (e.g. `[Twitch]`) and the default
|
||||||
|
chat-message format is `{prefix} | {username} > {message}`. Pressing Done in the
|
||||||
|
settings menu saves the prefix and chat format to these files, and the menu
|
||||||
|
reads them back each time it opens. An unclosed placeholder such as `{message`
|
||||||
|
is closed automatically.
|
||||||
|
|
||||||
Delete an `events:` line to restore that event's default. Every event is shown
|
Delete an `events:` line to restore that event's default. Every event is shown
|
||||||
in chat by default; change where each one goes (chat, action bar, toast, hidden)
|
in chat by default; change where each one goes (chat, action bar, toast, hidden)
|
||||||
in the settings menu.
|
in the settings menu.
|
||||||
|
|||||||
+1
-1
@@ -9,6 +9,6 @@ loom_version=1.19.3
|
|||||||
legacy_loom_version=1.14.10
|
legacy_loom_version=1.14.10
|
||||||
java_version=25
|
java_version=25
|
||||||
|
|
||||||
mod_version=0.1.5
|
mod_version=0.1.6
|
||||||
maven_group=dev.streamchat
|
maven_group=dev.streamchat
|
||||||
archives_base_name=stream-chat
|
archives_base_name=stream-chat
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public final class StreamChatConfig {
|
|||||||
private static final Path DIR = FabricLoader.getInstance().getConfigDir().resolve("stream-chat");
|
private static final Path DIR = FabricLoader.getInstance().getConfigDir().resolve("stream-chat");
|
||||||
private static final Path PATH = DIR.resolve("stream-chat.json");
|
private static final Path PATH = DIR.resolve("stream-chat.json");
|
||||||
private static final Path LEGACY_PATH = FabricLoader.getInstance().getConfigDir().resolve("stream-chat.json");
|
private static final Path LEGACY_PATH = FabricLoader.getInstance().getConfigDir().resolve("stream-chat.json");
|
||||||
|
private static final String CHAT_FORMAT = "{prefix} | {username} > {message}";
|
||||||
private static final Map<Platform, Map<String, String>> DEFAULT_FORMATS = defaultFormats();
|
private static final Map<Platform, Map<String, String>> DEFAULT_FORMATS = defaultFormats();
|
||||||
private static final Pattern PLACEHOLDER =
|
private static final Pattern PLACEHOLDER =
|
||||||
Pattern.compile("\\{(prefix|platform|event|username|message|data\\.[A-Za-z0-9_]+)}");
|
Pattern.compile("\\{(prefix|platform|event|username|message|data\\.[A-Za-z0-9_]+)}");
|
||||||
@@ -43,7 +44,7 @@ public final class StreamChatConfig {
|
|||||||
private static Map<Platform, Map<String, String>> defaultFormats() {
|
private static Map<Platform, Map<String, String>> defaultFormats() {
|
||||||
Map<Platform, Map<String, String>> all = new EnumMap<>(Platform.class);
|
Map<Platform, Map<String, String>> all = new EnumMap<>(Platform.class);
|
||||||
Map<String, String> twitch = new LinkedHashMap<>();
|
Map<String, String> twitch = new LinkedHashMap<>();
|
||||||
twitch.put("ChatMessage", "{prefix}{username} > {message}");
|
twitch.put("ChatMessage", CHAT_FORMAT);
|
||||||
twitch.put("Follow", "{prefix}{username} followed");
|
twitch.put("Follow", "{prefix}{username} followed");
|
||||||
twitch.put("Sub", "{prefix}{username} subscribed");
|
twitch.put("Sub", "{prefix}{username} subscribed");
|
||||||
twitch.put("ReSub", "{prefix}{username} resubscribed: {message}");
|
twitch.put("ReSub", "{prefix}{username} resubscribed: {message}");
|
||||||
@@ -52,7 +53,7 @@ public final class StreamChatConfig {
|
|||||||
twitch.put("Raid", "{prefix}{username} raided with {data.viewers} viewers");
|
twitch.put("Raid", "{prefix}{username} raided with {data.viewers} viewers");
|
||||||
all.put(Platform.TWITCH, twitch);
|
all.put(Platform.TWITCH, twitch);
|
||||||
Map<String, String> youtube = new LinkedHashMap<>();
|
Map<String, String> youtube = new LinkedHashMap<>();
|
||||||
youtube.put("Message", "{prefix}{username} > {message}");
|
youtube.put("Message", CHAT_FORMAT);
|
||||||
youtube.put("SuperChat", "{prefix}{username} sent a Super Chat {data.amount}: {message}");
|
youtube.put("SuperChat", "{prefix}{username} sent a Super Chat {data.amount}: {message}");
|
||||||
youtube.put("SuperSticker", "{prefix}{username} sent a Super Sticker");
|
youtube.put("SuperSticker", "{prefix}{username} sent a Super Sticker");
|
||||||
youtube.put("MemberMilestone", "{prefix}{username} member milestone: {message}");
|
youtube.put("MemberMilestone", "{prefix}{username} member milestone: {message}");
|
||||||
@@ -60,7 +61,7 @@ public final class StreamChatConfig {
|
|||||||
youtube.put("GiftMembershipReceived", "{prefix}{username} received a gifted membership");
|
youtube.put("GiftMembershipReceived", "{prefix}{username} received a gifted membership");
|
||||||
all.put(Platform.YOUTUBE, youtube);
|
all.put(Platform.YOUTUBE, youtube);
|
||||||
Map<String, String> tiktok = new LinkedHashMap<>();
|
Map<String, String> tiktok = new LinkedHashMap<>();
|
||||||
tiktok.put("chat", "{prefix}{username} > {message}");
|
tiktok.put("chat", CHAT_FORMAT);
|
||||||
tiktok.put("gift", "{prefix}{username} sent {message} x{data.repeatCount}");
|
tiktok.put("gift", "{prefix}{username} sent {message} x{data.repeatCount}");
|
||||||
tiktok.put("share", "{prefix}{username} shared the stream");
|
tiktok.put("share", "{prefix}{username} shared the stream");
|
||||||
tiktok.put("follow", "{prefix}{username} followed");
|
tiktok.put("follow", "{prefix}{username} followed");
|
||||||
@@ -89,9 +90,9 @@ public final class StreamChatConfig {
|
|||||||
public Map<String, String> emoteReplacements = new HashMap<>();
|
public Map<String, String> emoteReplacements = new HashMap<>();
|
||||||
|
|
||||||
public StreamChatConfig() {
|
public StreamChatConfig() {
|
||||||
prefixes.put("TWITCH", "[Twitch] | ");
|
prefixes.put("TWITCH", "[Twitch]");
|
||||||
prefixes.put("YOUTUBE", "[YouTube] | ");
|
prefixes.put("YOUTUBE", "[YouTube]");
|
||||||
prefixes.put("TIKTOK", "[TikTok] | ");
|
prefixes.put("TIKTOK", "[TikTok]");
|
||||||
templates.put("TWITCH", "{prefix}{username} > {message}");
|
templates.put("TWITCH", "{prefix}{username} > {message}");
|
||||||
templates.put("YOUTUBE", "{prefix}{username} > {message}");
|
templates.put("YOUTUBE", "{prefix}{username} > {message}");
|
||||||
templates.put("TIKTOK", "{prefix}{username} > {message}");
|
templates.put("TIKTOK", "{prefix}{username} > {message}");
|
||||||
@@ -162,6 +163,7 @@ public final class StreamChatConfig {
|
|||||||
if (file.prefix != null) prefixes.put(name, file.prefix);
|
if (file.prefix != null) prefixes.put(name, file.prefix);
|
||||||
if (file.usernameColor != null) usernameColors.put(name, file.usernameColor);
|
if (file.usernameColor != null) usernameColors.put(name, file.usernameColor);
|
||||||
if (file.format != null && !file.format.isBlank()) templates.put(name, file.format);
|
if (file.format != null && !file.format.isBlank()) templates.put(name, file.format);
|
||||||
|
file.events.replaceAll((event, format) -> closeBraces(format));
|
||||||
eventFormats.computeIfAbsent(name, key -> new LinkedHashMap<>()).putAll(file.events);
|
eventFormats.computeIfAbsent(name, key -> new LinkedHashMap<>()).putAll(file.events);
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not read " + path + "; using defaults.", exception);
|
LOGGER.log(Level.SEVERE, "Could not read " + path + "; using defaults.", exception);
|
||||||
@@ -203,7 +205,7 @@ public final class StreamChatConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getPrefix(Platform platform) {
|
public String getPrefix(Platform platform) {
|
||||||
return prefixes.getOrDefault(platform.name(), "[" + platform.name() + "] | ");
|
return prefixes.getOrDefault(platform.name(), "[" + platform.name() + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String format(StreamEvent event) {
|
public String format(StreamEvent event) {
|
||||||
@@ -267,7 +269,13 @@ public final class StreamChatConfig {
|
|||||||
|
|
||||||
public void setChatFormat(Platform platform, String format) {
|
public void setChatFormat(Platform platform, String format) {
|
||||||
eventFormats.computeIfAbsent(platform.name(), key -> new LinkedHashMap<>())
|
eventFormats.computeIfAbsent(platform.name(), key -> new LinkedHashMap<>())
|
||||||
.put(EVENT_NAMES.get(platform).get(0), format);
|
.put(EVENT_NAMES.get(platform).get(0), closeBraces(format));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Appends a missing '}' so a half-typed placeholder such as "{message" still works. */
|
||||||
|
static String closeBraces(String format) {
|
||||||
|
int open = format.lastIndexOf('{');
|
||||||
|
return open >= 0 && format.indexOf('}', open) < 0 ? format + "}" : format;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Re-reads every config file from disk into this instance. */
|
/** Re-reads every config file from disk into this instance. */
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public final class StreamChatScreen extends Screen {
|
|||||||
private EditBox tikFinityUrl;
|
private EditBox tikFinityUrl;
|
||||||
private EditBox prefix;
|
private EditBox prefix;
|
||||||
private EditBox template;
|
private EditBox template;
|
||||||
|
private Platform boxPlatform;
|
||||||
private final List<AbstractWidget> scrollable = new ArrayList<>();
|
private final List<AbstractWidget> scrollable = new ArrayList<>();
|
||||||
private final List<Integer> baseY = new ArrayList<>();
|
private final List<Integer> baseY = new ArrayList<>();
|
||||||
private int scroll;
|
private int scroll;
|
||||||
@@ -41,6 +42,8 @@ public final class StreamChatScreen extends Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
|
// Window resizes re-run init(); keep unsaved edits instead of reverting to the stored values.
|
||||||
|
if (prefix != null) commitFormatting();
|
||||||
int left = width / 2 - 190;
|
int left = width / 2 - 190;
|
||||||
int rowWidth = 380;
|
int rowWidth = 380;
|
||||||
int buttonWidth = 120;
|
int buttonWidth = 120;
|
||||||
@@ -94,6 +97,7 @@ public final class StreamChatScreen extends Screen {
|
|||||||
|
|
||||||
prefix = new EditBox(font, left, 230, rowWidth, 20, Component.literal("Platform prefix"));
|
prefix = new EditBox(font, left, 230, rowWidth, 20, Component.literal("Platform prefix"));
|
||||||
prefix.setValue(config.getPrefix(selectedPlatform));
|
prefix.setValue(config.getPrefix(selectedPlatform));
|
||||||
|
boxPlatform = selectedPlatform;
|
||||||
prefix.setMaxLength(128);
|
prefix.setMaxLength(128);
|
||||||
addRenderableWidget(prefix);
|
addRenderableWidget(prefix);
|
||||||
template = new EditBox(font, left, 270, rowWidth, 20, Component.literal("Chat message format"));
|
template = new EditBox(font, left, 270, rowWidth, 20, Component.literal("Chat message format"));
|
||||||
@@ -183,31 +187,30 @@ public final class StreamChatScreen extends Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
config.streamerBotUrl = streamerBotUrl.getValue().trim();
|
commitFormatting();
|
||||||
config.streamerBotPassword = streamerBotPassword.getValue();
|
|
||||||
config.tikFinityUrl = tikFinityUrl.getValue().trim();
|
|
||||||
config.prefixes.put(selectedPlatform.name(), prefix.getValue());
|
|
||||||
config.setChatFormat(selectedPlatform, template.getValue());
|
|
||||||
config.save();
|
config.save();
|
||||||
connections.configurationChanged();
|
connections.configurationChanged();
|
||||||
minecraft.setScreen(parent);
|
minecraft.setScreen(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void select(Platform platform) {
|
private void commitFormatting() {
|
||||||
config.streamerBotUrl = streamerBotUrl.getValue().trim();
|
config.streamerBotUrl = streamerBotUrl.getValue().trim();
|
||||||
config.streamerBotPassword = streamerBotPassword.getValue();
|
config.streamerBotPassword = streamerBotPassword.getValue();
|
||||||
config.tikFinityUrl = tikFinityUrl.getValue().trim();
|
config.tikFinityUrl = tikFinityUrl.getValue().trim();
|
||||||
config.prefixes.put(selectedPlatform.name(), prefix.getValue());
|
config.prefixes.put(boxPlatform.name(), prefix.getValue());
|
||||||
config.setChatFormat(selectedPlatform, template.getValue());
|
config.setChatFormat(boxPlatform, template.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void select(Platform platform) {
|
||||||
|
commitFormatting();
|
||||||
selectedPlatform = platform;
|
selectedPlatform = platform;
|
||||||
prefix.setValue(config.getPrefix(platform));
|
|
||||||
template.setValue(config.getChatFormat(platform));
|
|
||||||
rebuildRoutes();
|
rebuildRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadConfig() {
|
private void reloadConfig() {
|
||||||
config.reload();
|
config.reload();
|
||||||
connections.configurationChanged();
|
connections.configurationChanged();
|
||||||
|
prefix = null;
|
||||||
rebuildRoutes();
|
rebuildRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public final class StreamChatScreen extends Screen {
|
|||||||
private EditBox tikFinityUrl;
|
private EditBox tikFinityUrl;
|
||||||
private EditBox prefix;
|
private EditBox prefix;
|
||||||
private EditBox template;
|
private EditBox template;
|
||||||
|
private Platform boxPlatform;
|
||||||
private final List<AbstractWidget> scrollable = new ArrayList<>();
|
private final List<AbstractWidget> scrollable = new ArrayList<>();
|
||||||
private final List<Integer> baseY = new ArrayList<>();
|
private final List<Integer> baseY = new ArrayList<>();
|
||||||
private int scroll;
|
private int scroll;
|
||||||
@@ -42,6 +43,8 @@ public final class StreamChatScreen extends Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
|
// Window resizes re-run init(); keep unsaved edits instead of reverting to the stored values.
|
||||||
|
if (prefix != null) commitFormatting();
|
||||||
int left = width / 2 - 190;
|
int left = width / 2 - 190;
|
||||||
int rowWidth = 380;
|
int rowWidth = 380;
|
||||||
int buttonWidth = 120;
|
int buttonWidth = 120;
|
||||||
@@ -95,6 +98,7 @@ public final class StreamChatScreen extends Screen {
|
|||||||
|
|
||||||
prefix = new EditBox(font, left, 230, rowWidth, 20, Component.literal("Platform prefix"));
|
prefix = new EditBox(font, left, 230, rowWidth, 20, Component.literal("Platform prefix"));
|
||||||
prefix.setValue(config.getPrefix(selectedPlatform));
|
prefix.setValue(config.getPrefix(selectedPlatform));
|
||||||
|
boxPlatform = selectedPlatform;
|
||||||
prefix.setMaxLength(128);
|
prefix.setMaxLength(128);
|
||||||
addRenderableWidget(prefix);
|
addRenderableWidget(prefix);
|
||||||
template = new EditBox(font, left, 270, rowWidth, 20, Component.literal("Chat message format"));
|
template = new EditBox(font, left, 270, rowWidth, 20, Component.literal("Chat message format"));
|
||||||
@@ -184,31 +188,30 @@ public final class StreamChatScreen extends Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
config.streamerBotUrl = streamerBotUrl.getValue().trim();
|
commitFormatting();
|
||||||
config.streamerBotPassword = streamerBotPassword.getValue();
|
|
||||||
config.tikFinityUrl = tikFinityUrl.getValue().trim();
|
|
||||||
config.prefixes.put(selectedPlatform.name(), prefix.getValue());
|
|
||||||
config.setChatFormat(selectedPlatform, template.getValue());
|
|
||||||
config.save();
|
config.save();
|
||||||
connections.configurationChanged();
|
connections.configurationChanged();
|
||||||
minecraft.setScreen(parent);
|
minecraft.setScreen(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void select(Platform platform) {
|
private void commitFormatting() {
|
||||||
config.streamerBotUrl = streamerBotUrl.getValue().trim();
|
config.streamerBotUrl = streamerBotUrl.getValue().trim();
|
||||||
config.streamerBotPassword = streamerBotPassword.getValue();
|
config.streamerBotPassword = streamerBotPassword.getValue();
|
||||||
config.tikFinityUrl = tikFinityUrl.getValue().trim();
|
config.tikFinityUrl = tikFinityUrl.getValue().trim();
|
||||||
config.prefixes.put(selectedPlatform.name(), prefix.getValue());
|
config.prefixes.put(boxPlatform.name(), prefix.getValue());
|
||||||
config.setChatFormat(selectedPlatform, template.getValue());
|
config.setChatFormat(boxPlatform, template.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void select(Platform platform) {
|
||||||
|
commitFormatting();
|
||||||
selectedPlatform = platform;
|
selectedPlatform = platform;
|
||||||
prefix.setValue(config.getPrefix(platform));
|
|
||||||
template.setValue(config.getChatFormat(platform));
|
|
||||||
rebuildRoutes();
|
rebuildRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadConfig() {
|
private void reloadConfig() {
|
||||||
config.reload();
|
config.reload();
|
||||||
connections.configurationChanged();
|
connections.configurationChanged();
|
||||||
|
prefix = null;
|
||||||
rebuildRoutes();
|
rebuildRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user