Skip to content

Commit

Permalink
Updated to v0.26-b4.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Feb 13, 2024
2 parents d0d1a84 + 0669641 commit e551b64
Show file tree
Hide file tree
Showing 48 changed files with 1,889 additions and 301 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {
implementation fileTree(dir: 'assets/lib', include: ['*.jar'])
implementation 'net.java.dev.jna:jna:5.12.1'
implementation 'net.java.dev.jna:jna-platform:5.12.1'
implementation 'com.formdev:flatlaf:2.6'
implementation 'com.formdev:flatlaf:3.2.5'

testImplementation 'junit:junit:4.12'
}
Expand Down
4 changes: 4 additions & 0 deletions src/chatty/ChannelState.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public synchronized boolean setFollowersOnly(int minutes) {
return false;
}

public synchronized int followersOnly() {
return followersOnly;
}

/**
* Get the info text based on the current state.
*
Expand Down
11 changes: 9 additions & 2 deletions src/chatty/Logging.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package chatty;

import chatty.Chatty.PathType;
import chatty.gui.laf.LaFChanger;
import chatty.util.RingBuffer;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -91,8 +92,14 @@ public void publish(LogRecord record) {
}
if (record.getLevel() == Level.SEVERE) {
if (client.g != null) {
boolean compact = record.getMessage().startsWith("FlatLaf: Failed to parse:");
client.g.error(record, compact ? new LinkedList<>() : lastMessages.getItems());
String msg = record.getMessage();
boolean flatLafError = msg.startsWith("FlatLaf: Failed to parse:");
if (flatLafError) {
LaFChanger.loggedFlatLookAndFeelError(msg+" "+record.getThrown().getLocalizedMessage());
}
else {
client.g.error(record, lastMessages.getItems());
}
}
} else if (record.getLevel() == USERINFO) {
client.warning(record.getMessage());
Expand Down
16 changes: 11 additions & 5 deletions src/chatty/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ public void defineSettings() {
settings.addString("locale", "");
settings.addString("timezone", "");

settings.addBoolean("inputLimitsEnabled", true);

settings.addBoolean("macScreenMenuBar", true);
settings.addBoolean("macSystemAppearance", true);

Expand All @@ -237,7 +239,6 @@ public void defineSettings() {
settings.addString("timestamp","HH:mm");
settings.addString("timestampTimezone", "");
settings.addBoolean("capitalizedNames", true);
settings.addBoolean("ircv3CapitalizedNames", true);
settings.addBoolean("correctlyCapitalizedNames", false);
settings.addMap("customNames", new HashMap<>(), Setting.STRING);
settings.addBoolean("actionColored", false);
Expand Down Expand Up @@ -400,7 +401,11 @@ public void defineSettings() {
settings.addLong("favoritesSorting", 20);

settings.addList("gameFavorites", new ArrayList(), Setting.STRING);


settings.addBoolean("historyServiceEnabled", false);
settings.addLong("historyServiceLimit", 30);
settings.addList("historyServiceExcluded", new ArrayList(), Setting.STRING);

//=======================
// Channel Admin Features
//=======================
Expand All @@ -426,6 +431,10 @@ public void defineSettings() {
settings.addString("commercialHotkey","");
settings.addBoolean("adDelay", false);
settings.addLong("adDelayLength", 300);

// Moderation Presets
settings.addString("slowmodeDurations", "3s\n5s\n10s\n20s\n30s\n60s\n120s");
settings.addString("followeronlyDurations", "0m\n10m\n30m\n1h\n1d\n7d\n30d\n90d");

//=======
// Window
Expand Down Expand Up @@ -960,9 +969,6 @@ public void overrideSettings() {
}
settings.setAdd("securedPorts", (long)443);
}
if (switchedFromVersionBefore("0.8.4")) {
settings.setBoolean("ircv3CapitalizedNames", true);
}
if (switchedFromVersionBefore("0.8.5b4")) {
String currentValue = settings.getString("timeoutButtons");
if (!StringUtil.toLowerCase(currentValue).contains("/modunmod")) {
Expand Down
50 changes: 44 additions & 6 deletions src/chatty/TwitchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import chatty.util.IconManager;
import chatty.util.ffz.FrankerFaceZ;
import chatty.util.ffz.FrankerFaceZListener;
import chatty.util.history.HistoryManager;
import chatty.util.history.HistoryMessage;
import chatty.util.ImageCache;
import chatty.util.LogUtil;
import chatty.util.MacAwtOptions;
Expand Down Expand Up @@ -82,15 +84,11 @@
import chatty.util.api.eventsub.payloads.RaidPayload;
import chatty.util.api.eventsub.payloads.ShieldModePayload;
import chatty.util.api.eventsub.payloads.ShoutoutPayload;
import chatty.util.api.pubsub.RewardRedeemedMessageData;
import chatty.util.api.pubsub.Message;
import chatty.util.api.pubsub.ModeratorActionData;
import chatty.util.api.pubsub.PubSubListener;
import chatty.util.api.pubsub.UserModerationMessageData;
import chatty.util.chatlog.ChatLog;
import chatty.util.commands.CustomCommand;
import chatty.util.commands.Parameters;
import chatty.util.irc.MsgTags;
import chatty.util.irc.UserTagsUtil;
import chatty.util.settings.FileManager;
import chatty.util.settings.Settings;
import chatty.util.settings.SettingsListener;
Expand Down Expand Up @@ -194,6 +192,8 @@ public class TwitchClient {
private final AutoModCommandHelper autoModCommandHelper;

public final RoomManager roomManager;

public final HistoryManager historyManager;

/**
* Holds the UserManager instance, which manages all the user objects.
Expand Down Expand Up @@ -258,6 +258,7 @@ public TwitchClient(Map<String, String> args) {
settingsManager.startAutoSave(this);

MacAwtOptions.setMacLookSettings(settings);
GuiUtil.inputLimitsEnabled = settings.getBoolean("inputLimitsEnabled");

Chatty.setSettings(settings);

Expand Down Expand Up @@ -355,6 +356,8 @@ public TwitchClient(Map<String, String> args) {

roomManager = new RoomManager(new MyRoomUpdatedListener());
channelFavorites = new ChannelFavorites(settings, roomManager);

historyManager = new HistoryManager(settings);

c = new TwitchConnection(new Messages(), settings, "main", roomManager);
c.setUserSettings(new User.UserSettings(
Expand Down Expand Up @@ -718,6 +721,7 @@ public void closeChannel(String channel) {
chatLog.closeChannel(room.getFilename());
updateStreamInfoChannelOpen(channel);
}
historyManager.resetMessageSeen(Helper.toStream(channel));
}

private void closeChannelStuff(Room room) {
Expand Down Expand Up @@ -2850,6 +2854,7 @@ public void accessDenied() {
@Override
public void receivedUsericons(List<Usericon> icons) {
usericonManager.addDefaultIcons(icons);
g.updateModButtons(null);
if (refreshRequests.contains("badges2")) {
g.printLine("Badges2 updated.");
refreshRequests.remove("badges2");
Expand Down Expand Up @@ -3270,7 +3275,37 @@ public void requestChannelEmotes(String channel) {
}
// api.getEmotesByStreams(Helper.toStream(channel)); // Removed
}


/**
* Requests the chat history
*
* @param stream The name of the channel
*/
public void requestChannelHistory(String stream) {
// Check in Settings if active/channel in blacklist
//settings.
if (!historyManager.isEnabled()) {
return;
}
if (historyManager.isChannelExcluded(stream)) {
return;
}
Room room = Room.createRegular("#" + stream);
g.printSystem(room, "### Pulling information from history service. ###");

// Get the actual list of messages
List<HistoryMessage> history = historyManager.getHistoricChatMessages(room);

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. ###");
}

private class EmoteListener implements EmoticonListener {

@Override
Expand Down Expand Up @@ -3457,6 +3492,7 @@ public void onChannelJoined(User user) {
api.getEmotesByChannelId(stream, null, false);
requestChannelEmotes(stream);
frankerFaceZ.joined(stream);
requestChannelHistory(stream);
checkModLogListen(user);
checkPointsListen(user);
api.removeShieldModeCache(user.getRoom());
Expand Down Expand Up @@ -3522,6 +3558,7 @@ public void onChannelMessage(User user, String text, boolean action, MsgTags tag
addressbookCommands(user.getChannel(), user, text);
modCommandAddStreamHighlight(user, text, tags);
}
historyManager.setMessageSeen(user.getStream());
}
}

Expand Down Expand Up @@ -3869,6 +3906,7 @@ private class ChannelStateUpdater implements ChannelStateListener {
@Override
public void channelStateUpdated(ChannelState state) {
g.updateState(true);
g.channelStateUpdated(state);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/TwitchCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void addNewCommands(Commands commands, TwitchClient client) {
TwitchApi.CHAT_SETTINGS_FOLLOWER_MODE, true);
}
else {
updateChatSettings(client, p, " ("+formatDuration(minutes / 60)+")",
updateChatSettings(client, p, " ("+formatDuration(minutes * 60)+")",
TwitchApi.CHAT_SETTINGS_FOLLOWER_MODE, true,
TwitchApi.CHAT_SETTINGS_FOLLOWER_MODE_DURATION, minutes);
}
Expand Down
83 changes: 6 additions & 77 deletions src/chatty/TwitchConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import chatty.util.StringUtil;
import chatty.util.api.Emoticons;
import chatty.util.irc.IrcBadges;
import chatty.util.irc.UserTagsUtil;
import chatty.util.settings.Settings;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -830,10 +831,12 @@ void onJoin(String channel, String nick) {
joinChecker.cancel(channel);
debug("JOINED: " + channel);
User user = userJoined(channel, nick);
if (this == irc && !onChannel(channel)) {
boolean onChannel = onChannel(channel);
// Change before notifying listener
joinedChannels.add(channel);
if (this == irc && !onChannel) {
listener.onChannelJoined(user);
}
joinedChannels.add(channel);
} else {
/**
* Another user has joined a channel we are currently in.
Expand Down Expand Up @@ -945,81 +948,7 @@ void onModeChange(String channel, String nick, boolean modeAdded, String mode, S
}

private void updateUserFromTags(User user, MsgTags tags) {
if (tags.isEmpty()) {
return;
}
/**
* Any and all tag values may be null, so account for that when
* checking against them.
*/
// Whether anything in the user changed to warrant an update
boolean changed = false;

IrcBadges badges = IrcBadges.parse(tags.get("badges"));
if (user.setTwitchBadges(badges)) {
changed = true;
}

IrcBadges badgeInfo = IrcBadges.parse(tags.get("badge-info"));
String subMonths = badgeInfo.get("subscriber");
if (subMonths == null) {
subMonths = badgeInfo.get("founder");
}
if (subMonths != null) {
user.setSubMonths(Helper.parseShort(subMonths, (short)0));
}

if (settings.getBoolean("ircv3CapitalizedNames")) {
if (user.setDisplayNick(StringUtil.trim(tags.get("display-name")))) {
changed = true;
}
}

// Update color
String color = tags.get("color");
if (color != null && !color.isEmpty()) {
user.setColor(color);
}

// Update user status
boolean turbo = tags.isTrue("turbo") || badges.hasId("turbo") || badges.hasId("premium");
if (user.setTurbo(turbo)) {
changed = true;
}
boolean subscriber = badges.hasId("subscriber") || badges.hasId("founder");
if (user.setSubscriber(subscriber)) {
changed = true;
}
if (user.setVip(badges.hasId("vip"))) {
changed = true;
}
if (user.setModerator(badges.hasId("moderator"))) {
changed = true;
}
if (user.setAdmin(badges.hasId("admin"))) {
changed = true;
}
if (user.setStaff(badges.hasId("staff"))) {
changed = true;
}

// Temporarily check both for containing a value as Twitch is
// changing it
// String userType = tags.get("user-type");
// if (user.setModerator("mod".equals(userType))) {
// changed = true;
// }
// if (user.setStaff("staff".equals(userType))) {
// changed = true;
// }
// if (user.setAdmin("admin".equals(userType))) {
// changed = true;
// }
// if (user.setGlobalMod("global_mod".equals(userType))) {
// changed = true;
// }

user.setId(tags.get("user-id"));
boolean changed = UserTagsUtil.updateUserFromTags(user, tags);

if (changed && user != users.specialUser) {
listener.onUserUpdated(user);
Expand Down
12 changes: 10 additions & 2 deletions src/chatty/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,24 @@ public synchronized boolean maxLinesExceeded() {
return numLines == userSettings.maxLines && numLines < numberOfLines;
}

public synchronized void addMessage(String line, boolean action, String id) {
addMessage(line, action, id, System.currentTimeMillis());
}

/**
* Adds a single chatmessage with the current time.
*
* @param line
* @param action
* @param id
* @param timestamp
*/
public synchronized void addMessage(String line, boolean action, String id) {
public synchronized void addMessage(String line, boolean action, String id, long timestamp) {
if (timestamp == -1) {
timestamp = System.currentTimeMillis();
}
setFirstSeen();
addLine(new TextMessage(System.currentTimeMillis(), line, action, id, null));
addLine(new TextMessage(timestamp, line, action, id, null));
replayCachedLowTrust();
numberOfMessages++;
}
Expand Down
Loading

0 comments on commit e551b64

Please sign in to comment.