Skip to content

Commit

Permalink
Added option to change the prefix + added support for Skyblock Addons…
Browse files Browse the repository at this point in the history
… Z color code
  • Loading branch information
NopoTheGamer committed Jan 8, 2022
1 parent 25b13d4 commit d3a5639
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
30 changes: 15 additions & 15 deletions src/main/java/me/mini_bomba/streamchatmod/StreamChatMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ public void checkUpdates() {
latestVersion = newLatestVersion;
latestCommit = newLatestCommit;
LOGGER.warn("New version available: " + newLatestVersion + (newLatestCommit != null ? "@" + newLatestCommit.shortHash : "") + "!");
IChatComponent component1 = new ChatComponentText(EnumChatFormatting.DARK_PURPLE + "[TWITCH] " + EnumChatFormatting.GOLD + "New update published: " + newLatestVersion + (PRERELEASE ? "@" + newLatestCommit.shortHash : ""));
IChatComponent component1 = new ChatComponentText(config.getTwitchPrefix1().replace(config.getTwitchPrefixLastChar(), (config.getTwitchPrefixLastChar() + " ")) + EnumChatFormatting.GOLD + "New update published: " + newLatestVersion + (PRERELEASE ? "@" + newLatestCommit.shortHash : ""));
IChatComponent component2 = null;
if (PRERELEASE && newLatestCommit != null)
component2 = new ChatComponentText(EnumChatFormatting.DARK_PURPLE + "[TWITCH] " + EnumChatFormatting.GRAY + "Update commit message: " + EnumChatFormatting.AQUA + newLatestCommit.shortMessage);
component2 = new ChatComponentText(config.getTwitchPrefix1().replace(config.getTwitchPrefixLastChar(), (config.getTwitchPrefixLastChar() + " ")) + EnumChatFormatting.GRAY + "Update commit message: " + EnumChatFormatting.AQUA + newLatestCommit.shortMessage);
IChatComponent component3 = new ChatComponentText("" + EnumChatFormatting.GRAY + EnumChatFormatting.ITALIC + "Want to check for updates only on startup? Click here!");
ChatStyle style = new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/mini-bomba/StreamChatMod/releases"))
.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(EnumChatFormatting.GREEN + "Click here to see mod releases on GitHub!")));
Expand Down Expand Up @@ -595,7 +595,7 @@ private void onTwitchMessage(ChannelMessageEvent event) {
}

private void onTwitchFollow(FollowEvent event) {
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE + "[TWITCH] " + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD + event.getUser().getName() + EnumChatFormatting.DARK_GREEN + " is now following " + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD + event.getChannel().getName() + EnumChatFormatting.DARK_GREEN + "!");
StreamUtils.queueAddMessage(config.getTwitchPrefix1().replace(config.getTwitchPrefixLastChar(), (config.getTwitchPrefixLastChar() + " ")) + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD + event.getUser().getName() + EnumChatFormatting.DARK_GREEN + " is now following " + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD + event.getChannel().getName() + EnumChatFormatting.DARK_GREEN + "!");
if (this.config.playSoundOnFollow.getBoolean()) new Thread(new TwitchFollowSoundScheduler(this)).start();
}

Expand All @@ -607,7 +607,7 @@ private void onTwitchMessageDeleted(IRCMessageEvent event) {
private void onTwitchChatClear(ClearChatEvent event) {
if (config.allowMessageDeletion.getBoolean()) StreamUtils.queueClearTwitchChat(event.getChannel().getId());
boolean showChannel = config.forceShowChannelName.getBoolean() || (twitch != null && twitch.getChat().getChannels().size() > 1);
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE + "[TWITCH" + (showChannel ? "/" + event.getChannel().getName() : "") + "] " + EnumChatFormatting.GRAY + "The chat has been cleared.");
StreamUtils.queueAddMessage(config.getPrefixWithoutLast() + (showChannel ? "/" + event.getChannel().getName() : "") + config.getTwitchPrefixLastChar() + " " + EnumChatFormatting.GRAY + "The chat has been cleared.");
}

private void onUserTimedOut(UserTimeoutEvent event) {
Expand All @@ -628,35 +628,35 @@ private void onTwitchNotice(ChannelNoticeEvent event) {
switch (type) {
// Chat mode updates
case EMOTE_ONLY_OFF:
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE + "[TWITCH" + (showChannel ? "/" + event.getChannel().getName() : "") + "] " + EnumChatFormatting.GRAY + (message == null ? "Emote only mode has been disabled" : message));
StreamUtils.queueAddMessage(config.getPrefixWithoutLast() + (showChannel ? "/" + event.getChannel().getName() : "") + config.getTwitchPrefixLastChar() + " " + EnumChatFormatting.GRAY + (message == null ? "Emote only mode has been disabled" : message));
break;
case EMOTE_ONLY_ON:
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE+"[TWITCH"+(showChannel ? "/"+event.getChannel().getName() : "")+"] "+EnumChatFormatting.GRAY+(message == null ? "Emote only mode has been enabled" : message));
StreamUtils.queueAddMessage(config.getPrefixWithoutLast()+(showChannel ? "/"+event.getChannel().getName() : "")+ config.getTwitchPrefixLastChar() + " "+EnumChatFormatting.GRAY+(message == null ? "Emote only mode has been enabled" : message));
break;
case FOLLOWERS_OFF:
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE+"[TWITCH"+(showChannel ? "/"+event.getChannel().getName() : "")+"] "+EnumChatFormatting.GRAY+(message == null ? "Followers only mode has been disabled" : message));
StreamUtils.queueAddMessage(config.getPrefixWithoutLast()+(showChannel ? "/"+event.getChannel().getName() : "")+ config.getTwitchPrefixLastChar() + " "+EnumChatFormatting.GRAY+(message == null ? "Followers only mode has been disabled" : message));
break;
case FOLLOWERS_ON:
case FOLLOWERS_ONZERO:
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE+"[TWITCH"+(showChannel ? "/"+event.getChannel().getName() : "")+"] "+EnumChatFormatting.GRAY+(message == null ? "Followers only mode has been enabled" : message));
StreamUtils.queueAddMessage(config.getPrefixWithoutLast()+(showChannel ? "/"+event.getChannel().getName() : "")+ config.getTwitchPrefixLastChar() + " "+EnumChatFormatting.GRAY+(message == null ? "Followers only mode has been enabled" : message));
break;
case R9K_OFF:
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE+"[TWITCH"+(showChannel ? "/"+event.getChannel().getName() : "")+"] "+EnumChatFormatting.GRAY+(message == null ? "Unique only mode has been disabled" : message));
StreamUtils.queueAddMessage(config.getPrefixWithoutLast()+(showChannel ? "/"+event.getChannel().getName() : "")+ config.getTwitchPrefixLastChar() + " "+EnumChatFormatting.GRAY+(message == null ? "Unique only mode has been disabled" : message));
break;
case R9K_ON:
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE+"[TWITCH"+(showChannel ? "/"+event.getChannel().getName() : "")+"] "+EnumChatFormatting.GRAY+(message == null ? "Unique only mode has been enabled" : message));
StreamUtils.queueAddMessage(config.getPrefixWithoutLast()+(showChannel ? "/"+event.getChannel().getName() : "")+ config.getTwitchPrefixLastChar() + " "+EnumChatFormatting.GRAY+(message == null ? "Unique only mode has been enabled" : message));
break;
case SLOW_OFF:
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE+"[TWITCH"+(showChannel ? "/"+event.getChannel().getName() : "")+"] "+EnumChatFormatting.GRAY+(message == null ? "Slow mode has been disabled" : message));
StreamUtils.queueAddMessage(config.getPrefixWithoutLast()+(showChannel ? "/"+event.getChannel().getName() : "")+ config.getTwitchPrefixLastChar() + " "+EnumChatFormatting.GRAY+(message == null ? "Slow mode has been disabled" : message));
break;
case SLOW_ON:
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE+"[TWITCH"+(showChannel ? "/"+event.getChannel().getName() : "")+"] "+EnumChatFormatting.GRAY+(message == null ? "Slow mode has been enabled" : message));
StreamUtils.queueAddMessage(config.getPrefixWithoutLast()+(showChannel ? "/"+event.getChannel().getName() : "")+ config.getTwitchPrefixLastChar() + " "+EnumChatFormatting.GRAY+(message == null ? "Slow mode has been enabled" : message));
break;
case SUBS_OFF:
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE+"[TWITCH"+(showChannel ? "/"+event.getChannel().getName() : "")+"] "+EnumChatFormatting.GRAY+(message == null ? "Sub only mode has been disabled" : message));
StreamUtils.queueAddMessage(config.getPrefixWithoutLast()+(showChannel ? "/"+event.getChannel().getName() : "")+ config.getTwitchPrefixLastChar() + " "+EnumChatFormatting.GRAY+(message == null ? "Sub only mode has been disabled" : message));
break;
case SUBS_ON:
StreamUtils.queueAddMessage(EnumChatFormatting.DARK_PURPLE+"[TWITCH"+(showChannel ? "/"+event.getChannel().getName() : "")+"] "+EnumChatFormatting.GRAY+(message == null ? "Sub only mode has been enabled" : message));
StreamUtils.queueAddMessage(config.getPrefixWithoutLast()+(showChannel ? "/"+event.getChannel().getName() : "")+ config.getTwitchPrefixLastChar() + " "+EnumChatFormatting.GRAY+(message == null ? "Sub only mode has been enabled" : message));
break;
// /twitchchat
case MSG_BANNED:
Expand Down Expand Up @@ -808,7 +808,7 @@ public void printTwitchStatus() {
}

public void printTwitchStatus(boolean includePrefix) {
String prefix = includePrefix ? EnumChatFormatting.DARK_PURPLE+"[TWITCH] " : "";
String prefix = includePrefix ? EnumChatFormatting.DARK_PURPLE+config.getTwitchPrefix1().replace(config.getTwitchPrefixLastChar(), config.getTwitchPrefixLastChar() + " ") : "";
IChatComponent component = new ChatComponentText(prefix + EnumChatFormatting.GRAY + "Mod version: " + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD + VERSION + (PRERELEASE ? EnumChatFormatting.GRAY + "@" + EnumChatFormatting.AQUA + GIT_HASH : "") + EnumChatFormatting.GRAY + " (" + (latestVersion == null || (PRERELEASE && latestCommit == null) ? EnumChatFormatting.RED + "Could not check latest version" : (latestVersion.equals(VERSION) && (!PRERELEASE || latestCommit.shortHash.equals(GIT_HASH)) ? EnumChatFormatting.GREEN + "Latest version" : EnumChatFormatting.GOLD + "Update available: " + latestVersion + (PRERELEASE ? "@" + latestCommit.shortHash : "")) ) + EnumChatFormatting.GRAY + ")");
IChatComponent commitMessage = null;
if (latestVersion != null && !latestVersion.equals(VERSION) || (PRERELEASE && latestCommit != null && !latestCommit.shortHash.equals(GIT_HASH))) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/me/mini_bomba/streamchatmod/StreamConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class StreamConfig {
public final Property subOnlyFormatting;
public final Property minecraftChatPrefix;
public final Property allowMessageDeletion;
public final Property twitchPrefix;
public final Property twitchPrefixLastChar;
// tokens
protected final Property twitchToken;
// twitch
Expand Down Expand Up @@ -72,6 +74,8 @@ public StreamConfig(File configFile) {
showFFZGlobalEmotes = config.get("emotes", "ffz_globals", true);
showFFZChannelEmotes = config.get("emotes", "ffz_channel", true);
allowAnimatedEmotes = config.get("emotes", "animated", true);
twitchPrefix = config.get("common", "twitch_prefix", "&5[TWITCH");
twitchPrefixLastChar = config.get("common", "twitch_prefix_last_char", "]");
saveIfChanged();
}

Expand Down Expand Up @@ -105,4 +109,15 @@ public boolean revokeTwitchToken() {
return code == 200;
}

public String getTwitchPrefix1() {
return twitchPrefix.getString().replace("&", "\u00a7") + getTwitchPrefixLastChar();
}

public String getTwitchPrefixLastChar() {
return twitchPrefixLastChar.getString();
}

public String getPrefixWithoutLast() {
return twitchPrefix.getString().replace("&", "\u00a7");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class TwitchMessageHandler implements Runnable {
private final StreamChatMod mod;
private static final Logger LOGGER = LogManager.getLogger();
private static final char formatChar = '\u00a7';
private static final String validFormats = "0123456789abcdefklmnorABCDEFKLMNOR";
private static final String validFormats = "0123456789abcdefklmnorABCDEFKLMNORzZ";
public static final Pattern urlPattern = Pattern.compile("https?://[^.\\s/]+(?:\\.[^.\\s/]+)+\\S*");
private static final Pattern formatCodePattern = Pattern.compile(formatChar + "[0-9a-fA-Fk-rK-R]");
private static final Pattern formatCodePattern = Pattern.compile(formatChar + "[0-9a-fA-Fk-rK-RzZ]");
private static final String clipsDomain = "https://clips.twitch.tv/";

public TwitchMessageHandler(StreamChatMod mod, ChannelMessageEvent event) {
Expand Down Expand Up @@ -106,7 +106,7 @@ public void run() {

Matcher matcher = urlPattern.matcher(message);
List<ClipComponentMapping> clips = new ArrayList<>();
IChatComponent component = new ChatComponentTwitchMessage(event.getMessageEvent().getMessageId().orElse(""), event.getChannel().getId(), event.getUser().getId(), EnumChatFormatting.DARK_PURPLE + "[TWITCH" + (showChannel ? "/" + event.getChannel().getName() : "") + "]" + prefix + EnumChatFormatting.WHITE + event.getUser().getName() + EnumChatFormatting.GRAY + " >> ");
IChatComponent component = new ChatComponentTwitchMessage(event.getMessageEvent().getMessageId().orElse(""), event.getChannel().getId(), event.getUser().getId(), mod.config.getPrefixWithoutLast() + (showChannel ? "/" + event.getChannel().getName() : "") + mod.config.getTwitchPrefixLastChar() + prefix + EnumChatFormatting.WHITE + event.getUser().getName() + EnumChatFormatting.GRAY + " >> ");
int lastEnd = 0;
while (matcher.find()) {
if (matcher.start() > lastEnd)
Expand Down

0 comments on commit d3a5639

Please sign in to comment.