Skip to content

Commit

Permalink
Updated to v0.26-b6.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Mar 6, 2024
2 parents 1e043ce + 8db1f1a commit 2362bb8
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/chatty/TwitchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,11 @@ private void addCommands() {
commands.add("marker", p -> {
commandAddStreamMarker(p.getRoom(), p.getArgs());
});
commands.add("createClip", p -> {
api.createClip(p.getRoom().getStream(), result -> {
g.printLine(p.getRoom(), result);
});
});
c.addNewCommands(commands, this);
commands.add("addStreamHighlight", p -> {
commandAddStreamHighlight(p.getRoom(), p.getArgs());
Expand Down
33 changes: 33 additions & 0 deletions src/chatty/User.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package chatty;

import chatty.gui.Highlighter;
import chatty.gui.colors.UsercolorManager;
import chatty.util.api.usericons.Usericon;
import chatty.util.api.usericons.UsericonManager;
Expand Down Expand Up @@ -588,6 +589,38 @@ public synchronized int getNumberOfSimilarChatMessages(String compareMsg, int me
return result;
}

public synchronized int getMatchingMessages(Highlighter.HighlightItem item, int num, long time, boolean beforeTime) {
if (lines == null) {
return 0;
}
int result = 0;
int numMsgs = 0;
for (int i=lines.size() - 1; i>=0; i--) {
Message m = lines.get(i);
if (beforeTime) {
if (m.time > time) {
continue;
}
}
else {
if (m.time < time) {
return result;
}
}
if (m instanceof TextMessage) {
TextMessage tm = (TextMessage) m;
if (item.matchesTextOnly(tm.text, null)) {
result++;
}
numMsgs++;
if (numMsgs == num) {
return result;
}
}
}
return result;
}

public synchronized int getNumberOfMessagesAfterBan() {
if (lines == null) {
return -1;
Expand Down
6 changes: 6 additions & 0 deletions src/chatty/gui/Channels.java
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,12 @@ private static boolean isChanOffline(DockContent content) {
}
return false;
}

public void closeModPanels() {
for (Channel chan : getChannels()) {
chan.closeModPanel();
}
}

/**
* Sets the focus to the input bar when clicked anywhere on the channel.
Expand Down
116 changes: 110 additions & 6 deletions src/chatty/gui/Highlighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import chatty.Helper;
import chatty.Logging;
import chatty.User;
import chatty.util.DateTime;
import chatty.util.Debugging;
import chatty.util.MiscUtil;
import chatty.util.Pair;
Expand Down Expand Up @@ -441,12 +442,12 @@ private void clearRecentMatches() {
* retrieve all match indices and some meta information.
*/
public static class HighlightItem {

public enum Type {
REGULAR("Regular chat messages"),
INFO("Info messages"),
ANY("Any type of message"),
TEXT_MATCH_TEST("Only match text, any message type");
TEXT_MATCHING_ONLY("Only match text, any message type");

public final String description;

Expand Down Expand Up @@ -618,6 +619,12 @@ public boolean matches(Type type, String text, int msgStart, int msgEnd, Blackli

private List<String> routingTargets;

private int msgsReq = 1;
private int msgsLimit = 0;
private long msgsDuration = 0;
private boolean msgsBeforeDuration;
private boolean msgsMatchOuter;

//--------------------------
// Debugging
//--------------------------
Expand Down Expand Up @@ -812,6 +819,103 @@ else if (item.startsWith("!status:")) {
return checkStatus(user, s, false);
});
}
else if (item.startsWith("msgs:") || item.startsWith("!msgs:")) {
boolean inverted = item.startsWith("!msgs:");
if (inverted) {
item = item.substring(1);
}
List<String> listEntries = parseStringListPrefix(item, "msgs:", s -> s);
List<HighlightItem> hlItems = new ArrayList<HighlightItem>() {

@Override
public String toString() {
StringBuilder b = new StringBuilder("\n");
for (HighlightItem hlItem : this) {
if (b.length() > 1) {
b.append("OR\n");
}
b.append(" ");
if (hlItem.msgsMatchOuter) {
b.append("Text match from outer item\n");
}
else {
b.append(hlItem.getMatchInfo().replaceAll("\\n(?!$)", "\n "));
}
}
return b.toString();
}

};
for (String entry : listEntries) {
hlItems.add(new HighlightItem(entry));
}
addUserItem(inverted ? "Don't " : "" + "Match user messages", hlItems, user -> {
boolean matched = false;
for (HighlightItem hlItem : hlItems) {
long time = -1;
if (hlItem.msgsDuration > 0) {
time = System.currentTimeMillis() - hlItem.msgsDuration;
}
int num = user.getMatchingMessages(
hlItem.msgsMatchOuter ? HighlightItem.this : hlItem,
hlItem.msgsLimit,
time,
hlItem.msgsBeforeDuration);
if (num >= hlItem.msgsReq) {
matched = true;
break;
}
}
if (inverted) {
return !matched;
}
return matched;
});
}
else if (item.startsWith("mreq:")) {
try {
msgsReq = Integer.parseInt(parsePrefix(item, "mreq:"));
}
catch (NumberFormatException ex) {
// Change nothing
}
}
else if (item.startsWith("mlimit:")) {
try {
msgsLimit = Integer.parseInt(parsePrefix(item, "mlimit:"));
}
catch (NumberFormatException ex) {
// Change nothing
}
}
else if (item.startsWith("mtime:")) {
String value = parsePrefix(item, "mtime:");
msgsBeforeDuration = false;
if (value.startsWith(">")) {
value = value.substring(1);
msgsBeforeDuration = true;
}
if (value.startsWith("<")) {
value = value.substring(1);
}
try {
msgsDuration = DateTime.parseDuration(value);
}
catch (NumberFormatException ex) {
// Change nothing
}
}
else if (item.startsWith("mtype:")) {
try {
String value = parsePrefix(item, "mtype:");
if (value.equals("outer")) {
msgsMatchOuter = true;
}
}
catch (NumberFormatException ex) {
// Change nothing
}
}
else if (item.startsWith("mystatus:")) {
Set<Status> s = parseStatus(parsePrefix(item, "mystatus:"));
addLocalUserItem("My User Status", s, user -> {
Expand Down Expand Up @@ -1888,8 +1992,8 @@ public boolean matchesAny(String text, Blacklist blacklist) {
return matches(Type.ANY, text, blacklist, null, null);
}

public boolean matchesTest(String text, Blacklist blacklist) {
return matches(Type.TEXT_MATCH_TEST, text, blacklist, null, null);
public boolean matchesTextOnly(String text, Blacklist blacklist) {
return matches(Type.TEXT_MATCHING_ONLY, text, blacklist, null, null);
}

public boolean matches(Type type, String text, User user, User localUser, MsgTags tags) {
Expand Down Expand Up @@ -1964,7 +2068,7 @@ public boolean matches(Type type, String text, int msgStart, int msgEnd,
// Type
//------
if (type != appliesToType && appliesToType != Type.ANY
&& type != Type.ANY && type != Type.TEXT_MATCH_TEST) {
&& type != Type.ANY && type != Type.TEXT_MATCHING_ONLY) {
return false;
}

Expand Down Expand Up @@ -2000,7 +2104,7 @@ public boolean matches(Type type, String text, int msgStart, int msgEnd,

// System.out.println(raw);
for (Item item : matchItems) {
if (type == Type.TEXT_MATCH_TEST && !item.matchesOnText) {
if (type == Type.TEXT_MATCHING_ONLY && !item.matchesOnText) {
continue;
}
boolean match = item.matches(type, text, msgStart, msgEnd, blacklist, channel, ab, user, localUser, tags);
Expand Down
1 change: 1 addition & 0 deletions src/chatty/gui/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,7 @@ public void stateChanged(ChangeEvent e) {
openFollowerDialog();
}
}
channels.closeModPanels();
dockedDialogs.activeContentChanged();
routingManager.setChannel(channels.getLastActiveChannel());
state.update(true);
Expand Down
13 changes: 7 additions & 6 deletions src/chatty/gui/components/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum Type {

private static final int DIVIDER_SIZE = 5;

private final JPanel inputPanel;
private final ChannelEditBox input;
private final ChannelTextPane text;
private final UserList users;
Expand Down Expand Up @@ -118,7 +119,7 @@ public Channel(final Room room, Type type, MainGui main, StyleManager styleManag
installLimits(input);
TextSelectionMenu.install(input);

JPanel inputPanel = new JPanel(new BorderLayout());
inputPanel = new JPanel(new BorderLayout());
inputPanel.add(input, BorderLayout.CENTER);

modPanelButton = new JButton("M");
Expand Down Expand Up @@ -157,7 +158,7 @@ public void updateModPanel() {
}
}

private void closeModPanel() {
public void closeModPanel() {
if (modPanelPopup != null) {
modPanelPopup.hide();
modPanelPopup = null;
Expand Down Expand Up @@ -500,20 +501,20 @@ public Dimension getMinimumSize() {
* Toggle visibility for the text input box.
*/
public final void toggleInput() {
input.setVisible(!input.isVisible());
inputPanel.setVisible(!inputPanel.isVisible());
revalidate();
}

private boolean inputPreviouslyShown = true;

public final void hideInput() {
inputPreviouslyShown = input.isVisible();
input.setVisible(false);
inputPreviouslyShown = inputPanel.isVisible();
inputPanel.setVisible(false);
revalidate();
}

public final void restoreInput() {
input.setVisible(inputPreviouslyShown);
inputPanel.setVisible(inputPreviouslyShown);
revalidate();
}

Expand Down
2 changes: 2 additions & 0 deletions src/chatty/gui/components/help/help-builtin_commands.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ <h3>Moderation</h3>
<h3><a name="commands-twitch">Other Twitch Commands</a></h3>
<ul>
<li><a href="help.html#streamhighlights">Stream Highlights / Markers commands</a> (including <code>/marker</code>)</li>
<li><code>/createClip</code> - Attempt to create a clip. If it succeeds
it will output the clip edit link.</li>
</ul>

<h2><a name="commands-settings">Settings / Customization Commands</a></h2>
Expand Down
33 changes: 33 additions & 0 deletions src/chatty/gui/components/help/help-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,39 @@ <h3><a name="Highlight_Meta_Matching">Meta Prefixes (Matching)</a></h3>
updated on channel join and when sending a message, so e.g. if you
get modded while already in the channel it will not be recognized
until after you have sent a message.</li>
<li><code>msgs:</code> / <code>!msgs:</code> matches on the
past messages of the user as they are shown in the User Dialog,
not including the message that triggered this Highlight checking.<br />
The value is a list of one or several Highlight items, which will be
used to match against the text of the user's past messages (only one
item has to match, to require several items to match use separate
<code>msgs:</code> prefixes).<br />
For example <code>msgs:"mlimit:1 start:!v","!vote"</code> checks if
the latest message begins with "!v" or any message contains "!vote".
The usual text matching related prefixes can be used, as well as
these additional prefixes:<br />
<ul>
<li><code>mlimit:</code> limits how many messages are checked
(starting from the latest), for example <code>mlimit:2</code>
only checks the latest two messages (by default it checks
all).</li>
<li><code>mtime:</code> limits how long ago messages are
checked, for example <code>mtime:1h</code> only checks
messages from the last hour, whereas <code>mtime:>1h</code>
only checks messages from <em>before</em> the last hour (by
default it checks all).</li>
<li><code>mreq:</code> defines how many messages must match, for
example <code>mreq:3</code> requires at least three past
messages to match (by default at least one has to match).</li>
<li><code>mtype:outer</code> ignores text matching in the <code>msgs:</code>
prefix itself (so for <code>msgs:"mtype:outer abc"</code>
the "abc" would have no effect) and instead uses the outer
item's text matching. For example <code>msgs:"mtype:outer" start:!vote</code>
would match if both the message and also a past message
begin with "!vote" (<code>msgs:"start:!vote" start:!vote</code>
would have the same effect).</li>
</ul>
</li>
<li><code>config:</code> to specify on or more options (separated by comma, no spaces):
<ul>
<li><code>config:firstmsg</code> - Restrict matching to the
Expand Down
5 changes: 3 additions & 2 deletions src/chatty/gui/components/help/help-troubleshooting.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ <h3>Error: Java is not recognized as an internal or external command (Windows)</
should point to Java.</p>

<h3>Find errors in debug.log</h3>
<p>See next section. Of course you'll have to navigate to the folder
manually.</p>
<p>Check if Chatty writes to any files in the <code>debuglogs</code> folder
(by default <code>&lt;homedir&gt;/.chatty/debuglogs</code>,
for example <code>C:\Users\yourname\.chatty\debuglogs</code>).</p>

<h2>
<a name="visual-glitches">Visual Artifacts/Glitches</a>
Expand Down
3 changes: 2 additions & 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-b5)</a></h1>
<h1><a name="top">Chatty (Version: 0.26-b6)</a></h1>
<table>
<tr>
<td valign="top">
Expand Down Expand Up @@ -1462,6 +1462,7 @@ <h2>
<li>Website: <a href="https://chatty.github.io">https://chatty.github.io</a></li>
<li>E-Mail: [email protected]</li>
<li>Twitter: <a href="https://twitter.com/ChattyClient">@ChattyClient</a></li>
<li>Bluesky: <a href="https://bsky.app/profile/chattyclient.bsky.social">@chattyclient.bsky.social</a></li>
<li>Mastodon: <a href="https://mstdn.social/@chattyclient">mstdn.social/@chattyclient</a></li>
<li>Discord: <a href="https://discord.gg/WTuqGeJ">Chatty Discord Invite</a></li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions src/chatty/gui/components/settings/HighlighterTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ private void updateInfoText() {
testResult.setText("Empty item.");
} else if (highlightItem.hasError()) {
testResult.setText("Error: "+highlightItem.getError());
} else if (highlightItem.matchesTest(getTestText(), blacklist)) {
} else if (highlightItem.matchesTextOnly(getTestText(), blacklist)) {
testResult.setText("Matched.");
} else {
String failedReason = highlightItem.getFailedReason();
Expand Down Expand Up @@ -523,7 +523,7 @@ private void updateMatches(StyledDocument doc) {
Match m = blacklistMatches.get(i);
doc.setCharacterAttributes(m.start, m.end - m.start, blacklistAttr, false);
}
} else if (blacklistItem.matchesTest(getTestText(), null)) {
} else if (blacklistItem.matchesTextOnly(getTestText(), null)) {
doc.setCharacterAttributes(0, doc.getLength(), blacklistAttr, false);
}
}
Expand Down
Loading

0 comments on commit 2362bb8

Please sign in to comment.