Skip to content

Commit

Permalink
v0.8.4b5, add mod action log support
Browse files Browse the repository at this point in the history
- Add initial PubSub connection support
- Add setting to show mod actions in chat
- Add setting to log mod actions to chatlog
- Add dialog to show mod actions
- Add request/caching of user IDs to TwitchApi
- Include user ID in ChannelInfo
- Add PubSub debug tab to Debug Window
- Fix some dialogs not reopening on start (even with appropriate setting)
  • Loading branch information
tduva committed Sep 10, 2016
1 parent 484763f commit 848a7d1
Show file tree
Hide file tree
Showing 22 changed files with 1,130 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/chatty/Chatty.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Chatty {
* by points. May contain a single "b" for beta versions, anything following
* it will be ignored for version checking.
*/
public static final String VERSION = "0.8.4b4";
public static final String VERSION = "0.8.4b5";

/**
* Enable Version Checker (if you compile and distribute this yourself, you
Expand Down
3 changes: 3 additions & 0 deletions src/chatty/Logging.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public void publish(LogRecord record) {
if (record.getSourceClassName().startsWith("chatty.util.ffz.Websocket")) {
client.debugFFZ(record.getMessage());
}
if (record.getSourceClassName().startsWith("chatty.util.api.pubsub.")) {
client.debugPubSub(record.getMessage());
}
}
if (record.getLevel() == Level.SEVERE) {
if (client.g != null) {
Expand Down
3 changes: 3 additions & 0 deletions src/chatty/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void defineSettings() {

settings.addList("securedPorts", new LinkedHashSet<>(Arrays.asList((long)6697, (long)443)), Setting.LONG);
settings.addBoolean("membershipEnabled", true);
settings.addString("pubsub", "wss://pubsub-edge.twitch.tv");

// Auto-join channels
settings.addString("channel", "");
Expand Down Expand Up @@ -414,6 +415,7 @@ void defineSettings() {
settings.addBoolean("showModMessages", false);
settings.addBoolean("twitchnotifyAsInfo", true);
settings.addBoolean("printStreamStatus", true);
settings.addBoolean("showModActions", false);

// Timeouts/Bans
settings.addBoolean("showBanMessages", false);
Expand Down Expand Up @@ -463,6 +465,7 @@ void defineSettings() {
settings.addBoolean("logInfo", true);
settings.addBoolean("logViewerstats", true);
settings.addBoolean("logViewercount", false);
settings.addBoolean("logModAction", true);
settings.addList("logWhitelist",new ArrayList(), Setting.STRING);
settings.addList("logBlacklist",new ArrayList(), Setting.STRING);
settings.addString("logPath", "");
Expand Down
56 changes: 56 additions & 0 deletions src/chatty/TwitchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
import chatty.util.api.FollowerInfo;
import chatty.util.api.StreamInfo.ViewerStats;
import chatty.util.api.TwitchApi.RequestResult;
import chatty.util.api.UserIDs;
import chatty.util.api.pubsub.Message;
import chatty.util.api.pubsub.ModeratorActionData;
import chatty.util.api.pubsub.PubSubListener;
import chatty.util.chatlog.ChatLog;
import chatty.util.settings.Settings;
import chatty.util.settings.SettingsListener;
Expand Down Expand Up @@ -94,6 +98,8 @@ public class TwitchClient {
*/
public final TwitchApi api;

public final chatty.util.api.pubsub.Manager pubsub;

public final TwitchEmotes twitchemotes;

public final BTTVEmotes bttvEmotes;
Expand Down Expand Up @@ -187,6 +193,9 @@ public TwitchClient(Map<String, String> args) {
settingsManager.overrideSettings();
settingsManager.debugSettings();

pubsub = new chatty.util.api.pubsub.Manager(
settings.getString("pubsub"), new PubSubResults(), api);

frankerFaceZ = new FrankerFaceZ(new EmoticonsListener(), settings);
frankerFaceZ.autoUpdateFeatureFridayEmotes();

Expand Down Expand Up @@ -915,6 +924,9 @@ else if (command.equals("ffzglobal")) {
else if (command.equals("ffzws")) {
g.printSystem("[FFZ-WS] Status: "+frankerFaceZ.getWsStatus());
}
else if (command.equals("pubsubstatus")) {
g.printSystem("[PubSub] Status: "+pubsub.getStatus());
}
else if (command.equals("refresh")) {
commandRefresh(channel, parameter);
}
Expand Down Expand Up @@ -1117,6 +1129,16 @@ else if (command.equals("bantest")) {
frankerFaceZ.connectWs();
} else if (command.equals("wsdisconnect")) {
frankerFaceZ.disconnectWs();
} else if (command.equals("psconnect")) {
pubsub.connect();
} else if (command.equals("psdisconnect")) {
pubsub.disconnect();
} else if (command.equals("modactiontest")) {
List<String> args = new ArrayList<String>();
args.add("tirean");
args.add("300");
args.add("still not using LiveSplit Autosplitter D:");
g.printModerationAction(new ModeratorActionData("", "", "tduvatest", "timeout", args, "tduva"));
} else if (command.equals("loadsoferrors")) {
for (int i=0;i<10000;i++) {
SwingUtilities.invokeLater(new Runnable() {
Expand All @@ -1127,6 +1149,14 @@ public void run() {
}
});
}
} else if (command.equals("getuserid")) {
g.printSystem(parameter+": "+api.getUserId(parameter, new UserIDs.UserIDListener() {

@Override
public void setUserId(String username, long userId) {
g.printSystem(username+": "+userId);
}
}));
}
}

Expand Down Expand Up @@ -1554,6 +1584,13 @@ public void debugFFZ(String line) {
g.printDebugFFZ(line);
}

public void debugPubSub(String line) {
if (shuttingDown || g == null) {
return;
}
g.printDebugPubSub(line);
}

/**
* Output a warning.
*
Expand All @@ -1580,6 +1617,23 @@ public final void warning(String line) {
}
}

private class PubSubResults implements PubSubListener {

@Override
public void messageReceived(Message message) {
if (message.data != null && message.data instanceof ModeratorActionData) {
ModeratorActionData data = (ModeratorActionData)message.data;
g.printModerationAction(data);
chatLog.modAction(data);
}
}

@Override
public void info(String info) {
g.printDebugPubSub(info);
}

}

/**
* Redirects request results from the API.
Expand Down Expand Up @@ -2038,6 +2092,7 @@ public void exit() {
logAllViewerstats();
c.disconnect();
frankerFaceZ.disconnectWs();
pubsub.disconnect();
g.cleanUp();
chatLog.close();
System.exit(0);
Expand Down Expand Up @@ -2232,6 +2287,7 @@ public void onBan(User user, long duration, String reason) {
@Override
public void onRegistered() {
g.updateHighlightSetUsername(c.getUsername());
pubsub.listenModLog(c.getUsername(), settings.getString("token"));
}

@Override
Expand Down
78 changes: 70 additions & 8 deletions src/chatty/gui/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import chatty.gui.components.FollowersDialog;
import chatty.gui.components.LiveStreamsDialog;
import chatty.gui.components.LivestreamerDialog;
import chatty.gui.components.ModerationLog;
import chatty.gui.components.NewsDialog;
import chatty.gui.components.srl.SRL;
import chatty.gui.components.SearchDialog;
Expand All @@ -59,6 +60,7 @@
import chatty.util.api.Emoticons.TagEmotes;
import chatty.util.api.FollowerInfo;
import chatty.util.api.TwitchApi.RequestResult;
import chatty.util.api.pubsub.ModeratorActionData;
import chatty.util.hotkeys.HotkeyManager;
import chatty.util.settings.Setting;
import chatty.util.settings.SettingChangeListener;
Expand Down Expand Up @@ -125,6 +127,7 @@ public class MainGui extends JFrame implements Runnable {
private FollowersDialog followerDialog;
private FollowersDialog subscribersDialog;
private StreamChat streamChat;
private ModerationLog moderationLog;

// Helpers
private final Highlighter highlighter = new Highlighter();
Expand Down Expand Up @@ -252,6 +255,8 @@ private void createGui() {
streamChat = new StreamChat(this, styleManager, contextMenuListener,
client.settings.getBoolean("streamChatBottom"));

moderationLog = new ModerationLog(this);

//this.getContentPane().setBackground(new Color(0,0,0,0));

getSettingsDialog();
Expand Down Expand Up @@ -286,6 +291,7 @@ private void createGui() {
windowStateManager.addWindow(emotesDialog, "emotes", true, true);
windowStateManager.addWindow(followerDialog, "followers", true, true);
windowStateManager.addWindow(subscribersDialog, "subscribers", true, true);
windowStateManager.addWindow(moderationLog, "moderationLog", true, true);
windowStateManager.addWindow(streamChat, "streamChat", true, true);

guiCreated = true;
Expand Down Expand Up @@ -467,6 +473,15 @@ public void actionPerformed(ActionEvent e) {
}
});

addMenuAction("dialog.moderationLog", "Dialog: Toggle Moderation Log",
"Moderation Log", KeyEvent.VK_UNDEFINED, new AbstractAction() {

@Override
public void actionPerformed(ActionEvent e) {
toggleModerationLog();
}
});

addMenuAction("dialog.addressbook", "Dialog: Toggle Addressbook",
"Addressbook", KeyEvent.VK_UNDEFINED, new AbstractAction() {

Expand Down Expand Up @@ -905,14 +920,21 @@ public void saveWindowStates() {
* Reopen some windows if enabled.
*/
private void reopenWindows() {
reopenWindow(liveStreamsDialog);
reopenWindow(highlightedMessages);
reopenWindow(ignoredMessages);
reopenWindow(channelInfoDialog);
reopenWindow(addressbookDialog);
reopenWindow(adminDialog);
reopenWindow(emotesDialog);
reopenWindow(streamChat);
// reopenWindow(liveStreamsDialog);
// reopenWindow(highlightedMessages);
// reopenWindow(ignoredMessages);
// reopenWindow(channelInfoDialog);
// reopenWindow(addressbookDialog);
// reopenWindow(adminDialog);
// reopenWindow(emotesDialog);
// reopenWindow(streamChat);
// reopenWindow(moderationLog);
// reopenWindow(followerDialog);
// reopenWindow(subscribersDialog);

for (Window window : windowStateManager.getWindows()) {
reopenWindow(window);
}
}

/**
Expand Down Expand Up @@ -940,6 +962,8 @@ private void reopenWindow(Window window) {
openFollowerDialog();
} else if (window == subscribersDialog) {
openSubscriberDialog();
} else if (window == moderationLog) {
openModerationLog();
} else if (window == streamChat) {
openStreamChat();
}
Expand Down Expand Up @@ -2102,6 +2126,17 @@ private void toggleSubscriberDialog() {
}
}

private void openModerationLog() {
windowStateManager.setWindowPosition(moderationLog);
moderationLog.showDialog();
}

private void toggleModerationLog() {
if (!closeDialog(moderationLog)) {
openModerationLog();
}
}

private void openUpdateDialog() {
updateMessage.setLocationRelativeTo(this);
updateMessage.showDialog();
Expand Down Expand Up @@ -2788,6 +2823,33 @@ public void run() {
});
}

public void printDebugPubSub(final String line) {
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
debugWindow.printLinePubSub(line);
}
});
}

public void printModerationAction(final ModeratorActionData data) {
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
moderationLog.add(data);
String channel = Helper.toValidChannel(data.stream);
if (client.settings.getBoolean("showModActions") && channels.isChannel(channel)) {
channels.getChannel(channel).printLine(String.format("[ModAction] %s: /%s %s",
data.created_by,
data.moderation_action,
StringUtil.join(data.args, " ")));
}
}
});
}

/**
* Outputs a line to the debug window
*
Expand Down
2 changes: 2 additions & 0 deletions src/chatty/gui/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public MainMenu(ActionListener actionListener, ItemListener itemListener,
addItem(extra,"dialog.followers","Followers");
addItem(extra,"dialog.subscribers","Subscribers");
extra.addSeparator();
addItem(extra,"dialog.moderationLog", "Moderation Log");
extra.addSeparator();
JMenu streamChat = new JMenu("Stream Chat");
addItem(streamChat,"dialog.streamchat", "Open");
addCheckboxItem(streamChat, "streamChatResizable", "Resizable");
Expand Down
9 changes: 8 additions & 1 deletion src/chatty/gui/WindowStateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.awt.Window;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

Expand Down Expand Up @@ -82,6 +83,10 @@ public void addWindow(Window window, String id, boolean saveSize, boolean reopen
attachedWindowManager.attach(window);
}

public Set<Window> getWindows() {
return new HashSet<>(windows.keySet());
}

/**
* Sets the primary window, which can be restored even if the other windows
* are set to not restore.
Expand Down Expand Up @@ -239,7 +244,9 @@ public boolean wasOpen(Window window) {
* @return {@code true} if it should be reopened, {@code false} otherwise
*/
public boolean shouldReopen(Window window) {
return mode() >= REOPEN_ON_START && wasOpen(window);
StateItem item = windows.get(window);
return mode() >= REOPEN_ON_START
&& item != null && item.reopen && item.wasOpen;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/chatty/gui/components/DebugWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class DebugWindow extends JFrame {
private final JTextArea text;
private final JTextArea textIrcLog;
private final JTextArea textFFZLog;
private final JTextArea textPubSubLog;

public DebugWindow(ItemListener listener) {
setTitle("Debug");
Expand All @@ -40,12 +41,16 @@ public DebugWindow(ItemListener listener) {

// FFZ WS log
textFFZLog = createLogArea();

// PubSub WS log
textPubSubLog = createLogArea();

// Tabs
JTabbedPane tabs = new JTabbedPane();
tabs.addTab("Log", new JScrollPane(text));
tabs.addTab("Irc log", new JScrollPane(textIrcLog));
tabs.addTab("FFZ-WS", new JScrollPane(textFFZLog));
tabs.addTab("PubSub", new JScrollPane(textPubSubLog));

// Settings (Checkboxes)
logIrc.setToolTipText("Logging IRC traffic can reduce performance");
Expand Down Expand Up @@ -88,6 +93,10 @@ public void printLineFFZ(String line) {
printLine(textFFZLog, line);
}

public void printLinePubSub(String line) {
printLine(textPubSubLog, line);
}

private void printLine(JTextArea text, String line) {
try {
Document doc = text.getDocument();
Expand Down
Loading

0 comments on commit 848a7d1

Please sign in to comment.