use of gui.forms.GUIViewerList in project Botnak by Gocnak.
the class UserManager method beat.
@Override
public void beat() {
beating = true;
String[] channels = Settings.channelManager.getChannelNames();
URL url;
for (String chan : channels) {
String chanOut = chan.substring(1);
GUIViewerList list = GUIMain.viewerLists.get(chanOut);
if (list != null) {
try {
url = new URL("http://tmi.twitch.tv/group/user/" + chan.substring(1) + "/chatters");
String line = Utils.createAndParseBufferedReader(url.openStream());
if (!line.isEmpty()) {
final Enumeration<TreePath> beforePaths = list.beforePaths();
final int beforeScroll = list.beforeScroll();
JSONObject site = new JSONObject(line);
JSONObject chatters = site.getJSONObject("chatters");
JSONArray mods = chatters.getJSONArray("moderators");
readAndUpdate(mods, list, GUIViewerList.ViewerType.MOD);
JSONArray staff = chatters.getJSONArray("staff");
readAndUpdate(staff, list, GUIViewerList.ViewerType.STAFF);
JSONArray admins = chatters.getJSONArray("admins");
readAndUpdate(admins, list, GUIViewerList.ViewerType.ADMIN);
JSONArray global_mods = chatters.getJSONArray("global_mods");
readAndUpdate(global_mods, list, GUIViewerList.ViewerType.GLOBAL_MOD);
JSONArray viewers = chatters.getJSONArray("viewers");
readAndUpdate(viewers, list, GUIViewerList.ViewerType.VIEWER);
EventQueue.invokeLater(() -> list.updateRoot(beforePaths, beforeScroll));
Thread.sleep(2000);
}
} catch (Exception e) {
GUIMain.log(e);
}
}
}
}
use of gui.forms.GUIViewerList in project Botnak by Gocnak.
the class PaneMenuListener method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) e.getSource();
if (source != null && source.getText() != null) {
ChatPane pane = Utils.getChatPane(GUIMain.channelPane.getSelectedIndex());
String text = source.getText();
if (text.startsWith("Pop-out")) {
if (pane != null) {
pane.createPopOut();
}
} else if (text.startsWith("Toggle Tab")) {
if (pane != null) {
pane.setShouldPulse(text.contains("ON"));
} else {
CombinedChatPane ccp = Utils.getCombinedChatPane(GUIMain.channelPane.getSelectedIndex());
if (ccp != null) {
ccp.setShouldPulse(text.contains("ON"));
}
}
} else if (text.startsWith("View viewer")) {
if (pane != null) {
GUIViewerList newVL = new GUIViewerList(pane.getChannel());
newVL.setVisible(true);
GUIMain.viewerLists.put(pane.getChannel(), newVL);
}
} else if (text.startsWith("Remove ")) {
if (pane != null) {
if (GUIMain.viewer != null) {
GUIMain.viewer.doLeave(pane.getChannel());
}
if (GUIMain.bot != null) {
GUIMain.bot.doLeave(pane.getChannel());
}
GUIMain.channelSet.remove(pane.getChannel());
GUIMain.chatPanes.remove(pane.getChannel());
pane.deletePane();
GUIMain.channelPane.updateIndexes();
}
} else if (text.startsWith("Disband")) {
CombinedChatPane ccp = Utils.getCombinedChatPane(GUIMain.channelPane.getSelectedIndex());
if (ccp != null) {
ccp.disbandTab();
}
} else if (text.startsWith("Go to")) {
//ex: Go to gocnak's channel
// 0123456 ^ substring
String name = text.substring(6, text.indexOf("'"));
Utils.openWebPage("http://twitch.tv/" + name);
} else if (text.startsWith("Clear ")) {
if (pane == null)
pane = Utils.getCombinedChatPane(GUIMain.channelPane.getSelectedIndex());
if (pane != null) {
//The combined could return null, still have to check
if (pane instanceof CombinedChatPane)
pane = ((CombinedChatPane) pane).getActiveChatPane();
pane.resetCleanupCounter();
final ChatPane pane1 = pane;
EventQueue.invokeLater(() -> {
//this should be fine, no need for message queue since clearing would be situational anyways
if (Settings.logChat.getValue()) {
String[] toPrint = pane1.getText().split("\\n");
Utils.logChat(toPrint, pane1.getChannel(), 1);
}
pane1.getTextPane().setText(null);
});
}
}
if (source instanceof JCheckBoxMenuItem) {
String channel = source.getText();
if (channel != null) {
CombinedChatPane ccp = Utils.getCombinedChatPane(GUIMain.channelPane.getSelectedIndex());
if (ccp == null || ccp.getActiveChannel().equalsIgnoreCase(channel)) {
return;
}
ccp.setActiveChannel(channel);
if (channel.equalsIgnoreCase("All")) {
ccp.setDefaultScrollPane();
} else {
//and pulse the + tab as well
ccp.setActiveScrollPane(channel);
}
}
}
}
}
use of gui.forms.GUIViewerList in project Botnak by Gocnak.
the class ChatPane method deletePane.
/**
* Deletes the pane and removes the tab from the tabbed pane.
*/
public void deletePane() {
if (Settings.logChat.getValue()) {
Utils.logChat(getText().split("\\n"), chan, 2);
}
GUIViewerList list = GUIMain.viewerLists.get(chan);
if (list != null) {
list.dispose();
}
if (getPoppedOutPane() != null) {
getPoppedOutPane().dispose();
}
GUIMain.channelPane.removeTabAt(index);
GUIMain.channelPane.setSelectedIndex(index - 1);
}
Aggregations