Skip to content

Commit

Permalink
Updated to v0.26-b5.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Feb 26, 2024
2 parents e551b64 + dd731ab commit 1e043ce
Show file tree
Hide file tree
Showing 19 changed files with 492 additions and 116 deletions.
5 changes: 5 additions & 0 deletions src/chatty/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ public void defineSettings() {
settings.addBoolean("historyServiceEnabled", false);
settings.addLong("historyServiceLimit", 30);
settings.addList("historyServiceExcluded", new ArrayList(), Setting.STRING);
settings.addBoolean("historyMessageHighlight", false);
settings.addBoolean("historyMessageMsgColors", false);
settings.addBoolean("historyMessageIgnore", true);
settings.addBoolean("historyMessageRouting", false);
settings.addBoolean("historyMessageNotifications", false);

//=======================
// Channel Admin Features
Expand Down
35 changes: 22 additions & 13 deletions src/chatty/TwitchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import chatty.util.chatlog.ChatLog;
import chatty.util.commands.CustomCommand;
import chatty.util.commands.Parameters;
import chatty.util.history.QueuedMessage;
import chatty.util.irc.MsgTags;
import chatty.util.irc.UserTagsUtil;
import chatty.util.settings.FileManager;
Expand Down Expand Up @@ -721,7 +722,7 @@ public void closeChannel(String channel) {
chatLog.closeChannel(room.getFilename());
updateStreamInfoChannelOpen(channel);
}
historyManager.resetMessageSeen(Helper.toStream(channel));
historyManager.channelClosed(Helper.toStream(channel));
}

private void closeChannelStuff(Room room) {
Expand Down Expand Up @@ -3290,20 +3291,26 @@ public void requestChannelHistory(String stream) {
if (historyManager.isChannelExcluded(stream)) {
return;
}
Room room = Room.createRegular("#" + stream);
String channelName = Helper.toChannel(stream);
Room room = Room.createRegular(channelName);
g.printSystem(room, "### Pulling information from history service. ###");

// Get the actual list of messages
List<HistoryMessage> history = historyManager.getHistoricChatMessages(room);
// Get the actual list of messages asynchronously
historyManager.getHistoricChatMessages(room, history -> {
for (int i = 0; i < history.size(); i++) {
HistoryMessage currentMsg = history.get(i);
User user = c.getUser(channelName, currentMsg.userName);
UserTagsUtil.updateUserFromTags(user, currentMsg.tags);
g.printMessage(user, currentMsg.message, currentMsg.action, currentMsg.tags);
}
g.printSystem(room, "### Finished with history logs. ###");
historyManager.setMessageSeen(stream);

for (int i = 0; i < history.size(); i++) {
HistoryMessage currentMsg = history.get(i);
User user = c.getUser("#"+stream, currentMsg.userName);
UserTagsUtil.updateUserFromTags(user, currentMsg.tags);
g.printMessage(user, currentMsg.message, currentMsg.action, currentMsg.tags);
}
historyManager.setMessageSeen(stream);
g.printSystem(room, "### Finished with history logs. ###");
// Output messages that arrived live while loading the history
for (QueuedMessage msg : historyManager.getQueuedMessages(stream)) {
g.printMessage(msg.user, msg.text, msg.action, msg.tags);
}
});
}

private class EmoteListener implements EmoticonListener {
Expand Down Expand Up @@ -3550,7 +3557,9 @@ public void onChannelMessage(User user, String text, boolean action, MsgTags tag
g.printPointsNotice(user, info, text, tags);
}
else {
g.printMessage(user, text, action, tags);
if (!historyManager.addQueueMessage(user, text, tags, action)) {
g.printMessage(user, text, action, tags);
}
if (tags.isReply() && tags.hasReplyUserMsg() && tags.hasId()) {
ReplyManager.addReply(tags.getReplyParentMsgId(), tags.getId(), String.format("<%s> %s", user.getName(), text), tags.getReplyUserMsg());
}
Expand Down
17 changes: 17 additions & 0 deletions src/chatty/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,23 @@ public synchronized int getNumberOfSimilarChatMessages(String compareMsg, int me
return result;
}

public synchronized int getNumberOfMessagesAfterBan() {
if (lines == null) {
return -1;
}
int msgsAfterBan = 0;
for (int i=lines.size() - 1; i>=0; i--) {
Message m = lines.get(i);
if (m instanceof TextMessage) {
msgsAfterBan++;
}
else if (m instanceof BanMessage) {
return msgsAfterBan;
}
}
return -1;
}

public synchronized TextMessage getMessage(String msgId) {
if (msgId == null) {
return null;
Expand Down
34 changes: 34 additions & 0 deletions src/chatty/gui/Highlighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ public boolean matches(Type type, String text, int msgStart, int msgEnd, Blackli

private boolean overrideIgnored;

private boolean matchHistoric;

/**
* 0 - Always disabled
* 1 - Depends on default
Expand Down Expand Up @@ -951,6 +953,15 @@ else if (part.equals("hypechat")) {
return tags.getHypeChatAmountText() != null;
});
}
else if (part.equals("historic")) {
addTagsItem("History Service Message", null, tags -> {
matchHistoric = true;
return tags.isHistoricMsg();
});
}
else if (part.equals("historic2")) {
matchHistoric = true;
}
else if (part.startsWith("repeatedmsg")) {
// String options = parsePrefix(item, "repeatmsg:");
// String[] split = options.split("/");
Expand Down Expand Up @@ -1009,6 +1020,25 @@ public boolean matches(Type type, String text, int msgStart, int msgEnd, Blackli
}
});
}
else if (part.startsWith("afterban")) {
String[] split = part.split("\\|");
int matchNumber;
if (split.length == 2 && split[1].matches("[0-9]+")) {
matchNumber = Integer.parseInt(split[1]);
}
else {
matchNumber = Integer.MAX_VALUE;
}
addUserItem("Messages after ban/timeout", matchNumber < Integer.MAX_VALUE ? matchNumber : null, user -> {
/**
* When matching takes place the latest user
* message won't be added yet, so look for
* smaller than the current number.
*/
int msgs = user.getNumberOfMessagesAfterBan();
return msgs != -1 && msgs < matchNumber;
});
}
});
parseBadges(list);
parseTags(list);
Expand Down Expand Up @@ -1832,6 +1862,10 @@ public boolean overrideIgnored() {
return overrideIgnored;
}

public boolean matchHistoric() {
return matchHistoric;
}

public boolean substitutesEnabled(boolean substitutesDefault) {
if (substitutesEnabled == 0) {
return false;
Expand Down
22 changes: 19 additions & 3 deletions src/chatty/gui/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import chatty.util.dnd.DockPopout;
import chatty.util.gif.FocusUpdates;
import chatty.util.gif.GifUtil;
import chatty.util.history.HistoryUtil;
import chatty.util.seventv.WebPUtil;
import java.util.function.Consumer;
import org.json.simple.JSONValue;
Expand Down Expand Up @@ -3576,7 +3577,12 @@ public void run() {

boolean isOwnMessage = isOwnUsername(user.getName()) || (whisper && action);
boolean ignoredUser = (userIgnored(user, whisper) && !isOwnMessage);
// May be necessary to check even if ignoredUser, to get ignore matchings later on
boolean ignored = checkMsg(ignoreList, "ignore", text, -2, -2, user, localUser, tags, isOwnMessage, false) || ignoredUser;
if (!HistoryUtil.checkAllowMatch(tags, "Ignore", ignoreList.getLastMatchItem(), client.settings)) {
ignored = false;
ignoredUser = false;
}

boolean highlighted = false;
List<Match> highlightMatches = null;
Expand All @@ -3589,6 +3595,9 @@ public void run() {
|| client.settings.getBoolean("highlightIgnored")
? false : ignored;
highlighted = checkMsg(highlighter, "highlight", text, -2, -2, user, localUser, tags, isOwnMessage, rejectIgnoredWithoutPrefix);
if (!HistoryUtil.checkAllowMatch(tags, "Highlight", highlighter.getLastMatchItem(), client.settings)) {
highlighted = false;
}
if (highlighted) {
if (client.settings.getBoolean("highlightOverrideIgnored")
|| highlighter.getLastMatchItem().overrideIgnored()) {
Expand All @@ -3597,7 +3606,9 @@ public void run() {
}
}

if (!ignored || client.settings.getBoolean("logIgnored")) {
boolean allowLog = !tags.isHistoricMsg();
if ((!ignored || client.settings.getBoolean("logIgnored"))
&& allowLog) {
client.chatLog.bits(chan.getFilename(), user, bitsAmount);
client.chatLog.message(chan.getFilename(), user, text, action, null);
}
Expand Down Expand Up @@ -3652,7 +3663,8 @@ public void run() {
ignoreSource, tags);
ignoredMessagesHelper.ignoredMessage(channel);
}
if (ignoredUser || !ignoreList.getLastMatchItem().noLog()) {
if ((ignoredUser || !ignoreList.getLastMatchItem().noLog())
&& allowLog) {
client.chatLog.message("ignored", user, text, action, channel);
}
}
Expand Down Expand Up @@ -3693,6 +3705,9 @@ public void run() {
}
if (!(highlighted || hlByPoints) || client.settings.getBoolean("msgColorsPrefer")) {
MsgColorItem colorItem = msgColorManager.getMsgColor(user, localUser, text, -2, -2, tags);
if (!HistoryUtil.checkAllowMatch(tags, "msgColors", colorItem.getMatcher(), client.settings)) {
colorItem = MsgColorManager.EMPTY;
}
if (!colorItem.isEmpty()) {
message.color = colorItem.getForegroundIfEnabled();
message.backgroundColor = colorItem.getBackgroundIfEnabled();
Expand All @@ -3716,7 +3731,8 @@ public void run() {
if (!highlighter.getLastMatchItem().hide()) {
highlightedMessages.addMessage(channel, message);
}
if (!highlighter.getLastMatchItem().noLog()) {
if (!highlighter.getLastMatchItem().noLog()
&& allowLog) {
client.chatLog.message("highlighted", user, text, action, channel);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/gui/colors/MsgColorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class MsgColorManager {

private static final MsgColorItem EMPTY = new MsgColorItem(null, null, false, null, false);
public static final MsgColorItem EMPTY = new MsgColorItem(null, null, false, null, false);

private static final String DATA_SETTING = "msgColors";
private static final String ENABLED_SETTING = "msgColorsEnabled";
Expand Down
16 changes: 16 additions & 0 deletions src/chatty/gui/components/help/help-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -1045,12 +1045,28 @@ <h3><a name="Highlight_Meta_Matching">Meta Prefixes (Matching)</a></h3>
match, for example <code>config:repeatedmsg|4</code> requires
4 repeated messages (can't be lower than the Repetition
Detection setting).</li>
<li><code>config:afterban|number</code> - Matches on the number
of messages after the user was banned/timed out (based on
the bans/messages visible in the User Dialog). <code>config:afterban|1</code>
matches the first message after a ban, <code>config:afterban|5</code>
up to the fifth message. The number is optional, so
<code>config:afterban</code> matches all messages after a
ban. If the user was not banned (or Chatty doesn't know
about it) then this never matches.</li>
<li><code>config:info</code> - This item applies to info
messages instead of regular user messages</li>
<li><code>config:any</code> - This item applies to both info
messages and regular user messages</li>
<li><code>config:hl</code> - Restrict matching to user messages
highlighted by using channel points</li>
<li><code>config:historic</code> - Applies to messages loaded
from the history service on channel join. This also allows
historic message to be matched for features that are
otherwise turned off in the History settings.</li>
<li><code>config:historic2</code> - Allows historic message to be
matched for features that are otherwise turned off in the
History settings, but does not restrict the match to just
historic messages.</li>
<li><code>config:b|id/version</code> - Match a Twitch Badge
(version optional, if several are specified in the same
<code>config:</code> prefix, only one has to match).</li>
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/gui/components/help/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1><a name="top">Chatty (Version: 0.26-b4)</a></h1>
<h1><a name="top">Chatty (Version: 0.26-b5)</a></h1>
<table>
<tr>
<td valign="top">
Expand Down
34 changes: 19 additions & 15 deletions src/chatty/gui/components/routing/RoutingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import chatty.util.Pair;
import chatty.util.StringUtil;
import chatty.util.chatlog.ChatLog;
import chatty.util.history.HistoryUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -126,22 +127,25 @@ public void addUserMessage(RoutingTargets targets, UserMessage message, User loc
for (Map.Entry<String, Pair<String, HighlightItem>> t : targets.getResultTargets().entrySet()) {
String name = t.getValue().key;
HighlightItem hlItem = t.getValue().value;
RoutingTarget target = getTarget(name);
UserMessage thisMessage = message.copy();
thisMessage.routingSource = hlItem;
target.addMessage(localUser.getChannel(), thisMessage);


RoutingTargetSettings ts = getSettings(name);

switch (ts.openOnMessage) {
case 1: // Any message
case 2: // Regular chat message
channels.addContent(target.getContent());
}

if (ts.shouldLog()) {
chatLog.message(ts.getPrefixedLogFilename(), message.user, message.text, message.action, message.user.getChannel());
if (HistoryUtil.checkAllowMatch(message.tags, "Routing", hlItem, main.getSettings())) {
RoutingTarget target = getTarget(name);
UserMessage thisMessage = message.copy();
thisMessage.routingSource = hlItem;
target.addMessage(localUser.getChannel(), thisMessage);


RoutingTargetSettings ts = getSettings(name);

switch (ts.openOnMessage) {
case 1: // Any message
case 2: // Regular chat message
channels.addContent(target.getContent());
}

if (ts.shouldLog() && (message.tags == null || !message.tags.isHistoricMsg())) {
chatLog.message(ts.getPrefixedLogFilename(), message.user, message.text, message.action, message.user.getChannel());
}
}
}
}
Expand Down
22 changes: 20 additions & 2 deletions src/chatty/gui/components/settings/HistorySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package chatty.gui.components.settings;

import chatty.gui.components.LinkLabel;
import chatty.lang.Language;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
Expand Down Expand Up @@ -101,17 +102,34 @@ public HistorySettings(SettingsDialog d) {
30, 40, 50, 60,
70, 80, 90, 100);
SettingsUtil.addStandardSetting(externalHistory, "historyServiceLimit", 2, historyServiceLimit, true);

String matchOptionsTip = "Using the matching prefix \"config:historic2\" will allow "
+ "the match even for features that are disabled here, while \"config:historic\" does the same but will restrict the match to history messages only.";
JLabel matchOptionsLabel = new JLabel("Allow for history messages:");
matchOptionsLabel.setToolTipText(SettingsUtil.addTooltipLinebreaks(matchOptionsTip));
externalHistory.add(matchOptionsLabel,
SettingsDialog.makeGbcSub2(0, 3, 2, 1, GridBagConstraints.WEST));

JPanel matchOptions = new JPanel();
matchOptions.add(d.addSimpleBooleanSetting("historyMessageHighlight", Language.getString("settings.page.highlight"), matchOptionsTip));
matchOptions.add(d.addSimpleBooleanSetting("historyMessageIgnore", Language.getString("settings.page.ignore"), matchOptionsTip));
matchOptions.add(d.addSimpleBooleanSetting("historyMessageMsgColors", Language.getString("settings.page.msgColors"), matchOptionsTip));
matchOptions.add(d.addSimpleBooleanSetting("historyMessageRouting", "Routing", matchOptionsTip));
matchOptions.add(d.addSimpleBooleanSetting("historyMessageNotifications", Language.getString("settings.page.notifications"), matchOptionsTip));

externalHistory.add(matchOptions,
SettingsDialog.makeGbcSub2(0, 4, 2, 1, GridBagConstraints.WEST));

externalHistory.add(new JLabel("Excluded channels:"),
SettingsDialog.makeGbcSub2(0, 3, 2, 1, GridBagConstraints.WEST));
SettingsDialog.makeGbcSub2(0, 5, 2, 1, GridBagConstraints.WEST));

ListSelector excludedChannels = d.addListSetting("historyServiceExcluded",
"Channel to be excluded from history",
250, 200,
false, true);
final ChannelFormatter formatter = new ChannelFormatter();
excludedChannels.setDataFormatter(formatter);
externalHistory.add(excludedChannels, SettingsDialog.makeGbcSub2(0, 4, 2, 1, GridBagConstraints.WEST));
externalHistory.add(excludedChannels, SettingsDialog.makeGbcSub2(0, 6, 2, 1, GridBagConstraints.WEST));

SettingsUtil.addSubsettings(historyServiceEnabled, historyServiceLimit, excludedChannels);
}
Expand Down
Loading

0 comments on commit 1e043ce

Please sign in to comment.