Skip to content

Commit

Permalink
Updated to v0.15-b6.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed May 26, 2021
2 parents 5a65320 + d161c0e commit 79c94c6
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/chatty/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ public static void setDefaultTimezone(String input) {
MainSettings.DEFAULT_TIMEZONE = TimeZone.getDefault();
TimeZone tz = TimeZone.getTimeZone(input);
TimeZone.setDefault(tz);
DateTime.setTimeZone(tz);
LOGGER.info(String.format("[Timezone] Set to %s [%s]", tz.getDisplayName(), input));
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/chatty/TwitchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,8 @@ else if (command.equals("bantest")) {
args.add("tduva");
ModeratorActionData data = new ModeratorActionData("", "", "", room.getStream(), "denied_automod_message", args, "asdas", "TEST");
g.printModerationAction(data, false);
} else if (command.equals("simulatepubsub")) {
pubsub.simulate(parameter);
} else if (command.equals("repeat")) {
String[] split = parameter.split(" ", 2);
int count = Integer.parseInt(split[0]);
Expand Down
5 changes: 4 additions & 1 deletion src/chatty/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public synchronized void addInfo(String message, String text) {

public synchronized void addModAction(ModeratorActionData data) {
setFirstSeen();
addLine(new ModAction(System.currentTimeMillis(), data.getCommandAndParameters()));
addLine(new ModAction(System.currentTimeMillis(), data.moderation_action+" "+ModLogInfo.makeArgsText(data)));
}

private List<ModeratorActionData> cachedBanInfo;
Expand Down Expand Up @@ -1222,6 +1222,9 @@ public InfoMessage(long time, String message, String text) {

public static class ModAction extends Message {

/**
* For display, may be formatted differently depending on the command.
*/
public final String commandAndParameters;

public ModAction(long time, String commandAndParameters) {
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/gui/components/ModerationLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void add(ModeratorActionData data) {
DateTime.currentTime(),
data.created_by,
data.moderation_action,
ModLogInfo.makeArgs(data));
ModLogInfo.makeArgsText(data));

if (channel.equals(currentLoadedChannel)) {
printLine(log, line);
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/gui/components/help/help-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ <h3><a name="Highlight_Meta_Matching">Meta Prefixes (Matching)</a></h3>
the same message (this requires the <a href="#RepeatMsg">Repetition Detection</a> in
the Moderation settings to be enabled). Can optionally
restrict how many repetitions are required for this to
match, for example <code>config:repeatmsg|4</code> requires
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:info</code> - This item applies to info
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.15-b5)</a></h1>
<h1><a name="top">Chatty (Version: 0.15-b6)</a></h1>
<table>
<tr>
<td valign="top">
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/gui/components/settings/ModerationSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public ModerationSettings(final SettingsDialog d) {
repeatMsgPanel.add(testSim,
SettingsDialog.makeGbc(2, 3, 2, 1, GridBagConstraints.EAST));

repeatMsgPanel.add(new LinkLabel("Tip: Add <code>config:repeatmsg</code> to e.g. [help:Highlight Highlight] list to match on detected repetition.",
repeatMsgPanel.add(new LinkLabel("Tip: Add <code>config:repeatedmsg</code> to e.g. [help:Highlight Highlight] list to match on detected repetition.",
d.getSettingsHelpLinkLabelListener()),
SettingsDialog.makeGbc(0, 5, 4, 1));
}
Expand Down
15 changes: 11 additions & 4 deletions src/chatty/gui/components/textpane/ModLogInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ private static String makeText(ModeratorActionData data) {
return String.format("[ModAction] %s: /%s %s",
data.created_by,
data.moderation_action,
makeArgs(data));
makeArgsText(data));
}

public static String makeArgs(ModeratorActionData data) {
public static String makeArgsText(ModeratorActionData data) {
if (data.type == ModeratorActionData.Type.AUTOMOD_REJECTED && data.args.size() == 3) {
return String.format("%s (%s): %s",
data.args.get(0), data.args.get(2), data.args.get(1));
return String.format("[%s] <%s> %s",
data.args.get(2), data.args.get(0), data.args.get(1));
}
if ((data.type == ModeratorActionData.Type.AUTOMOD_APPROVED || data.type == ModeratorActionData.Type.AUTOMOD_DENIED) && data.args.size() > 1) {
return String.format("<%s> %s",
data.args.get(0), data.args.get(1));
}
if (data.moderation_action.equals("delete") && data.args.size() > 1) {
return String.format("%s (%s)", data.args.get(0), data.args.get(1));
}
return StringUtil.join(data.args, " ");
}
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/gui/components/userinfo/PastMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ else if (m instanceof User.AutoModMessage) {
b.append(DateTime.format(m.getTime(), timestampFormat)).append(">");
b.append("Filtered by AutoMod");
if (!StringUtil.isNullOrEmpty(ma.reason)) {
b.append(" (").append(ma.reason).append(")");
b.append(" [").append(ma.reason).append("]");
}
b.append(": ").append(ma.message);
b.append("\n");
Expand Down
15 changes: 15 additions & 0 deletions src/chatty/util/DateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -34,6 +35,20 @@ public class DateTime {
public static final long DAY = HOUR * 24;
public static final long YEAR = DAY * 365;

/**
* Update the timezone for the formatters. These may be initialized before
* the default timezone is set (e.g. from this class being used for logging
* or other stuff), so probably need to update them.
*
* @param tz The timezone to set
*/
public static void setTimeZone(TimeZone tz) {
FULL_DATETIME.setTimeZone(tz);
SDF.setTimeZone(tz);
SDF2.setTimeZone(tz);
SDF3.setTimeZone(tz);
}

public static int currentHour12Hour() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.HOUR);
Expand Down
27 changes: 18 additions & 9 deletions src/chatty/util/OtherBadges.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,24 @@ public boolean handleData(String data) {
return false;
}
};
// if (forcedRefresh || !cache.load()) {
if (true) {
String url = "https://zik.one/chatty/badges";
UrlRequest request = new UrlRequest(url);
request.setLabel("Other Badges");
request.async((result, responseCode) -> {
cache.dataReceived(result, forcedRefresh);
});
}
/**
* Always run in separate thread, since loading from cache would run
* badge image loading in GUI thread.
*
* A solution similar to emotes might be better, where the images load
* on demand, but this will do for now.
*/
new Thread(() -> {
// if (forcedRefresh || !cache.load()) {
if (true) {
String url = "https://zik.one/chatty/badges";
UrlRequest request = new UrlRequest(url);
request.setLabel("Other Badges");
request.async((result, responseCode) -> {
cache.dataReceived(result, forcedRefresh);
});
}
}).start();
}

private static List<Usericon> parseUsericons(String json) {
Expand Down
2 changes: 0 additions & 2 deletions src/chatty/util/api/TwitchApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public enum RequestResultCode {

protected final StreamInfoManager streamInfoManager;
protected final EmoticonManager2 emoticonManager2;
protected final CheerEmoticonManager cheersManager;
protected final CheerEmoticonManager2 cheersManager2;
protected final FollowerManager followerManager;
protected final FollowerManager subscriberManager;
Expand All @@ -61,7 +60,6 @@ public TwitchApi(TwitchApiResultListener apiResultListener,
StreamInfoListener streamInfoListener) {
this.resultListener = apiResultListener;
this.streamInfoManager = new StreamInfoManager(this, streamInfoListener);
cheersManager = new CheerEmoticonManager(apiResultListener);
cheersManager2 = new CheerEmoticonManager2(this, resultListener);
followerManager = new FollowerManager(Follower.Type.FOLLOWER, this, resultListener);
subscriberManager = new FollowerManager(Follower.Type.SUBSCRIBER, this, resultListener);
Expand Down
11 changes: 10 additions & 1 deletion src/chatty/util/api/pubsub/Connections.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
public class Connections {

private static final int MAX_CONNECTIONS = 2;
private static final int MAX_CONNECTIONS = 6;

private final List<PubSub> connections;
private final URI server;
Expand Down Expand Up @@ -103,6 +103,15 @@ public synchronized void sendPing() {
}
}

/**
* Only for testing. May cause issues.
*
* @param text
*/
public synchronized void simulate(String text) {
connections.get(0).handleReceived(text);
}

private MessageHandler createHandler(int id) {
return new MessageHandler() {

Expand Down
28 changes: 28 additions & 0 deletions src/chatty/util/api/pubsub/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ public void handleConnect(int id, JWSClient c) {
}
}

/**
* Only for testing. May cause issues.
*
* @param input
*/
public void simulate(String input) {
c.simulate(input);
}


//==========================
// Topics / various
Expand Down Expand Up @@ -127,6 +136,7 @@ public void setLocalUsername(String username) {
public void listenModLog(String username, String token) {
this.token = token;
addTopic(new ModLog(username));
addTopic(new AutoMod(username));
}

/**
Expand All @@ -136,6 +146,7 @@ public void listenModLog(String username, String token) {
*/
public void unlistenModLog(String username) {
removeTopic(new ModLog(username));
removeTopic(new AutoMod(username));
}

public void listenPoints(String username, String token) {
Expand Down Expand Up @@ -376,6 +387,23 @@ public String make() {

}

private class AutoMod extends StreamTopic {

AutoMod(String stream) {
super(stream);
}

@Override
public String make() {
String userId = getUserId(stream);
if (userId != null && localUserId != null) {
return "automod-queue."+localUserId+"."+userId;
}
return null;
}

}

private class Points extends StreamTopic {

Points(String stream) {
Expand Down
5 changes: 5 additions & 0 deletions src/chatty/util/api/pubsub/MessageData.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package chatty.util.api.pubsub;

import chatty.util.Debugging;
import java.util.Map;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
Expand All @@ -27,9 +28,13 @@ public static MessageData decode(JSONObject data, Map<String, String> userIds) t
}
String topic = (String)data.get("topic");
String message = (String)data.get("message");
Debugging.println("automod-msg", "%s: %s", topic, message);
if (topic.startsWith("chat_moderator_actions")) {
return ModeratorActionData.decode(topic, message, userIds);
}
else if (topic.startsWith("automod-queue.")) {
return ModeratorActionData.decodeAutoMod(topic, message, userIds);
}
else if (topic.startsWith("channel-points-channel-v1")) {
UserinfoMessageData result = UserinfoMessageData.decode(topic, message, userIds);
if (result != null) {
Expand Down
Loading

0 comments on commit 79c94c6

Please sign in to comment.