Search in sources :

Example 1 with StreamInfo

use of chatty.util.api.StreamInfo in project chatty by chatty.

the class Speedruncom method openCurrentGame.

public void openCurrentGame(Channel chan) {
    if (Helper.isRegularChannel(chan.getStreamName())) {
        StreamInfo info = twitchApi.getStreamInfo(chan.getStreamName(), null);
        if (info.isValid() && !info.getGame().isEmpty()) {
            String game = info.getGame();
            UrlOpener.openUrlPrompt(chan, "https://speedrun.com/" + replaceForUrl(game));
            return;
        }
    }
    UrlOpener.openUrlPrompt(chan, "https://speedrun.com");
}
Also used : StreamInfo(chatty.util.api.StreamInfo)

Example 2 with StreamInfo

use of chatty.util.api.StreamInfo in project chatty by chatty.

the class TwitchClient method testCommands.

private void testCommands(Room room, String command, String parameter) {
    String channel = room.getChannel();
    if (command.equals("addchans")) {
        String[] splitSpace = parameter.split(" ");
        String[] split2 = splitSpace[0].split(",");
        for (String chan : split2) {
        // g.printLine(chan, "test");
        }
    } else if (command.equals("settestuser")) {
        String[] split = parameter.split(" ");
        createTestUser(split[0], split[1]);
    } else if (command.equals("setemoteset")) {
        testUser.setEmoteSets(parameter);
    } else if (command.equals("setemoteset2")) {
        getSpecialUser().setEmoteSets(parameter);
    } else if (command.equals("getemoteset")) {
        g.printLine(g.emoticons.getEmoticons(Integer.parseInt(parameter)).toString());
    } else if (command.equals("testcolor")) {
        testUser.setColor(parameter);
    } else if (command.equals("testupdatenotification")) {
        g.setUpdateAvailable("[test]");
    } else if (command.equals("testannouncement")) {
        g.setAnnouncementAvailable(Boolean.parseBoolean(parameter));
    } else if (command.equals("removechan")) {
        g.removeChannel(parameter);
    } else if (command.equals("testtimer")) {
        new Thread(new TestTimer(this, new Integer(parameter))).start();
    } else // }
    if (command.equals("bantest")) {
        int duration = -1;
        String reason = "";
        if (parameter != null) {
            String[] split = parameter.split(" ", 2);
            duration = Integer.parseInt(split[0]);
            if (split.length > 1) {
                reason = split[1];
            }
        }
        g.userBanned(testUser, duration, reason, null);
    } else if (command.equals("bantest2")) {
        String[] split = parameter.split(" ", 3);
        int duration = -1;
        if (split.length > 1) {
            duration = Integer.parseInt(split[1]);
        }
        String reason = "";
        if (split.length > 2) {
            reason = split[2];
        }
        g.userBanned(c.getUser(channel, split[0]), duration, reason, null);
    } else if (command.equals("userjoined")) {
        c.userJoined("#test", parameter);
    } else if (command.equals("echomessage")) {
        String[] parts = parameter.split(" ");
    // g.printMessage(parts[0], testUser, parts[1], false, null, 0);
    } else if (command.equals("loadffz")) {
        frankerFaceZ.requestEmotes(parameter, true);
    } else if (command.equals("testtw")) {
        g.showTokenWarning();
    } else if (command.equals("tsonline")) {
        testStreamInfo.set(parameter, "Game", 123, -1, StreamType.LIVE);
        g.addStreamInfo(testStreamInfo);
    } else if (command.equals("tsoffline")) {
        testStreamInfo.setOffline();
        g.addStreamInfo(testStreamInfo);
    } else if (command.equals("testspam")) {
        g.printLine("test" + spamProtection.getAllowance() + spamProtection.tryMessage());
    } else if (command.equals("spamprotectioninfo")) {
        g.printSystem("Spam Protection: " + c.getSpamProtectionInfo());
    } else if (command.equals("tsv")) {
        testStreamInfo.set("Title", "Game", Integer.parseInt(parameter), -1, StreamType.LIVE);
    } else if (command.equals("tsvs")) {
        System.out.println(testStreamInfo.getViewerStats(true));
    } else if (command.equals("tsaoff")) {
        StreamInfo info = api.getStreamInfo(g.getActiveStream(), null);
        info.setOffline();
    } else if (command.equals("tsaon")) {
        StreamInfo info = api.getStreamInfo(g.getActiveStream(), null);
        info.set("Test", "Game", 12, System.currentTimeMillis() - 1000, StreamType.LIVE);
    } else if (command.equals("tston")) {
        StreamInfo info = api.getStreamInfo("tduva", null);
        info.set("Test 2", "Game", 12, System.currentTimeMillis() - 1000, StreamType.LIVE);
    } else if (command.equals("usericonsinfo")) {
        usericonManager.debug();
    } else if (command.equals("userlisttest")) {
    // g.printMessage("test1", testUser, "short message", false, null, 0);
    // g.printMessage("test2", testUser, "short message2", false, null, 0);
    // g.printCompact("test3", "MOD", testUser);
    // g.printCompact("test3", "MOD", testUser);
    // g.printCompact("test3", "MOD", testUser);
    // g.printCompact("test3", "MOD", testUser);
    // g.printCompact("test3", "MOD", testUser);
    // g.printCompact("test3", "MOD", testUser);
    // g.printCompact("test3", "MOD", testUser);
    // g.printMessage("test3", testUser, "longer message abc hmm fwef wef wef wefwe fwe ewfwe fwef wwefwef"
    // + "fjwfjfwjefjwefjwef wfejfkwlefjwoefjwf wfjwoeifjwefiowejfef wefjoiwefj", false, null, 0);
    // g.printMessage("test3", testUser, "longer message abc hmm fwef wef wef wefwe fwe ewfwe fwef wwefwef"
    // + "fjwfjfwjefjwefjwoeifjwefiowejfef wefjoiwefj", false, null, 0);
    // g.printMessage("test3", testUser, "longer wef wef wefwe fwe ewfwe fwef wwefwef"
    // + "fjwfjfwjefjwefjwef wfejfkwlefjwoefjwf wfjwoeifjwefiowejfef wefjoiwefj", false, null, 0);
    // g.printCompact("test4", "MOD", testUser);
    // g.printCompact("test5", "MOD", testUser);
    // g.printCompact("test6", "MOD", testUser);
    // g.printCompact("test7", "MOD", testUser);
    // g.printCompact("test8", "MOD", testUser);
    // g.printCompact("test9", "MOD", testUser);
    // g.printMessage("test10", testUser, "longer message abc hmm fwef wef wef wefwe fwe ewfwe fwef wwefwef"
    // + "fjwfjfwjefjwefjwef wfejfkwlefjwoefjwf wfjwoeifjwefiowejfef wefjoiwefj", false, null, 0);
    } else if (command.equals("requestfollowers")) {
        api.getFollowers(parameter);
    } else if (command.equals("simulate2")) {
        c.simulate(parameter);
    } else if (command.equals("simulate")) {
        if (parameter.equals("bits")) {
            parameter = "bits " + g.emoticons.getCheerEmotesString(null);
        } else if (parameter.equals("bitslocal")) {
            parameter = "bits " + g.emoticons.getCheerEmotesString(Helper.toStream(channel));
        } else if (parameter.startsWith("bits ")) {
            parameter = "bits " + parameter.substring("bits ".length());
        }
        String raw = RawMessageTest.simulateIRC(channel, parameter, c.getUsername());
        if (raw != null) {
            c.simulate(raw);
        }
    } else if (command.equals("lb")) {
        String[] split = parameter.split("&");
        String message = "";
        for (int i = 0; i < split.length; i++) {
            if (!message.isEmpty()) {
                message += "\r";
            }
            message += split[i];
        }
        sendMessage(channel, message);
    } else if (command.equals("c1")) {
        sendMessage(channel, (char) 1 + parameter);
    } else if (command.equals("gc")) {
        Runtime.getRuntime().gc();
        LogUtil.logMemoryUsage();
    } else if (command.equals("wsconnect")) {
        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<>();
        args.add("tirean");
        args.add("300");
        args.add("still not using LiveSplit Autosplitter D:");
        g.printModerationAction(new ModeratorActionData("", "", "tduvatest", "timeout", args, "tduva", ""), false);
    } else if (command.equals("modactiontest2")) {
        List<String> args = new ArrayList<>();
        args.add("tduva");
        args.add("fuck and stuff like that, rather long message and whatnot Kappa b " + new Random().nextInt(100));
        g.printModerationAction(new ModeratorActionData("", "", parameter == null ? "tduvatest" : parameter, "twitchbot_rejected", args, "twitchbot", "TEST" + Math.random()), false);
    } else if (command.equals("repeat")) {
        String[] split = parameter.split(" ", 2);
        int count = Integer.parseInt(split[0]);
        for (int i = 0; i < count; i++) {
            commandInput(room, "/" + split[1]);
        }
    } else if (command.equals("modactiontest3")) {
        List<String> args = new ArrayList<>();
        args.add("tduva");
        g.printModerationAction(new ModeratorActionData("", "", "tduvatest", "approved_twitchbot_message", args, "tduvatest", "TEST" + Math.random()), false);
    } else if (command.equals("loadsoferrors")) {
        for (int i = 0; i < 10000; i++) {
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    Helper.unhandledException();
                }
            });
        }
    } else if (command.equals("getuserid")) {
        if (parameter == null) {
            g.printSystem("Parameter required.");
        } else {
            api.getUserIdAsap(r -> {
                String result = r.getData().toString();
                if (r.hasError()) {
                    result += " Error: " + r.getError();
                }
                g.printSystem(result);
            }, parameter.split("[ ,]"));
        }
    } else if (command.equals("getuserids2")) {
        api.getUserIDsTest2(parameter);
    } else if (command.equals("getuserids3")) {
        api.getUserIDsTest3(parameter);
    }
}
Also used : ModeratorActionData(chatty.util.api.pubsub.ModeratorActionData) StreamInfo(chatty.util.api.StreamInfo)

Example 3 with StreamInfo

use of chatty.util.api.StreamInfo in project chatty by chatty.

the class LiveStreamsList method addListeners.

private void addListeners() {
    ComponentListener cl = new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            // Trick from kleopatra:
            // https://stackoverflow.com/questions/7306295/swing-jlist-with-multiline-text-and-dynamic-height
            // next line possible if list is of type JXList
            // list.invalidateCellSizeCache();
            // for core: force cache invalidation by temporarily setting fixed height
            setFixedCellHeight(10);
            setFixedCellHeight(-1);
        }
    };
    addComponentListener(cl);
    JListActionHelper.install(this, (a, l, s) -> {
        if (a == Action.CONTEXT_MENU) {
            StreamInfosContextMenu m = new StreamInfosContextMenu(s, true);
            for (ContextMenuListener cml : contextMenuListeners) {
                m.addContextMenuListener(cml);
            }
            lastContextMenu = m;
            m.show(this, l.x, l.y);
        } else if (a == Action.ENTER) {
            List<String> channels = new ArrayList<>();
            s.forEach(si -> channels.add(si.stream));
            for (ContextMenuListener cml : contextMenuListeners) {
                cml.streamsMenuItemClicked(new ActionEvent(s, 0, "join"), channels);
            }
        } else if (a == Action.DOUBLE_CLICK || a == Action.SPACE) {
            StreamInfo info = getSelectedValue();
            if (info != null && liveStreamListener != null) {
                liveStreamListener.liveStreamClicked(info);
            }
        }
    });
}
Also used : Color(java.awt.Color) Timer(java.util.Timer) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener) Helper(chatty.Helper) ArrayList(java.util.ArrayList) Border(javax.swing.border.Border) HashSet(java.util.HashSet) SwingUtilities(javax.swing.SwingUtilities) ComponentListener(java.awt.event.ComponentListener) TitledBorder(javax.swing.border.TitledBorder) TimerTask(java.util.TimerTask) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) JPopupMenu(javax.swing.JPopupMenu) JList(javax.swing.JList) Set(java.util.Set) StreamInfo(chatty.util.api.StreamInfo) BorderFactory(javax.swing.BorderFactory) ComponentEvent(java.awt.event.ComponentEvent) StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) ComponentAdapter(java.awt.event.ComponentAdapter) Action(chatty.gui.components.JListActionHelper.Action) List(java.util.List) DateTime(chatty.util.DateTime) JTextArea(javax.swing.JTextArea) Comparator(java.util.Comparator) ComponentListener(java.awt.event.ComponentListener) StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) ActionEvent(java.awt.event.ActionEvent) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener) StreamInfo(chatty.util.api.StreamInfo) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 4 with StreamInfo

use of chatty.util.api.StreamInfo in project chatty by chatty.

the class LiveStreamsRemovedList method openContextMenu.

/**
 * Open context menu for this user, if the event points at one.
 *
 * @param e
 */
private void openContextMenu(MouseEvent e) {
    if (e.isPopupTrigger()) {
        selectClicked(e, false);
        List<RemovedListItem> selectedItems = list.getSelectedValuesList();
        List<StreamInfo> selected = new ArrayList<>();
        for (RemovedListItem item : selectedItems) {
            selected.add(item.getStreamInfo());
        }
        StreamInfosContextMenu m = new StreamInfosContextMenu(selected, false);
        for (ContextMenuListener cml : contextMenuListeners) {
            m.addContextMenuListener(cml);
        }
        m.show(list, e.getX(), e.getY());
    }
}
Also used : StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) StreamInfo(chatty.util.api.StreamInfo) ArrayList(java.util.ArrayList) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener)

Example 5 with StreamInfo

use of chatty.util.api.StreamInfo in project chatty by chatty.

the class CustomCommands method command.

public synchronized String command(CustomCommand command, Parameters parameters, Room room) {
    // Add some more parameters
    parameters.put("chan", Helper.toStream(room.getChannel()));
    parameters.put("stream", room.getStream());
    if (!command.getIdentifiersWithPrefix("stream").isEmpty()) {
        System.out.println("request");
        String stream = Helper.toValidStream(room.getStream());
        StreamInfo streamInfo = api.getStreamInfo(stream, null);
        if (streamInfo.isValid()) {
            parameters.put("streamstatus", streamInfo.getFullStatus());
            if (streamInfo.getOnline()) {
                parameters.put("streamuptime", DateTime.agoUptimeCompact2(streamInfo.getTimeStartedWithPicnic()));
                parameters.put("streamtitle", streamInfo.getTitle());
                parameters.put("streamgame", streamInfo.getGame());
                parameters.put("streamviewers", String.valueOf(streamInfo.getViewers()));
            }
        }
    }
    // Add parameters for custom replacements
    Set<String> customIdentifiers = command.getIdentifiersWithPrefix("_");
    for (String identifier : customIdentifiers) {
        CustomCommand replacement = getCommand(replacements, identifier, room.getOwnerChannel());
        if (replacement != null) {
            parameters.put(identifier, replacement.replace(parameters));
        }
    }
    return command.replace(parameters);
}
Also used : StreamInfo(chatty.util.api.StreamInfo)

Aggregations

StreamInfo (chatty.util.api.StreamInfo)7 ContextMenuListener (chatty.gui.components.menus.ContextMenuListener)2 StreamInfosContextMenu (chatty.gui.components.menus.StreamInfosContextMenu)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Helper (chatty.Helper)1 Action (chatty.gui.components.JListActionHelper.Action)1 DateTime (chatty.util.DateTime)1 ModeratorActionData (chatty.util.api.pubsub.ModeratorActionData)1 Color (java.awt.Color)1 Component (java.awt.Component)1 ActionEvent (java.awt.event.ActionEvent)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 ComponentListener (java.awt.event.ComponentListener)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Set (java.util.Set)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1